@@ -211,14 +211,6 @@ CHIP_ERROR BLEManagerImpl::_Init()
211
211
{
212
212
CHIP_ERROR err;
213
213
214
- // Initialize the Chip BleLayer.
215
- #if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
216
- err = BleLayer::Init (this , this , this , &DeviceLayer::SystemLayer ());
217
- #else
218
- err = BleLayer::Init (this , this , &DeviceLayer::SystemLayer ());
219
- #endif
220
- SuccessOrExit (err);
221
-
222
214
// Create FreeRTOS sw timer for BLE timeouts and interval change.
223
215
sbleAdvTimeoutTimer = xTimerCreate (" BleAdvTimer" , // Just a text name, not used by the RTOS kernel
224
216
1 , // == default timer period
@@ -227,6 +219,16 @@ CHIP_ERROR BLEManagerImpl::_Init()
227
219
BleAdvTimeoutHandler // timer callback handler
228
220
);
229
221
222
+ VerifyOrReturnError (sbleAdvTimeoutTimer != nullptr , CHIP_ERROR_NO_MEMORY);
223
+
224
+ // Initialize the Chip BleLayer.
225
+ #if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
226
+ err = BleLayer::Init (this , this , this , &DeviceLayer::SystemLayer ());
227
+ #else
228
+ err = BleLayer::Init (this , this , &DeviceLayer::SystemLayer ());
229
+ #endif
230
+ SuccessOrExit (err);
231
+
230
232
mRXCharAttrHandle = 0 ;
231
233
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
232
234
mC3CharAttrHandle = 0 ;
@@ -254,8 +256,11 @@ CHIP_ERROR BLEManagerImpl::_Init()
254
256
255
257
void BLEManagerImpl::_Shutdown ()
256
258
{
257
- BleLayer::Shutdown ( );
259
+ VerifyOrReturn (sbleAdvTimeoutTimer != nullptr );
258
260
xTimerDelete (sbleAdvTimeoutTimer, portMAX_DELAY);
261
+ sbleAdvTimeoutTimer = nullptr ;
262
+
263
+ BleLayer::Shutdown ();
259
264
260
265
// selectively setting kGATTServiceStarted flag, in order to notify the state machine to stop the CHIPoBLE GATT service
261
266
mFlags .ClearAll ().Set (Flags::kGATTServiceStarted );
@@ -723,13 +728,17 @@ CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr)
723
728
}
724
729
void BLEManagerImpl::CancelBleAdvTimeoutTimer (void )
725
730
{
731
+ VerifyOrReturn (sbleAdvTimeoutTimer != nullptr );
732
+
726
733
if (xTimerStop (sbleAdvTimeoutTimer, pdMS_TO_TICKS (0 )) == pdFAIL)
727
734
{
728
735
ChipLogError (DeviceLayer, " Failed to stop BledAdv timeout timer" );
729
736
}
730
737
}
731
738
void BLEManagerImpl::StartBleAdvTimeoutTimer (uint32_t aTimeoutInMs)
732
739
{
740
+ VerifyOrReturn (sbleAdvTimeoutTimer != nullptr );
741
+
733
742
if (xTimerIsTimerActive (sbleAdvTimeoutTimer))
734
743
{
735
744
CancelBleAdvTimeoutTimer ();
0 commit comments