@@ -76,8 +76,7 @@ namespace Internal {
76
76
77
77
namespace {
78
78
79
- TimerHandle_t sbleAdvTimeoutTimer; // FreeRTOS sw timer.
80
- #if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
79
+ #ifdef CONFIG_ENABLE_ESP32_BLE_CONTROLLER
81
80
static constexpr uint16_t kNewConnectionScanTimeout = 60 ;
82
81
static constexpr uint16_t kConnectTimeout = 20 ;
83
82
#endif
@@ -212,16 +211,6 @@ CHIP_ERROR BLEManagerImpl::_Init()
212
211
{
213
212
CHIP_ERROR err;
214
213
215
- // Create FreeRTOS sw timer for BLE timeouts and interval change.
216
- sbleAdvTimeoutTimer = xTimerCreate (" BleAdvTimer" , // Just a text name, not used by the RTOS kernel
217
- 1 , // == default timer period
218
- false , // no timer reload (==one-shot)
219
- (void *) this , // init timer id = ble obj context
220
- BleAdvTimeoutHandler // timer callback handler
221
- );
222
-
223
- VerifyOrReturnError (sbleAdvTimeoutTimer != nullptr , CHIP_ERROR_NO_MEMORY);
224
-
225
214
// Initialize the Chip BleLayer.
226
215
#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
227
216
err = BleLayer::Init (this , this , this , &DeviceLayer::SystemLayer ());
@@ -257,9 +246,7 @@ CHIP_ERROR BLEManagerImpl::_Init()
257
246
258
247
void BLEManagerImpl::_Shutdown ()
259
248
{
260
- VerifyOrReturn (sbleAdvTimeoutTimer != nullptr );
261
- xTimerDelete (sbleAdvTimeoutTimer, portMAX_DELAY);
262
- sbleAdvTimeoutTimer = nullptr ;
249
+ CancelBleAdvTimeoutTimer ();
263
250
264
251
BleLayer::Shutdown ();
265
252
@@ -294,7 +281,7 @@ CHIP_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val)
294
281
return err;
295
282
}
296
283
297
- void BLEManagerImpl::BleAdvTimeoutHandler (TimerHandle_t xTimer )
284
+ void BLEManagerImpl::BleAdvTimeoutHandler (System::Layer *, void * )
298
285
{
299
286
if (BLEMgrImpl ().mFlags .Has (Flags::kFastAdvertisingEnabled ))
300
287
{
@@ -306,7 +293,6 @@ void BLEManagerImpl::BleAdvTimeoutHandler(TimerHandle_t xTimer)
306
293
BLEMgrImpl ().mFlags .Clear (Flags::kExtAdvertisingEnabled );
307
294
BLEMgrImpl ().StartBleAdvTimeoutTimer (CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_CHANGE_TIME_MS);
308
295
#endif
309
- PlatformMgr ().ScheduleWork (DriveBLEState, 0 );
310
296
}
311
297
#if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
312
298
else
@@ -316,9 +302,9 @@ void BLEManagerImpl::BleAdvTimeoutHandler(TimerHandle_t xTimer)
316
302
BLEMgrImpl ().mFlags .Set (Flags::kExtAdvertisingEnabled );
317
303
BLEMgr ().SetAdvertisingMode (BLEAdvertisingMode::kSlowAdvertising );
318
304
BLEMgrImpl ().mFlags .Set (Flags::kAdvertisingRefreshNeeded , 1 );
319
- PlatformMgr ().ScheduleWork (DriveBLEState, 0 );
320
305
}
321
306
#endif
307
+ PlatformMgr ().ScheduleWork (DriveBLEState, 0 );
322
308
}
323
309
324
310
CHIP_ERROR BLEManagerImpl::_SetAdvertisingMode (BLEAdvertisingMode mode)
@@ -729,26 +715,17 @@ CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr)
729
715
}
730
716
void BLEManagerImpl::CancelBleAdvTimeoutTimer (void )
731
717
{
732
- VerifyOrReturn (sbleAdvTimeoutTimer != nullptr );
733
-
734
- if (xTimerStop (sbleAdvTimeoutTimer, pdMS_TO_TICKS (0 )) == pdFAIL)
718
+ if (SystemLayer ().IsTimerActive (BleAdvTimeoutHandler, nullptr ))
735
719
{
736
- ChipLogError (DeviceLayer, " Failed to stop BledAdv timeout timer " );
720
+ SystemLayer (). CancelTimer (BleAdvTimeoutHandler, nullptr );
737
721
}
738
722
}
739
723
void BLEManagerImpl::StartBleAdvTimeoutTimer (uint32_t aTimeoutInMs)
740
724
{
741
- VerifyOrReturn (sbleAdvTimeoutTimer != nullptr );
742
-
743
- if (xTimerIsTimerActive (sbleAdvTimeoutTimer))
744
- {
745
- CancelBleAdvTimeoutTimer ();
746
- }
725
+ CancelBleAdvTimeoutTimer ();
747
726
748
- // timer is not active, change its period to required value (== restart).
749
- // FreeRTOS- Block for a maximum of 100 ticks if the change period command
750
- // cannot immediately be sent to the timer command queue.
751
- if (xTimerChangePeriod (sbleAdvTimeoutTimer, pdMS_TO_TICKS (aTimeoutInMs), pdMS_TO_TICKS (100 )) != pdPASS)
727
+ CHIP_ERROR err = SystemLayer ().StartTimer (System::Clock::Milliseconds32 (aTimeoutInMs), BleAdvTimeoutHandler, nullptr );
728
+ if ((err != CHIP_NO_ERROR))
752
729
{
753
730
ChipLogError (DeviceLayer, " Failed to start BledAdv timeout timer" );
754
731
}
0 commit comments