Skip to content

Commit c5ab509

Browse files
[Silabs][SiWx917] 917 SoC and NCP sleepy Improvements for the better power consumption (project-chip#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 <commits@restyled.io>
1 parent fc61ca0 commit c5ab509

15 files changed

+193
-34
lines changed

examples/platform/silabs/BaseApplication.cpp

+25-1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ Identify gIdentify = {
146146
bool BaseApplication::sIsProvisioned = false;
147147
bool BaseApplication::sIsFactoryResetTriggered = false;
148148
LEDWidget * BaseApplication::sAppActionLed = nullptr;
149+
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
150+
BaseApplicationDelegate BaseApplication::sAppDelegate = BaseApplicationDelegate();
151+
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
149152

150153
#ifdef DIC_ENABLE
151154
namespace {
@@ -163,6 +166,28 @@ void AppSpecificConnectivityEventCallback(const ChipDeviceEvent * event, intptr_
163166
} // namespace
164167
#endif // DIC_ENABLE
165168

169+
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
170+
void BaseApplicationDelegate::OnCommissioningSessionStarted()
171+
{
172+
isComissioningStarted = true;
173+
}
174+
void BaseApplicationDelegate::OnCommissioningSessionStopped()
175+
{
176+
isComissioningStarted = false;
177+
}
178+
void BaseApplicationDelegate::OnCommissioningWindowClosed()
179+
{
180+
if (!BaseApplication::GetProvisionStatus() && !isComissioningStarted)
181+
{
182+
int32_t status = wfx_power_save(RSI_SLEEP_MODE_8, STANDBY_POWER_SAVE_WITH_RAM_RETENTION);
183+
if (status != SL_STATUS_OK)
184+
{
185+
ChipLogError(DeviceLayer, "Failed to enable the TA Deep Sleep");
186+
}
187+
}
188+
}
189+
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
190+
166191
/**********************************************************
167192
* AppTask Definitions
168193
*********************************************************/
@@ -261,7 +286,6 @@ CHIP_ERROR BaseApplication::Init()
261286
#if CHIP_ENABLE_OPENTHREAD
262287
BaseApplication::sIsProvisioned = ConnectivityMgr().IsThreadProvisioned();
263288
#endif
264-
265289
return err;
266290
}
267291

examples/platform/silabs/BaseApplication.h

+15
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "FreeRTOS.h"
3131
#include "timers.h" // provides FreeRTOS timer support
3232
#include <app/clusters/identify-server/identify-server.h>
33+
#include <app/server/AppDelegate.h>
3334
#include <app/util/config.h>
3435
#include <ble/BLEEndPoint.h>
3536
#include <lib/core/CHIPError.h>
@@ -62,6 +63,17 @@
6263
#define APP_ERROR_START_TIMER_FAILED CHIP_APPLICATION_ERROR(0x05)
6364
#define APP_ERROR_STOP_TIMER_FAILED CHIP_APPLICATION_ERROR(0x06)
6465

66+
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
67+
class BaseApplicationDelegate : public AppDelegate
68+
{
69+
private:
70+
bool isComissioningStarted;
71+
void OnCommissioningSessionStarted() override;
72+
void OnCommissioningSessionStopped() override;
73+
void OnCommissioningWindowClosed() override;
74+
};
75+
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
76+
6577
/**********************************************************
6678
* BaseApplication Declaration
6779
*********************************************************/
@@ -75,6 +87,9 @@ class BaseApplication
7587
static bool sIsProvisioned;
7688
static bool sIsFactoryResetTriggered;
7789
static LEDWidget * sAppActionLed;
90+
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
91+
static BaseApplicationDelegate sAppDelegate;
92+
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
7893

7994
/**
8095
* @brief Create AppTask task and Event Queue

examples/platform/silabs/MatterConfig.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include "AppConfig.h"
21+
#include "BaseApplication.h"
2122
#include "OTAConfig.h"
2223
#include <MatterConfig.h>
2324

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

258+
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
259+
initParams.appDelegate = &BaseApplication::sAppDelegate;
260+
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
257261
// Init Matter Server and Start Event Loop
258262
err = chip::Server::GetInstance().Init(initParams);
259263

@@ -303,10 +307,6 @@ CHIP_ERROR SilabsMatterConfig::InitWiFi(void)
303307
extern "C" void vApplicationIdleHook(void)
304308
{
305309
#if SIWX_917 && CHIP_CONFIG_ENABLE_ICD_SERVER
306-
if (ConnectivityMgr().IsWiFiStationConnected())
307-
{
308-
// Let the M4 sleep once commissioning is done and device is in idle state
309-
sl_wfx_host_si91x_sleep_wakeup();
310-
}
310+
sl_wfx_host_si91x_sleep_wakeup();
311311
#endif
312312
}

examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c

+22-9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#if SL_ICD_ENABLED && SIWX_917
4545
#include "rsi_rom_power_save.h"
4646
#include "sl_si91x_button_pin_config.h"
47+
#include "sl_si91x_driver.h"
4748
#include "sl_si91x_m4_ps.h"
4849

4950
// TODO: should be removed once we are getting the press interrupt for button 0 with sleep
@@ -188,8 +189,8 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t
188189
SILABS_LOG("F: Join Event received with %u bytes payload\n", result_length);
189190
callback_status = *(sl_status_t *) result;
190191
wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTED);
191-
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries++);
192192
is_wifi_disconnection_event = true;
193+
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries++);
193194
if (is_wifi_disconnection_event || wfx_rsi.join_retries <= WFX_RSI_CONFIG_MAX_JOIN)
194195
{
195196
xEventGroupSetBits(wfx_rsi.events, WFX_EVT_STA_START_JOIN);
@@ -256,28 +257,36 @@ void sl_wfx_host_si91x_sleep_wakeup()
256257
* @brief
257258
* Setting the RS911x in DTIM sleep based mode
258259
*
259-
* @param[in] None
260+
* @param[in] sl_si91x_ble_state : State to set for the BLE
261+
sl_si91x_wifi_state : State to set for the WiFi
260262
* @return
261263
* None
262264
*********************************************************************/
263-
int32_t wfx_rsi_power_save()
265+
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)
264266
{
265267
int32_t status;
266-
status = rsi_bt_power_save_profile(2, 0);
268+
269+
status = rsi_bt_power_save_profile(sl_si91x_ble_state, 0);
267270
if (status != RSI_SUCCESS)
268271
{
269272
SILABS_LOG("BT Powersave Config Failed, Error Code : 0x%lX", status);
270273
return status;
271274
}
272-
273-
sl_wifi_performance_profile_t wifi_profile = { .profile = ASSOCIATED_POWER_SAVE };
275+
sl_wifi_performance_profile_t wifi_profile = { .profile = sl_si91x_wifi_state };
274276
status = sl_wifi_set_performance_profile(&wifi_profile);
275277
if (status != RSI_SUCCESS)
276278
{
277279
SILABS_LOG("Powersave Config Failed, Error Code : 0x%lX", status);
278280
return status;
279281
}
280-
wfx_rsi.dev_state |= WFX_RSI_ST_SLEEP_READY;
282+
if (sl_si91x_wifi_state == HIGH_PERFORMANCE)
283+
{
284+
wfx_rsi.dev_state &= ~(WFX_RSI_ST_SLEEP_READY);
285+
}
286+
else
287+
{
288+
wfx_rsi.dev_state |= WFX_RSI_ST_SLEEP_READY;
289+
}
281290
return status;
282291
}
283292
#endif /* SL_ICD_ENABLED */
@@ -376,7 +385,7 @@ static sl_status_t wfx_rsi_init(void)
376385
}
377386

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

