@@ -33,6 +33,26 @@ constexpr uint32_t TASK_BLOCK_BIT = (1 << CONFIG_NIMBLE_CPP_FREERTOS_TASK_BLOCK_
3333
3434static const char * LOG_TAG = " NimBLEUtils" ;
3535
36+ /* *
37+ * @brief Constructor.
38+ * @param [in] pInstance An instance of the class that is waiting.
39+ * @param [in] flags General purpose flags for the caller.
40+ * @param [in] buf A buffer for data.
41+ */
42+ NimBLETaskData::NimBLETaskData (void * pInstance = nullptr , int flags = 0 , void * buf = nullptr )
43+ : m_pInstance(pInstance), m_flags(flags), m_pBuf(buf) {
44+ # if defined INC_FREERTOS_H
45+ m_pHandle = xTaskGetCurrentTaskHandle ();
46+ # else
47+ m_pHandle = new ble_npl_sem;
48+ if (ble_npl_sem_init (static_cast <ble_npl_sem*>(m_pHandle), 0 ) != BLE_NPL_OK) {
49+ NIMBLE_LOGE (LOG_TAG, " Failed to create semaphore" );
50+ delete m_pHandle;
51+ m_pHandle = nullptr ;
52+ }
53+ # endif
54+ }
55+
3656/* *
3757 * @brief Blocks the calling task until released or timeout.
3858 * @param [in] taskData A pointer to the task data structure.
@@ -54,20 +74,13 @@ bool NimBLEUtils::taskWait(const NimBLETaskData& taskData, uint32_t timeout) {
5474 return true ;
5575 }
5676
57- taskData.m_pHandle = xTaskGetCurrentTaskHandle ();
5877 return xTaskNotifyWait (0 , TASK_BLOCK_BIT, nullptr , ticks) == pdTRUE;
5978
6079# else
61- ble_npl_sem sem;
62- ble_npl_error_t err = ble_npl_sem_init (&sem, 0 );
63- if (err != BLE_NPL_OK) {
64- NIMBLE_LOGE (LOG_TAG, " Failed to create semaphore" );
65- return false ;
66- }
67-
68- taskData.m_pHandle = &sem;
69- err = ble_npl_sem_pend (&sem, ticks);
70- ble_npl_sem_deinit (&sem);
80+ ble_npl_sem* sem = static_cast <ble_npl_sem*>(taskData.m_pHandle );
81+ ble_npl_error_t err = ble_npl_sem_pend (sem, ticks);
82+ ble_npl_sem_deinit (sem);
83+ delete taskData.m_pHandle ;
7184 taskData.m_pHandle = nullptr ;
7285 return err == BLE_NPL_OK;
7386# endif
0 commit comments