Skip to content

Commit

Permalink
Merge branch 'release_2.5-1.4' into bugfix/rs9116-update-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rosahay-silabs authored Nov 29, 2024
2 parents c1f6e78 + 29ada74 commit 06e62dd
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 45 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
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
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
55 changes: 48 additions & 7 deletions src/platform/silabs/wifi/SiWx/WifiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,17 @@ sl_status_t ScanCallback(sl_wifi_event_t event, sl_wifi_scan_result_t * scan_res
sl_status_t status = SL_STATUS_OK;
if (SL_WIFI_CHECK_IF_EVENT_FAILED(event))
{
ChipLogError(DeviceLayer, "Scan Netwrok Failed: 0x%lx", *reinterpret_cast<sl_status_t *>(status));
if (scan_result != nullptr)
{
status = *reinterpret_cast<sl_status_t *>(scan_result);
ChipLogError(DeviceLayer, "ScanCallback: failed: 0x%lx", static_cast<uint32_t>(status));
}

#if WIFI_ENABLE_SECURITY_WPA3_TRANSITION
security = SL_WIFI_WPA3;
#else
security = SL_WIFI_WPA_WPA2_MIXED;
#endif /* WIFI_ENABLE_SECURITY_WPA3_TRANSITION */

status = SL_STATUS_FAIL;
}
else
{
Expand Down Expand Up @@ -408,6 +411,45 @@ sl_status_t SetWifiConfigurations()
return status;
}

/**
* @brief Callback function for the SL_WIFI_JOIN_EVENTS group
*
* This callback handler will be invoked when any event within join event group occurs, providing the event details and any associated data
* The callback doesn't get called when we join a network using the sl net APIs
*
* @note In case of failure, the 'result' parameter will be of type sl_status_t, and the 'resultLenght' parameter should be ignored
*
* @param[in] event sl_wifi_event_t that triggered the callback
* @param[in] result Pointer to the response data received
* @param[in] result_length Length of the data received in bytes
* @param[in] arg Optional user provided argument
*
* @return sl_status_t Returns the status of the operation
*/
sl_status_t JoinCallback(sl_wifi_event_t event, char * result, uint32_t resultLenght, void * arg)
{
sl_status_t status = SL_STATUS_OK;
wfx_rsi.dev_state.Clear(WifiState::kStationConnecting);
if (SL_WIFI_CHECK_IF_EVENT_FAILED(event))
{
status = *reinterpret_cast<sl_status_t *>(result);
ChipLogError(DeviceLayer, "JoinCallback: failed: 0x%lx", static_cast<uint32_t>(status));
wfx_rsi.dev_state.Clear(WifiState::kStationConnected);
wfx_retry_connection(++wfx_rsi.join_retries);
return status;
}

/*
* Join was complete - Do the DHCP
*/
ChipLogDetail(DeviceLayer, "JoinCallback: success");
memset(&temp_reset, 0, sizeof(temp_reset));

WifiEvent wifievent = WifiEvent::kStationConnect;
sl_matter_wifi_post_event(wifievent);
wfx_rsi.join_retries = 0;
return status;
}
sl_status_t JoinWifiNetwork(void)
{
VerifyOrReturnError(!wfx_rsi.dev_state.HasAny(WifiState::kStationConnecting, WifiState::kStationConnected),
Expand All @@ -420,6 +462,9 @@ sl_status_t JoinWifiNetwork(void)
status = SetWifiConfigurations();
VerifyOrReturnError(status == SL_STATUS_OK, status, ChipLogError(DeviceLayer, "Failure to set the Wifi Configurations!"));

status = sl_wifi_set_join_callback(JoinCallback, nullptr);
VerifyOrReturnError(status == SL_STATUS_OK, status);

status = sl_net_up((sl_net_interface_t) SL_NET_WIFI_CLIENT_INTERFACE, SL_NET_DEFAULT_WIFI_CLIENT_PROFILE_ID);

if (status == SL_STATUS_OK || status == SL_STATUS_IN_PROGRESS)
Expand All @@ -437,16 +482,12 @@ sl_status_t JoinWifiNetwork(void)

// failure only happens when the firmware returns an error
ChipLogError(DeviceLayer, "sl_wifi_connect failed: 0x%lx", static_cast<uint32_t>(status));
VerifyOrReturnError((wfx_rsi.join_retries <= MAX_JOIN_RETRIES_COUNT), status);

wfx_rsi.dev_state.Clear(WifiState::kStationConnecting).Clear(WifiState::kStationConnected);

ChipLogProgress(DeviceLayer, "Connection retry attempt %d", wfx_rsi.join_retries);
wfx_retry_connection(++wfx_rsi.join_retries);

WifiEvent event = WifiEvent::kStationStartJoin;
sl_matter_wifi_post_event(event);

return status;
}

Expand Down
7 changes: 3 additions & 4 deletions third_party/silabs/SiWx917_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,9 @@ template("siwx917_sdk") {
}

if (sl_uart_log_output) {
defines += [
"SILABS_LOG_OUT_UART=1",
"SILABS_LOG_OUT_RTT=0",
]
defines += [ "SILABS_LOG_OUT_UART=1" ]
} else {
defines += [ "SILABS_LOG_OUT_UART=0" ]
}

if (chip_build_libshell) { # matter shell
Expand Down
7 changes: 3 additions & 4 deletions third_party/silabs/efr32_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,9 @@ template("efr32_sdk") {
}

if (sl_uart_log_output) {
defines += [
"SILABS_LOG_OUT_UART=1",
"SILABS_LOG_OUT_RTT=0",
]
defines += [ "SILABS_LOG_OUT_UART=1" ]
} else {
defines += [ "SILABS_LOG_OUT_UART=0" ]
}

if (use_silabs_thread_lib) {
Expand Down

0 comments on commit 06e62dd

Please sign in to comment.