From 7ee811141bd98f15e93da141b5a90d0e26296550 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Tue, 19 Mar 2019 16:08:04 +0000 Subject: [PATCH 1/3] BLE - Add CordioHCIDriver::on_host_stack_inactivity This callback should be called by the host stack when it has no pending activities. It allows a driver to put its controller to sleep. --- .../targets/TARGET_CORDIO/driver/CordioHCIDriver.cpp | 4 ++++ .../targets/TARGET_CORDIO/driver/CordioHCIDriver.h | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.cpp index 271ff9463a..f1c704583a 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.cpp @@ -283,6 +283,10 @@ uint16_t CordioHCIDriver::write(uint8_t type, uint16_t len, uint8_t *pData) return _transport_driver.write(type, len, pData); } +void CordioHCIDriver::on_host_stack_inactivity() +{ +} + } // namespace cordio } // namespace vendor } // namespace ble diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.h index bf83389241..737bce73de 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.h @@ -134,6 +134,16 @@ public: */ uint16_t write(uint8_t type, uint16_t len, uint8_t *pData); + /** + * React to host stack inactivity. + * + * The host stack invoke this function when it is inactive. It allows a + * driver to put its controller to sleep if all the conditions are met. + * + * Any call to write signals to the driver that the host stack is active. + */ + virtual void on_host_stack_inactivity(); + protected: /** * Return a default set of memory pool that the Cordio stack can use. From 63b7e69d89ad16f332ffdac65321961836a7ce98 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Tue, 19 Mar 2019 16:16:52 +0000 Subject: [PATCH 2/3] BLE - Signal to the HCI driver when the host stack is inactive --- .../FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp index f8587f7aac..6215960dcf 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp @@ -564,6 +564,9 @@ void BLE::callDispatcher() timestamp_t nextTimestamp = (timestamp_t) (WsfTimerNextExpiration(&pTimerRunning) * WSF_MS_PER_TICK) * 1000; if (pTimerRunning) { nextTimeout.attach_us(timeoutCallback, nextTimestamp); + } else { + critical_section.disable(); + _hci_driver->on_host_stack_inactivity(); } } } From 339c57f6a7fb65144cb7ed54b74ad71c7912263d Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Tue, 19 Mar 2019 16:26:29 +0000 Subject: [PATCH 3/3] BLE - Use low power timeout in cordio::BLE::callDispatcher . --- features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp index 6215960dcf..e4cadc531c 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp @@ -555,7 +555,7 @@ void BLE::callDispatcher() wsfOsDispatcher(); - static Timeout nextTimeout; + static LowPowerTimeout nextTimeout; CriticalSectionLock critical_section; if (wsfOsReadyToSleep()) {