Skip to content

Commit cfc4116

Browse files
committed
Added changes for TX timer
1 parent 41f5afb commit cfc4116

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

src/platform/silabs/BLEManagerImpl.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
198198

199199
#if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE)
200200
void HandleRXCharWrite(rsi_ble_event_write_t * evt);
201+
void StartBleSendIndicationTimeoutTimer(uint32_t aTimeoutInMs);
202+
void CancelBleSendIndicationTimeoutTimer(void);
203+
static void BleSendIndicationTimeoutHandler(TimerHandle_t xTimer);
201204
#else
202205
void HandleRXCharWrite(volatile sl_bt_msg_t * evt);
203206
#endif
@@ -209,12 +212,6 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
209212
static void DriveBLEState(intptr_t arg);
210213
static void BleAdvTimeoutHandler(TimerHandle_t xTimer);
211214
uint8_t GetTimerHandle(uint8_t connectionHandle, bool allocate);
212-
213-
214-
#if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE)
215-
protected:
216-
static void OnSendIndicationTimeout(System::Layer * aLayer, void * appState);
217-
#endif
218215
};
219216

220217
/**

src/platform/silabs/rs911x/BLEManagerImpl.cpp

+42-9
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ namespace {
250250
#define BLE_SEND_INDICATION_TIMER_PERIOD_MS (10)
251251

252252
TimerHandle_t sbleAdvTimeoutTimer; // FreeRTOS sw timer.
253+
TimerHandle_t sbleSendIndicationTimeoutTimer; // FreeRTOS sw timer.
253254

254255
const uint8_t UUID_CHIPoBLEService[] = { 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
255256
0x00, 0x10, 0x00, 0x00, 0xF6, 0xFF, 0x00, 0x00 };
@@ -294,6 +295,13 @@ CHIP_ERROR BLEManagerImpl::_Init()
294295
BleAdvTimeoutHandler // timer callback handler
295296
);
296297

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+
297305
mFlags.ClearAll().Set(Flags::kAdvertisingEnabled, CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART);
298306
mFlags.Set(Flags::kFastAdvertisingEnabled, true);
299307
PlatformMgr().ScheduleWork(DriveBLEState, 0);
@@ -466,21 +474,16 @@ uint16_t BLEManagerImpl::GetMTU(BLE_CONNECTION_OBJECT conId) const
466474
return (conState != NULL) ? conState->mtu : 0;
467475
}
468476

469-
void BLEManagerImpl::OnSendIndicationTimeout(System::Layer * aLayer, void * appState)
470-
{
471-
BLEManagerImpl * pBLEManagerImpl = reinterpret_cast<BLEManagerImpl *>(appState);
472-
pBLEManagerImpl->HandleSoftTimerEvent();
473-
}
474-
475477
bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId,
476478
PacketBufferHandle data)
477479
{
478480
int32_t status = 0;
479481
status = rsi_ble_indicate_value(event_msg.resp_enh_conn.dev_addr, event_msg.rsi_ble_measurement_hndl, (data->DataLength()),
480482
data->Start());
481483

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");
484487

485488
if (status != RSI_SUCCESS)
486489
{
@@ -935,8 +938,8 @@ void BLEManagerImpl::HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId)
935938
ChipDeviceEvent event;
936939
event.Type = DeviceEventType::kCHIPoBLEIndicateConfirm;
937940
event.CHIPoBLEIndicateConfirm.ConId = conId;
938-
DeviceLayer::SystemLayer().CancelTimer(OnSendIndicationTimeout, this);
939941
PlatformMgr().PostEventOrDie(&event);
942+
CancelBleSendIndicationTimeoutTimer();
940943
}
941944

942945

@@ -1119,6 +1122,36 @@ void BLEManagerImpl::StartBleAdvTimeoutTimer(uint32_t aTimeoutInMs)
11191122
}
11201123
}
11211124

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+
11221155
void BLEManagerImpl::DriveBLEState(intptr_t arg)
11231156
{
11241157
sInstance.DriveBLEState();

0 commit comments

Comments
 (0)