From 82b18a5c27657751b872d68eeeb41ebaf58f959f Mon Sep 17 00:00:00 2001 From: Liyou Zhou Date: Tue, 24 Nov 2015 13:20:08 +0000 Subject: [PATCH] Porting some of the changes made to nordic files from ble-nrf51822 module --- .../components/ble/common/ble_conn_params.c | 42 ++++++++++++++++++- .../config/device_manager_cnfg.h | 2 +- .../device_manager_peripheral.c | 3 +- .../pstorage/config/pstorage_platform.h | 2 +- .../hci_transport/hci_mem_pool_internal.h | 6 +-- 5 files changed, 46 insertions(+), 9 deletions(-) diff --git a/source/nordic_sdk/components/ble/common/ble_conn_params.c b/source/nordic_sdk/components/ble/common/ble_conn_params.c index ba44312..2b78831 100644 --- a/source/nordic_sdk/components/ble/common/ble_conn_params.c +++ b/source/nordic_sdk/components/ble/common/ble_conn_params.c @@ -34,17 +34,25 @@ #include #include "nordic_common.h" #include "ble_hci.h" -#include "app_timer.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; @@ -68,10 +76,16 @@ static bool is_conn_params_ok(ble_gap_conn_params_t * p_conn_params) } +#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 @@ -146,15 +160,24 @@ uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init) 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 */ } @@ -163,7 +186,9 @@ static void conn_params_negotiation(void) // 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) @@ -189,11 +214,15 @@ static void conn_params_negotiation(void) 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 @@ -228,18 +257,24 @@ static void on_connect(ble_evt_t * p_ble_evt) 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 } @@ -262,6 +297,7 @@ static void on_write(ble_evt_t * p_ble_evt) } else { +#ifdef USE_APP_TIMER uint32_t err_code; // Stop timer if running @@ -270,6 +306,9 @@ static void on_write(ble_evt_t * p_ble_evt) { m_conn_params_config.error_handler(err_code); } +#else /* #if !USE_APP_TIMER */ + m_conn_params_timer.detach(); +#endif /* #if !USE_APP_TIMER */ } } } @@ -310,7 +349,6 @@ void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt) } } - uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t * new_params) { uint32_t err_code; diff --git a/source/nordic_sdk/components/ble/device_manager/config/device_manager_cnfg.h b/source/nordic_sdk/components/ble/device_manager/config/device_manager_cnfg.h index de34fa7..ff9863e 100644 --- a/source/nordic_sdk/components/ble/device_manager/config/device_manager_cnfg.h +++ b/source/nordic_sdk/components/ble/device_manager/config/device_manager_cnfg.h @@ -85,7 +85,7 @@ * be stored. In such cases, application will be notified with DM_DEVICE_CONTEXT_FULL * as event result at the completion of the security procedure. */ -#define DEVICE_MANAGER_MAX_BONDS 7 +#define DEVICE_MANAGER_MAX_BONDS 2 /** diff --git a/source/nordic_sdk/components/ble/device_manager/device_manager_peripheral.c b/source/nordic_sdk/components/ble/device_manager/device_manager_peripheral.c index 2cd41cd..83f31ed 100644 --- a/source/nordic_sdk/components/ble/device_manager/device_manager_peripheral.c +++ b/source/nordic_sdk/components/ble/device_manager/device_manager_peripheral.c @@ -31,7 +31,6 @@ */ #include "device_manager.h" -#include "app_trace.h" #include "pstorage.h" #include "ble_hci.h" #include "app_error.h" @@ -162,7 +161,7 @@ typedef enum * @note That if ENABLE_DEBUG_LOG_SUPPORT is disabled, having DM_DISABLE_LOGS has no effect. * @{ */ -#define nDM_DISABLE_LOGS /**< Enable this macro to disable any logs from this module. */ +#define DM_DISABLE_LOGS /**< Enable this macro to disable any logs from this module. */ #ifndef DM_DISABLE_LOGS #define DM_LOG app_trace_log /**< Used for logging details. */ diff --git a/source/nordic_sdk/components/drivers_nrf/pstorage/config/pstorage_platform.h b/source/nordic_sdk/components/drivers_nrf/pstorage/config/pstorage_platform.h index 6313508..84b9796 100644 --- a/source/nordic_sdk/components/drivers_nrf/pstorage/config/pstorage_platform.h +++ b/source/nordic_sdk/components/drivers_nrf/pstorage/config/pstorage_platform.h @@ -69,7 +69,7 @@ static __INLINE uint32_t pstorage_flash_page_end() #define PSTORAGE_SWAP_ADDR PSTORAGE_DATA_END_ADDR /**< Top-most page is used as swap area for clear and update. */ #define PSTORAGE_MAX_BLOCK_SIZE PSTORAGE_FLASH_PAGE_SIZE /**< Maximum size of block that can be registered with the module. Should be configured based on system requirements. And should be greater than or equal to the minimum size. */ -#define PSTORAGE_CMD_QUEUE_SIZE 10 /**< Maximum number of flash access commands that can be maintained by the module for all applications. Configurable. */ +#define PSTORAGE_CMD_QUEUE_SIZE 2 /**< Maximum number of flash access commands that can be maintained by the module for all applications. Configurable. */ /** Abstracts persistently memory block identifier. */ diff --git a/source/nordic_sdk/components/libraries/bootloader_dfu/hci_transport/hci_mem_pool_internal.h b/source/nordic_sdk/components/libraries/bootloader_dfu/hci_transport/hci_mem_pool_internal.h index d68fc5c..ac03e2f 100644 --- a/source/nordic_sdk/components/libraries/bootloader_dfu/hci_transport/hci_mem_pool_internal.h +++ b/source/nordic_sdk/components/libraries/bootloader_dfu/hci_transport/hci_mem_pool_internal.h @@ -42,10 +42,10 @@ #ifndef MEM_POOL_INTERNAL_H__ #define MEM_POOL_INTERNAL_H__ -#define TX_BUF_SIZE 32u /**< TX buffer size in bytes. */ -#define RX_BUF_SIZE 600u /**< RX buffer size in bytes. */ +#define TX_BUF_SIZE 4u /**< TX buffer size in bytes. */ +#define RX_BUF_SIZE 32u /**< RX buffer size in bytes. */ -#define RX_BUF_QUEUE_SIZE 2u /**< RX buffer element size. */ +#define RX_BUF_QUEUE_SIZE 8u /**< RX buffer element size. */ #endif // MEM_POOL_INTERNAL_H__