From ebe4aaa25c95974954c5051ed02ccb22c3b565f8 Mon Sep 17 00:00:00 2001 From: CW-B-W Date: Sat, 19 Aug 2023 11:23:40 +0800 Subject: [PATCH] Fix NimBLEDevice::init() task priority problem When the priority of NimBLEDevice::init() is greater than (tskIDLE_PRIORITY+1), NimBLEDevice::init() will block NimBLE host task and wait for NimBLE host task infinitely --- src/NimBLEDevice.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/NimBLEDevice.cpp b/src/NimBLEDevice.cpp index 43ba2190..157bc073 100644 --- a/src/NimBLEDevice.cpp +++ b/src/NimBLEDevice.cpp @@ -68,6 +68,7 @@ NimBLEServer* NimBLEDevice::m_pServer = nullptr; #endif uint32_t NimBLEDevice::m_passkey = 123456; bool NimBLEDevice::m_synced = false; +SemaphoreHandle_t m_synced_sem = xSemaphoreCreateBinary(); #if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER) # if CONFIG_BT_NIMBLE_EXT_ADV NimBLEExtAdvertising* NimBLEDevice::m_bleAdvertising = nullptr; @@ -807,6 +808,7 @@ void NimBLEDevice::onSync(void) taskYIELD(); m_synced = true; + xSemaphoreGive(m_synced_sem); if(initialized) { #if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER) @@ -906,6 +908,7 @@ void NimBLEDevice::init(const std::string &deviceName) { } // Wait for host and controller to sync before returning and accepting new tasks + xSemaphoreTake(m_synced_sem, portMAX_DELAY); while(!m_synced){ taskYIELD(); }