Skip to content

Commit

Permalink
[Silabs][SiWx917] 917 SoC and NCP sleepy Improvements for the better …
Browse files Browse the repository at this point in the history
…power consumption (#32216)

* letting our device sleep when it is uncommissioned

* using the default clk for the 917 SoC

* reducing the firmware retry to 5

* formatting changes reverting which was not needed

* Restyled by clang-format

* fix the warning for the 917 SoC

* Restyled by clang-format

* addressing review comments

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Apr 25, 2024
1 parent 37cdb5f commit 2798185
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 34 deletions.
26 changes: 25 additions & 1 deletion examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ Identify gIdentify = {
bool BaseApplication::sIsProvisioned = false;
bool BaseApplication::sIsFactoryResetTriggered = false;
LEDWidget * BaseApplication::sAppActionLed = nullptr;
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
BaseApplicationDelegate BaseApplication::sAppDelegate = BaseApplicationDelegate();
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917

#ifdef DIC_ENABLE
namespace {
Expand All @@ -163,6 +166,28 @@ void AppSpecificConnectivityEventCallback(const ChipDeviceEvent * event, intptr_
} // namespace
#endif // DIC_ENABLE

#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
void BaseApplicationDelegate::OnCommissioningSessionStarted()
{
isComissioningStarted = true;
}
void BaseApplicationDelegate::OnCommissioningSessionStopped()
{
isComissioningStarted = false;
}
void BaseApplicationDelegate::OnCommissioningWindowClosed()
{
if (!BaseApplication::GetProvisionStatus() && !isComissioningStarted)
{
int32_t status = wfx_power_save(RSI_SLEEP_MODE_8, STANDBY_POWER_SAVE_WITH_RAM_RETENTION);
if (status != SL_STATUS_OK)
{
ChipLogError(DeviceLayer, "Failed to enable the TA Deep Sleep");
}
}
}
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917

/**********************************************************
* AppTask Definitions
*********************************************************/
Expand Down Expand Up @@ -261,7 +286,6 @@ CHIP_ERROR BaseApplication::Init()
#if CHIP_ENABLE_OPENTHREAD
BaseApplication::sIsProvisioned = ConnectivityMgr().IsThreadProvisioned();
#endif

return err;
}

Expand Down
15 changes: 15 additions & 0 deletions examples/platform/silabs/BaseApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "FreeRTOS.h"
#include "timers.h" // provides FreeRTOS timer support
#include <app/clusters/identify-server/identify-server.h>
#include <app/server/AppDelegate.h>
#include <app/util/config.h>
#include <ble/BLEEndPoint.h>
#include <lib/core/CHIPError.h>
Expand Down Expand Up @@ -62,6 +63,17 @@
#define APP_ERROR_START_TIMER_FAILED CHIP_APPLICATION_ERROR(0x05)
#define APP_ERROR_STOP_TIMER_FAILED CHIP_APPLICATION_ERROR(0x06)

#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
class BaseApplicationDelegate : public AppDelegate
{
private:
bool isComissioningStarted;
void OnCommissioningSessionStarted() override;
void OnCommissioningSessionStopped() override;
void OnCommissioningWindowClosed() override;
};
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917

/**********************************************************
* BaseApplication Declaration
*********************************************************/
Expand All @@ -75,6 +87,9 @@ class BaseApplication
static bool sIsProvisioned;
static bool sIsFactoryResetTriggered;
static LEDWidget * sAppActionLed;
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
static BaseApplicationDelegate sAppDelegate;
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917

/**
* @brief Create AppTask task and Event Queue
Expand Down
10 changes: 5 additions & 5 deletions examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "AppConfig.h"
#include "BaseApplication.h"
#include "OTAConfig.h"
#include <MatterConfig.h>

Expand Down Expand Up @@ -254,6 +255,9 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
initParams.endpointNativeParams = static_cast<void *>(&nativeParams);
#endif

#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
initParams.appDelegate = &BaseApplication::sAppDelegate;
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
// Init Matter Server and Start Event Loop
err = chip::Server::GetInstance().Init(initParams);

Expand Down Expand Up @@ -303,10 +307,6 @@ CHIP_ERROR SilabsMatterConfig::InitWiFi(void)
extern "C" void vApplicationIdleHook(void)
{
#if SIWX_917 && CHIP_CONFIG_ENABLE_ICD_SERVER
if (ConnectivityMgr().IsWiFiStationConnected())
{
// Let the M4 sleep once commissioning is done and device is in idle state
sl_wfx_host_si91x_sleep_wakeup();
}
sl_wfx_host_si91x_sleep_wakeup();
#endif
}
31 changes: 22 additions & 9 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#if SL_ICD_ENABLED && SIWX_917
#include "rsi_rom_power_save.h"
#include "sl_si91x_button_pin_config.h"
#include "sl_si91x_driver.h"
#include "sl_si91x_m4_ps.h"

// TODO: should be removed once we are getting the press interrupt for button 0 with sleep
Expand Down Expand Up @@ -188,8 +189,8 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t
SILABS_LOG("F: Join Event received with %u bytes payload\n", result_length);
callback_status = *(sl_status_t *) result;
wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTED);
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries++);
is_wifi_disconnection_event = true;
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries++);
if (is_wifi_disconnection_event || wfx_rsi.join_retries <= WFX_RSI_CONFIG_MAX_JOIN)
{
xEventGroupSetBits(wfx_rsi.events, WFX_EVT_STA_START_JOIN);
Expand Down Expand Up @@ -256,28 +257,36 @@ void sl_wfx_host_si91x_sleep_wakeup()
* @brief
* Setting the RS911x in DTIM sleep based mode
*
* @param[in] None
* @param[in] sl_si91x_ble_state : State to set for the BLE
sl_si91x_wifi_state : State to set for the WiFi
* @return
* None
*********************************************************************/
int32_t wfx_rsi_power_save()
int32_t wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state)
{
int32_t status;
status = rsi_bt_power_save_profile(2, 0);

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

sl_wifi_performance_profile_t wifi_profile = { .profile = ASSOCIATED_POWER_SAVE };
sl_wifi_performance_profile_t wifi_profile = { .profile = sl_si91x_wifi_state };
status = sl_wifi_set_performance_profile(&wifi_profile);
if (status != RSI_SUCCESS)
{
SILABS_LOG("Powersave Config Failed, Error Code : 0x%lX", status);
return status;
}
wfx_rsi.dev_state |= WFX_RSI_ST_SLEEP_READY;
if (sl_si91x_wifi_state == HIGH_PERFORMANCE)
{
wfx_rsi.dev_state &= ~(WFX_RSI_ST_SLEEP_READY);
}
else
{
wfx_rsi.dev_state |= WFX_RSI_ST_SLEEP_READY;
}
return status;
}
#endif /* SL_ICD_ENABLED */
Expand Down Expand Up @@ -376,7 +385,7 @@ static sl_status_t wfx_rsi_init(void)
}

