Skip to content

Commit

Permalink
Pull request project-chip#1621: Adds configUSE_TICKLESS_IDLE 1 suppor…
Browse files Browse the repository at this point in the history
…t for SiWx917

Merge in WMN_TOOLS/matter from feature/MATTER-2705-add-rtc-timer/RC_2.3.0-1.3-alpha.2-hotfix to RC_2.3.0-1.3-alpha.3

Squashed commit of the following:

commit 0d04f32fc513761866f0f57ddb7ab8916af1b76e
Author: chbansal <chirag.bansal@silabs.com>
Date:   Sat Mar 9 12:29:42 2024 +0530

    refactoring post wakeup proceeds

commit 1b7e78b7e82e3942ec2dd7cefb1cd13e562a0788
Author: Rohan Sahay <rohan.sahay@silabs.com>
Date:   Fri Mar 8 16:51:09 2024 +0530

    Remove unnecessary include statement

commit d5ee0fbc532f9c03ddc77026859981323ecebd38
Author: Rohan Sahay <rohan.sahay@silabs.com>
Date:   Fri Mar 8 16:44:17 2024 +0530

    Update SiWx917_sdk.gni to use si91x_alarm_based_periodic_wakeup instead of si91x_alarm_based_wakeup

... and 23 more commits
  • Loading branch information
rosahay-silabs authored and mkardous-silabs committed Mar 9, 2024
1 parent 84203f3 commit 8f34809
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 68 deletions.
14 changes: 12 additions & 2 deletions examples/platform/silabs/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,21 @@ extern uint32_t SystemCoreClock;
/* Energy saving modes. */
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
#define configUSE_TICKLESS_IDLE 1
#elif SL_ICD_ENABLED && SIWX_917
#define configUSE_TICKLESS_IDLE 1
#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 70
#define configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING(x) vTaskPreSuppressTicksAndSleepProcessing(&x)
#define configPRE_SLEEP_PROCESSING(x) sl_wfx_host_si91x_sleep(&x)
#define configPOST_SLEEP_PROCESSING(x) sl_si91x_post_sleep_update_ticks(&x)
#else
#define configUSE_TICKLESS_IDLE 0
#endif // SL_CATALOG_POWER_MANAGER_PRESENT

#if defined(SIWX_917)
#define configTICK_RATE_HZ (1000)
#else
#define configTICK_RATE_HZ (1024)
#endif // SIWX_917
/* Definition used by Keil to replace default system clock source. */
#define configOVERRIDE_DEFAULT_TICK_CONFIGURATION 1

Expand Down Expand Up @@ -203,8 +213,8 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_PRIORITIES (56)
#if SIWX_917 && SL_ICD_ENABLED
#define configMINIMAL_STACK_SIZE (1024) /* Number of words to use for Idle and Timer stacks */
#else // For EFR32
#define configMINIMAL_STACK_SIZE (320) /* Number of words to use for Idle and Timer stacks */
#else // For EFR32
#define configMINIMAL_STACK_SIZE (320) /* Number of words to use for Idle and Timer stacks */
#endif

#ifdef HEAP_MONITORING
Expand Down
17 changes: 15 additions & 2 deletions examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,22 @@ CHIP_ERROR SilabsMatterConfig::InitWiFi(void)
// ================================================================================
// FreeRTOS Callbacks
// ================================================================================
#if SIWX_917 && CHIP_CONFIG_ENABLE_ICD_SERVER
static bool is_sleep_ready = false;
void vTaskPreSuppressTicksAndSleepProcessing(uint16_t * xExpectedIdleTime)
{
if (!is_sleep_ready)
{
*xExpectedIdleTime = 0;
}
}
#endif // SIWX_917 && CHIP_CONFIG_ENABLE_ICD_SERVER

extern "C" void vApplicationIdleHook(void)
{
#if SIWX_917 && CHIP_CONFIG_ENABLE_ICD_SERVER
sl_wfx_host_si91x_sleep_wakeup();
#endif
invoke_btn_press_event();
// is_sleep_ready is required since wfx_is_sleep_ready() is not FreeRTOS scheduler agnostic
is_sleep_ready = wfx_is_sleep_ready();
#endif // SIWX_917 && CHIP_CONFIG_ENABLE_ICD_SERVER
}
80 changes: 47 additions & 33 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
#if SL_ICD_ENABLED && SIWX_917
#include "rsi_rom_power_save.h"
#include "sl_si91x_button_pin_config.h"
#include "sl_si91x_m4_ps.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
#define BUTTON_PRESSED 1
Expand Down Expand Up @@ -214,38 +214,51 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t
}

