Skip to content

Commit a3e38b7

Browse files
Address review comments
1 parent 3ddf3bc commit a3e38b7

File tree

11 files changed

+110
-33
lines changed

11 files changed

+110
-33
lines changed

examples/platform/silabs/MatterConfig.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ void SilabsMatterConfig::AppInit()
203203

204204
CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
205205
{
206+
using namespace chip::DeviceLayer::Silabs;
207+
206208
CHIP_ERROR err;
207209
#ifdef SL_WIFI
208210
// Because OpenThread needs to use memory allocation during its Key operations, we initialize the memory management for thread
@@ -234,10 +236,9 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
234236
ReturnErrorOnFailure(InitWiFi());
235237

236238
#if CHIP_CONFIG_ENABLE_ICD_SERVER
237-
ReturnErrorOnFailure(DeviceLayer::Silabs::WifiSleepManager::GetInstance().Init(
238-
&DeviceLayer::Silabs::WifiInterface::GetInstance(), &DeviceLayer::Silabs::WifiInterface::GetInstance()));
239+
ReturnErrorOnFailure(WifiSleepManager::GetInstance().Init(&WifiInterface::GetInstance(), &WifiInterface::GetInstance()));
239240
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
240-
#endif
241+
#endif // SL_WIFI
241242

242243
ReturnErrorOnFailure(PlatformMgr().InitChipStack());
243244

src/platform/silabs/ConfigurationManagerImpl.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <platform/internal/GenericConfigurationManagerImpl.ipp>
3030
#include <platform/silabs/SilabsConfig.h>
3131
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
32+
#include <platform/silabs/wifi/icd/WifiSleepManager.h>
3233

3334
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION
3435
#include <platform/silabs/wifi/WifiInterface.h>

src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context)
162162

163163
#if CHIP_CONFIG_ENABLE_ICD_SERVER
164164
// Setting the device in high performance - no-sleep mode during OTA tranfer
165-
DeviceLayer::Silabs::WifiSleepManager::GetInstance().RequestHighPerformance();
165+
DeviceLayer::Silabs::WifiSleepManager::GetInstance().RequestHighPerformanceWithTransition();
166166
#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER*/
167167

168168
imageProcessor->mDownloader->OnPreparedForDownload(CHIP_NO_ERROR);
@@ -220,7 +220,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
220220

221221
#if CHIP_CONFIG_ENABLE_ICD_SERVER
222222
// Setting the device is in high performace - no-sleepy mode before soft reset as soft reset is not happening in sleep mode
223-
DeviceLayer::Silabs::WifiSleepManager::GetInstance().RequestHighPerformance();
223+
DeviceLayer::Silabs::WifiSleepManager::GetInstance().RequestHighPerformanceWithTransition();
224224
#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER*/
225225

226226
if (mReset)

src/platform/silabs/tests/args.gni

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import("//build/chip/tests.gni")
15+
import("//build_overrides/chip.gni")
16+
import("${chip_root}/build/chip/tests.gni")
1617

