Skip to content

Commit

Permalink
[Silabs] RS911x not going into power save upon power cycle (#26260)
Browse files Browse the repository at this point in the history
* Calling power save at only position

* stopping the ble advertisement after sta was connected

* removing the condition for wf200 and keeping it only for rs9116

* addressing review comments

* Restyled by clang-format

* Restyled by gn

* address review comments

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jan 17, 2024
1 parent 556e505 commit 4535372
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 53 deletions.
34 changes: 17 additions & 17 deletions examples/platform/silabs/efr32/rs911x/rsi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ int32_t wfx_rsi_disconnect()
return status;
}

#if CHIP_DEVICE_CONFIG_ENABLE_SED
/******************************************************************
* @fn wfx_rsi_power_save()
* @brief
Expand All @@ -190,16 +191,29 @@ int32_t wfx_rsi_disconnect()
* @return
* None
*********************************************************************/
void wfx_rsi_power_save()
int32_t wfx_rsi_power_save()
{
int32_t status = rsi_wlan_power_save_profile(RSI_SLEEP_MODE_2, RSI_MAX_PSP);
int32_t status;
#ifdef RSI_BLE_ENABLE
status = rsi_bt_power_save_profile(RSI_SLEEP_MODE_2, RSI_MAX_PSP);
if (status != RSI_SUCCESS)
{
SILABS_LOG("BT Powersave Config Failed, Error Code : 0x%lX", status);
return status;
}
#endif /* RSI_BLE_ENABLE */

status = rsi_wlan_power_save_profile(RSI_SLEEP_MODE_2, RSI_MAX_PSP);
if (status != RSI_SUCCESS)
{
SILABS_LOG("Powersave Config Failed, Error Code : 0x%lX", status);
return;
return status;
}
SILABS_LOG("Powersave Config Success");
return status;
}
#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */

/******************************************************************
* @fn wfx_rsi_join_cb(uint16_t status, const uint8_t *buf, const uint16_t len)
* @brief
Expand Down Expand Up @@ -596,13 +610,6 @@ void wfx_rsi_task(void * arg)
{
wfx_dhcp_got_ipv4((uint32_t) sta_netif->ip_addr.u_addr.ip4.addr);
hasNotifiedIPV4 = true;
#if CHIP_DEVICE_CONFIG_ENABLE_SED
#ifndef RSI_BLE_ENABLE
// enabling the power save mode for RS9116 if sleepy device is enabled
// if BLE is used on the rs9116 then powersave config is done after ble disconnect event
wfx_rsi_power_save();
#endif /* RSI_BLE_ENABLE */
#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */
if (!hasNotifiedWifiConnectivity)
{
wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac);
Expand All @@ -622,13 +629,6 @@ void wfx_rsi_task(void * arg)
{
wfx_ipv6_notify(GET_IPV6_SUCCESS);
hasNotifiedIPV6 = true;
#if CHIP_DEVICE_CONFIG_ENABLE_SED
#ifndef RSI_BLE_ENABLE
// enabling the power save mode for RS9116 if sleepy device is enabled
// if BLE is used on the rs9116 then powersave config is done after ble disconnect event
wfx_rsi_power_save();
#endif /* RSI_BLE_ENABLE */
#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */
if (!hasNotifiedWifiConnectivity)
{
wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac);
Expand Down
3 changes: 3 additions & 0 deletions examples/platform/silabs/efr32/rs911x/wfx_rsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap);
int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info);
int32_t wfx_rsi_reset_count();
int32_t wfx_rsi_disconnect();
#if CHIP_DEVICE_CONFIG_ENABLE_SED
int32_t wfx_rsi_power_save();
#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */
#define SILABS_LOG(...) efr32Log(__VA_ARGS__);

#ifdef __cplusplus
Expand Down
20 changes: 20 additions & 0 deletions examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "event_groups.h"
#include "task.h"

#include "rsi_error.h"
#include "wfx_host_events.h"
#include "wfx_rsi.h"

Expand Down Expand Up @@ -195,6 +196,25 @@ sl_status_t wfx_connect_to_ap(void)
return SL_STATUS_OK;
}

#if CHIP_DEVICE_CONFIG_ENABLE_SED
/*********************************************************************
* @fn sl_status_t wfx_power_save()
* @brief
* Implements the power save in sleepy application
* @param[in] None
* @return SL_STATUS_OK if successful,
* SL_STATUS_FAIL otherwise
***********************************************************************/
sl_status_t wfx_power_save()
{
if (wfx_rsi_power_save() != RSI_ERROR_NONE)
{
return SL_STATUS_FAIL;
}
return SL_STATUS_OK;
}
#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */

