Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Silabs][Wi-Fi] Added Implementation for timeouts waiting for a TX Confirmation Event BLE #2

Closed
wants to merge 10 commits into from
3 changes: 3 additions & 0 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 Down
57 changes: 55 additions & 2 deletions src/platform/silabs/rs911x/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,10 @@ namespace {
#define BLE_CONFIG_MAX_CE_LENGTH (0xFFFF) // Leave to max value

#define BLE_DEFAULT_TIMER_PERIOD_MS (1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't these be in the header file?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Header file is common for both efr32 and rs911x so keeping it here

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#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)

I see this code there, so I guess this can be added to this, or this code can be moved from there to here

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

#define BLE_SEND_INDICATION_TIMER_PERIOD_MS (400)
shgutte marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -293,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
BleSendIndicationTimeoutHandler // 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 @@ -471,6 +480,11 @@ 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());

ChipLogProgress(DeviceLayer, "StartTimer start");
shgutte marked this conversation as resolved.
Show resolved Hide resolved
StartBleSendIndicationTimeoutTimer(BLE_SEND_INDICATION_TIMER_PERIOD_MS);
ChipLogProgress(DeviceLayer, "StartTimer Stop");
shgutte marked this conversation as resolved.
Show resolved Hide resolved

if (status != RSI_SUCCESS)
{
ChipLogProgress(DeviceLayer, "indication failed with error code %lx ", status);
Expand Down Expand Up @@ -925,12 +939,20 @@ void BLEManagerImpl::HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId)
event.Type = DeviceEventType::kCHIPoBLEIndicateConfirm;
event.CHIPoBLEIndicateConfirm.ConId = conId;
PlatformMgr().PostEventOrDie(&event);
CancelBleSendIndicationTimeoutTimer();
}

// TODO:: Need to Implement

void BLEManagerImpl::HandleSoftTimerEvent(void)
{
// TODO:: Need to Implement
uint8_t connHandle = 1;
ChipLogProgress(DeviceLayer, "BLEManagerImpl::HandleSoftTimerEvent CHIPOBLE_PROTOCOL_ABORT");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this log ?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log to tell we are aborting the connection because of timeout

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an error case? The function name suggests a handler for Soft Timer Event.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is same in EFR32 as well

ChipDeviceEvent event;
event.Type = DeviceEventType::kCHIPoBLEConnectionError;
event.CHIPoBLEConnectionError.ConId = connHandle;
event.CHIPoBLEConnectionError.Reason = BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT;
ChipLogProgress(DeviceLayer, "BLEManagerImpl::HandleSoftTimerEvent CHIPOBLE_PROTOCOL_ABORT");
shgutte marked this conversation as resolved.
Show resolved Hide resolved
PlatformMgr().PostEventOrDie(&event);
}

bool BLEManagerImpl::RemoveConnection(uint8_t connectionHandle)
Expand Down Expand Up @@ -1101,6 +1123,37 @@ void BLEManagerImpl::StartBleAdvTimeoutTimer(uint32_t aTimeoutInMs)
}
}


void BLEManagerImpl::BleSendIndicationTimeoutHandler(TimerHandle_t xTimer)
{
ChipLogProgress(DeviceLayer, "BleSendIndicationTimeoutHandler::Start");
shgutte marked this conversation as resolved.
Show resolved Hide resolved
sInstance.HandleSoftTimerEvent();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log should be given here and should it be a progress log ?

}

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)
shgutte marked this conversation as resolved.
Show resolved Hide resolved
{
ChipLogError(DeviceLayer, "Failed to start BledAdv timeout timer");
}
}

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