1718
declare_args() {
1819
# Build argument to enable Silabs specific unit tests

src/platform/silabs/wifi/BUILD.gn

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import("//build_overrides/chip.gni")
1616
import("//build_overrides/lwip.gni")
1717
import("${chip_root}/src/platform/device.gni")
18+
import("${chip_root}/src/platform/silabs/tests/args.gni")
1819
import("${chip_root}/third_party/silabs/efr32_sdk.gni")
1920
import("${chip_root}/third_party/silabs/silabs_board.gni")
2021

@@ -35,7 +36,8 @@ declare_args() {
3536
sl_enable_wifi_debug = false
3637
}
3738

38-
if (chip_enable_wifi && !wifi_soc) {
39+
# Workaround to prevent the assert when we are building the unit tests
40+
if (chip_enable_wifi && !wifi_soc && !sl_build_unit_tests) {
3941
assert(use_rs9116 || use_wf200 || use_SiWx917)
4042
import("${chip_root}/src/platform/silabs/wifi/args.gni")
4143

@@ -100,7 +102,7 @@ config("wifi-platform-config") {
100102
}
101103
}
102104

103-
source_set("wifi-state-provider") {
105+
source_set("state-provider") {
104106
sources = [ "${silabs_platform_dir}/wifi/WifiStateProvider.h" ]
105107

106108
public_configs = [ ":wifi-platform-config" ]
@@ -116,7 +118,7 @@ source_set("wifi-platform") {
116118
public_configs = [ ":wifi-platform-config" ]
117119

118120
public_deps = [
119-
":wifi-state-provider",
121+
":state-provider",
120122
"${chip_root}/src/app/icd/server:icd-server-config",
121123
"${chip_root}/src/inet",
122124
"${chip_root}/src/lib/support",

src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,9 @@ void WiseconnectWifiInterface::MatterWifiTask(void * arg)
489489
VerifyOrReturn(status == SL_STATUS_OK,
490490
ChipLogError(DeviceLayer, "MatterWifiTask: SiWxPlatformInit failed: 0x%lx", static_cast<uint32_t>(status)));
491491

492+
// Remove High performance request after the device is initialized
493+
// chip::DeviceLayer::Silabs::WifiSleepManager::GetInstance().RemoveHighPerformanceRequest();
494+
492495
WifiInterfaceImpl::GetInstance().NotifyWifiTaskInitialized();
493496

494497
ChipLogDetail(DeviceLayer, "MatterWifiTask: starting event loop");
@@ -509,6 +512,9 @@ CHIP_ERROR WifiInterfaceImpl::InitWiFiStack(void)
509512
{
510513
sl_status_t status = SL_STATUS_OK;
511514

515+
// Force the device to high performance mode during the init sequence.
516+
chip::DeviceLayer::Silabs::WifiSleepManager::GetInstance().RequestHighPerformanceWithoutTransition();
517+
512518
status = sl_net_init(SL_NET_WIFI_CLIENT_INTERFACE, &config, &wifi_client_context, nullptr);
513519
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR_INTERNAL, ChipLogError(DeviceLayer, "sl_net_init failed: %lx", status));
514520

@@ -705,7 +711,7 @@ sl_status_t WifiInterfaceImpl::JoinWifiNetwork(void)
705711
// To avoid IOP issues, it is recommended to enable high-performance mode before joining the network.
706712
// TODO: Remove this once the IOP issue related to power save mode switching is fixed in the Wi-Fi SDK.
707713
#if CHIP_CONFIG_ENABLE_ICD_SERVER
708-
chip::DeviceLayer::Silabs::WifiSleepManager::GetInstance().RequestHighPerformance();
714+
chip::DeviceLayer::Silabs::WifiSleepManager::GetInstance().RequestHighPerformanceWithTransition();
709715
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
710716

711717
status = sl_net_up(SL_NET_WIFI_CLIENT_INTERFACE, SL_NET_DEFAULT_WIFI_CLIENT_PROFILE_ID);

src/platform/silabs/wifi/icd/BUILD.gn

+1-6
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,12 @@ source_set("wifi-sleep-manager") {
2525
sources = [
2626
"${chip_root}/src/platform/silabs/wifi/icd/WifiSleepManager.cpp",
2727
"${chip_root}/src/platform/silabs/wifi/icd/WifiSleepManager.h",
28-
29-
# TODO: Remove duplicated source files - This is a temporary workaround until the efr32_sdk.gni assert is refactored
30-
# This source is necessary because we can't use anything in the src/platform/silabs/wifi/BUILD.gn due to the efr32_sdk.gni import
31-
# The import causes an assert when building unit-tests due the silabs_board not being defined
32-
#
33-
"${chip_root}/src/platform/silabs/wifi/WifiStateProvider.h",
3428
]
3529

3630
public_deps = [
3731
":power-save-interface",
3832
"${chip_root}/src/app/icd/server:configuration-data",
3933
"${chip_root}/src/lib/core",
34+
"${chip_root}/src/platform/silabs/wifi:state-provider",
4035
]
4136
}

src/platform/silabs/wifi/icd/WifiSleepManager.cpp

+14-5
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@ CHIP_ERROR WifiSleepManager::Init(PowerSaveInterface * platformInterface, WifiSt
3737
return VerifyAndTransitionToLowPowerMode(PowerEvent::kGenericEvent);
3838
}
3939

40-
CHIP_ERROR WifiSleepManager::RequestHighPerformance()
40+
CHIP_ERROR WifiSleepManager::RequestHighPerformance(bool triggerTransition)
4141
{
4242
VerifyOrReturnError(mHighPerformanceRequestCounter < std::numeric_limits<uint8_t>::max(), CHIP_ERROR_INTERNAL,
4343
ChipLogError(DeviceLayer, "High performance request counter overflow"));
4444

4545
mHighPerformanceRequestCounter++;
4646

47-
// We don't do the mHighPerformanceRequestCounter check here; the check is in the VerifyAndTransitionToLowPowerMode function
48-
ReturnErrorOnFailure(VerifyAndTransitionToLowPowerMode(PowerEvent::kGenericEvent));
47+
if (triggerTransition)
48+
{
49+
// We don't do the mHighPerformanceRequestCounter check here; the check is in the VerifyAndTransitionToLowPowerMode function
50+
ReturnErrorOnFailure(VerifyAndTransitionToLowPowerMode(PowerEvent::kGenericEvent));
51+
}
4952

5053
return CHIP_NO_ERROR;
5154
}
@@ -90,8 +93,8 @@ CHIP_ERROR WifiSleepManager::HandlePowerEvent(PowerEvent event)
9093

9194
CHIP_ERROR WifiSleepManager::VerifyAndTransitionToLowPowerMode(PowerEvent event)
9295
{
93-
VerifyOrDieWithMsg(mWifiStateProvider != nullptr, DeviceLayer, "WifiSleepManager is not initialized");
94-
VerifyOrDieWithMsg(mPowerSaveInterface != nullptr, DeviceLayer, "WifiSleepManager is not initialized");
96+
VerifyOrDieWithMsg(mWifiStateProvider != nullptr, DeviceLayer, "WifiStateProvider is not initialized");
97+
VerifyOrDieWithMsg(mPowerSaveInterface != nullptr, DeviceLayer, "PowerSaveInterface is not initialized");
9598

9699
ReturnErrorOnFailure(HandlePowerEvent(event));
97100

@@ -117,6 +120,8 @@ CHIP_ERROR WifiSleepManager::VerifyAndTransitionToLowPowerMode(PowerEvent event)
117120

118121
CHIP_ERROR WifiSleepManager::ConfigureDTIMBasedSleep()
119122
{
123+
VerifyOrDieWithMsg(mPowerSaveInterface != nullptr, DeviceLayer, "PowerSaveInterface is not initialized");
124+
120125
ReturnLogErrorOnFailure(mPowerSaveInterface->ConfigureBroadcastFilter(false));
121126

122127
// Allowing the device to go to sleep must be the last actions to avoid configuration failures.
@@ -128,12 +133,16 @@ CHIP_ERROR WifiSleepManager::ConfigureDTIMBasedSleep()
128133

129134
CHIP_ERROR WifiSleepManager::ConfigureDeepSleep()
130135
{
136+
VerifyOrDieWithMsg(mPowerSaveInterface != nullptr, DeviceLayer, "PowerSaveInterface is not initialized");
137+
131138
ReturnLogErrorOnFailure(mPowerSaveInterface->ConfigurePowerSave(PowerSaveInterface::PowerSaveConfiguration::kDeepSleep, 0));
132139
return CHIP_NO_ERROR;
133140
}
134141

135142
CHIP_ERROR WifiSleepManager::ConfigureHighPerformance()
136143
{
144+
VerifyOrDieWithMsg(mPowerSaveInterface != nullptr, DeviceLayer, "PowerSaveInterface is not initialized");
145+
137146
ReturnLogErrorOnFailure(
138147
mPowerSaveInterface->ConfigurePowerSave(PowerSaveInterface::PowerSaveConfiguration::kHighPerformance, 0));
139148
return CHIP_NO_ERROR;

src/platform/silabs/wifi/icd/WifiSleepManager.h

+43-9
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,26 @@ class WifiSleepManager
6161

6262
inline void HandleCommissioningSessionStarted()
6363
{
64-
mIsCommissioningInProgress = true;
65-
66-
// TODO: Remove High Performance Req during commissioning when sleep issues are resolved
67-
WifiSleepManager::GetInstance().RequestHighPerformance();
64+
bool wasCommissioningInProgress = mIsCommissioningInProgress;
65+
mIsCommissioningInProgress = true;
66+
67+
if (!wasCommissioningInProgress)
68+
{
69+
// TODO: Remove High Performance Req during commissioning when sleep issues are resolved
70+
WifiSleepManager::GetInstance().RequestHighPerformanceWithTransition();
71+
}
6872
}
6973

7074
inline void HandleCommissioningSessionStopped()
7175
{
72-
mIsCommissioningInProgress = false;
73-
74-
// TODO: Remove High Performance Req during commissioning when sleep issues are resolved
75-
WifiSleepManager::GetInstance().RemoveHighPerformanceRequest();
76+
bool wasCommissioningInProgress = mIsCommissioningInProgress;
77+
mIsCommissioningInProgress = false;
78+
79+
if (wasCommissioningInProgress)
80+
{
81+
// TODO: Remove High Performance Req during commissioning when sleep issues are resolved
82+
WifiSleepManager::GetInstance().RemoveHighPerformanceRequest();
83+
}
7684
}
7785

7886
/**
@@ -86,7 +94,22 @@ class WifiSleepManager
8694
* @return CHIP_ERROR CHIP_NO_ERROR if the chip was set to high performance or already in high performance
8795
* CHIP_ERROR_INTERNAL, if the high performance configuration failed
8896
*/
89-
CHIP_ERROR RequestHighPerformance();
97+
CHIP_ERROR RequestHighPerformanceWithTransition() { return RequestHighPerformance(true); }
98+
99+
/**
100+
* @brief Public API to increase the HighPerformance request counter without transitioning the Wi-Fi chip to High Performance.
101+
* The transition to a different power mode will be done the next the VerifyAndTransitionToLowPowerMode is called.
102+
*
103+
* This API does not call the VerifyAndTransitionToLowPowerMode function.
104+
* To trigger the update directly adding a high performance request, call RequestHighPerformanceWithTransition.
105+
*
106+
* This API can be called before the Init function. By doing so, the device will transition to High Performance during
107+
* the Init sequence
108+
*
109+
* @return CHIP_ERROR CHIP_NO_ERROR if the chip was set to high performance or already in high performance
110+
* CHIP_ERROR_INTERNAL, if the high performance configuration failed
111+
*/
112+
CHIP_ERROR RequestHighPerformanceWithoutTransition() { return RequestHighPerformance(false); }
90113

91114
/**
92115
* @brief Public API to remove request to keep the Wi-Fi chip in High Performance.
@@ -161,6 +184,17 @@ class WifiSleepManager
161184
*/
162185
CHIP_ERROR ConfigureDTIMBasedSleep();
163186

187+
/**
188+
* @brief Increments the HighPerformance request counter and triggers the transition to High Performance if requested.
189+
*
190+
* @param triggerTransition true, triggers the transition to High Performance
191+
* false, only increments the HighPerformance request counter
192+
*
193+
* @return CHIP_ERROR CHIP_NO_ERROR if the req removal and sleep transition succeed
194+
* CHIP_ERROR_INTERNAL, if the req removal or the transition to sleep failed
195+
*/
196+
CHIP_ERROR RequestHighPerformance(bool triggerTransition);
197+
164198
static WifiSleepManager mInstance;
165199

166200
PowerSaveInterface * mPowerSaveInterface = nullptr;

src/platform/silabs/wifi/icd/tests/TestWifiSleepManager.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ TEST_F(TestWifiSleepManager, TestRequestHighPerformanceMaxCounter)
129129
// Set the counter to its maximum value
130130
for (uint8_t i = 0; i < std::numeric_limits<uint8_t>::max(); i++)
131131
{
132-
EXPECT_EQ(WifiSleepManager::GetInstance().RequestHighPerformance(), CHIP_NO_ERROR);
132+
EXPECT_EQ(WifiSleepManager::GetInstance().RequestHighPerformanceWithTransition(), CHIP_NO_ERROR);
133133
EXPECT_EQ(mMock.GetLastPowerSaveConfiguration(), PowerSaveInterface::PowerSaveConfiguration::kHighPerformance);
134134
EXPECT_TRUE(mMock.WasConfigurePowerSaveCalled());
135135
}
136136

137137
// The next request should fail
138-
EXPECT_EQ(WifiSleepManager::GetInstance().RequestHighPerformance(), CHIP_ERROR_INTERNAL);
138+
EXPECT_EQ(WifiSleepManager::GetInstance().RequestHighPerformanceWithTransition(), CHIP_ERROR_INTERNAL);
139139
EXPECT_FALSE(mMock.WasConfigurePowerSaveCalled());
140140

141141
// Reset the counter & validate reset
@@ -148,7 +148,7 @@ TEST_F(TestWifiSleepManager, TestRequestHighPerformanceMaxCounter)
148148

149149
TEST_F(TestWifiSleepManager, TestRequestRemoveHighPerformance)
150150
{
151-
EXPECT_EQ(WifiSleepManager::GetInstance().RequestHighPerformance(), CHIP_NO_ERROR);
151+
EXPECT_EQ(WifiSleepManager::GetInstance().RequestHighPerformanceWithTransition(), CHIP_NO_ERROR);
152152
EXPECT_EQ(mMock.GetLastPowerSaveConfiguration(), PowerSaveInterface::PowerSaveConfiguration::kHighPerformance);
153153
EXPECT_TRUE(mMock.WasConfigurePowerSaveCalled());
154154

@@ -199,3 +199,16 @@ TEST_F(TestWifiSleepManager, TestVerifyOrTransitionStandardOperation)
199199
EXPECT_TRUE(mMock.WasConfigureBroadcastFilterCalled());
200200
EXPECT_FALSE(mMock.WasBroadcastFilterEnabled());
201201
}
202+
203+
TEST_F(TestWifiSleepManager, TestRequestHighPerformanceWithoutProvisioning)
204+
{
205+
EXPECT_EQ(WifiSleepManager::GetInstance().VerifyAndTransitionToLowPowerMode(WifiSleepManager::PowerEvent::kGenericEvent),
206+
CHIP_NO_ERROR);
207+
208+
PowerSaveInterface::PowerSaveConfiguration config = mMock.GetLastPowerSaveConfiguration();
209+
EXPECT_EQ(PowerSaveInterface::PowerSaveConfiguration::kDeepSleep, config);
210+
211+
// The configuration should not change
212+
EXPECT_EQ(WifiSleepManager::GetInstance().RequestHighPerformanceWithoutTransition(), CHIP_NO_ERROR);
213+
EXPECT_EQ(mMock.GetLastPowerSaveConfiguration(), config);
214+
}

third_party/silabs/silabs_board.gni

+15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import("//build_overrides/chip.gni")
16+
import("${chip_root}/src/platform/silabs/tests/args.gni")
17+
1518
declare_args() {
1619
# Silabs wireless starter kit plug-in boards featuring specific mcu family and mcu model.
1720
# Find more information at https://www.silabs.com/development-tools/wireless.
@@ -77,6 +80,16 @@ if (silabs_board == "") {
7780
silabs_board = getenv("SILABS_BOARD")
7881
}
7982

83+
# Workaround to enable unit-tests when depending on files that import this gni
84+
if (silabs_board == "" && sl_build_unit_tests) {
85+
print("Building the unit test configuration since silabs_board is not set.")
86+
print("If you are building the efr32 test_driver, a board is required.")
87+
88+
silabs_board = "unit-test"
89+
silabs_family = "unit-test"
90+
silabs_mcu = "unit-test"
91+
}
92+
8093
assert(silabs_board != "", "silabs_board must be specified")
8194

8295
# Si917 WIFI board ----------
@@ -190,6 +203,8 @@ if (silabs_board == "BRD4338A" || silabs_board == "BRD2605A" ||
190203
print("Using custom board configuration")
191204
print("silabs_family:", silabs_family)
192205
print("silabs_mcu:", silabs_mcu)
206+
} else if (silabs_board == "unit-test") {
207+
# Do nothing
193208
} else {
194209
assert(
195210
false,

0 commit comments

Comments
 (0)