Skip to content

Commit

Permalink
Add checks for timer handler
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamdp committed Apr 24, 2024
1 parent 7b6d6c3 commit a37e2ad
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/platform/ESP32/nimble/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,6 @@ CHIP_ERROR BLEManagerImpl::_Init()
{
CHIP_ERROR err;

// Initialize the Chip BleLayer.
#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
err = BleLayer::Init(this, this, this, &DeviceLayer::SystemLayer());
#else
err = BleLayer::Init(this, this, &DeviceLayer::SystemLayer());
#endif
SuccessOrExit(err);

// Create FreeRTOS sw timer for BLE timeouts and interval change.
sbleAdvTimeoutTimer = xTimerCreate("BleAdvTimer", // Just a text name, not used by the RTOS kernel
1, // == default timer period
Expand All @@ -227,6 +219,16 @@ CHIP_ERROR BLEManagerImpl::_Init()
BleAdvTimeoutHandler // timer callback handler
);

VerifyOrReturnError(sbleAdvTimeoutTimer != nullptr, CHIP_ERROR_NO_MEMORY);

// Initialize the Chip BleLayer.
#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
err = BleLayer::Init(this, this, this, &DeviceLayer::SystemLayer());
#else
err = BleLayer::Init(this, this, &DeviceLayer::SystemLayer());
#endif
SuccessOrExit(err);

mRXCharAttrHandle = 0;
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
mC3CharAttrHandle = 0;
Expand Down Expand Up @@ -254,8 +256,11 @@ CHIP_ERROR BLEManagerImpl::_Init()

void BLEManagerImpl::_Shutdown()
{
BleLayer::Shutdown();
VerifyOrReturn(sbleAdvTimeoutTimer != nullptr);
xTimerDelete(sbleAdvTimeoutTimer, portMAX_DELAY);
sbleAdvTimeoutTimer = nullptr;

BleLayer::Shutdown();

// selectively setting kGATTServiceStarted flag, in order to notify the state machine to stop the CHIPoBLE GATT service
mFlags.ClearAll().Set(Flags::kGATTServiceStarted);
Expand Down Expand Up @@ -723,13 +728,17 @@ CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr)
}
void BLEManagerImpl::CancelBleAdvTimeoutTimer(void)
{
VerifyOrReturn(sbleAdvTimeoutTimer != nullptr);

if (xTimerStop(sbleAdvTimeoutTimer, pdMS_TO_TICKS(0)) == pdFAIL)
{
ChipLogError(DeviceLayer, "Failed to stop BledAdv timeout timer");
}
}
void BLEManagerImpl::StartBleAdvTimeoutTimer(uint32_t aTimeoutInMs)
{
VerifyOrReturn(sbleAdvTimeoutTimer != nullptr);

if (xTimerIsTimerActive(sbleAdvTimeoutTimer))
{
CancelBleAdvTimeoutTimer();
Expand Down

0 comments on commit a37e2ad

Please sign in to comment.