Skip to content

Commit

Permalink
Added changes for TX timer
Browse files Browse the repository at this point in the history
  • Loading branch information
shgutte committed Feb 2, 2024
1 parent 41f5afb commit cfc4116
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
9 changes: 3 additions & 6 deletions src/platform/silabs/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla

#if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE)
void HandleRXCharWrite(rsi_ble_event_write_t * evt);
void StartBleSendIndicationTimeoutTimer(uint32_t aTimeoutInMs);
void CancelBleSendIndicationTimeoutTimer(void);
static void BleSendIndicationTimeoutHandler(TimerHandle_t xTimer);
#else
void HandleRXCharWrite(volatile sl_bt_msg_t * evt);
#endif
Expand All @@ -209,12 +212,6 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
static void DriveBLEState(intptr_t arg);
static void BleAdvTimeoutHandler(TimerHandle_t xTimer);
uint8_t GetTimerHandle(uint8_t connectionHandle, bool allocate);


#if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE)
protected:
static void OnSendIndicationTimeout(System::Layer * aLayer, void * appState);
#endif
};

/**
Expand Down
51 changes: 42 additions & 9 deletions src/platform/silabs/rs911x/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ namespace {
#define BLE_SEND_INDICATION_TIMER_PERIOD_MS (10)

TimerHandle_t sbleAdvTimeoutTimer; // FreeRTOS sw timer.
TimerHandle_t sbleSendIndicationTimeoutTimer; // FreeRTOS sw timer.

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

sbleSendIndicationTimeoutTimer = xTimerCreate("SendIndicationTimer", // Just a text name, not used by the RTOS kernel
pdMS_TO_TICKS(BLE_SEND_INDICATION_TIMER_PERIOD_MS), // == default timer period
false, // no timer reload (==one-shot)
(void *) this, // init timer id = ble obj context
BleAdvTimeoutHandler // timer callback handler
);

mFlags.ClearAll().Set(Flags::kAdvertisingEnabled, CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART);
mFlags.Set(Flags::kFastAdvertisingEnabled, true);
PlatformMgr().ScheduleWork(DriveBLEState, 0);
Expand Down Expand Up @@ -466,21 +474,16 @@ uint16_t BLEManagerImpl::GetMTU(BLE_CONNECTION_OBJECT conId) const
return (conState != NULL) ? conState->mtu : 0;
}

void BLEManagerImpl::OnSendIndicationTimeout(System::Layer * aLayer, void * appState)
{
BLEManagerImpl * pBLEManagerImpl = reinterpret_cast<BLEManagerImpl *>(appState);
pBLEManagerImpl->HandleSoftTimerEvent();
}

bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId,
PacketBufferHandle data)
{
int32_t status = 0;
status = rsi_ble_indicate_value(event_msg.resp_enh_conn.dev_addr, event_msg.rsi_ble_measurement_hndl, (data->DataLength()),
data->Start());

// start timer for light indication confirmation. Long delay for spake2 indication
DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(BLE_SEND_INDICATION_TIMER_PERIOD_MS), OnSendIndicationTimeout, this);
ChipLogProgress(DeviceLayer, "StartTimer start");
StartBleSendIndicationTimeoutTimer(BLE_SEND_INDICATION_TIMER_PERIOD_MS);
ChipLogProgress(DeviceLayer, "StartTimer Stop");

if (status != RSI_SUCCESS)
{
Expand Down Expand Up @@ -935,8 +938,8 @@ void BLEManagerImpl::HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId)
ChipDeviceEvent event;
event.Type = DeviceEventType::kCHIPoBLEIndicateConfirm;
event.CHIPoBLEIndicateConfirm.ConId = conId;
DeviceLayer::SystemLayer().CancelTimer(OnSendIndicationTimeout, this);
PlatformMgr().PostEventOrDie(&event);
CancelBleSendIndicationTimeoutTimer();
}


Expand Down Expand Up @@ -1119,6 +1122,36 @@ void BLEManagerImpl::StartBleAdvTimeoutTimer(uint32_t aTimeoutInMs)
}
}


void BLEManagerImpl::BleSendIndicationTimeoutHandler(TimerHandle_t xTimer)
{
sInstance.HandleSoftTimerEvent();
}

void BLEManagerImpl::CancelBleSendIndicationTimeoutTimer(void)
{
if (xTimerStop(sbleSendIndicationTimeoutTimer, pdMS_TO_TICKS(0)) == pdFAIL)
{
ChipLogError(DeviceLayer, "Failed to stop BledAdv timeout timer");
}
}

void BLEManagerImpl::StartBleSendIndicationTimeoutTimer(uint32_t aTimeoutInMs)
{
if (xTimerIsTimerActive(sbleSendIndicationTimeoutTimer))
{
CancelBleAdvTimeoutTimer();
}

// timer is not active, change its period to required value (== restart).
// FreeRTOS- Block for a maximum of 100 ticks if the change period command
// cannot immediately be sent to the timer command queue.
if (xTimerChangePeriod(sbleSendIndicationTimeoutTimer, pdMS_TO_TICKS(aTimeoutInMs), pdMS_TO_TICKS(100)) != pdPASS)
{
ChipLogError(DeviceLayer, "Failed to start BledAdv timeout timer");
}
}

void BLEManagerImpl::DriveBLEState(intptr_t arg)
{
sInstance.DriveBLEState();
Expand Down

0 comments on commit cfc4116

Please sign in to comment.