@@ -82,7 +82,6 @@ namespace Internal {
82
82
83
83
namespace {
84
84
85
- TimerHandle_t sbleAdvTimeoutTimer; // FreeRTOS sw timer.
86
85
#ifdef CONFIG_ENABLE_ESP32_BLE_CONTROLLER
87
86
static constexpr uint16_t kNewConnectionScanTimeout = 60 ;
88
87
static constexpr uint16_t kConnectTimeout = 20 ;
@@ -209,16 +208,6 @@ CHIP_ERROR BLEManagerImpl::_Init()
209
208
{
210
209
CHIP_ERROR err;
211
210
212
- // Create FreeRTOS sw timer for BLE timeouts and interval change.
213
- sbleAdvTimeoutTimer = xTimerCreate (" BleAdvTimer" , // Just a text name, not used by the RTOS kernel
214
- 1 , // == default timer period
215
- false , // no timer reload (==one-shot)
216
- (void *) this , // init timer id = ble obj context
217
- BleAdvTimeoutHandler // timer callback handler
218
- );
219
-
220
- VerifyOrReturnError (sbleAdvTimeoutTimer != nullptr , CHIP_ERROR_NO_MEMORY);
221
-
222
211
// Initialize the Chip BleLayer.
223
212
#ifdef CONFIG_ENABLE_ESP32_BLE_CONTROLLER
224
213
err = BleLayer::Init (this , this , this , &DeviceLayer::SystemLayer ());
@@ -253,9 +242,7 @@ CHIP_ERROR BLEManagerImpl::_Init()
253
242
254
243
void BLEManagerImpl::_Shutdown ()
255
244
{
256
- VerifyOrReturn (sbleAdvTimeoutTimer != nullptr );
257
- xTimerDelete (sbleAdvTimeoutTimer, portMAX_DELAY);
258
- sbleAdvTimeoutTimer = nullptr ;
245
+ CancelBleAdvTimeoutTimer ();
259
246
260
247
BleLayer::Shutdown ();
261
248
@@ -286,7 +273,7 @@ CHIP_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val)
286
273
return err;
287
274
}
288
275
289
- void BLEManagerImpl::BleAdvTimeoutHandler (TimerHandle_t xTimer )
276
+ void BLEManagerImpl::BleAdvTimeoutHandler (System::Layer *, void * )
290
277
{
291
278
if (BLEMgrImpl ().mFlags .Has (Flags::kFastAdvertisingEnabled ))
292
279
{
@@ -298,7 +285,6 @@ void BLEManagerImpl::BleAdvTimeoutHandler(TimerHandle_t xTimer)
298
285
BLEMgrImpl ().mFlags .Clear (Flags::kExtAdvertisingEnabled );
299
286
BLEMgrImpl ().StartBleAdvTimeoutTimer (CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_CHANGE_TIME_MS);
300
287
#endif
301
- PlatformMgr ().ScheduleWork (DriveBLEState, 0 );
302
288
}
303
289
#if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
304
290
else
@@ -308,9 +294,9 @@ void BLEManagerImpl::BleAdvTimeoutHandler(TimerHandle_t xTimer)
308
294
BLEMgrImpl ().mFlags .Set (Flags::kExtAdvertisingEnabled );
309
295
BLEMgr ().SetAdvertisingMode (BLEAdvertisingMode::kSlowAdvertising );
310
296
BLEMgrImpl ().mFlags .Set (Flags::kAdvertisingRefreshNeeded , 1 );
311
- PlatformMgr ().ScheduleWork (DriveBLEState, 0 );
312
297
}
313
298
#endif
299
+ PlatformMgr ().ScheduleWork (DriveBLEState, 0 );
314
300
}
315
301
316
302
CHIP_ERROR BLEManagerImpl::_SetAdvertisingMode (BLEAdvertisingMode mode)
@@ -719,26 +705,17 @@ CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr)
719
705
}
720
706
void BLEManagerImpl::CancelBleAdvTimeoutTimer (void )
721
707
{
722
- VerifyOrReturn (sbleAdvTimeoutTimer != nullptr );
723
-
724
- if (xTimerStop (sbleAdvTimeoutTimer, pdMS_TO_TICKS (0 )) == pdFAIL)
708
+ if (SystemLayer ().IsTimerActive (BleAdvTimeoutHandler, nullptr ))
725
709
{
726
- ChipLogError (DeviceLayer, " Failed to stop BledAdv timeout timer " );
710
+ SystemLayer (). CancelTimer (BleAdvTimeoutHandler, nullptr );
727
711
}
728
712
}
729
713
void BLEManagerImpl::StartBleAdvTimeoutTimer (uint32_t aTimeoutInMs)
730
714
{
731
- VerifyOrReturn (sbleAdvTimeoutTimer != nullptr );
732
-
733
- if (xTimerIsTimerActive (sbleAdvTimeoutTimer))
734
- {
735
- CancelBleAdvTimeoutTimer ();
736
- }
715
+ CancelBleAdvTimeoutTimer ();
737
716
738
- // timer is not active, change its period to required value (== restart).
739
- // FreeRTOS- Block for a maximum of 100 ticks if the change period command
740
- // cannot immediately be sent to the timer command queue.
741
- if (xTimerChangePeriod (sbleAdvTimeoutTimer, pdMS_TO_TICKS (aTimeoutInMs), pdMS_TO_TICKS (100 )) != pdPASS)
717
+ CHIP_ERROR err = SystemLayer ().StartTimer (System::Clock::Milliseconds32 (aTimeoutInMs), BleAdvTimeoutHandler, nullptr );
718
+ if ((err != CHIP_NO_ERROR))
742
719
{
743
720
ChipLogError (DeviceLayer, " Failed to start BledAdv timeout timer" );
744
721
}
0 commit comments