Skip to content

Commit

Permalink
[SL-UP] Introduce PlatformSleepManager to manage Wi-Fi sleep states (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
mkardous-silabs authored Nov 19, 2024
1 parent 67f03dd commit 2a8e7d9
Show file tree
Hide file tree
Showing 16 changed files with 333 additions and 256 deletions.
61 changes: 25 additions & 36 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <platform/silabs/NetworkCommissioningWiFiDriver.h>
#include <platform/silabs/wifi/WifiInterfaceAbstraction.h>

#if CHIP_CONFIG_ENABLE_ICD_SERVER
#include <platform/silabs/wifi/icd/WifiSleepManager.h>
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
#endif // SL_WIFI

#ifdef DIC_ENABLE
Expand Down Expand Up @@ -182,25 +186,23 @@ BaseApplicationDelegate BaseApplication::sAppDelegate = BaseApplicationDelegate(
void BaseApplicationDelegate::OnCommissioningSessionStarted()
{
isComissioningStarted = true;

#if SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER
WifiSleepManager::GetInstance().HandleCommissioningSessionStarted();
#endif // SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER
}

void BaseApplicationDelegate::OnCommissioningSessionStopped()
{
isComissioningStarted = false;

#if SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER
WifiSleepManager::GetInstance().HandleCommissioningSessionStopped();
#endif // SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER
}

void BaseApplicationDelegate::OnCommissioningWindowClosed()
{
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
if (!BaseApplication::GetProvisionStatus() && !isComissioningStarted)
{
int32_t status = wfx_power_save(RSI_SLEEP_MODE_8, DEEP_SLEEP_WITH_RAM_RETENTION);
if (status != SL_STATUS_OK)
{
ChipLogError(AppServer, "Failed to enable the TA Deep Sleep");
}
}
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
if (BaseApplication::GetProvisionStatus())
{
// After the device is provisioned and the commissioning passed
Expand All @@ -215,8 +217,14 @@ void BaseApplicationDelegate::OnCommissioningWindowClosed()
#endif // QR_CODE_ENABLED
#endif // DISPLAY_ENABLED
}

#if SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER
WifiSleepManager::GetInstance().HandleCommissioningWindowClose();
#endif // SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER
}

void BaseApplicationDelegate::OnCommissioningWindowOpened() {}

void BaseApplicationDelegate::OnFabricCommitted(const FabricTable & fabricTable, FabricIndex fabricIndex)
{
// If we commissioned our first fabric, Update the commissioned status of the App
Expand Down Expand Up @@ -896,44 +904,25 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t)
{
#if SL_WIFI
chip::app::DnssdServer::Instance().StartServer();
#if CHIP_CONFIG_ENABLE_ICD_SERVER
WifiSleepManager::GetInstance().HandleInternetConnectivityChange();
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
#endif // SL_WIFI

#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)
// on power cycle, let the device go to sleep after connection is established
if (BaseApplication::sAppDelegate.isCommissioningInProgress() == false)
{
#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(AppServer, "wfx_power_save failed: 0x%lx", err);
}
}
#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER && RS911X_WIFI */
}
}
break;

case DeviceEventType::kCommissioningComplete: {
#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(AppServer, "wfx_power_save failed: 0x%lx", err);
}
#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER && RS911X_WIFI */
#if SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER
WifiSleepManager::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)
Expand Down
1 change: 1 addition & 0 deletions examples/platform/silabs/BaseApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class BaseApplicationDelegate : public AppDelegate, public chip::FabricTable::De
private:
// AppDelegate
bool isComissioningStarted = false;
void OnCommissioningWindowOpened() override;
void OnCommissioningSessionStarted() override;
void OnCommissioningSessionStopped() override;
void OnCommissioningWindowClosed() override;
Expand Down
14 changes: 12 additions & 2 deletions examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
#include "AppConfig.h"
#include "BaseApplication.h"
#include <MatterConfig.h>
#include <app/icd/server/ICDServerConfig.h>
#include <cmsis_os2.h>

#include <mbedtls/platform.h>

#ifdef SL_WIFI
#include <platform/silabs/wifi/WifiInterfaceAbstraction.h>

#if CHIP_CONFIG_ENABLE_ICD_SERVER
#include <platform/silabs/wifi/icd/WifiSleepManager.h>
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
#endif /* SL_WIFI */

#if PW_RPC_ENABLED
Expand Down Expand Up @@ -240,7 +244,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::WifiSleepManager::GetInstance().Init();
VerifyOrReturnError(err == CHIP_NO_ERROR, err);
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
#endif // SL_WIFI

ReturnErrorOnFailure(PlatformMgr().InitChipStack());

Expand Down Expand Up @@ -299,6 +308,7 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
#endif

initParams.appDelegate = &BaseApplication::sAppDelegate;

// Init Matter Server and Start Event Loop
err = chip::Server::GetInstance().Init(initParams);

Expand Down
5 changes: 0 additions & 5 deletions examples/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ source_set("siwx917-common") {
}
}

# Sl-Only: Support for the Wi-Fi Sleep Manager
if (chip_enable_icd_server) {
public_deps += [ "${silabs_common_plat_dir}/wifi/icd:sleep-manager" ]
}

# DIC
if (enable_dic) {
public_deps +=
Expand Down
37 changes: 0 additions & 37 deletions examples/platform/silabs/wifi/icd/BUILD.gn

This file was deleted.

40 changes: 0 additions & 40 deletions examples/platform/silabs/wifi/icd/SleepManager.cpp

This file was deleted.

61 changes: 0 additions & 61 deletions examples/platform/silabs/wifi/icd/SleepManager.h

This file was deleted.

5 changes: 0 additions & 5 deletions src/platform/silabs/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@
#define CHIP_DEVICE_CONFIG_ENABLE_IPV4 0
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */

#if SL_ICD_ENABLED
#define CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL chip::System::Clock::Milliseconds32(300)
#define CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL chip::System::Clock::Milliseconds32(10)
#endif /* SL_ICD_ENABLED */

#endif /* SL_WIFI */

// ========== Platform-specific Configuration =========
Expand Down
2 changes: 1 addition & 1 deletion src/platform/silabs/CHIPDevicePlatformEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace DeviceEventType {
*/
enum PublicPlatformSpecificEventTypes
{
/* None currently defined */
// No public platform specific events
};

/**
Expand Down
Loading

0 comments on commit 2a8e7d9

Please sign in to comment.