From bc241ac9d09aa6f688ee33bc7650bb6a2e8faabd Mon Sep 17 00:00:00 2001 From: Mathieu Kardous <84793247+mkardous-silabs@users.noreply.github.com> Date: Mon, 9 Dec 2024 15:57:16 -0500 Subject: [PATCH] [SL-UP] Fix Wi-Fi Sleep Manager commissioning progress check from clean boot (#167) --- examples/platform/silabs/BaseApplication.cpp | 4 +-- .../wifi/icd/ApplicationSleepManager.cpp | 10 +++---- .../silabs/wifi/icd/WifiSleepManager.cpp | 26 ++++++++++++++++--- .../silabs/wifi/icd/WifiSleepManager.h | 20 +++++++++++++- 4 files changed, 49 insertions(+), 11 deletions(-) diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp index 1176ea6fa7..668b9a318f 100644 --- a/examples/platform/silabs/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -931,7 +931,7 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t) #if SL_WIFI chip::app::DnssdServer::Instance().StartServer(); #if CHIP_CONFIG_ENABLE_ICD_SERVER - WifiSleepManager::GetInstance().VerifyAndTransitionToLowPowerMode(); + WifiSleepManager::GetInstance().VerifyAndTransitionToLowPowerMode(WifiSleepManager::PowerEvent::kConnectivityChange); #endif // CHIP_CONFIG_ENABLE_ICD_SERVER #endif // SL_WIFI @@ -946,7 +946,7 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t) case DeviceEventType::kCommissioningComplete: { #if SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER - WifiSleepManager::GetInstance().VerifyAndTransitionToLowPowerMode(); + WifiSleepManager::GetInstance().VerifyAndTransitionToLowPowerMode(WifiSleepManager::PowerEvent::kCommissioningComplete); #endif // SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER // SL-Only diff --git a/examples/platform/silabs/wifi/icd/ApplicationSleepManager.cpp b/examples/platform/silabs/wifi/icd/ApplicationSleepManager.cpp index 7896be0c35..d53dafb25f 100644 --- a/examples/platform/silabs/wifi/icd/ApplicationSleepManager.cpp +++ b/examples/platform/silabs/wifi/icd/ApplicationSleepManager.cpp @@ -43,17 +43,17 @@ CHIP_ERROR ApplicationSleepManager::Init() void ApplicationSleepManager::OnCommissioningWindowOpened() { mIsCommissionningWindowOpen = true; -#if ( ( defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 ) ) +#if (defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1) mWifiSleepManager->VerifyAndTransitionToLowPowerMode(); -#endif // ( ( defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 ) ) +#endif // (defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1) } void ApplicationSleepManager::OnCommissioningWindowClosed() { mIsCommissionningWindowOpen = false; -#if ( ( defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 ) ) +#if (defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1) mWifiSleepManager->VerifyAndTransitionToLowPowerMode(); -#endif // ( ( defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 ) ) +#endif // (defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1) } void ApplicationSleepManager::OnSubscriptionEstablished(chip::app::ReadHandler & aReadHandler) @@ -103,7 +103,7 @@ bool ApplicationSleepManager::CanGoToLIBasedSleep() canGoToLIBasedSleep = false; break; } - ChipLogProgress(AppServer, "All Fabrics have at least 1 active subscription!"); + ChipLogProgress(AppServer, "Fabric index %u has an active subscriptions!", it->GetFabricIndex()); } } diff --git a/src/platform/silabs/wifi/icd/WifiSleepManager.cpp b/src/platform/silabs/wifi/icd/WifiSleepManager.cpp index 2bff2372b8..0a1eedf9ea 100644 --- a/src/platform/silabs/wifi/icd/WifiSleepManager.cpp +++ b/src/platform/silabs/wifi/icd/WifiSleepManager.cpp @@ -108,7 +108,7 @@ CHIP_ERROR WifiSleepManager::RequestHighPerformance() mHighPerformanceRequestCounter++; - // We don't do the mHighPerformanceRequestCounter check here; the check is in TransitionToLowPowerMode function + // We don't do the mHighPerformanceRequestCounter check here; the check is in VerifyAndTransitionToLowPowerMode function ReturnErrorOnFailure(VerifyAndTransitionToLowPowerMode()); return CHIP_NO_ERROR; @@ -121,14 +121,34 @@ CHIP_ERROR WifiSleepManager::RemoveHighPerformanceRequest() mHighPerformanceRequestCounter--; - // We don't do the mHighPerformanceRequestCounter check here; the check is in TransitionToLowPowerMode function + // We don't do the mHighPerformanceRequestCounter check here; the check is in VerifyAndTransitionToLowPowerMode function ReturnErrorOnFailure(VerifyAndTransitionToLowPowerMode()); return CHIP_NO_ERROR; } -CHIP_ERROR WifiSleepManager::VerifyAndTransitionToLowPowerMode() +CHIP_ERROR WifiSleepManager::HandlePowerEvent(PowerEvent event) { + switch (event) + { + case PowerEvent::kCommissioningComplete: + ChipLogProgress(AppServer, "WifiSleepManager: Handling Commissioning Complete Event"); + mIsCommissioningInProgress = false; + break; + case PowerEvent::kConnectivityChange: + case PowerEvent::kGenericEvent: + // No additional processing needed for these events at the moment + break; + default: + ChipLogError(AppServer, "Unknown Power Event"); + return CHIP_ERROR_INVALID_ARGUMENT; + } + return CHIP_NO_ERROR; +} + +CHIP_ERROR WifiSleepManager::VerifyAndTransitionToLowPowerMode(PowerEvent event) +{ + ReturnErrorOnFailure(HandlePowerEvent(event)); #if SLI_SI917 // 917 SoC & NCP if (mHighPerformanceRequestCounter > 0) diff --git a/src/platform/silabs/wifi/icd/WifiSleepManager.h b/src/platform/silabs/wifi/icd/WifiSleepManager.h index 5ee2f4a9a6..e402b78524 100644 --- a/src/platform/silabs/wifi/icd/WifiSleepManager.h +++ b/src/platform/silabs/wifi/icd/WifiSleepManager.h @@ -35,6 +35,13 @@ class WifiSleepManager static WifiSleepManager & GetInstance() { return mInstance; } + enum class PowerEvent : uint8_t + { + kGenericEvent = 0, + kCommissioningComplete = 1, + kConnectivityChange = 2, + }; + /** * @brief Class implements the callbacks that the application can implement * to alter the WifiSleepManager behaviors. @@ -122,15 +129,26 @@ class WifiSleepManager * 3. If no commissioning is in progress and the device is unprovisioned, configure deep sleep. * 4. If the application callback allows, configure LI based sleep; otherwise, configure DTIM based sleep. * + * @param event PowerEvent triggering the Verify and transition to low power mode processing + * * @return CHIP_ERROR CHIP_NO_ERROR if the device was transitionned to low power * CHIP_ERROR_INTERNAL if an error occured */ - CHIP_ERROR VerifyAndTransitionToLowPowerMode(); + CHIP_ERROR VerifyAndTransitionToLowPowerMode(PowerEvent event = PowerEvent::kGenericEvent); private: WifiSleepManager() = default; ~WifiSleepManager() = default; + /** + * @brief Function to handle the power events before transitionning the device to the appropriate low power mode. + * + * @param event PowerEvent to handle + * @return CHIP_ERROR CHIP_NO_ERROR if the event was handled successfully + * CHIP_ERROR_INVALID_ARGUMENT if the event is not supported + */ + CHIP_ERROR HandlePowerEvent(PowerEvent event); + static WifiSleepManager mInstance; bool mIsCommissioningInProgress = false;