#if SL_ICD_ENABLED

#if SIWX_917
/******************************************************************
* @fn sl_wfx_host_si91x_sleep_wakeup()
* @brief
* M4 going to sleep
*
* @param[in] None
* @return
* None
*********************************************************************/
void sl_wfx_host_si91x_sleep_wakeup()
// Required to invoke button press event during sleep as falling edge is not detected
void invoke_btn_press_event()
{
if (wfx_rsi.dev_state & WFX_RSI_ST_SLEEP_READY)
// TODO: should be removed once we are getting the press interrupt for button 0 with sleep
if (!RSI_NPSSGPIO_GetPin(SL_BUTTON_BTN0_PIN) && !btn0_pressed)
{
// TODO: should be removed once we are getting the press interrupt for button 0 with sleep
if (!RSI_NPSSGPIO_GetPin(SL_BUTTON_BTN0_PIN) && !btn0_pressed)
{
sl_button_on_change(SL_BUTTON_BTN0_NUMBER, BUTTON_PRESSED);
btn0_pressed = true;
}
if (RSI_NPSSGPIO_GetPin(SL_BUTTON_BTN0_PIN))
{
btn0_pressed = false;
/* Configure RAM Usage and Retention Size */
sl_si91x_m4_sleep_wakeup();
#if SILABS_LOG_ENABLED
silabsInitLog();
#endif
}
sl_button_on_change(SL_BUTTON_BTN0_NUMBER, BUTTON_PRESSED);
btn0_pressed = true;
}
if (RSI_NPSSGPIO_GetPin(SL_BUTTON_BTN0_PIN))
{
btn0_pressed = false;
}
}

/**
* @brief Checks if the Wi-Fi module is ready for sleep.
*
* This function checks if the Wi-Fi module is ready to enter sleep mode.
*
* @return true if the Wi-Fi module is ready for sleep, false otherwise.
*/
bool wfx_is_sleep_ready()
{
// BRD4002A board BTN_PRESS is 0 when pressed, release is 1
// sli_si91x_is_sleep_ready requires OS Scheduler to be active
return ((RSI_NPSSGPIO_GetPin(SL_BUTTON_BTN0_PIN) != 0) && (wfx_rsi.dev_state & WFX_RSI_ST_SLEEP_READY) &&
sli_si91x_is_sleep_ready());
}

/**
* @brief Sleeps for a specified duration and then wakes up.
*
* This function puts the SI91x host into sleep mode for the specified duration
* in milliseconds and then wakes it up.
*
* @param sleep_time_ms The duration in milliseconds to sleep.
*/
void sl_wfx_host_si91x_sleep(uint16_t * sleep_time_ms)
{
SL_ASSERT(sleep_time_ms != NULL);
sl_si91x_m4_sleep_wakeup(sleep_time_ms);
}

#endif /* SIWX_917 */

/******************************************************************
Expand All @@ -258,7 +271,7 @@ void sl_wfx_host_si91x_sleep_wakeup()
* @return
* None
*********************************************************************/
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 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;

