From de44016689091c99425f671082ba65495f5e962a Mon Sep 17 00:00:00 2001 From: Paolo Calao Date: Wed, 2 Sep 2020 10:46:28 +0200 Subject: [PATCH] [portenta] Send service pack updates through mbed initialization The mbed ble stack is initialized at the beginning in order to exploit the service pack transfer. Once it has been initialized, the queue used to dispatch the ble events is stopped. At this point the mbed stack is no more used and ArduinoBLE exploits directly the low level uart transport layer. --- src/utility/HCICordioTransport.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/utility/HCICordioTransport.cpp b/src/utility/HCICordioTransport.cpp index 15f0e128..ab92818b 100644 --- a/src/utility/HCICordioTransport.cpp +++ b/src/utility/HCICordioTransport.cpp @@ -25,6 +25,11 @@ #include #include +#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) +#include "ble/BLE.h" +#include +#endif + // Parts of this file are based on: https://github.com/ARMmbed/mbed-os-cordio-hci-passthrough/pull/2 // With permission from the Arm Mbed team to re-license @@ -174,6 +179,17 @@ HCICordioTransportClass::~HCICordioTransportClass() { } +#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) +events::EventQueue eventQueue(10 * EVENTS_EVENT_SIZE); +void scheduleMbedBleEvents(BLE::OnEventsToProcessCallbackContext *context) { + eventQueue.call(mbed::Callback(&context->ble, &BLE::processEvents)); +} + +void completeCallback(BLE::InitializationCompleteCallbackContext *context) { + eventQueue.break_dispatch(); +} +#endif + int HCICordioTransportClass::begin() { _rxBuf.clear(); @@ -183,8 +199,20 @@ int HCICordioTransportClass::begin() init_wsf(bufPoolDesc); #endif +#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) + BLE &ble = BLE::Instance(); + ble.onEventsToProcess(scheduleMbedBleEvents); + + ble.init(completeCallback); + eventQueue.dispatch(10000); + + if (!ble.hasInitialized()){ + return 0; + } +#else CordioHCIHook::getDriver().initialize(); CordioHCIHook::getDriver().start_reset_sequence(); +#endif if (bleLoopThread == NULL) { bleLoopThread = new rtos::Thread(); @@ -205,7 +233,6 @@ void HCICordioTransportClass::end() delete bleLoopThread; bleLoopThread = NULL; } - CordioHCIHook::getDriver().terminate(); _begun = false;