Skip to content

Commit

Permalink
[Silabs][Wi-Fi] Added Implementation for timeouts waiting for a TX Co…
Browse files Browse the repository at this point in the history
…nfirmation Event BLE (project-chip#32333)

* Added changes for BLE TX timeout

* Added changes for the BLE callback handler

* Added changes for the build error for the TX timer fix

* Fix for the Matter tx timer for indication

* Added changes for the restyler

* Added restyler changes

* Added changes for the Ble manager impl

* Stating the timer after success of send indication

* Update src/platform/silabs/rs911x/BLEManagerImpl.cpp

* Restyled by clang-format

---------

Co-authored-by: mkardous-silabs <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Junior Martinez <[email protected]>
  • Loading branch information
4 people authored Mar 25, 2024
1 parent 437c574 commit f5b2712
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
12 changes: 5 additions & 7 deletions src/platform/silabs/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@

#pragma once
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE

#if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE)
#define BLE_MIN_CONNECTION_INTERVAL_MS 45 // 45 msec
#define BLE_MAX_CONNECTION_INTERVAL_MS 45 // 45 msec
#define BLE_SLAVE_LATENCY_MS 0
#define BLE_TIMEOUT_MS 400
#endif // (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE)
#include "FreeRTOS.h"
#include "timers.h"
#if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE)
Expand Down Expand Up @@ -209,6 +202,11 @@ 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
32 changes: 24 additions & 8 deletions src/platform/silabs/rs911x/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ extern "C" {
#include <setup_payload/AdditionalDataPayloadGenerator.h>
#endif

#define BLE_MIN_CONNECTION_INTERVAL_MS 45
#define BLE_MAX_CONNECTION_INTERVAL_MS 45
#define BLE_SLAVE_LATENCY_MS 0
#define BLE_TIMEOUT_MS 400
#define BLE_DEFAULT_TIMER_PERIOD_MS (1)
#define BLE_SEND_INDICATION_TIMER_PERIOD_MS (5000)

extern sl_wfx_msg_t event_msg;

StaticTask_t rsiBLETaskStruct;
Expand Down Expand Up @@ -246,8 +253,6 @@ namespace {
#define BLE_CONFIG_MIN_CE_LENGTH (0) // Leave to min value
#define BLE_CONFIG_MAX_CE_LENGTH (0xFFFF) // Leave to max value

#define BLE_DEFAULT_TIMER_PERIOD_MS (1)

TimerHandle_t sbleAdvTimeoutTimer; // FreeRTOS sw timer.

const uint8_t UUID_CHIPoBLEService[] = { 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
Expand Down Expand Up @@ -301,6 +306,18 @@ CHIP_ERROR BLEManagerImpl::_Init()
return err;
}

void BLEManagerImpl::OnSendIndicationTimeout(System::Layer * aLayer, void * appState)
{
// TODO: change the connection handle with the ble device ID
uint8_t connHandle = 1;
ChipLogProgress(DeviceLayer, "BLEManagerImpl::HandleSoftTimerEvent CHIPOBLE_PROTOCOL_ABORT");
ChipDeviceEvent event;
event.Type = DeviceEventType::kCHIPoBLEConnectionError;
event.CHIPoBLEConnectionError.ConId = connHandle;
event.CHIPoBLEConnectionError.Reason = BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT;
PlatformMgr().PostEventOrDie(&event);
}

uint16_t BLEManagerImpl::_NumConnections(void)
{
uint16_t numCons = 0;
Expand Down Expand Up @@ -423,6 +440,7 @@ void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)

case DeviceEventType::kCHIPoBLEIndicateConfirm: {
ChipLogProgress(DeviceLayer, "_OnPlatformEvent kCHIPoBLEIndicateConfirm");
DeviceLayer::SystemLayer().CancelTimer(OnSendIndicationTimeout, this);
HandleIndicationConfirmation(event->CHIPoBLEIndicateConfirm.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_TX);
}
break;
Expand Down Expand Up @@ -471,12 +489,16 @@ bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUU
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());

if (status != RSI_SUCCESS)
{
ChipLogProgress(DeviceLayer, "indication failed with error code %lx ", status);
return false;
}

// start timer for the indication Confirmation Event
DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(BLE_SEND_INDICATION_TIMER_PERIOD_MS),
OnSendIndicationTimeout, this);
return true;
}

Expand Down Expand Up @@ -927,12 +949,6 @@ void BLEManagerImpl::HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId)
PlatformMgr().PostEventOrDie(&event);
}

// TODO:: Need to Implement
void BLEManagerImpl::HandleSoftTimerEvent(void)
{
// TODO:: Need to Implement
}

bool BLEManagerImpl::RemoveConnection(uint8_t connectionHandle)
{
CHIPoBLEConState * bleConnState = GetConnectionState(connectionHandle, true);
Expand Down

0 comments on commit f5b2712

Please sign in to comment.