Skip to content

Commit

Permalink
Merge branch 'release_2.5-1.4' into bugfix/refrigerator-alarm-cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
shgutte authored Nov 29, 2024
2 parents 33e220f + 29ada74 commit b1a334c
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 56 deletions.
16 changes: 16 additions & 0 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
#include <platform/silabs/tracing/SilabsTracing.h>
#endif // MATTER_TRACING_ENABLED

// sl-only
#if SL_MATTER_ENABLE_APP_SLEEP_MANAGER
#include <ApplicationSleepManager.h>
#endif // SL_MATTER_ENABLE_APP_SLEEP_MANAGER

/**********************************************************
* Defines and Constants
*********************************************************/
Expand Down Expand Up @@ -213,8 +218,19 @@ void BaseApplicationDelegate::OnCommissioningSessionStopped()
#endif // SL_WIFI && CHIP_CONFIG_ENABLE_ICD_SERVER
}

void BaseApplicationDelegate::OnCommissioningWindowOpened()
{
#if SL_MATTER_ENABLE_APP_SLEEP_MANAGER
app::Silabs::ApplicationSleepManager::GetInstance().OnCommissioningWindowOpened();
#endif // SL_MATTER_ENABLE_APP_SLEEP_MANAGER
}

void BaseApplicationDelegate::OnCommissioningWindowClosed()
{
#if SL_MATTER_ENABLE_APP_SLEEP_MANAGER
app::Silabs::ApplicationSleepManager::GetInstance().OnCommissioningWindowClosed();
#endif // SL_MATTER_ENABLE_APP_SLEEP_MANAGER

if (BaseApplication::GetProvisionStatus())
{
// After the device is provisioned and the commissioning passed
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 @@ -74,6 +74,7 @@ class BaseApplicationDelegate : public AppDelegate, public chip::FabricTable::De
void OnCommissioningSessionStarted() override;
void OnCommissioningSessionStopped() override;
void OnCommissioningWindowClosed() override;
void OnCommissioningWindowOpened() override;

// FabricTable::Delegate
void OnFabricCommitted(const chip::FabricTable & fabricTable, chip::FabricIndex fabricIndex) override;
Expand Down
10 changes: 3 additions & 7 deletions examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,6 @@ void SilabsMatterConfig::AppInit()
ChipLogProgress(DeviceLayer, "Starting scheduler");
VerifyOrDie(sMainTaskHandle); // We can't proceed if the Main Task creation failed.

#if MATTER_TRACING_ENABLED
SilabsTracer::Instance().TimeTraceEnd(TimeTraceOperation::kBootup);
#endif // MATTER_TRACING_ENABLED
GetPlatform().StartScheduler();

// Should never get here.
Expand Down Expand Up @@ -334,15 +331,11 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)

initParams.appDelegate = &BaseApplication::sAppDelegate;

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

// [sl-only]: Configure Wi-Fi App Sleep Manager
#if SL_MATTER_ENABLE_APP_SLEEP_MANAGER
err = app::Silabs::ApplicationSleepManager::GetInstance()
.SetFabricTable(&Server::GetInstance().GetFabricTable())
.SetSubscriptionInfoProvider(app::InteractionModelEngine::GetInstance())
.SetCommissioningWindowManager(&Server::GetInstance().GetCommissioningWindowManager())
.SetWifiSleepManager(&WifiSleepManager::GetInstance())
.Init();
VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "ApplicationSleepManager init failed"));
Expand All @@ -352,6 +345,9 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
&app::Silabs::ApplicationSleepManager::GetInstance());
#endif // SL_MATTER_ENABLE_APP_SLEEP_MANAGER

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

