Skip to content

Fix nordic cordio support #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: ble-extended-advertising
Choose a base branch
from
3 changes: 3 additions & 0 deletions features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "ble/generic/GenericGap.h"
#include "ble/generic/GenericSecurityManager.h"
#include "SimpleEventQueue.h"
#include "Timer.h"

namespace ble {
namespace vendor {
Expand Down Expand Up @@ -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:
Expand Down
29 changes: 18 additions & 11 deletions features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() { }
Expand All @@ -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();
Expand Down Expand Up @@ -389,6 +393,7 @@ void BLE::stack_setup()
void BLE::start_stack_reset()
{
_hci_driver->initialize();
stack_setup();
DmDevReset();
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
{ }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down