/*********************************************************************
* @fn void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif)
* @brief
Expand Down
5 changes: 2 additions & 3 deletions src/platform/silabs/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
void HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId);
void HandleTXCharCCCDWrite(rsi_ble_event_write_t * evt);
void HandleSoftTimerEvent(void);
CHIP_ERROR StartAdvertising(void);
#else
void HandleConnectEvent(volatile sl_bt_msg_t * evt);
void HandleConnectionCloseEvent(volatile sl_bt_msg_t * evt);
Expand All @@ -81,8 +80,9 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
void HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId);
void HandleTXCharCCCDWrite(volatile sl_bt_msg_t * evt);
void HandleSoftTimerEvent(volatile sl_bt_msg_t * evt);
CHIP_ERROR StartAdvertising(void);
#endif // RSI_BLE_ENABLE
CHIP_ERROR StartAdvertising(void);
CHIP_ERROR StopAdvertising(void);

#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
#ifdef RSI_BLE_ENABLE
Expand Down Expand Up @@ -187,7 +187,6 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
CHIP_ERROR MapBLEError(int bleErr);
void DriveBLEState(void);
CHIP_ERROR ConfigureAdvertisingData(void);
CHIP_ERROR StopAdvertising(void);
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
CHIP_ERROR EncodeAdditionalDataTlv();
#endif
Expand Down
13 changes: 12 additions & 1 deletion src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,18 @@ void ConnectivityManagerImpl::OnStationConnected()
event.Type = DeviceEventType::kWiFiConnectivityChange;
event.WiFiConnectivityChange.Result = kConnectivity_Established;
(void) PlatformMgr().PostEvent(&event);

// Setting the rs911x in the power save mode
#if (CHIP_DEVICE_CONFIG_ENABLE_SED && RS911X_WIFI)
// TODO: Remove stop advertising after BLEManagerImpl is fixed
#if RSI_BLE_ENABLE
chip::DeviceLayer::Internal::BLEManagerImpl().StopAdvertising();
#endif /* RSI_BLE_ENABLE */
sl_status_t err = wfx_power_save();
if (err != SL_STATUS_OK)
{
ChipLogError(DeviceLayer, "Power save config for Wifi failed");
}
#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED && RS911X_WIFI */
UpdateInternetConnectivityState();
}

Expand Down
38 changes: 9 additions & 29 deletions src/platform/silabs/efr32/rs911x/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,23 +661,21 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
return CHIP_NO_ERROR; // err;
}

// TODO:: Implementation need to be done.
CHIP_ERROR BLEManagerImpl::StopAdvertising(void)
{
CHIP_ERROR err = CHIP_NO_ERROR;
int32_t status = 0;
if (mFlags.Has(Flags::kAdvertising))
// TODO: add the below code in a condition if (mFlags.Has(Flags::kAdvertising))
// Since DriveBLEState is not called the device is still advertising
mFlags.Clear(Flags::kAdvertising).Clear(Flags::kRestartAdvertising);
mFlags.Set(Flags::kFastAdvertisingEnabled, true);
status = rsi_ble_stop_advertising();
if (status != RSI_SUCCESS)
{
mFlags.Clear(Flags::kAdvertising).Clear(Flags::kRestartAdvertising);
mFlags.Set(Flags::kFastAdvertisingEnabled, true);
status = rsi_ble_stop_advertising();
if (status != RSI_SUCCESS)
{
ChipLogProgress(DeviceLayer, "advertising failed to stop, with status = 0x%lx", status);
}
advertising_set_handle = 0xff;
CancelBleAdvTimeoutTimer();
ChipLogProgress(DeviceLayer, "advertising failed to stop, with status = 0x%lx", status);
}
advertising_set_handle = 0xff;
CancelBleAdvTimeoutTimer();

// exit:
return err;
Expand Down Expand Up @@ -723,24 +721,6 @@ void BLEManagerImpl::HandleConnectionCloseEvent(uint16_t reason)

ChipLogProgress(DeviceLayer, "Disconnect Event for handle : %d", connHandle);

#if CHIP_DEVICE_CONFIG_ENABLE_SED
int32_t status;
status = rsi_bt_power_save_profile(RSI_SLEEP_MODE_2, RSI_MAX_PSP);
if (status != RSI_SUCCESS)
{
SILABS_LOG("BT Powersave Config Failed, Error Code : 0x%lX", status);
return;
}

status = rsi_wlan_power_save_profile(RSI_SLEEP_MODE_2, RSI_MAX_PSP);
if (status != RSI_SUCCESS)
{
SILABS_LOG("WLAN Powersave Config Failed, Error Code : 0x%lX", status);
return;
}
SILABS_LOG("Powersave Config Success");
#endif

if (RemoveConnection(connHandle))
{
ChipDeviceEvent event;
Expand Down
4 changes: 4 additions & 0 deletions src/platform/silabs/efr32/wifi/wfx_host_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ void wfx_ip_changed_notify(int got_ip);
void wfx_ipv6_notify(int got_ip);

#ifdef RS911X_WIFI
/* RSI Power Save */
#if CHIP_DEVICE_CONFIG_ENABLE_SED
sl_status_t wfx_power_save();
#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */
/* RSI for LWIP */
void * wfx_rsi_alloc_pkt(void);
void wfx_rsi_pkt_add_data(void * p, uint8_t * buf, uint16_t len, uint16_t off);
Expand Down
11 changes: 8 additions & 3 deletions third_party/silabs/efr32_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,15 @@ template("efr32_sdk") {
"SL_CATALOG_POWER_MANAGER_PRESENT",
"SL_CATALOG_SLEEPTIMER_PRESENT",
"SL_SLEEP_TIME_MS=${sleep_time_ms}",

# Used for wifi devices to get packet details
"WIFI_DEBUG_ENABLED=1",
]

if (defined(invoker.chip_enable_wifi) && invoker.chip_enable_wifi) {
defines += [
# Used for wifi devices to get packet details
# TODO: Remove this flag, once the communication is fixed
"WIFI_DEBUG_ENABLED=1",
]
}
}

if (chip_build_libshell) { # matter shell
Expand Down

0 comments on commit 4535372

Please sign in to comment.