#if MATTER_TRACING_ENABLED
static Tracing::Silabs::BackendImpl backend;
Tracing::Register(backend);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
extern "C" {
#endif
#include <sparkfun_sgp40.h>
#include <sparkfun_sgp40_i2c.h>
}
#include "sl_i2cspm_instances.h"
#endif // USE_SPARKFUN_AIR_QUALITY_SENSOR
Expand Down
39 changes: 34 additions & 5 deletions examples/platform/silabs/wifi/icd/ApplicationSleepManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ CHIP_ERROR ApplicationSleepManager::Init()
VerifyOrReturnError(mFabricTable != nullptr, CHIP_ERROR_INVALID_ARGUMENT, ChipLogError(AppServer, "FabricTable is null"));
VerifyOrReturnError(mSubscriptionsInfoProvider != nullptr, CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(AppServer, "SubscriptionsInfoProvider is null"));
VerifyOrReturnError(mCommissioningWindowManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(AppServer, "CommissioningWindowManager is null"));
VerifyOrReturnError(mWifiSleepManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(AppServer, "WifiSleepManager is null"));

Expand All @@ -42,6 +40,18 @@ CHIP_ERROR ApplicationSleepManager::Init()
return CHIP_NO_ERROR;
}

void ApplicationSleepManager::OnCommissioningWindowOpened()
{
mIsCommissionningWindowOpen = true;
mWifiSleepManager->VerifyAndTransitionToLowPowerMode();
}

void ApplicationSleepManager::OnCommissioningWindowClosed()
{
mIsCommissionningWindowOpen = false;
mWifiSleepManager->VerifyAndTransitionToLowPowerMode();
}

void ApplicationSleepManager::OnSubscriptionEstablished(chip::app::ReadHandler & aReadHandler)
{
mWifiSleepManager->VerifyAndTransitionToLowPowerMode();
Expand Down Expand Up @@ -71,10 +81,29 @@ void ApplicationSleepManager::OnFabricCommitted(const chip::FabricTable & fabric

bool ApplicationSleepManager::CanGoToLIBasedSleep()
{
// TODO: Implement your logic here
bool canGoToLIBasedSleep = true;

if (mIsCommissionningWindowOpen)
{
ChipLogProgress(AppServer, "Commissioning Window is Open - Cannot go to LI based sleep");
canGoToLIBasedSleep = false;
}
else
{
for (auto it = mFabricTable->begin(); it != mFabricTable->end(); ++it)
{
if (!mSubscriptionsInfoProvider->FabricHasAtLeastOneActiveSubscription(it->GetFabricIndex()))
{
ChipLogProgress(AppServer, "Fabric index %u has no active subscriptions - Cannot go to LI based sleep",
it->GetFabricIndex());
canGoToLIBasedSleep = false;
break;
}
ChipLogProgress(AppServer, "All Fabrics have at least 1 active subscription!");
}
}

ChipLogProgress(AppServer, "CanGoToLIBasedSleep was called!");
return false;
return canGoToLIBasedSleep;
}

} // namespace Silabs
Expand Down
32 changes: 23 additions & 9 deletions examples/platform/silabs/wifi/icd/ApplicationSleepManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,26 @@ class ApplicationSleepManager : public chip::app::ReadHandler::ApplicationCallba
return *this;
}

ApplicationSleepManager & SetCommissioningWindowManager(chip::CommissioningWindowManager * commissioningWindowManager)
{
mCommissioningWindowManager = commissioningWindowManager;
return *this;
}

ApplicationSleepManager & SetWifiSleepManager(chip::DeviceLayer::Silabs::WifiSleepManager * wifiSleepManager)
{
mWifiSleepManager = wifiSleepManager;
return *this;
}

/**
* @brief Sets the commissioning window state to open and calls the WifiSleepManager VerifyAndTransitionToLowPowerMode.
* The VerifyAndTransitionToLowPowerMode function is responsible of then queriyng the ApplicationSleepManager to
* determine in which low power state the Wi-Fi device can transition to.
*/
void OnCommissioningWindowOpened();

/**
* @brief Sets the commissioning window state to open and calls the WifiSleepManager VerifyAndTransitionToLowPowerMode.
* The VerifyAndTransitionToLowPowerMode function is responsible of then queriyng the ApplicationSleepManager to
* determine in which low power state the Wi-Fi device can transition to.
*/
void OnCommissioningWindowClosed();

// ReadHandler::ApplicationCallback implementation

