From 11010442cdb7801cf5850548e4e3846545e2060f Mon Sep 17 00:00:00 2001 From: chirag-silabs <100861685+chirag-silabs@users.noreply.github.com> Date: Thu, 27 Apr 2023 01:06:30 +0530 Subject: [PATCH] [Silabs] RS911x not going into power save upon power cycle (#26260) * 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 --- .../platform/silabs/efr32/rs911x/rsi_if.c | 34 ++++++++--------- .../platform/silabs/efr32/rs911x/wfx_rsi.h | 3 ++ .../silabs/efr32/rs911x/wfx_rsi_host.c | 20 ++++++++++ src/platform/silabs/BLEManagerImpl.h | 5 +-- .../silabs/ConnectivityManagerImpl_WIFI.cpp | 13 ++++++- .../silabs/efr32/rs911x/BLEManagerImpl.cpp | 38 +++++-------------- .../silabs/efr32/wifi/wfx_host_events.h | 4 ++ third_party/silabs/efr32_sdk.gni | 11 ++++-- 8 files changed, 75 insertions(+), 53 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/rsi_if.c b/examples/platform/silabs/efr32/rs911x/rsi_if.c index 324f635f3015f0..dae7b0cd4f762e 100644 --- a/examples/platform/silabs/efr32/rs911x/rsi_if.c +++ b/examples/platform/silabs/efr32/rs911x/rsi_if.c @@ -181,6 +181,7 @@ int32_t wfx_rsi_disconnect() return status; } +#if CHIP_DEVICE_CONFIG_ENABLE_SED /****************************************************************** * @fn wfx_rsi_power_save() * @brief @@ -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 @@ -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); @@ -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); diff --git a/examples/platform/silabs/efr32/rs911x/wfx_rsi.h b/examples/platform/silabs/efr32/rs911x/wfx_rsi.h index 846644f2ba7f55..7292970a11c011 100644 --- a/examples/platform/silabs/efr32/rs911x/wfx_rsi.h +++ b/examples/platform/silabs/efr32/rs911x/wfx_rsi.h @@ -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 diff --git a/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c b/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c index 9f89a678dfce0a..0691c21670518a 100644 --- a/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c +++ b/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c @@ -30,6 +30,7 @@ #include "event_groups.h" #include "task.h" +#include "rsi_error.h" #include "wfx_host_events.h" #include "wfx_rsi.h" @@ -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 diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h index 330aad5a1c4be6..da6ce3bb4e3002 100644 --- a/src/platform/silabs/BLEManagerImpl.h +++ b/src/platform/silabs/BLEManagerImpl.h @@ -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); @@ -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 @@ -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 diff --git a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp index edbff853f34e8f..6b10b294b5ad02 100644 --- a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp +++ b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp @@ -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(); } diff --git a/src/platform/silabs/efr32/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/efr32/rs911x/BLEManagerImpl.cpp index f03e9d1356543c..4a910e0a29aae5 100644 --- a/src/platform/silabs/efr32/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/efr32/rs911x/BLEManagerImpl.cpp @@ -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; @@ -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; diff --git a/src/platform/silabs/efr32/wifi/wfx_host_events.h b/src/platform/silabs/efr32/wifi/wfx_host_events.h index 1d41c750517c82..c0724b7237e808 100644 --- a/src/platform/silabs/efr32/wifi/wfx_host_events.h +++ b/src/platform/silabs/efr32/wifi/wfx_host_events.h @@ -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); diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index 97de1caf125afe..f84e257af916f5 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -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