From 10a0af2deb32d6ba077ef1fa03ad5f87d105fff0 Mon Sep 17 00:00:00 2001 From: Chirag Bansal Date: Thu, 8 Feb 2024 13:15:11 +0000 Subject: [PATCH] Pull request #1534: [MATTER-3042] :Allow M4 to go to sleep when it is uncommissioned Merge in WMN_TOOLS/matter from feature/917_sleepy_uncommissioned to RC_2.3.0-1.3 Squashed commit of the following: commit 0d5350c7dc0468aeb1c7bcf7f8cb8833b8e1427a Author: chbansal Date: Thu Feb 8 15:07:37 2024 +0530 reverting the DIC_ENABLE macro to back place commit 5df0f689f39525889979e6e609f56b463611c3dc Author: chbansal Date: Wed Feb 7 23:15:22 2024 +0530 Adding different Appdelegate to not allow the DUT go to sleep in between commissioning commit 4bfd3a125ec5561325ee29b263479821253cc69d Author: chbansal Date: Wed Feb 7 21:43:01 2024 +0530 reverting the BLEManagerImpl.cpp ... and 7 more commits --- examples/platform/silabs/BaseApplication.cpp | 27 ++++++++-- examples/platform/silabs/BaseApplication.h | 16 +++++- examples/platform/silabs/MatterConfig.cpp | 10 ++-- .../silabs/SiWx917/SiWx917/sl_wifi_if.c | 23 ++++++--- .../platform/silabs/SiWx917/SiWx917/wfx_rsi.h | 2 +- .../silabs/SiWx917/SiWx917/wfx_rsi_host.c | 7 +-- .../efr32/rs911x/hal/sl_board_configuration.h | 2 - .../platform/silabs/efr32/rs911x/wfx_rsi.h | 4 ++ .../silabs/efr32/rs911x/wfx_rsi_host.c | 16 ++++++ .../silabs/ConnectivityManagerImpl_WIFI.cpp | 4 ++ .../silabs/SiWx917/OTAImageProcessorImpl.cpp | 49 +++++++++++++++---- .../silabs/SiWx917/wifi/wfx_host_events.h | 5 +- .../silabs/SiWx917/wifi/wfx_notify.cpp | 39 +++++++++++++++ .../silabs/efr32/wifi/wfx_host_events.h | 8 +++ src/platform/silabs/rs911x/BLEManagerImpl.cpp | 1 + third_party/silabs/matter_support | 2 +- 16 files changed, 179 insertions(+), 36 deletions(-) diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp index 5ba9a26fe6982a..3be5a296a6eaa3 100644 --- a/examples/platform/silabs/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -26,7 +26,7 @@ #include "AppTask.h" #include -#define APP_ACTION_BUTTON 1 +#define APP_ACTION_BUTTON 1 #ifdef DISPLAY_ENABLED #include "lcd.h" @@ -44,9 +44,9 @@ #include #include #include +#include #include #include -#include #if CHIP_ENABLE_OPENTHREAD #include @@ -148,6 +148,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 { @@ -165,6 +168,23 @@ 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() +{ + ChipLogProgress(DeviceLayer, "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 *********************************************************/ @@ -263,7 +283,6 @@ CHIP_ERROR BaseApplication::Init() #if CHIP_ENABLE_OPENTHREAD BaseApplication::sIsProvisioned = ConnectivityMgr().IsThreadProvisioned(); #endif - return err; } @@ -741,7 +760,7 @@ void BaseApplication::ScheduleFactoryReset() { PlatformMgr().ScheduleWork([](intptr_t) { // Press both buttons to request provisioning - if(GetPlatform().GetButtonState(APP_ACTION_BUTTON)) + if (GetPlatform().GetButtonState(APP_ACTION_BUTTON)) { Provision::Manager::GetInstance().RequestProvision(); } diff --git a/examples/platform/silabs/BaseApplication.h b/examples/platform/silabs/BaseApplication.h index b38f0e58e1c305..15a580857ba025 100644 --- a/examples/platform/silabs/BaseApplication.h +++ b/examples/platform/silabs/BaseApplication.h @@ -30,6 +30,7 @@ #include "FreeRTOS.h" #include "timers.h" // provides FreeRTOS timer support #include +#include #include #include #include @@ -62,10 +63,20 @@ #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 +{ +public: + bool isComissioningStarted; + void OnCommissioningSessionStarted() override; + void OnCommissioningSessionStopped() override; + void OnCommissioningWindowClosed() override; +}; +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917 + /********************************************************** * BaseApplication Declaration *********************************************************/ - class BaseApplication { @@ -75,6 +86,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 diff --git a/examples/platform/silabs/MatterConfig.cpp b/examples/platform/silabs/MatterConfig.cpp index 3e14f86e54bf27..6cc4181cf2de45 100644 --- a/examples/platform/silabs/MatterConfig.cpp +++ b/examples/platform/silabs/MatterConfig.cpp @@ -18,6 +18,7 @@ */ #include "AppConfig.h" +#include "BaseApplication.h" #include "OTAConfig.h" #include @@ -261,6 +262,9 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName) initParams.endpointNativeParams = static_cast(&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); @@ -310,10 +314,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 } diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c index f78539d9817170..ae823db86bafc3 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c +++ b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c @@ -188,8 +188,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); @@ -256,28 +256,35 @@ 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 */ @@ -630,11 +637,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); } } } diff --git a/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h b/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h index 6721071a1de181..998b3ac1ef5d7a 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h +++ b/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h @@ -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 diff --git a/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.c b/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.c index 8f1f895f9683f9..31968d4fa113f9 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.c +++ b/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.c @@ -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; } diff --git a/examples/platform/silabs/efr32/rs911x/hal/sl_board_configuration.h b/examples/platform/silabs/efr32/rs911x/hal/sl_board_configuration.h index 4310bf719f8179..5591467580bbc4 100644 --- a/examples/platform/silabs/efr32/rs911x/hal/sl_board_configuration.h +++ b/examples/platform/silabs/efr32/rs911x/hal/sl_board_configuration.h @@ -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_ */ \ No newline at end of file diff --git a/examples/platform/silabs/efr32/rs911x/wfx_rsi.h b/examples/platform/silabs/efr32/rs911x/wfx_rsi.h index 4d692064a5768f..07217056cef11b 100644 --- a/examples/platform/silabs/efr32/rs911x/wfx_rsi.h +++ b/examples/platform/silabs/efr32/rs911x/wfx_rsi.h @@ -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 diff --git a/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c b/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c index 331895bd3e524e..888939f696124e 100644 --- a/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c +++ b/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c @@ -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 @@ -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 */ /********************************************************************* diff --git a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp index c1a1a7de4c0ed1..214b0974668fbb 100644 --- a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp +++ b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp @@ -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"); diff --git a/src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp b/src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp index b4755995e36b01..f06bcaff7cb738 100644 --- a/src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp @@ -21,7 +21,7 @@ #include #include - +#include "wfx_host_events.h" #ifdef __cplusplus extern "C" { #endif @@ -35,8 +35,7 @@ extern "C" { #define RPS_HEADER 1 #define RPS_DATA 2 -/// No error, operation OK -#define SL_BOOTLOADER_OK 0L + #define SL_STATUS_FW_UPDATE_DONE SL_STATUS_SI91X_NO_AP_FOUND uint8_t flag = RPS_HEADER; @@ -124,7 +123,7 @@ CHIP_ERROR OTAImageProcessorImpl::ConfirmCurrentImage() void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) { - int32_t err = SL_BOOTLOADER_OK; + int32_t status = 0; auto * imageProcessor = reinterpret_cast(context); if (imageProcessor == nullptr) @@ -148,14 +147,19 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) imageProcessor->mHeaderParser.Init(); - // Not calling bootloader_eraseStorageSlot(mSlotId) here because we erase during each write + //Setting the device is in high performace - no-sleepy mode while OTA tranfer +#if (CHIP_CONFIG_ENABLE_ICD_SERVER) + status = wfx_power_save(RSI_ACTIVE ,HIGH_PERFORMANCE); + if (status != SL_STATUS_OK) { + ChipLogError(DeviceLayer,"Failed to enable the TA Deep Sleep"); + } +#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER*/ imageProcessor->mDownloader->OnPreparedForDownload(CHIP_NO_ERROR); } void OTAImageProcessorImpl::HandleFinalize(intptr_t context) { - uint32_t err = SL_BOOTLOADER_OK; int32_t status = 0; auto * imageProcessor = reinterpret_cast(context); if (imageProcessor == nullptr) @@ -177,7 +181,7 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) } else { - ChipLogError(SoftwareUpdate, "ERROR: In HandleFinalize for last chunk rsi_fwup() error %ld", status); + ChipLogError(SoftwareUpdate, "ERROR: In HandleFinalize for last chunk sl_si91x_fwup_load() error %ld", status); imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); return; } @@ -185,12 +189,21 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) } imageProcessor->ReleaseBlock(); + //Setting the device back to power save mode when transfer is completed successfully +#if (CHIP_CONFIG_ENABLE_ICD_SERVER) + sl_status_t err = wfx_power_save(RSI_SLEEP_MODE_2, ASSOCIATED_POWER_SAVE); + if (err != SL_STATUS_OK) + { + ChipLogError(DeviceLayer, "Power save config for Wifi failed"); + } +#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER*/ + ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully"); } void OTAImageProcessorImpl::HandleApply(intptr_t context) { - uint32_t err = SL_BOOTLOADER_OK; + int32_t status = 0; ChipLogProgress(SoftwareUpdate, "OTAImageProcessorImpl::HandleApply()"); @@ -199,6 +212,14 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully in HandleApply"); + //Setting the device is in high performace - no-sleepy mode before soft reset as soft reset is not happening in sleep mode +#if (CHIP_CONFIG_ENABLE_ICD_SERVER) + status = wfx_power_save(RSI_ACTIVE ,HIGH_PERFORMANCE); + if (status != SL_STATUS_OK) { + ChipLogError(DeviceLayer,"Failed to enable the TA Deep Sleep"); + } +#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER*/ + if (mReset) { ChipLogProgress(SoftwareUpdate, "M4 Firmware update complete"); @@ -217,13 +238,21 @@ void OTAImageProcessorImpl::HandleAbort(intptr_t context) return; } + //Setting the device back to power save mode when transfer is aborted in the middle +#if (CHIP_CONFIG_ENABLE_ICD_SERVER) + sl_status_t err = wfx_power_save(RSI_SLEEP_MODE_2, ASSOCIATED_POWER_SAVE); + if (err != SL_STATUS_OK) + { + ChipLogError(DeviceLayer, "Power save config for Wifi failed"); + } +#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER*/ + // Not clearing the image storage area as it is done during each write imageProcessor->ReleaseBlock(); } void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) { - uint32_t err = SL_BOOTLOADER_OK; int32_t status = 0; int32_t content_block = 0; auto * imageProcessor = reinterpret_cast(context); @@ -280,7 +309,7 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) } else { - ChipLogError(SoftwareUpdate, "ERROR: In HandleFinalize for last chunk rsi_fwup() error %ld", status); + ChipLogError(SoftwareUpdate, "ERROR: In HandleProcessBlock sl_si91x_fwup_load() error %ld", status); imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); return; } diff --git a/src/platform/silabs/SiWx917/wifi/wfx_host_events.h b/src/platform/silabs/SiWx917/wifi/wfx_host_events.h index e153a12c0461ae..4d3aac83cc4db4 100644 --- a/src/platform/silabs/SiWx917/wifi/wfx_host_events.h +++ b/src/platform/silabs/SiWx917/wifi/wfx_host_events.h @@ -32,6 +32,9 @@ #include "sl_status.h" +#include "rsi_common_apis.h" +#include "sl_wifi_device.h" + #define SL_WIFI_ALLOCATE_COMMAND_BUFFER_WAIT_TIME_MS 1000 /* Wi-Fi events*/ #define SL_WFX_STARTUP_IND_ID (1) @@ -246,7 +249,7 @@ sl_status_t sl_si91x_host_process_data_frame(sl_wifi_interface_t interface, sl_w void * sl_si91x_host_get_buffer_data(sl_wifi_buffer_t * buffer, uint16_t offset, uint16_t * data_length); #if SL_ICD_ENABLED -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); #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 3d0f56cf14f442..2bca17e0c4d1cc 100644 --- a/src/platform/silabs/SiWx917/wifi/wfx_notify.cpp +++ b/src/platform/silabs/SiWx917/wifi/wfx_notify.cpp @@ -26,11 +26,24 @@ #include "silabs_utils.h" #include "task.h" #include "wfx_host_events.h" +#include "BaseApplication.h" #ifdef RS911X_WIFI #include "wfx_rsi.h" #endif +#if SL_ICD_ENABLED +#ifdef __cplusplus +extern "C" { +#endif +#include "sl_si91x_m4_ps.h" +extern "C" uint8_t m4_alarm_initialization_done; +extern "C" void set_alarm_interrupt_timer(uint16_t interval); +#ifdef __cplusplus +} +#endif +#endif // SL_ICD_ENABLED + #include // #include #include @@ -191,6 +204,11 @@ 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. @@ -199,7 +217,20 @@ void wfx_retry_interval_handler(bool is_wifi_disconnection_event, uint16_t retry if (retryJoin < MAX_JOIN_RETRIES_COUNT) { 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); + wfx_rsi_power_save(RSI_SLEEP_MODE_8, STANDBY_POWER_SAVE_WITH_RAM_RETENTION); + // Adding a small delay, to trigger the idle task and letting the device go to sleep + // TODO: Change this to a callback/event handler + vTaskDelay(pdMS_TO_TICKS(5)); + } else { + vTaskDelay(pdMS_TO_TICKS(WLAN_RETRY_TIMER_MS)); + } +#else vTaskDelay(pdMS_TO_TICKS(WLAN_RETRY_TIMER_MS)); +#endif // SL_ICD_ENABLED } else { @@ -218,7 +249,15 @@ void wfx_retry_interval_handler(bool is_wifi_disconnection_event, uint16_t retry retryInterval = WLAN_MAX_RETRY_TIMER_MS; } 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); + // Adding a small delay, to trigger the idle task and letting the device go to sleep + // TODO: Change this to a callback/event handler + vTaskDelay(pdMS_TO_TICKS(5)); +#else vTaskDelay(pdMS_TO_TICKS(retryInterval)); +#endif // SL_ICD_ENABLED retryInterval += retryInterval; } } diff --git a/src/platform/silabs/efr32/wifi/wfx_host_events.h b/src/platform/silabs/efr32/wifi/wfx_host_events.h index 4070cf4ea93700..585dddfe1ca3de 100644 --- a/src/platform/silabs/efr32/wifi/wfx_host_events.h +++ b/src/platform/silabs/efr32/wifi/wfx_host_events.h @@ -26,6 +26,7 @@ #include "task.h" #include "timers.h" + typedef struct __attribute__((__packed__)) sl_wfx_get_counters_cnf_body_s { uint32_t status; @@ -103,6 +104,9 @@ typedef struct __attribute__((__packed__)) sl_wfx_mib_req_s #include "sl_status.h" #include "sl_wifi_constants.h" +#include "rsi_common_apis.h" +#include "sl_wifi_device.h" + #define SL_WIFI_ALLOCATE_COMMAND_BUFFER_WAIT_TIME_MS 1000 #endif @@ -365,7 +369,11 @@ void * wfx_rsi_alloc_pkt(void); #ifdef RS911X_WIFI /* RSI Power Save */ #if SL_ICD_ENABLED +#if SLI_SI917 +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); +#else sl_status_t wfx_power_save(); +#endif /* SLI_SI917 */ #endif /* SL_ICD_ENABLED */ /* RSI for LWIP */ void wfx_rsi_pkt_add_data(void * p, uint8_t * buf, uint16_t len, uint16_t off); diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index a32d46b30f2715..e121e111b285d4 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -755,6 +755,7 @@ CHIP_ERROR BLEManagerImpl::StopAdvertising(void) { ChipLogProgress(DeviceLayer, "advertising failed to stop, with status = 0x%lx", status); } + } return err; } diff --git a/third_party/silabs/matter_support b/third_party/silabs/matter_support index 70800e2f6d5fbc..cccd1916ffed50 160000 --- a/third_party/silabs/matter_support +++ b/third_party/silabs/matter_support @@ -1 +1 @@ -Subproject commit 70800e2f6d5fbc972d22387fd4969a92568b455b +Subproject commit cccd1916ffed5082ff06fd0c7d612294469fe55e