582591
sl_wifi_set_join_callback(join_callback_handler, NULL);
583592

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

598+
sl_wifi_advanced_client_configuration_t client_config = { .max_retry_attempts = 5 };
599+
sl_wifi_set_advanced_client_configuration(SL_WIFI_CLIENT_INTERFACE, &client_config);
600+
#endif // SL_ICD_ENABLED
588601
/* Try to connect Wifi with given Credentials
589602
* untill there is a success or maximum number of tries allowed
590603
*/
@@ -629,11 +642,11 @@ static sl_status_t wfx_rsi_do_join(void)
629642
wfx_rsi.join_retries);
630643
wfx_rsi.join_retries += 1;
631644
wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED);
645+
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries);
632646
if (is_wifi_disconnection_event || wfx_rsi.join_retries <= MAX_JOIN_RETRIES_COUNT)
633647
{
634648
xEventGroupSetBits(wfx_rsi.events, WFX_EVT_STA_START_JOIN);
635649
}
636-
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries);
637650
}
638651
}
639652
}

examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ int32_t wfx_rsi_disconnect();
9595
int32_t wfx_wifi_rsi_init(void);
9696
#if SL_ICD_ENABLED
9797
void sl_wfx_host_si91x_sleep_wakeup();
98-
int32_t wfx_rsi_power_save();
98+
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);
9999
#endif /* SL_ICD_ENABLED */
100100