Expand All @@ -275,11 +288,12 @@ int32_t wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state,sl_s
SILABS_LOG("Powersave Config Failed, Error Code : 0x%lX", status);
return status;
}
if(sl_si91x_wifi_state == HIGH_PERFORMANCE)
if (sl_si91x_wifi_state == HIGH_PERFORMANCE)
{
wfx_rsi.dev_state &= ~(WFX_RSI_ST_SLEEP_READY);
}
else{
else
{
wfx_rsi.dev_state |= WFX_RSI_ST_SLEEP_READY;
}
return status;
Expand Down Expand Up @@ -380,7 +394,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((uint32_t *)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 @@ -591,7 +605,7 @@ static sl_status_t wfx_rsi_do_join(void)
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_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
Expand Down
3 changes: 2 additions & 1 deletion examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ int32_t wfx_rsi_reset_count();
int32_t wfx_rsi_disconnect();
int32_t wfx_wifi_rsi_init(void);
#if SL_ICD_ENABLED
void sl_wfx_host_si91x_sleep_wakeup();
void vTaskPreSuppressTicksAndSleepProcessing(uint16_t * xExpectedIdleTime);
void sl_wfx_host_si91x_sleep(uint16_t * sleep_time_ms);
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 */

Expand Down
6 changes: 5 additions & 1 deletion examples/platform/silabs/ldscripts/SiWx917-common.ld
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ SECTIONS
{
KEEP(*(.isr_vector))
KEEP(*(.reset_handler))
*(EXCLUDE_FILE(*sl_si91x_bus.c.o *sl_si91x_driver.c.o *sli_si91x_multithreaded.c.o *rsi_hal_mcu_m4_ram.c.o *rsi_hal_mcu_m4_rom.c.o *rsi_deepsleep_soc.c.o *croutine.c.o *event_groups.c.o *list.c.o *queue.c.o *stream_buffer.c.o *tasks.c.o *timers.c.o *cmsis_os2.c.o *freertos_umm_malloc_host.c.o *malloc_buffers.c.o *sl_rsi_utility.c.o *port.c.o *heap_*.c.o) .text*)
*(EXCLUDE_FILE(*sl_si91x_bus.c.o *sl_si91x_driver.c.o *sli_si91x_multithreaded.c.o *rsi_hal_mcu_m4_ram.c.o *rsi_hal_mcu_m4_rom.c.o *rsi_deepsleep_soc.c.o *croutine.c.o *event_groups.c.o *list.c.o *queue.c.o *stream_buffer.c.o *tasks.c.o *timers.c.o *cmsis_os2.c.o *freertos_umm_malloc_host.c.o *malloc_buffers.c.o *sl_rsi_utility.c.o *port.c.o *heap_*.c.o *os_systick.c.o *sl_wifi_if.c.o *sl_si91x_m4_ps.c.o *sl_platform_wireless.c.o) .text*)

/* .ctors */
*crtbegin.o(.ctors)
Expand Down Expand Up @@ -146,6 +146,10 @@ SECTIONS
*sl_rsi_utility.c.o(.text*)
*port.c.o(.text*)
*heap_*.c.o(.text*)
*os_systick.c.o(.text*)
*sl_wifi_if.c.o(.text*)
*sl_si91x_m4_ps.c.o(.text*)
*sl_platform_wireless.c.o(.text*)

. = ALIGN(4);
/* preinit data */
Expand Down
2 changes: 2 additions & 0 deletions src/platform/silabs/SiWx917/wifi/wfx_host_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ void * sl_si91x_host_get_buffer_data(sl_wifi_buffer_t * buffer, uint16_t offset,
#if SL_ICD_ENABLED
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);
void sl_button_on_change(uint8_t btn, uint8_t btnAction);
bool wfx_is_sleep_ready(void);
void invoke_btn_press_event(void);
#endif /* SL_ICD_ENABLED */

void wfx_ipv6_notify(int got_ip);
Expand Down
24 changes: 5 additions & 19 deletions src/platform/silabs/SiWx917/wifi/wfx_notify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

#include "AppConfig.h"

#include "BaseApplication.h"
#include "FreeRTOS.h"
#include "event_groups.h"
#include "silabs_utils.h"
#include "task.h"
#include "wfx_host_events.h"
#include "BaseApplication.h"

#ifdef RS911X_WIFI
#include "wfx_rsi.h"
Expand Down Expand Up @@ -204,11 +204,6 @@ void wfx_ip_changed_notify(int got_ip)
********************************************************************************************/
void wfx_retry_interval_handler(bool is_wifi_disconnection_event, uint16_t retryJoin)
{
#if SL_ICD_ENABLED
if (m4_alarm_initialization_done == false) {
initialize_m4_alarm();
}
#endif // SL_ICD_ENABLED
if (!is_wifi_disconnection_event)
{
/* After the reboot or a commissioning time device failed to connect with AP.
Expand All @@ -219,17 +214,12 @@ void wfx_retry_interval_handler(bool is_wifi_disconnection_event, uint16_t retry
SILABS_LOG("wfx_retry_interval_handler : Next attempt after %d Seconds", CONVERT_MS_TO_SEC(WLAN_RETRY_TIMER_MS));
#if SL_ICD_ENABLED
// TODO: cleanup the retry logic MATTER-1921
if(!BaseApplication::sAppDelegate.isComissioningStarted) {
set_alarm_interrupt_timer(WLAN_RETRY_TIMER_MS / 1000);
if (!BaseApplication::sAppDelegate.isComissioningStarted)
{
wfx_rsi_power_save(RSI_SLEEP_MODE_8, STANDBY_POWER_SAVE_WITH_RAM_RETENTION);
// TODO: remove this once TICKLESS_IDLE is applied. MATTER-3134
sl_wfx_host_si91x_sleep_wakeup();
} else {
vTaskDelay(pdMS_TO_TICKS(WLAN_RETRY_TIMER_MS));
}
#else
vTaskDelay(pdMS_TO_TICKS(WLAN_RETRY_TIMER_MS));
#endif // SL_ICD_ENABLED
vTaskDelay(pdMS_TO_TICKS(WLAN_RETRY_TIMER_MS));
}
else
{
Expand All @@ -249,13 +239,9 @@ void wfx_retry_interval_handler(bool is_wifi_disconnection_event, uint16_t retry
}
SILABS_LOG("wfx_retry_interval_handler : Next attempt after %d Seconds", CONVERT_MS_TO_SEC(retryInterval));
#if SL_ICD_ENABLED
set_alarm_interrupt_timer(retryInterval / 1000);
wfx_rsi_power_save(RSI_SLEEP_MODE_8, STANDBY_POWER_SAVE_WITH_RAM_RETENTION);
// TODO: remove this once TICKLESS_IDLE is applied. MATTER-3134
sl_wfx_host_si91x_sleep_wakeup();
#else
vTaskDelay(pdMS_TO_TICKS(retryInterval));
#endif // SL_ICD_ENABLED
vTaskDelay(pdMS_TO_TICKS(retryInterval));
retryInterval += retryInterval;
}
}
14 changes: 6 additions & 8 deletions third_party/silabs/SiWx917_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ examples_plat_dir = "${chip_root}/examples/platform/silabs/SiWx917"

declare_args() {
# Enable the Alarm Based Wakeup for 917 SoC when sleep is enabled
si91x_alarm_based_wakeup = false
si91x_alarm_based_periodic_wakeup = false

# Periodic time at which the 917 SoC should wakeup
si91x_alarm_periodic_time = 30
Expand Down Expand Up @@ -70,6 +70,7 @@ template("siwx917_sdk") {
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/crypto/trng/inc",

# si91x component
"${sdk_support_root}/matter/si91x/siwx917/BRD4338A/support/inc",
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/ahb_interface/inc",
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/inc",
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/sl_net/inc",
Expand Down Expand Up @@ -128,7 +129,6 @@ template("siwx917_sdk") {
"${efr32_sdk_root}/platform/service/sleeptimer/inc",
"${efr32_sdk_root}/platform/service/sleeptimer/config",
"${efr32_sdk_root}/platform/service/sleeptimer/src",
"${sdk_support_root}/matter/si91x/siwx917/BRD4338A/support/inc",

"${efr32_sdk_root}/platform/service/iostream/inc",
"${wifi_sdk_root}/components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc",
Expand Down Expand Up @@ -274,13 +274,11 @@ template("siwx917_sdk") {
"SL_ICD_SUPPORTED_CLIENTS_PER_FABRIC=${sl_icd_supported_clients_per_fabric}",
"SL_SI91X_MCU_WIRELESS_BASED_WAKEUP=1",
"SL_SI91X_MCU_BUTTON_BASED_WAKEUP=1",
"SL_SI91X_MCU_ALARM_BASED_WAKEUP=1",
]

if (si91x_alarm_based_wakeup) {
defines += [
"SL_SI91X_MCU_ALARM_BASED_WAKEUP=1",
"ALARM_PERIODIC_TIME=${si91x_alarm_periodic_time}",
]
if (si91x_alarm_based_periodic_wakeup) {
defines += [ "ALARM_PERIODIC_TIME=${si91x_alarm_periodic_time}" ]
}
}

Expand Down Expand Up @@ -503,7 +501,7 @@ template("siwx917_sdk") {

if (chip_enable_icd_server) {
sources += [
"${sdk_support_root}/matter/si91x/siwx917/BRD4338A/support/src/sl_si91x_m4_ps.c",
"${wifi_sdk_root}/components/device/silabs/si91x/mcu/drivers/peripheral_drivers/src/sl_si91x_m4_ps.c",
"${wifi_sdk_root}/components/device/silabs/si91x/mcu/drivers/systemlevel/src/rsi_rtc.c",
"${wifi_sdk_root}/components/device/silabs/si91x/mcu/drivers/systemlevel/src/rsi_time_period.c",
]
Expand Down
2 changes: 1 addition & 1 deletion third_party/silabs/wifi_sdk

0 comments on commit 8f34809

Please sign in to comment.