Skip to content

Commit

Permalink
refactor sleep manager to support all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
mkardous-silabs committed Nov 18, 2024
1 parent eb97335 commit 3b1928b
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 193 deletions.
58 changes: 21 additions & 37 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/PlatformSleepManager.h>
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
#endif // SL_WIFI

#ifdef DIC_ENABLE
Expand Down Expand Up @@ -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()
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 17 additions & 13 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/PlatformSleepManager.h>
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
#endif /* SL_WIFI */

#if PW_RPC_ENABLED
Expand All @@ -45,10 +49,9 @@
#include <platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h>
#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 <crypto/CHIPCryptoPAL.h>
// If building with the EFR32-provided crypto backend, we can use the
Expand Down Expand Up @@ -92,6 +95,8 @@ static chip::DeviceLayer::Internal::Efr32PsaOperationalKeystore gOperationalKeys
#include "sl_power_manager.h"
#endif

// #include "sl_si91x_power_manager.h"

/**********************************************************
* Defines
*********************************************************/
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions src/platform/silabs/CHIPDevicePlatformEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ namespace DeviceEventType {
*/
enum PublicPlatformSpecificEventTypes
{
kCommissioningWindowOpen = kRange_PublicPlatformSpecific,
kCommissioningWindowClose,
kCommissioningSessionStarted,
kCommissioningSessionStopped,
// No public platform specific events
};

/**
Expand Down
10 changes: 0 additions & 10 deletions src/platform/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
}
}
6 changes: 6 additions & 0 deletions src/platform/silabs/wifi/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]

Expand Down Expand Up @@ -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",
]
}
}
14 changes: 8 additions & 6 deletions src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/silabs/wifi/WifiInterfaceAbstraction.h>
#include <platform/silabs/wifi/icd/PlatformSleepManager.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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;
}
39 changes: 0 additions & 39 deletions src/platform/silabs/wifi/icd/BUILD.gn

This file was deleted.

Loading

0 comments on commit 3b1928b

Please sign in to comment.