From 8f3480965d7632e8631829381d09addadb877374 Mon Sep 17 00:00:00 2001 From: Rohan Sahay Date: Sat, 9 Mar 2024 19:21:26 +0000 Subject: [PATCH] Pull request #1621: Adds configUSE_TICKLESS_IDLE 1 support 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 Date: Sat Mar 9 12:29:42 2024 +0530 refactoring post wakeup proceeds commit 1b7e78b7e82e3942ec2dd7cefb1cd13e562a0788 Author: Rohan Sahay Date: Fri Mar 8 16:51:09 2024 +0530 Remove unnecessary include statement commit d5ee0fbc532f9c03ddc77026859981323ecebd38 Author: Rohan Sahay 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 --- examples/platform/silabs/FreeRTOSConfig.h | 14 +++- examples/platform/silabs/MatterConfig.cpp | 17 +++- .../silabs/SiWx917/SiWx917/sl_wifi_if.c | 80 +++++++++++-------- .../platform/silabs/SiWx917/SiWx917/wfx_rsi.h | 3 +- .../silabs/ldscripts/SiWx917-common.ld | 6 +- .../silabs/SiWx917/wifi/wfx_host_events.h | 2 + .../silabs/SiWx917/wifi/wfx_notify.cpp | 24 ++---- third_party/silabs/SiWx917_sdk.gni | 14 ++-- third_party/silabs/matter_support | 2 +- third_party/silabs/wifi_sdk | 2 +- 10 files changed, 96 insertions(+), 68 deletions(-) diff --git a/examples/platform/silabs/FreeRTOSConfig.h b/examples/platform/silabs/FreeRTOSConfig.h index 051b8126a7e965..3afe05152d8add 100644 --- a/examples/platform/silabs/FreeRTOSConfig.h +++ b/examples/platform/silabs/FreeRTOSConfig.h @@ -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 @@ -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 diff --git a/examples/platform/silabs/MatterConfig.cpp b/examples/platform/silabs/MatterConfig.cpp index 6cc4181cf2de45..0bdfd73716d4b3 100644 --- a/examples/platform/silabs/MatterConfig.cpp +++ b/examples/platform/silabs/MatterConfig.cpp @@ -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 } diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c index 04207f36fe9dae..e1422637292be9 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c +++ b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c @@ -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 @@ -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 */ /****************************************************************** @@ -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; @@ -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; @@ -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"); @@ -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 diff --git a/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h b/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h index 998b3ac1ef5d7a..14c8cb1b0a901f 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h +++ b/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h @@ -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 */ diff --git a/examples/platform/silabs/ldscripts/SiWx917-common.ld b/examples/platform/silabs/ldscripts/SiWx917-common.ld index faa396ff7c7ed0..1b752d98dd07fa 100644 --- a/examples/platform/silabs/ldscripts/SiWx917-common.ld +++ b/examples/platform/silabs/ldscripts/SiWx917-common.ld @@ -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) @@ -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 */ diff --git a/src/platform/silabs/SiWx917/wifi/wfx_host_events.h b/src/platform/silabs/SiWx917/wifi/wfx_host_events.h index a878d4679f55bf..6f2384b5b6db80 100644 --- a/src/platform/silabs/SiWx917/wifi/wfx_host_events.h +++ b/src/platform/silabs/SiWx917/wifi/wfx_host_events.h @@ -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); diff --git a/src/platform/silabs/SiWx917/wifi/wfx_notify.cpp b/src/platform/silabs/SiWx917/wifi/wfx_notify.cpp index 121b383c1aeebe..319f148a4e0ab3 100644 --- a/src/platform/silabs/SiWx917/wifi/wfx_notify.cpp +++ b/src/platform/silabs/SiWx917/wifi/wfx_notify.cpp @@ -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" @@ -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. @@ -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 { @@ -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; } } diff --git a/third_party/silabs/SiWx917_sdk.gni b/third_party/silabs/SiWx917_sdk.gni index 18814e6e1d4e32..53f152131dd1ff 100644 --- a/third_party/silabs/SiWx917_sdk.gni +++ b/third_party/silabs/SiWx917_sdk.gni @@ -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 @@ -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", @@ -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", @@ -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}" ] } } @@ -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", ] diff --git a/third_party/silabs/matter_support b/third_party/silabs/matter_support index 0146d2eb720b07..8e47dada5d5ba3 160000 --- a/third_party/silabs/matter_support +++ b/third_party/silabs/matter_support @@ -1 +1 @@ -Subproject commit 0146d2eb720b07da20454521d97339f7e366b5fb +Subproject commit 8e47dada5d5ba3fe358408d7682f28068150ad7b diff --git a/third_party/silabs/wifi_sdk b/third_party/silabs/wifi_sdk index b74599d842758d..a3f8e3c2415f3a 160000 --- a/third_party/silabs/wifi_sdk +++ b/third_party/silabs/wifi_sdk @@ -1 +1 @@ -Subproject commit b74599d842758de9ac4806c949fdf7bb612fa759 +Subproject commit a3f8e3c2415f3ac4eddfbc8769c3b3abc0fc7b4e