@@ -250,6 +250,7 @@ namespace {
250
250
#define BLE_SEND_INDICATION_TIMER_PERIOD_MS (10 )
251
251
252
252
TimerHandle_t sbleAdvTimeoutTimer; // FreeRTOS sw timer.
253
+ TimerHandle_t sbleSendIndicationTimeoutTimer; // FreeRTOS sw timer.
253
254
254
255
const uint8_t UUID_CHIPoBLEService[] = { 0xFB , 0x34 , 0x9B , 0x5F , 0x80 , 0x00 , 0x00 , 0x80 ,
255
256
0x00 , 0x10 , 0x00 , 0x00 , 0xF6 , 0xFF , 0x00 , 0x00 };
@@ -294,6 +295,13 @@ CHIP_ERROR BLEManagerImpl::_Init()
294
295
BleAdvTimeoutHandler // timer callback handler
295
296
);
296
297
298
+ sbleSendIndicationTimeoutTimer = xTimerCreate (" SendIndicationTimer" , // Just a text name, not used by the RTOS kernel
299
+ pdMS_TO_TICKS (BLE_SEND_INDICATION_TIMER_PERIOD_MS), // == default timer period
300
+ false , // no timer reload (==one-shot)
301
+ (void *) this , // init timer id = ble obj context
302
+ BleAdvTimeoutHandler // timer callback handler
303
+ );
304
+
297
305
mFlags .ClearAll ().Set (Flags::kAdvertisingEnabled , CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART);
298
306
mFlags .Set (Flags::kFastAdvertisingEnabled , true );
299
307
PlatformMgr ().ScheduleWork (DriveBLEState, 0 );
@@ -466,21 +474,16 @@ uint16_t BLEManagerImpl::GetMTU(BLE_CONNECTION_OBJECT conId) const
466
474
return (conState != NULL ) ? conState->mtu : 0 ;
467
475
}
468
476
469
- void BLEManagerImpl::OnSendIndicationTimeout (System::Layer * aLayer, void * appState)
470
- {
471
- BLEManagerImpl * pBLEManagerImpl = reinterpret_cast <BLEManagerImpl *>(appState);
472
- pBLEManagerImpl->HandleSoftTimerEvent ();
473
- }
474
-
475
477
bool BLEManagerImpl::SendIndication (BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId,
476
478
PacketBufferHandle data)
477
479
{
478
480
int32_t status = 0 ;
479
481
status = rsi_ble_indicate_value (event_msg.resp_enh_conn .dev_addr , event_msg.rsi_ble_measurement_hndl , (data->DataLength ()),
480
482
data->Start ());
481
483
482
- // start timer for light indication confirmation. Long delay for spake2 indication
483
- DeviceLayer::SystemLayer ().StartTimer (chip::System::Clock::Milliseconds32 (BLE_SEND_INDICATION_TIMER_PERIOD_MS), OnSendIndicationTimeout, this );
484
+ ChipLogProgress (DeviceLayer, " StartTimer start" );
485
+ StartBleSendIndicationTimeoutTimer (BLE_SEND_INDICATION_TIMER_PERIOD_MS);
486
+ ChipLogProgress (DeviceLayer, " StartTimer Stop" );
484
487
485
488
if (status != RSI_SUCCESS)
486
489
{
@@ -935,8 +938,8 @@ void BLEManagerImpl::HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId)
935
938
ChipDeviceEvent event;
936
939
event.Type = DeviceEventType::kCHIPoBLEIndicateConfirm ;
937
940
event.CHIPoBLEIndicateConfirm .ConId = conId;
938
- DeviceLayer::SystemLayer ().CancelTimer (OnSendIndicationTimeout, this );
939
941
PlatformMgr ().PostEventOrDie (&event);
942
+ CancelBleSendIndicationTimeoutTimer ();
940
943
}
941
944
942
945
@@ -1119,6 +1122,36 @@ void BLEManagerImpl::StartBleAdvTimeoutTimer(uint32_t aTimeoutInMs)
1119
1122
}
1120
1123
}
1121
1124
1125
+
1126
+ void BLEManagerImpl::BleSendIndicationTimeoutHandler (TimerHandle_t xTimer)
1127
+ {
1128
+ sInstance .HandleSoftTimerEvent ();
1129
+ }
1130
+
1131
+ void BLEManagerImpl::CancelBleSendIndicationTimeoutTimer (void )
1132
+ {
1133
+ if (xTimerStop (sbleSendIndicationTimeoutTimer, pdMS_TO_TICKS (0 )) == pdFAIL)
1134
+ {
1135
+ ChipLogError (DeviceLayer, " Failed to stop BledAdv timeout timer" );
1136
+ }
1137
+ }
1138
+
1139
+ void BLEManagerImpl::StartBleSendIndicationTimeoutTimer (uint32_t aTimeoutInMs)
1140
+ {
1141
+ if (xTimerIsTimerActive (sbleSendIndicationTimeoutTimer))
1142
+ {
1143
+ CancelBleAdvTimeoutTimer ();
1144
+ }
1145
+
1146
+ // timer is not active, change its period to required value (== restart).
1147
+ // FreeRTOS- Block for a maximum of 100 ticks if the change period command
1148
+ // cannot immediately be sent to the timer command queue.
1149
+ if (xTimerChangePeriod (sbleSendIndicationTimeoutTimer, pdMS_TO_TICKS (aTimeoutInMs), pdMS_TO_TICKS (100 )) != pdPASS)
1150
+ {
1151
+ ChipLogError (DeviceLayer, " Failed to start BledAdv timeout timer" );
1152
+ }
1153
+ }
1154
+
1122
1155
void BLEManagerImpl::DriveBLEState (intptr_t arg)
1123
1156
{
1124
1157
sInstance .DriveBLEState ();
0 commit comments