From a7e166c693875d3f8cec7adc209f5ff7b136fe89 Mon Sep 17 00:00:00 2001 From: Chirag Bansal Date: Wed, 8 Nov 2023 19:03:02 +0530 Subject: [PATCH] m4 sleep changes for 917 soc --- examples/platform/silabs/MatterConfig.cpp | 11 +- .../silabs/SiWx917/SiWx917/sl_wifi_if.c | 111 +++++++++++++++++- .../silabs/SiWx917/SiWx917/sl_wlan_config.h | 34 ++++-- .../platform/silabs/SiWx917/SiWx917/wfx_rsi.h | 3 + .../silabs/ldscripts/SiWx917-common.ld | 17 ++- src/platform/silabs/rs911x/BLEManagerImpl.cpp | 6 + third_party/silabs/SiWx917_sdk.gni | 48 +++++--- third_party/silabs/silabs_board.gni | 4 +- 8 files changed, 199 insertions(+), 35 deletions(-) diff --git a/examples/platform/silabs/MatterConfig.cpp b/examples/platform/silabs/MatterConfig.cpp index f9a1b7188beed9..646369c161f5a4 100644 --- a/examples/platform/silabs/MatterConfig.cpp +++ b/examples/platform/silabs/MatterConfig.cpp @@ -43,6 +43,9 @@ #ifdef SIWX_917 #include "wfx_rsi.h" +#if SL_ICD_ENABLED +extern "C" void M4_sleep_wakeup(void); +#endif /* SL_ICD_ENABLED */ #endif /* SIWX_917 */ using namespace ::chip; @@ -294,7 +297,13 @@ CHIP_ERROR SilabsMatterConfig::InitWiFi(void) // ================================================================================ // FreeRTOS Callbacks // ================================================================================ +extern "C" uint8_t test; extern "C" void vApplicationIdleHook(void) { - // FreeRTOS Idle callback +#if ((SIWX_917 == 1) && (SL_ICD_ENABLED == 1)) + if(ConnectivityMgr().IsWiFiStationConnected()) { + // Let the M4 sleep once commissioning is done and device is in idle state + M4_sleep_wakeup(); + } +#endif } diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c index 27b677432b30d5..47e355037ce776 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c +++ b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c @@ -35,6 +35,13 @@ #include "task.h" #include "wfx_host_events.h" +#include "rsi_m4.h" +#include "rsi_board.h" + +#include "ble_config.h" +#include "rsi_rom_power_save.h" +#include "sl_si91x_button_config.h" + #if (EXP_BOARD) #include "rsi_bt_common_apis.h" #endif @@ -194,6 +201,90 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t } #if SL_ICD_ENABLED +void IRQ026_Handler() +{ + RSI_PS_GetWkpUpStatus(); + + /*Clear interrupt */ + RSI_PS_ClrWkpUpStatus(NPSS_TO_MCU_WIRELESS_INTR); + + return; +} + +void wakeup_source_config(void) +{ + /*Configure the NPSS GPIO mode to wake upĀ  */ + RSI_NPSSGPIO_SetPinMux(NPSS_GPIO_2, NPSSGPIO_PIN_MUX_MODE2); + + /*Configure the NPSS GPIO direction to input */ + RSI_NPSSGPIO_SetDir(NPSS_GPIO_2, NPSS_GPIO_DIR_INPUT); + + /*Configure the NPSS GPIO interrupt polarity */ + RSI_NPSSGPIO_SetPolarity(NPSS_GPIO_2, NPSS_GPIO_INTR_LOW); + + /*Enable the REN*/ + RSI_NPSSGPIO_InputBufferEn(NPSS_GPIO_2, 1); + + /* Set the GPIO to wake from deep sleep */ + RSI_NPSSGPIO_SetWkpGpio(NPSS_GPIO_2_INTR); + + /* Un mask the NPSS GPIO interrupt*/ + RSI_NPSSGPIO_IntrUnMask(NPSS_GPIO_2_INTR); + + /*Select wake up sources */ + RSI_PS_SetWkpSources(GPIO_BASED_WAKEUP); + + /*Enable the NPSS GPIO interrupt slot*/ + NVIC_EnableIRQ(NPSS_TO_MCU_GPIO_INTR_IRQn); +} + +/****************************************************************** + * @fn M4_sleep_wakeup() + * @brief + * Setting the M4 to sleep + * + * @param[in] None + * @return + * None + *********************************************************************/ +void M4_sleep_wakeup() { + if (RSI_NPSSGPIO_GetPin(SL_BUTTON_BTN0_PIN)) + { + /* Configure RAM Usage and Retention Size */ + sl_si91x_configure_ram_retention(WISEMCU_256KB_RAM_IN_USE, WISEMCU_RETAIN_DEFAULT_RAM_DURING_SLEEP); + SILABS_LOG("M4 going to sleep"); + sl_si91x_trigger_sleep(SLEEP_WITH_RETENTION, + DISABLE_LF_MODE, + WKP_RAM_USAGE_LOCATION, + (uint32_t)RSI_PS_RestoreCpuContext, + IVT_OFFSET_ADDR, + RSI_WAKEUP_FROM_FLASH_MODE); + sli_m4_ta_interrupt_init(); + fpuInit(); + wakeup_source_config(); + silabsInitLog(); + /*Start of M4 init after wake up */ + SILABS_LOG("M4 wakeup successful"); + } +} + +/****************************************************************** + * @fn InitWakeupSource() + * @brief + * Setting the Wakeup Source of the M4 + * + * @param[in] None + * @return + * None + *********************************************************************/ +void InitWakeupSource() { + /* Configure Wakeup-Source */ + RSI_PS_SetWkpSources(WIRELESS_BASED_WAKEUP); + NVIC_SetPriority(WIRELESS_WAKEUP_IRQHandler, WIRELESS_WAKEUP_IRQHandler_Priority); + + /* Enable NVIC */ + NVIC_EnableIRQ(WIRELESS_WAKEUP_IRQHandler); +} /****************************************************************** * @fn wfx_rsi_power_save() * @brief @@ -213,7 +304,7 @@ int32_t wfx_rsi_power_save() return status; } - sl_wifi_performance_profile_t wifi_profile = { ASSOCIATED_POWER_SAVE }; + sl_wifi_performance_profile_t wifi_profile = { .profile = ASSOCIATED_POWER_SAVE }; status = sl_wifi_set_performance_profile(&wifi_profile); if (status != RSI_SUCCESS) { @@ -264,7 +355,19 @@ static sl_status_t wfx_rsi_init(void) SILABS_LOG("wfx_rsi_init failed %x", status); return status; } -#endif +#else // For SoC +#if SL_ICD_ENABLED + uint8_t xtal_enable = 1; + status = sl_si91x_m4_ta_secure_handshake(SI91X_ENABLE_XTAL, 1, &xtal_enable, 0, NULL); + if (status != SL_STATUS_OK) { + SILABS_LOG("Failed to bring m4_ta_secure_handshake: 0x%lx\r\n", status); + return; + } + SILABS_LOG("m4_ta_secure_handshake Success\r\n"); + InitWakeupSource(); +#endif /* SL_ICD_ENABLED */ +#endif /* !RSI_M4_INTERFACE */ + status = sl_wifi_get_mac_address(SL_WIFI_CLIENT_INTERFACE, (sl_mac_address_t *) &wfx_rsi.sta_mac.octet[0]); if (status != SL_STATUS_OK) { @@ -474,6 +577,10 @@ static sl_status_t wfx_rsi_do_join(void) sl_wifi_set_join_callback(join_callback_handler, NULL); + // 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); + /* Try to connect Wifi with given Credentials * untill there is a success or maximum number of tries allowed */ diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wlan_config.h b/examples/platform/silabs/SiWx917/SiWx917/sl_wlan_config.h index 8bf4e1a4ce51ad..89138e1c6c9aaa 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/sl_wlan_config.h +++ b/examples/platform/silabs/SiWx917/SiWx917/sl_wlan_config.h @@ -28,7 +28,22 @@ //! Disable feature #define RSI_DISABLE 0 -#define SI91X_LISTEN_INTERVAL 0 +//#define SI91X_LISTEN_INTERVAL 0 +#if COMMON_FLASH_EN +#define IVT_OFFSET_ADDR 0x81C2000 //0x8012000 /* */ +#define WKP_RAM_USAGE_LOCATION 0x24061EFC //0x24061000 /* */ +#define WKP_RAM_USAGE_LOCATION 0x24061000 /* rom - linker_nvm_end = __main_flash_end__; + linker_nvm_end = __main_flash_end__ - 4096; linker_nvm_begin = linker_nvm_end - SIZEOF(.nvm); linker_nvm_size = SIZEOF(.nvm); linker_storage_end = linker_nvm_begin; @@ -237,4 +249,3 @@ SECTIONS app_flash_end = 0x81c2000 + 0x200000; ASSERT( (linker_nvm_begin + SIZEOF(.nvm)) <= app_flash_end, "NVM3 is excessing the flash size !") } - diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index 717f0798c2068d..2352f1480dea3e 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -162,6 +162,12 @@ void sl_ble_event_handling_task(void) default: break; } + + if (chip::DeviceLayer::ConnectivityMgr().IsWiFiStationConnected()) { + // Once DUT is connected adding a 500ms delay + // TODO: Fix this with a better event handling + vTaskDelay(pdMS_TO_TICKS(500)); + } } } diff --git a/third_party/silabs/SiWx917_sdk.gni b/third_party/silabs/SiWx917_sdk.gni index 932ccebe79904c..fdceb93b9c8e1b 100644 --- a/third_party/silabs/SiWx917_sdk.gni +++ b/third_party/silabs/SiWx917_sdk.gni @@ -148,12 +148,12 @@ template("siwx917_sdk") { "SILABS_LOG_ENABLED=${silabs_log_enabled}", "SL_HEAP_SIZE=32768", "SL_WIFI=1", - "CCP_SI917_BRINGUP", - "SL_COMPONENT_CATALOG_PRESENT", - "RS911X_WIFI", + "CCP_SI917_BRINGUP=1", + "SL_COMPONENT_CATALOG_PRESENT=1", + "RS911X_WIFI=1", "RSI_WLAN_ENABLE", "RSI_WITH_OS", - "RSI_M4_INTERFACE", #Enable CCP bus Interface + "RSI_M4_INTERFACE=1", #Enable CCP bus Interface "RSI_WLAN_API_ENABLE", "LITTLE_ENDIAN_ORDER", "_CHIP_9118", @@ -167,31 +167,39 @@ template("siwx917_sdk") { "PLATFORM_HEADER=\"platform-header.h\"", "USE_NVM3=1", "RSI_ARM_CM4F", - "SIWX_917", - "CHIP_9117", + "SIWX_917=1", + "CHIP_9117=1", "BLE_ENABLE=1", "RSI_LITTLE_ENDIAN=1", "TINYCRYPT_PRIMITIVES", "OPTIMIZE_TINYCRYPT_ASM", "__error_t_defined", - "RSI_SAMPLE_HAL", - "ENABLE_IPMU_APIS", + "RSI_SAMPLE_HAL=1", + "ENABLE_IPMU_APIS=1", "ROM_BYPASS", - "DEBUG_UART", - "FLASH_BASED_EXECUTION_ENABLE", - "TA_DEEP_SLEEP_COMMON_FLASH", - "SL_WIFI_COMPONENT_INCLUDED", + "DEBUG_UART=1", + "FLASH_BASED_EXECUTION_ENABLE=1", + "TA_DEEP_SLEEP_COMMON_FLASH=1", + "SL_WIFI_COMPONENT_INCLUDED=1", "CHIP_917=1", "ROMDRIVER_PRESENT=1", "SL_CATALOG_FREERTOS_KERNEL_PRESENT=1", "SL_PLATFORM_EXAMPLES_ENABLE", "SI91X_DEVICE=1", "SI917_RADIO_BOARD=1", - "FLASH_PAGE_SIZE", - "SL_NVM3_PRESENT", + "FLASH_PAGE_SIZE=1", + "SL_NVM3_PRESENT=1", "ROM_WIRELESS", - "BRD4325A", #TODO: should be removed after SoC macro clean-up - "CONNECTIVITY_PLATFORM", + "BRD4325A=1", #TODO: should be removed after SoC macro clean-up + "SI917_SOC=1", + "EXT_IRQ_COUNT=75", + "FLASH_PAGE_SIZE=1", + "SI917_COMMON_FLASH=1", + "SRAM_BASE=0x0c", + "SRAM_SIZE=0x00040000", + "DEBUG_ENABLE=1", + "ENABLE_DEBUG_MODULE=1", + "SI917=1", ] if (silabs_board == "BRD4325B") { @@ -271,8 +279,12 @@ template("siwx917_sdk") { if (chip_enable_icd_server) { defines += [ - "SL_CATALOG_POWER_MANAGER_PRESENT", - "SL_CATALOG_SLEEPTIMER_PRESENT", + "WIFI_DEBUG_ENABLED=1", + "SL_ICD_ENABLED=1", + "SL_ACTIVE_MODE_THRESHOLD=${sl_active_mode_threshold_ms}", + "SL_ACTIVE_MODE_INTERVAL=${sl_active_mode_interval_ms}", + "SL_IDLE_MODE_INTERVAL=${sl_idle_mode_interval_s}", + "SL_ICD_SUPPORTED_CLIENTS_PER_FABRIC=${sl_icd_supported_clients_per_fabric}", ] } diff --git a/third_party/silabs/silabs_board.gni b/third_party/silabs/silabs_board.gni index cd433ed61da49c..01395b8ed9ca83 100644 --- a/third_party/silabs/silabs_board.gni +++ b/third_party/silabs/silabs_board.gni @@ -130,8 +130,8 @@ if (silabs_board == "BRD4304A") { } else if (silabs_board == "BRD4338A") { silabs_family = "SiWx917-common" silabs_mcu = "SiWG917M111MGTBA" - disable_lcd = false - show_qr_code = true + disable_lcd = true + show_qr_code = false wifi_soc = true wifi_soc_common_flash = true silabs_board_lower = "brd4338a"