diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h index fe3cc0e348b..a8083c3bbe7 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h @@ -31,6 +31,7 @@ #include "ble/generic/GenericGap.h" #include "ble/generic/GenericSecurityManager.h" #include "SimpleEventQueue.h" +#include "Timer.h" namespace ble { namespace vendor { @@ -153,6 +154,8 @@ class BLE : public ::BLEInstanceBase { ::BLE::InstanceID_t instanceID; mutable SimpleEventQueue _event_queue; + mbed::Timer _timer; + uint64_t _last_update_us; class SigningEventMonitorProxy : public pal::SigningEventMonitor { public: diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp index 08d04492bd6..6295055eb18 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp @@ -17,6 +17,7 @@ #include "mbed.h" #include "us_ticker_api.h" #include "BLE.h" +#include "CriticalSectionLock.h" #include "wsf_types.h" #include "wsf_msg.h" #include "wsf_os.h" @@ -95,10 +96,11 @@ namespace cordio { BLE::BLE(CordioHCIDriver& hci_driver) : initialization_status(NOT_INITIALIZED), instanceID(::BLE::DEFAULT_INSTANCE), - _event_queue() + _event_queue(), + _last_update_us(0) { _hci_driver = &hci_driver; - stack_setup(); + } BLE::~BLE() { } @@ -120,6 +122,8 @@ ble_error_t BLE::init( { switch (initialization_status) { case NOT_INITIALIZED: + _timer.reset(); + _timer.start(); _event_queue.initialize(this, instanceID); _init_callback = initCallback; start_stack_reset(); @@ -389,6 +393,7 @@ void BLE::stack_setup() void BLE::start_stack_reset() { _hci_driver->initialize(); + stack_setup(); DmDevReset(); } @@ -397,20 +402,22 @@ void BLE::callDispatcher() // process the external event queue _event_queue.process(); - // follow by stack events - static uint32_t lastTimeUs = us_ticker_read(); - uint32_t currTimeUs, deltaTimeMs; + _last_update_us += (uint64_t)_timer.read_high_resolution_us(); + _timer.reset(); - // Update the current cordio time - currTimeUs = us_ticker_read(); - deltaTimeMs = (currTimeUs - lastTimeUs) / 1000; - if (deltaTimeMs > 0) { - WsfTimerUpdate(deltaTimeMs / WSF_MS_PER_TICK); - lastTimeUs += deltaTimeMs * 1000; + uint64_t last_update_ms = (_last_update_us / 1000); + wsfTimerTicks_t wsf_ticks = (last_update_ms / WSF_MS_PER_TICK); + + if (wsf_ticks > 0) { + WsfTimerUpdate(wsf_ticks); + + _last_update_us -= (last_update_ms * 1000); } wsfOsDispatcher(); + CriticalSectionLock critical_section; + if (wsfOsReadyToSleep()) { static Timeout nextTimeout; // setup an mbed timer for the next Cordio timeout diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xGap.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xGap.cpp index e441fd4717a..f4b0d393b2c 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xGap.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xGap.cpp @@ -79,7 +79,7 @@ peer_address_type_t convert_nordic_address(uint8_t address) { } peer_address_type_t convert_identity_address(advertising_peer_address_type_t address) { - if (address == advertising_peer_address_type_t::PUBLIC_ADDRESS) { + if (address == advertising_peer_address_type_t::PUBLIC) { return peer_address_type_t::PUBLIC_IDENTITY; } else { return peer_address_type_t::RANDOM_STATIC_IDENTITY; diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xPalSecurityManager.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xPalSecurityManager.cpp index e797b85223f..36c7c1e0a28 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xPalSecurityManager.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xPalSecurityManager.cpp @@ -988,10 +988,10 @@ bool nRF5xSecurityManager::sm_handler(const ble_evt_t *evt) ); advertising_peer_address_type_t - address_type(advertising_peer_address_type_t::PUBLIC_ADDRESS); + address_type(advertising_peer_address_type_t::PUBLIC); if (pairing_cb->peer_id_key.id_addr_info.addr_type) { - address_type = advertising_peer_address_type_t::RANDOM_ADDRESS; + address_type = advertising_peer_address_type_t::RANDOM; } handler->on_keys_distributed_bdaddr( diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xPalSecurityManager.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xPalSecurityManager.h index 46482fcee43..32184507daf 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xPalSecurityManager.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF51/source/nRF5xPalSecurityManager.h @@ -90,7 +90,7 @@ class nRF5xSecurityManager : public ::ble::pal::SecurityManager { struct resolving_list_entry_t { resolving_list_entry_t() : peer_identity_address_type( - advertising_peer_address_type_t::PUBLIC_ADDRESS + advertising_peer_address_type_t::PUBLIC ) { } diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp index ae12ee7c279..5c343eafa52 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp @@ -108,7 +108,7 @@ peer_address_type_t convert_nordic_address(bool identity, uint8_t address) { } peer_address_type_t convert_identity_address(advertising_peer_address_type_t address) { - if (address == advertising_peer_address_type_t::PUBLIC_ADDRESS) { + if (address == advertising_peer_address_type_t::PUBLIC) { return peer_address_type_t::PUBLIC_IDENTITY; } else { return peer_address_type_t::RANDOM_STATIC_IDENTITY; diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xPalSecurityManager.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xPalSecurityManager.cpp index 5eb1310bb47..a1d6b1e7e90 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xPalSecurityManager.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xPalSecurityManager.cpp @@ -1022,10 +1022,10 @@ bool nRF5xSecurityManager::sm_handler(const ble_evt_t *evt) ); advertising_peer_address_type_t - address_type(advertising_peer_address_type_t::PUBLIC_ADDRESS); + address_type(advertising_peer_address_type_t::PUBLIC); if (pairing_cb->peer_id_key.id_addr_info.addr_type) { - address_type = advertising_peer_address_type_t::RANDOM_ADDRESS; + address_type = advertising_peer_address_type_t::RANDOM; } handler->on_keys_distributed_bdaddr( diff --git a/targets/targets.json b/targets/targets.json index 51224cf58d5..39ef583c2f8 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -6339,7 +6339,8 @@ "supported_form_factors": ["ARDUINO"], "inherits": ["MCU_NRF52832"], "release_versions": ["5"], - "device_name": "nRF52832_xxAA" + "device_name": "nRF52832_xxAA", + "macros": ["WSF_MAX_HANDLERS=10"] }, "SDT52832B": { "inherits": ["MCU_NRF52832"],