Nordic stack and drivers for the mbed BLE API
Fork of nRF51822 by
Revision 104:55e59c802b7f, committed 2015-04-15
- Comitter:
- rgrover1
- Date:
- Wed Apr 15 08:59:12 2015 +0100
- Parent:
- 103:138bdc859cc9
- Child:
- 105:7404a5b1b72f
- Commit message:
- Synchronized with git rev 149bfef7
Author: Rohit Grover
Allow ble_conn_params to still use APP_TIMER if needed.
Particularly in the case of the Bootloader.
This is made optional based on a preprocessor macro: USE_APP_TIMER.
Some Nordic code assumes the use of AppTimer, and if we replace it with mbed's timer, then a lot more code gets pulled in than necessary. Ideally this should not have been a problem, but it is, and the bootloader is a bit unforgiving in its size constraints.
Changed in this revision
--- a/nordic-sdk/components/ble/common/ble_conn_params.cpp Wed Apr 15 08:59:11 2015 +0100 +++ b/nordic-sdk/components/ble/common/ble_conn_params.cpp Wed Apr 15 08:59:12 2015 +0100 @@ -16,14 +16,23 @@ #include "ble_hci.h" #include "ble_srv_common.h" #include "app_util.h" + +#ifdef USE_APP_TIMER +#include "app_timer.h" +#else #include "mbed.h" +#endif static ble_conn_params_init_t m_conn_params_config; /**< Configuration as specified by the application. */ static ble_gap_conn_params_t m_preferred_conn_params; /**< Connection parameters preferred by the application. */ static uint8_t m_update_count; /**< Number of Connection Parameter Update messages that has currently been sent. */ static uint16_t m_conn_handle; /**< Current connection handle. */ static ble_gap_conn_params_t m_current_conn_params; /**< Connection parameters received in the most recent Connect event. */ +#ifdef USE_APP_TIMER +static app_timer_id_t m_conn_params_timer_id; /**< Connection parameters timer. */ +#else static Ticker m_conn_params_timer; +#endif static bool m_change_param = false; @@ -47,9 +56,16 @@ } +#ifdef USE_APP_TIMER +static void update_timeout_handler(void * p_context) +{ + UNUSED_PARAMETER(p_context); + +#else /* #if !USE_APP_TIMER */ static void update_timeout_handler(void) { m_conn_params_timer.detach(); /* this is supposed to be a single-shot timer callback */ +#endif /* #if !USE_APP_TIMER */ if (m_conn_handle != BLE_CONN_HANDLE_INVALID) { // Check if we have reached the maximum number of attempts @@ -124,14 +140,24 @@ m_conn_handle = BLE_CONN_HANDLE_INVALID; m_update_count = 0; +#ifdef USE_APP_TIMER + return app_timer_create(&m_conn_params_timer_id, + APP_TIMER_MODE_SINGLE_SHOT, + update_timeout_handler); +#else return NRF_SUCCESS; +#endif } uint32_t ble_conn_params_stop(void) { +#ifdef USE_APP_TIMER + return app_timer_stop(m_conn_params_timer_id); +#else /* #if !USE_APP_TIMER */ m_conn_params_timer.detach(); return NRF_SUCCESS; +#endif /* #if !USE_APP_TIMER */ } @@ -140,6 +166,9 @@ // Start negotiation if the received connection parameters are not acceptable if (!is_conn_params_ok(&m_current_conn_params)) { +#ifdef USE_APP_TIMER + uint32_t err_code; +#endif uint32_t timeout_ticks; if (m_change_param) @@ -165,7 +194,15 @@ timeout_ticks = m_conn_params_config.next_conn_params_update_delay; } +#ifdef USE_APP_TIMER + err_code = app_timer_start(m_conn_params_timer_id, timeout_ticks, NULL); + if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) + { + m_conn_params_config.error_handler(err_code); + } +#else m_conn_params_timer.attach(update_timeout_handler, timeout_ticks / 32768); +#endif } } else @@ -200,12 +237,24 @@ static void on_disconnect(ble_evt_t * p_ble_evt) { +#ifdef USE_APP_TIMER + uint32_t err_code; +#endif + m_conn_handle = BLE_CONN_HANDLE_INVALID; // Stop timer if running m_update_count = 0; // Connection parameters updates should happen during every connection +#ifdef USE_APP_TIMER + err_code = app_timer_stop(m_conn_params_timer_id); + if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) + { + m_conn_params_config.error_handler(err_code); + } +#else m_conn_params_timer.detach(); +#endif } @@ -228,8 +277,18 @@ } else { +#ifdef USE_APP_TIMER + uint32_t err_code; + // Stop timer if running + err_code = app_timer_stop(m_conn_params_timer_id); + if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) + { + m_conn_params_config.error_handler(err_code); + } +#else /* #if !USE_APP_TIMER */ m_conn_params_timer.detach(); +#endif /* #if !USE_APP_TIMER */ } } } @@ -270,8 +329,7 @@ } } - -uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t * new_params) +uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t *new_params) { uint32_t err_code;
--- a/nordic-sdk/components/ble/common/ble_conn_params.h Wed Apr 15 08:59:11 2015 +0100 +++ b/nordic-sdk/components/ble/common/ble_conn_params.h Wed Apr 15 08:59:12 2015 +0100 @@ -25,6 +25,10 @@ #include "ble.h" #include "ble_srv_common.h" +#ifdef __cplusplus +extern "C" { +#endif + /**@brief Connection Parameters Module event type. */ typedef enum { @@ -106,6 +110,10 @@ */ void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt); +#ifdef __cplusplus +} +#endif + #endif // BLE_CONN_PARAMS_H__ /** @} */ \ No newline at end of file