// Initiate and program the key required for TRNG hardware engine
status = sl_si91x_trng_program_key(trngKey, TRNGKEY_SIZE);
status = sl_si91x_trng_program_key((uint32_t *) trngKey, TRNGKEY_SIZE);
if (status != SL_STATUS_OK)
{
SILABS_LOG("TRNG Key Programming Failed");
Expand Down Expand Up @@ -581,10 +590,14 @@ static sl_status_t wfx_rsi_do_join(void)

sl_wifi_set_join_callback(join_callback_handler, NULL);

#if SL_ICD_ENABLED
// Setting the listen interval to 0 which will set it to DTIM interval
sl_wifi_listen_interval_t sleep_interval = { .listen_interval = 0 };
status = sl_wifi_set_listen_interval(SL_WIFI_CLIENT_INTERFACE, sleep_interval);

sl_wifi_advanced_client_configuration_t client_config = { .max_retry_attempts = 5 };
sl_wifi_set_advanced_client_configuration(SL_WIFI_CLIENT_INTERFACE, &client_config);
#endif // SL_ICD_ENABLED
/* Try to connect Wifi with given Credentials
* untill there is a success or maximum number of tries allowed
*/
Expand Down Expand Up @@ -629,11 +642,11 @@ static sl_status_t wfx_rsi_do_join(void)
wfx_rsi.join_retries);
wfx_rsi.join_retries += 1;
wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED);
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries);
if (is_wifi_disconnection_event || wfx_rsi.join_retries <= MAX_JOIN_RETRIES_COUNT)
{
xEventGroupSetBits(wfx_rsi.events, WFX_EVT_STA_START_JOIN);
}
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int32_t wfx_rsi_disconnect();
int32_t wfx_wifi_rsi_init(void);
#if SL_ICD_ENABLED
void sl_wfx_host_si91x_sleep_wakeup();
int32_t wfx_rsi_power_save();
int32_t wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state);
#endif /* SL_ICD_ENABLED */