/**
Expand All @@ -94,10 +102,14 @@ class ApplicationSleepManager : public chip::app::ReadHandler::ApplicationCallba
// WifiSleepManager::ApplicationCallback implementation

/**
* @brief TODO
* @brief Function encapsulates the application logic to determine if the Wi-Fi device can go into LI based sleep.
*
* @return true
* @return false
* - 1. Check if the commissioning window is open. If it is open, the Wi-Fi device cannot go to LI based sleep.
* - 2. Check if all Fabrics have at least 1 subscription. If there is at least one fabric without a subscription, the
* Wi-Fi cannot go to LI based sleep.
*
* @return true if the device can go to LI sleep
* false if the device cannot go to LI sleep
*/
bool CanGoToLIBasedSleep() override;

Expand Down Expand Up @@ -131,6 +143,8 @@ class ApplicationSleepManager : public chip::app::ReadHandler::ApplicationCallba
chip::app::SubscriptionsInfoProvider * mSubscriptionsInfoProvider = nullptr;
chip::CommissioningWindowManager * mCommissioningWindowManager = nullptr;
chip::DeviceLayer::Silabs::WifiSleepManager * mWifiSleepManager = nullptr;

bool mIsCommissionningWindowOpen = false;
};

} // namespace Silabs
Expand Down
4 changes: 2 additions & 2 deletions src/app/ReadHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ uint16_t ReadHandler::GetPublisherSelectedIntervalLimit()