101101
#ifdef __cplusplus

examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,14 @@ sl_status_t wfx_connect_to_ap(void)
194194
* @fn sl_status_t wfx_power_save()
195195
* @brief
196196
* Implements the power save in sleepy application
197-
* @param[in] None
197+
* @param[in] sl_si91x_ble_state : State to set for the BLE
198+
sl_si91x_wifi_state : State to set for the WiFi
198199
* @return SL_STATUS_OK if successful,
199200
* SL_STATUS_FAIL otherwise
200201
***********************************************************************/
201-
sl_status_t wfx_power_save()
202+
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)
202203
{
203-
if (wfx_rsi_power_save() != SL_STATUS_OK)
204+
if (wfx_rsi_power_save(sl_si91x_ble_state, sl_si91x_wifi_state) != SL_STATUS_OK)
204205
{
205206
return SL_STATUS_FAIL;
206207
}

examples/platform/silabs/efr32/rs911x/hal/sl_board_configuration.h

-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,4 @@ typedef struct
4848
#define INTERRUPT_PIN PIN(A, 7)
4949
#define SLEEP_CONFIRM_PIN PIN(A, 5) /* Exp hdr 7 */
5050
#endif
51-
52-
#define NETWORK_INTERFACE_VALID(x) (x == SL_NET_DEFAULT_WIFI_CLIENT_INTERFACE) || (x == SL_NET_DEFAULT_WIFI_AP_INTERFACE)
5351
#endif /* _RSI_BOARD_CONFIGURATION_H_ */

examples/platform/silabs/efr32/rs911x/wfx_rsi.h

+4
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info);
9292
int32_t wfx_rsi_reset_count();
9393
int32_t wfx_rsi_disconnect();
9494
#if SL_ICD_ENABLED
95+
#if SLI_SI917
96+
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);
97+
#else
9598
int32_t wfx_rsi_power_save();
99+
#endif /* SLI_SI917 */
96100
#endif /* SL_ICD_ENABLED */
97101

98102
#ifdef __cplusplus

examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c

+16
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,21 @@ sl_status_t wfx_connect_to_ap(void)
192192
}
193193

194194
#if SL_ICD_ENABLED
195+
#if SLI_SI917
196+
/*********************************************************************
197+
* @fn sl_status_t wfx_power_save()
198+
* @brief
199+
* Implements the power save in sleepy application
200+
* @param[in] sl_si91x_ble_state : State to set for the BLE
201+
sl_si91x_wifi_state : State to set for the WiFi
202+
* @return SL_STATUS_OK if successful,
203+
* SL_STATUS_FAIL otherwise
204+
***********************************************************************/
205+
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)
206+
{
207+
return (wfx_rsi_power_save(sl_si91x_ble_state, sl_si91x_wifi_state) ? SL_STATUS_FAIL : SL_STATUS_OK);
208+
}
209+
#else // For RS9116
195210
/*********************************************************************
196211
* @fn sl_status_t wfx_power_save()
197212
* @brief
@@ -204,6 +219,7 @@ sl_status_t wfx_power_save()
204219
{
205220
return (wfx_rsi_power_save() ? SL_STATUS_FAIL : SL_STATUS_OK);
206221
}
222+
#endif /* SLI_SI917 */
207223
#endif /* SL_ICD_ENABLED */
208224

209225
/*********************************************************************

src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,11 @@ void ConnectivityManagerImpl::OnStationConnected()
368368
(void) PlatformMgr().PostEvent(&event);
369369
// Setting the rs911x in the power save mode
370370
#if (CHIP_CONFIG_ENABLE_ICD_SERVER && RS911X_WIFI)
371+
#if SLI_SI917
372+
sl_status_t err = wfx_power_save(RSI_SLEEP_MODE_2, ASSOCIATED_POWER_SAVE);
373+
#else
371374
sl_status_t err = wfx_power_save();
375+
#endif /* SLI_SI917 */
372376
if (err != SL_STATUS_OK)
373377
{
374378
ChipLogError(DeviceLayer, "Power save config for Wifi failed");

0 commit comments

Comments
 (0)