#ifdef __cplusplus
Expand Down
7 changes: 4 additions & 3 deletions examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,14 @@ sl_status_t wfx_connect_to_ap(void)
* @fn sl_status_t wfx_power_save()
* @brief
* Implements the power save in sleepy application
* @param[in] None
* @param[in] sl_si91x_ble_state : State to set for the BLE
sl_si91x_wifi_state : State to set for the WiFi
* @return SL_STATUS_OK if successful,
* SL_STATUS_FAIL otherwise
***********************************************************************/
sl_status_t wfx_power_save()
sl_status_t wfx_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state)
{
if (wfx_rsi_power_save() != SL_STATUS_OK)
if (wfx_rsi_power_save(sl_si91x_ble_state, sl_si91x_wifi_state) != SL_STATUS_OK)
{
return SL_STATUS_FAIL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,4 @@ typedef struct
#define INTERRUPT_PIN PIN(A, 7)
#define SLEEP_CONFIRM_PIN PIN(A, 5) /* Exp hdr 7 */
#endif

#define NETWORK_INTERFACE_VALID(x) (x == SL_NET_DEFAULT_WIFI_CLIENT_INTERFACE) || (x == SL_NET_DEFAULT_WIFI_AP_INTERFACE)
#endif /* _RSI_BOARD_CONFIGURATION_H_ */
4 changes: 4 additions & 0 deletions examples/platform/silabs/efr32/rs911x/wfx_rsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ 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 SL_ICD_ENABLED
#if SLI_SI917
int32_t wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state);
#else
int32_t wfx_rsi_power_save();
#endif /* SLI_SI917 */
#endif /* SL_ICD_ENABLED */

#ifdef __cplusplus
Expand Down
16 changes: 16 additions & 0 deletions examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ sl_status_t wfx_connect_to_ap(void)
}

#if SL_ICD_ENABLED
#if SLI_SI917
/*********************************************************************
* @fn sl_status_t wfx_power_save()
* @brief
* Implements the power save in sleepy application
* @param[in] sl_si91x_ble_state : State to set for the BLE
sl_si91x_wifi_state : State to set for the WiFi
* @return SL_STATUS_OK if successful,
* SL_STATUS_FAIL otherwise
***********************************************************************/
sl_status_t wfx_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state)
{
return (wfx_rsi_power_save(sl_si91x_ble_state, sl_si91x_wifi_state) ? SL_STATUS_FAIL : SL_STATUS_OK);
}
#else // For RS9116
/*********************************************************************
* @fn sl_status_t wfx_power_save()
* @brief
Expand All @@ -204,6 +219,7 @@ sl_status_t wfx_power_save()
{
return (wfx_rsi_power_save() ? SL_STATUS_FAIL : SL_STATUS_OK);
}
#endif /* SLI_SI917 */
#endif /* SL_ICD_ENABLED */

/*********************************************************************
Expand Down
4 changes: 4 additions & 0 deletions src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,11 @@ void ConnectivityManagerImpl::OnStationConnected()
(void) PlatformMgr().PostEvent(&event);
// Setting the rs911x in the power save mode
#if (CHIP_CONFIG_ENABLE_ICD_SERVER && RS911X_WIFI)
#if SLI_SI917
sl_status_t err = wfx_power_save(RSI_SLEEP_MODE_2, ASSOCIATED_POWER_SAVE);
#else
sl_status_t err = wfx_power_save();
#endif /* SLI_SI917 */
if (err != SL_STATUS_OK)
{
ChipLogError(DeviceLayer, "Power save config for Wifi failed");
Expand Down
Loading

0 comments on commit 2798185

Please sign in to comment.