ReadHandler::ReadHandler(ManagementCallback & apCallback, Messaging::ExchangeContext * apExchangeContext,
InteractionType aInteractionType, Observer * observer, DataModel::Provider * apDataModel) :
mAttributePathExpandIterator(apDataModel, nullptr),
mExchangeCtx(*this), mManagementCallback(apCallback)
mAttributePathExpandIterator(apDataModel, nullptr), mExchangeCtx(*this), mManagementCallback(apCallback)
{
VerifyOrDie(apExchangeContext != nullptr);

Expand Down Expand Up @@ -152,6 +151,7 @@ ReadHandler::~ReadHandler()
auto * appCallback = mManagementCallback.GetAppCallback();
if (mFlags.Has(ReadHandlerFlags::ActiveSubscription) && appCallback)
{
mFlags.Clear(ReadHandlerFlags::ActiveSubscription);
appCallback->OnSubscriptionTerminated(*this);
}

Expand Down
13 changes: 4 additions & 9 deletions src/platform/silabs/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,8 @@
#include "uart.h"
#endif

// Enable RTT by default
#ifndef SILABS_LOG_OUT_RTT
#define SILABS_LOG_OUT_RTT 1
#endif

// SEGGER_RTT includes
#if SILABS_LOG_OUT_RTT
#if !SILABS_LOG_OUT_UART
#include "SEGGER_RTT.h"
#include "SEGGER_RTT_Conf.h"
#endif
Expand Down Expand Up @@ -137,7 +132,7 @@ static void PrintLog(const char * msg)
SEGGER_RTT_WriteNoLock(LOG_RTT_BUFFER_INDEX, msg, sz);
#endif // SILABS_LOG_OUT_UART

#if SILABS_LOG_OUT_RTT || PW_RPC_ENABLED
#if !SILABS_LOG_OUT_UART || PW_RPC_ENABLED
const char * newline = "\r\n";
sz = strlen(newline);
#if PW_RPC_ENABLED
Expand All @@ -155,7 +150,7 @@ static void PrintLog(const char * msg)
extern "C" void silabsInitLog(void)
{
#if SILABS_LOG_ENABLED
#if SILABS_LOG_OUT_RTT
#if !SILABS_LOG_OUT_UART
#if LOG_RTT_BUFFER_INDEX != 0
SEGGER_RTT_ConfigUpBuffer(LOG_RTT_BUFFER_INDEX, LOG_RTT_BUFFER_NAME, sLogBuffer, LOG_RTT_BUFFER_SIZE,
SEGGER_RTT_MODE_NO_BLOCK_TRIM);
Expand All @@ -165,7 +160,7 @@ extern "C" void silabsInitLog(void)
#else
SEGGER_RTT_SetFlagsUpBuffer(LOG_RTT_BUFFER_INDEX, SEGGER_RTT_MODE_NO_BLOCK_TRIM);
#endif
#endif // SILABS_LOG_OUT_RTT
#endif // !SILABS_LOG_OUT_UART

#ifdef PW_RPC_ENABLED
PigweedLogger::init();
Expand Down
17 changes: 9 additions & 8 deletions src/platform/silabs/tracing/SilabsTracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,21 @@ CHIP_ERROR SilabsTracer::StartWatermarksStorage(PersistentStorageDelegate * stor
CHIP_ERROR SilabsTracer::TimeTraceBegin(TimeTraceOperation aOperation)
{
// Log the start time of the operation
auto & tracker = mLatestTimeTrackers[static_cast<size_t>(aOperation)];
auto & tracker = mLatestTimeTrackers[to_underlying(aOperation)];
tracker.mStartTime = System::SystemClock().GetMonotonicTimestamp();
tracker.mOperation = aOperation;
tracker.mType = OperationType::kBegin;
tracker.mError = CHIP_NO_ERROR;

auto & watermark = mWatermarks[static_cast<size_t>(aOperation)];
auto & watermark = mWatermarks[to_underlying(aOperation)];
watermark.mTotalCount++;

return OutputTrace(tracker);
}

CHIP_ERROR SilabsTracer::TimeTraceEnd(TimeTraceOperation aOperation, CHIP_ERROR error)
{
auto & tracker = mLatestTimeTrackers[static_cast<size_t>(aOperation)];
auto & tracker = mLatestTimeTrackers[to_underlying(aOperation)];
tracker.mEndTime = System::SystemClock().GetMonotonicTimestamp();
tracker.mType = OperationType::kEnd;
tracker.mError = error;
Expand All @@ -203,7 +203,7 @@ CHIP_ERROR SilabsTracer::TimeTraceEnd(TimeTraceOperation aOperation, CHIP_ERROR
// Calculate the duration and update the time tracker
auto duration = tracker.mEndTime - tracker.mStartTime;

auto & watermark = mWatermarks[static_cast<size_t>(aOperation)];
auto & watermark = mWatermarks[to_underlying(aOperation)];
watermark.mSuccessfullCount++;
watermark.mMovingAverage = System::Clock::Milliseconds32(
(watermark.mMovingAverage.count() * (watermark.mSuccessfullCount - 1) + duration.count()) /
Expand Down Expand Up @@ -287,15 +287,16 @@ CHIP_ERROR SilabsTracer::OutputWaterMark(TimeTraceOperation aOperation)
{
VerifyOrReturnError(to_underlying(aOperation) < kNumTraces, CHIP_ERROR_INVALID_ARGUMENT,
ChipLogError(DeviceLayer, "Invalid TimeTraceOperation"));
size_t index = to_underlying(aOperation);
auto & watermark = mWatermarks[index];

VerifyOrReturnError(isLogInitialized(), CHIP_ERROR_UNINITIALIZED);
ChipLogProgress(DeviceLayer,
"| Operation: %-25s| MaxTime:%-5" PRIu32 "| MinTime:%-5" PRIu32 "| AvgTime:%-5" PRIu32 "| TotalCount:%-8" PRIu32
", SuccessFullCount:%-8" PRIu32 "| CountAboveAvg:%-8" PRIu32 "|",
TimeTraceOperationToString(aOperation), watermark.mMaxTimeMs.count(), watermark.mMinTimeMs.count(),
watermark.mMovingAverage.count(), watermark.mTotalCount, watermark.mSuccessfullCount, watermark.mCountAboveAvg);
TimeTraceOperationToString(aOperation), mWatermarks[to_underlying(aOperation)].mMaxTimeMs.count(),
mWatermarks[to_underlying(aOperation)].mMinTimeMs.count(),
mWatermarks[to_underlying(aOperation)].mMovingAverage.count(),
mWatermarks[to_underlying(aOperation)].mTotalCount, mWatermarks[to_underlying(aOperation)].mSuccessfullCount,
mWatermarks[to_underlying(aOperation)].mCountAboveAvg);

return CHIP_NO_ERROR;
}
Expand Down
Loading

0 comments on commit b1a334c

Please sign in to comment.