diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp index 8ad25d5e36..6d1af5140a 100644 --- a/examples/platform/silabs/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -67,6 +67,10 @@ #include #include #include + +#if CHIP_CONFIG_ENABLE_ICD_SERVER +#include +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER #endif // SL_WIFI #ifdef DIC_ENABLE @@ -183,16 +187,18 @@ void BaseApplicationDelegate::OnCommissioningSessionStarted() { isComissioningStarted = true; - ChipDeviceEvent event = { .Type = DeviceEventType::kCommissioningSessionStarted }; - (void) PlatformMgr().PostEvent(&event); +#if SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER + PlatformSleepManager::GetInstance().HandleCommissioningSessionStarted(); +#endif // SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER } void BaseApplicationDelegate::OnCommissioningSessionStopped() { isComissioningStarted = false; - ChipDeviceEvent event = { .Type = DeviceEventType::kCommissioningSessionStopped }; - (void) PlatformMgr().PostEvent(&event); +#if SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER + PlatformSleepManager::GetInstance().HandleCommissioningSessionStopped(); +#endif // SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER } void BaseApplicationDelegate::OnCommissioningWindowClosed() @@ -212,15 +218,12 @@ void BaseApplicationDelegate::OnCommissioningWindowClosed() #endif // DISPLAY_ENABLED } - ChipDeviceEvent event = { .Type = DeviceEventType::kCommissioningWindowClose }; - (void) PlatformMgr().PostEvent(&event); +#if SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER + PlatformSleepManager::GetInstance().HandleCommissioningWindowClose(); +#endif // SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER } -void BaseApplicationDelegate::OnCommissioningWindowOpened() -{ - ChipDeviceEvent event = { .Type = DeviceEventType::kCommissioningWindowOpen }; - (void) PlatformMgr().PostEvent(&event); -} +void BaseApplicationDelegate::OnCommissioningWindowOpened() {} void BaseApplicationDelegate::OnFabricCommitted(const FabricTable & fabricTable, FabricIndex fabricIndex) { @@ -899,44 +902,25 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t) if ((event->ThreadConnectivityChange.Result == kConnectivity_Established) || (event->InternetConnectivityChange.IPv6 == kConnectivity_Established)) { -#if SL_WIFI +#if SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER chip::app::DnssdServer::Instance().StartServer(); -#endif // SL_WIFI + PlatformSleepManager::GetInstance().HandleInternetConnectivityChange(); +#endif // SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER #if SILABS_OTA_ENABLED ChipLogProgress(AppServer, "Scheduling OTA Requestor initialization"); chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(OTAConfig::kInitOTARequestorDelaySec), InitOTARequestorHandler, nullptr); #endif // SILABS_OTA_ENABLED -#if (CHIP_CONFIG_ENABLE_ICD_SERVER && RS911X_WIFI) -#if !SLI_SI917 - // [sl-only] Only 9116 - 917 is managed by the SleepManager - // on power cycle, let the device go to sleep after connection is established - if (BaseApplication::sAppDelegate.isCommissioningInProgress() == false) - { - sl_status_t err = wfx_power_save(); - if (err != SL_STATUS_OK) - { - ChipLogError(AppServer, "wfx_power_save failed: 0x%lx", err); - } - } -#endif // !SLI_SI917 -#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER && RS911X_WIFI */ } } break; case DeviceEventType::kCommissioningComplete: { -#if (CHIP_CONFIG_ENABLE_ICD_SERVER && RS911X_WIFI) -#if !SLI_SI917 - // [sl-only] Only 9116 - 917 is managed by the SleepManager - sl_status_t status = wfx_power_save(); - if (status != SL_STATUS_OK) - { - ChipLogError(AppServer, "wfx_power_save failed: 0x%lx", status); - } -#endif /* !SLI_SI917 */ -#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER && RS911X_WIFI */ +#if SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER + PlatformSleepManager::GetInstance().HandleCommissioningComplete(); +#endif // SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER + // SL-Only #ifdef SL_CATALOG_ZIGBEE_STACK_COMMON_PRESENT #if defined(SL_MATTER_ZIGBEE_CMP) && defined(_SILICON_LABS_32B_SERIES_3) diff --git a/examples/platform/silabs/MatterConfig.cpp b/examples/platform/silabs/MatterConfig.cpp index 808bcfccf7..fbaf344350 100644 --- a/examples/platform/silabs/MatterConfig.cpp +++ b/examples/platform/silabs/MatterConfig.cpp @@ -20,12 +20,16 @@ #include "AppConfig.h" #include "BaseApplication.h" #include +#include #include - #include #ifdef SL_WIFI #include + +#if CHIP_CONFIG_ENABLE_ICD_SERVER +#include +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER #endif /* SL_WIFI */ #if PW_RPC_ENABLED @@ -45,10 +49,9 @@ #include #endif // SLI_SI91X_MCU_INTERFACE -// sl-only: Wi-Fi Sleep Manager support -#if SL_MATTER_SLEEP_MANAGER_ENABLED -#include "SleepManager.h" -#endif // SL_MATTER_SLEEP_MANAGER_ENABLED +// TODO: Add suport for the WF200 in the PlatformSleepManager +#if defined(RS911X_WIFI) || SLI_SI91X_MCU_INTERFACE +#endif // defined(RS911X_WIFI) || SLI_SI91X_MCU_INTERFACE #include // If building with the EFR32-provided crypto backend, we can use the @@ -92,6 +95,8 @@ static chip::DeviceLayer::Internal::Efr32PsaOperationalKeystore gOperationalKeys #include "sl_power_manager.h" #endif +// #include "sl_si91x_power_manager.h" + /********************************************************** * Defines *********************************************************/ @@ -245,7 +250,12 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName) // See comment above about OpenThread memory allocation as to why this is WIFI only here. ReturnErrorOnFailure(chip::Platform::MemoryInit()); ReturnErrorOnFailure(InitWiFi()); -#endif + +#if CHIP_CONFIG_ENABLE_ICD_SERVER + err = DeviceLayer::Silabs::PlatformSleepManager::GetInstance().Init(); + VerifyOrReturnError(err == CHIP_NO_ERROR, err); +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER +#endif // SL_WIFI ReturnErrorOnFailure(PlatformMgr().InitChipStack()); @@ -305,13 +315,7 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName) initParams.appDelegate = &BaseApplication::sAppDelegate; -#if SL_MATTER_SLEEP_MANAGER_ENABLED - err = DeviceLayer::Silabs::SleepManager::GetInstance() - .SetInteractionModelEngine(app::InteractionModelEngine::GetInstance()) - .SetFabricTable(&Server::GetInstance().GetFabricTable()) - .Init(); - VerifyOrReturnError(err == CHIP_NO_ERROR, err); -#endif // SL_MATTER_SLEEP_MANAGER_ENABLED + // sl_status_t status = sl_si91x_power_manager_add_ps_requirement(SL_SI91X_POWER_MANAGER_PS4); // Init Matter Server and Start Event Loop err = chip::Server::GetInstance().Init(initParams); diff --git a/src/platform/silabs/CHIPDevicePlatformEvent.h b/src/platform/silabs/CHIPDevicePlatformEvent.h index 482a02f2e7..bbdf3614f9 100644 --- a/src/platform/silabs/CHIPDevicePlatformEvent.h +++ b/src/platform/silabs/CHIPDevicePlatformEvent.h @@ -39,10 +39,7 @@ namespace DeviceEventType { */ enum PublicPlatformSpecificEventTypes { - kCommissioningWindowOpen = kRange_PublicPlatformSpecific, - kCommissioningWindowClose, - kCommissioningSessionStarted, - kCommissioningSessionStopped, + // No public platform specific events }; /** diff --git a/src/platform/silabs/efr32/BUILD.gn b/src/platform/silabs/efr32/BUILD.gn index ac9abb0eb8..f39628d484 100644 --- a/src/platform/silabs/efr32/BUILD.gn +++ b/src/platform/silabs/efr32/BUILD.gn @@ -162,16 +162,6 @@ static_library("efr32") { "${silabs_platform_dir}/NetworkCommissioningWiFiDriver.h", ] - # [sl-only] Support for the Wi-Fi Sleep Manager - if (chip_enable_icd_server) { - public_deps += [ "${silabs_common_plat_dir}/wifi/icd:sleep-manager" ] - } - - # [sl-only] Support for the Wi-Fi Sleep Manager public_deps += [ "${silabs_platform_dir}/wifi:wifi-platform" ] - - if (chip_enable_icd_server && use_SiWx917) { - public_deps += [ "${silabs_common_plat_dir}/wifi/icd:sleep-manager" ] - } } } diff --git a/src/platform/silabs/wifi/BUILD.gn b/src/platform/silabs/wifi/BUILD.gn index eb61e97854..3eefb0b783 100644 --- a/src/platform/silabs/wifi/BUILD.gn +++ b/src/platform/silabs/wifi/BUILD.gn @@ -108,6 +108,7 @@ source_set("wifi-platform") { public_deps = [ "${chip_root}/src/app/icd/server:icd-server-config", "${chip_root}/src/inet", + "${chip_root}/src/lib/core", "${chip_root}/src/lib/support", ] @@ -151,5 +152,10 @@ source_set("wifi-platform") { if (chip_enable_icd_server) { public_deps += [ "${chip_root}/src/app/icd/server:configuration-data" ] + + sources += [ + "${silabs_platform_dir}/wifi/icd/PlatformSleepManager.cpp", + "${silabs_platform_dir}/wifi/icd/PlatformSleepManager.h", + ] } } diff --git a/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp b/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp index 26bc1aa8f2..b09cdb56e4 100644 --- a/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp +++ b/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -53,9 +54,10 @@ osTimerId_t sRetryTimer; */ void RetryConnectionTimerHandler(void * arg) { -#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI91X_MCU_INTERFACE - wfx_power_save(RSI_ACTIVE, HIGH_PERFORMANCE, 0); -#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI91X_MCU_INTERFACE +#if CHIP_CONFIG_ENABLE_ICD_SERVER + Silabs::PlatformSleepManager::GetInstance().RequestHighPerformance(); +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER + if (wfx_connect_to_ap() != SL_STATUS_OK) { ChipLogError(DeviceLayer, "wfx_connect_to_ap() failed."); @@ -194,9 +196,9 @@ void wfx_retry_connection(uint16_t retryAttempt) } return; } -#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI91X_MCU_INTERFACE - wfx_power_save(RSI_SLEEP_MODE_8, DEEP_SLEEP_WITH_RAM_RETENTION, 0); -#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI91X_MCU_INTERFACE +#if CHIP_CONFIG_ENABLE_ICD_SERVER + Silabs::PlatformSleepManager::GetInstance().RemoveHighPerformanceRequest(); +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER ChipLogProgress(DeviceLayer, "wfx_retry_connection : Next attempt after %d Seconds", retryInterval); retryInterval += retryInterval; } diff --git a/src/platform/silabs/wifi/icd/BUILD.gn b/src/platform/silabs/wifi/icd/BUILD.gn deleted file mode 100644 index 27c1008fa9..0000000000 --- a/src/platform/silabs/wifi/icd/BUILD.gn +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (c) 2024 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build_overrides/chip.gni") - -config("platform-sleep-manager-config") { - include_dirs = [ "." ] - defines = [ "SL_MATTER_SLEEP_MANAGER_ENABLED=1" ] -} - -source_set("platform-sleep-manager") { - sources = [ - "PlatformSleepManager.cpp", - "PlatformSleepManager.h", - ] - - public_deps = [ - "${chip_root}/src/app:app", - "${chip_root}/src/app/icd/server:manager", - "${chip_root}/src/app/icd/server:observer", - "${chip_root}/src/credentials:credentials", - "${chip_root}/src/lib/core", - "${chip_root}/src/lib/support", - "${chip_root}/src/platform/silabs/wifi:wifi-platform", - ] - - public_configs = [ ":platform-sleep-manager-config" ] -} diff --git a/src/platform/silabs/wifi/icd/PlatformSleepManager.cpp b/src/platform/silabs/wifi/icd/PlatformSleepManager.cpp index bf33155397..9b123b4bfa 100644 --- a/src/platform/silabs/wifi/icd/PlatformSleepManager.cpp +++ b/src/platform/silabs/wifi/icd/PlatformSleepManager.cpp @@ -1,7 +1,24 @@ -#include "SleepManager.h" +/* + * + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include #include #include +#include using namespace chip::app; @@ -14,29 +31,19 @@ PlatformSleepManager PlatformSleepManager::mInstance; CHIP_ERROR PlatformSleepManager::Init() { - PlatformMgr().AddEventHandler(OnPlatformEvent, reinterpret_cast(this)); return CHIP_NO_ERROR; } void PlatformSleepManager::HandleCommissioningComplete() { - if (wfx_power_save(RSI_SLEEP_MODE_2, ASSOCIATED_POWER_SAVE, 0) != SL_STATUS_OK) - { - ChipLogError(AppServer, "wfx_power_save failed"); - } + TransitionToLowPowerMode(); } -void PlatformSleepManager::HandleInternetConnectivityChange(const ChipDeviceEvent * event) +void PlatformSleepManager::HandleInternetConnectivityChange() { - if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established) + if (!isCommissioningInProgress) { - if (!IsCommissioningInProgress()) - { - if - { - ChipLogError(AppServer, "wfx_power_save failed"); - } - } + TransitionToLowPowerMode(); } } @@ -44,60 +51,30 @@ void PlatformSleepManager::HandleCommissioningWindowClose() {} void PlatformSleepManager::HandleCommissioningSessionStarted() { - SetCommissioningInProgress(true); + isCommissioningInProgress = true; } void PlatformSleepManager::HandleCommissioningSessionStopped() { - SetCommissioningInProgress(false); -} - -void PlatformSleepManager::OnPlatformEvent(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg) -{ - PlatformSleepManager * manager = reinterpret_cast(arg); - VerifyOrDie(manager != nullptr); - - switch (event->Type) - { - case DeviceEventType::kCommissioningComplete: - manager->HandleCommissioningComplete(); - break; - - case DeviceEventType::kInternetConnectivityChange: - manager->HandleInternetConnectivityChange(event); - break; - - case DeviceEventType::kCommissioningWindowClose: - manager->HandleCommissioningWindowClose(); - break; - - case DeviceEventType::kCommissioningSessionStarted: - manager->HandleCommissioningSessionStarted(); - break; - - case DeviceEventType::kCommissioningSessionStopped: - manager->HandleCommissioningSessionStopped(); - break; - - default: - break; - } + isCommissioningInProgress = false; } CHIP_ERROR PlatformSleepManager::RequestHighPerformance() { - VerifyOrReturnError(mRequestHighPerformanceCounter < std::numeric_limits::max(), CHIP_ERROR_INTERNAL, + VerifyOrReturnError(mHighPerformanceRequestCounter < std::numeric_limits::max(), CHIP_ERROR_INTERNAL, ChipLogError(DeviceLayer, "High performance request counter overflow")); - if (mRequestHighPerformanceCounter == 0) + if (mHighPerformanceRequestCounter == 0) { +#if SLI_SI917 // 917 SoC & NCP VerifyOrReturnError(wfx_power_save(RSI_ACTIVE, HIGH_PERFORMANCE, 0) == SL_STATUS_OK, CHIP_ERROR_INTERNAL, ChipLogError(DeviceLayer, "Failed to set Wi-FI configuration to HighPerformance")); VerifyOrReturnError(ConfigureBroadcastFilter(false) == SL_STATUS_OK, CHIP_ERROR_INTERNAL, ChipLogError(DeviceLayer, "Failed to disable broadcast filter")); +#endif // SLI_SI917 } - mRequestHighPerformanceCounter++; + mHighPerformanceRequestCounter++; return CHIP_NO_ERROR; } @@ -121,16 +98,25 @@ CHIP_ERROR PlatformSleepManager::TransitionToLowPowerMode() VerifyOrReturnError(mHighPerformanceRequestCounter == 0, CHIP_NO_ERROR, ChipLogDetail(DeviceLayer, "High Performance Requested - Device cannot go to a lower power mode.")); - if (!ConnectivityMgr().IsWiFiStationProvisioned() && !IsCommissioningInProgress()) +#if SLI_SI917 // 917 SoC & NCP + // TODO: Clean this up when the Wi-Fi interface re-work is finished + wfx_wifi_provision_t wifiConfig; + wfx_get_wifi_provision(&wifiConfig); + + if (!(wifiConfig.ssid[0] != 0) && !isCommissioningInProgress) { - VerifyOrReturnError(wfx_power_save(RSI_SLEEP_MODE_8, DEEP_SLEEP_WITH_RAM_RETENTION, 0) != SL_STATUS_OK, - ChipLogError(DeviceLayer, "Failed to enable the TA Deep Sleep");) + VerifyOrReturnError(wfx_power_save(RSI_SLEEP_MODE_8, DEEP_SLEEP_WITH_RAM_RETENTION, 0) != SL_STATUS_OK, CHIP_ERROR_INTERNAL, + ChipLogError(DeviceLayer, "Failed to enable Deep Sleep.")); } else { - VerifyOrReturnError(wfx_power_save(RSI_SLEEP_MODE_2, ASSOCIATED_POWER_SAVE, 0) != SL_STATUS_OK, - ChipLogError(DeviceLayer, "Failed to enable the TA Deep Sleep");) + VerifyOrReturnError(wfx_power_save(RSI_SLEEP_MODE_2, ASSOCIATED_POWER_SAVE, 0) != SL_STATUS_OK, CHIP_ERROR_INTERNAL, + ChipLogError(DeviceLayer, "Failed to enable to go to sleep.")); } +#elif RS911X_WIFI // rs9116 + VerifyOrReturnError(wfx_power_save() != SL_STATUS_OK, CHIP_ERROR_INTERNAL, + ChipLogError(DeviceLayer, "Failed to enable to go to sleep.")); +#endif return CHIP_NO_ERROR; } diff --git a/src/platform/silabs/wifi/icd/PlatformSleepManager.h b/src/platform/silabs/wifi/icd/PlatformSleepManager.h index 1737e7194a..02c0abc79f 100644 --- a/src/platform/silabs/wifi/icd/PlatformSleepManager.h +++ b/src/platform/silabs/wifi/icd/PlatformSleepManager.h @@ -1,10 +1,22 @@ +/* + * + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #pragma once -#include -#include -#include -#include -#include #include namespace chip { @@ -51,36 +63,18 @@ class PlatformSleepManager */ CHIP_ERROR RemoveHighPerformanceRequest(); - static void OnPlatformEvent(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); - -private: - PlatformSleepManager() = default; - ~PlatformSleepManager() = default; - void HandleCommissioningComplete(); - void HandleInternetConnectivityChange(const chip::DeviceLayer::ChipDeviceEvent * event); + void HandleInternetConnectivityChange(); void HandleCommissioningWindowClose(); void HandleCommissioningSessionStarted(); void HandleCommissioningSessionStopped(); - /** - * @brief Set the commissioning status of the device - * - * @param[in] inProgress bool true if commissioning is in progress, false otherwise - */ - void SetCommissioningInProgress(bool inProgress) { isCommissioningInProgress = inProgress; } - - /** - * @brief Returns the current commissioning status of the device - * - * @return bool true if commissioning is in progress, false otherwise - */ - bool IsCommissioningInProgress() { return isCommissioningInProgress; } +private: + PlatformSleepManager() = default; + ~PlatformSleepManager() = default; /** * @brief Transition the device to the Lowest Power State. - * The function is responsible of deciding if the device can go to a LI based sleep - * or is required to stay in a DTIM based sleep to be able to receive mDNS messages * * @return CHIP_ERROR CHIP_NO_ERROR if the device was transitionned to low power * CHIP_ERROR_INTERNAL if an error occured