Skip to content

Commit 4e986d1

Browse files
Add selective listening framework
1 parent e8145ef commit 4e986d1

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

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

+25
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ namespace {
2525
// TODO: Once the platform sleep calls are unified, we can removed this ifdef
2626
#if SLI_SI917 // 917 SoC & NCP
2727

28+
/**
29+
* @brief Configures the Wi-Fi Chip to go to LI based sleep.
30+
* Function sets the listen interval the ICD Transort Slow Poll configuration and enables the broadcast filter.
31+
*
32+
* @return CHIP_ERROR CHIP_NO_ERROR if the configuration of the Wi-Fi chip was successful; otherwise CHIP_ERROR_INTERNAL
33+
*/
34+
CHIP_ERROR ConfigureLIBasedSleep()
35+
{
36+
VerifyOrReturnError(ConfigureBroadcastFilter(true) == SL_STATUS_OK, CHIP_ERROR_INTERNAL,
37+
ChipLogError(DeviceLayer, "Failed to configure broadcasts filter."));
38+
39+
// Allowing the device to go to sleep must be the last actions to avoid configuration failures.
40+
VerifyOrReturnError(ConfigurePowerSave(RSI_SLEEP_MODE_2, ASSOCIATED_POWER_SAVE,
41+
chip::ICDConfigurationData::GetInstance().GetSlowPollingInterval().count()) ==
42+
SL_STATUS_OK,
43+
CHIP_ERROR_INTERNAL, ChipLogError(DeviceLayer, "Failed to enable LI based sleep."));
44+
45+
return CHIP_NO_ERROR;
46+
}
47+
2848
/**
2949
* @brief Configures the Wi-Fi Chip to go to DTIM based sleep.
3050
* Function sets the listen interval to be synced with the DTIM beacon and disables the broadcast filter.
@@ -157,6 +177,11 @@ CHIP_ERROR WifiSleepManager::VerifyAndTransitionToLowPowerMode(PowerEvent event)
157177
return ConfigureDeepSleep();
158178
}
159179

180+
if (mCallback && mCallback->CanGoToLIBasedSleep())
181+
{
182+
return ConfigureLIBasedSleep();
183+
}
184+
160185
return ConfigureDTIMBasedSleep();
161186

162187
#else

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

+41
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,36 @@ class WifiSleepManager
4343
kConnectivityChange = 2,
4444
};
4545

46+
/**
47+
* @brief Class implements the callbacks that the application can implement
48+
* to alter the WifiSleepManager behaviors.
49+
*/
50+
class ApplicationCallback
51+
{
52+
public:
53+
virtual ~ApplicationCallback() = default;
54+
55+
/**
56+
* @brief Function informs the WifiSleepManager in which Low Power mode the device can go to.
57+
* The two supported sleep modes are DTIM based sleep and LI based sleep.
58+
*
59+
* When the function is called, the WifiSleepManager is about to go to sleep and using this function to make decision
60+
* as too wether it can go LI based sleep, lowest power mode, or DTIM based sleep.
61+
*
62+
* DTIM based sleep requires the Wi-Fi devices to be synced with the DTIM beacon.
63+
* In this mode, the broadcast filter is disabled and the device will process multicast and
64+
* broadcast messages.
65+
*
66+
* LI based sleep allows the Wi-Fi devices to sleep for configurable amounts of time without needing to be synced
67+
* with the DTIM beacon. The sleep time is configurable trough the ICD Manager feature-set.
68+
* In the LI based sleep, the broadcast filter is enabled.
69+
*
70+
* @return true The Wi-Fi Sleep Manager can go to LI based sleep
71+
* @return false The Wi-Fi Sleep Manager cannot go to LI based sleep or an error occured in the processing.
72+
*/
73+
virtual bool CanGoToLIBasedSleep() = 0;
74+
};
75+
4676
/**
4777
* @brief Init function that configure the SleepManager APIs based on the type of ICD.
4878
* Function validates that the SleepManager configuration were correctly set as well.
@@ -70,6 +100,14 @@ class WifiSleepManager
70100
WifiSleepManager::GetInstance().RemoveHighPerformanceRequest();
71101
}
72102

103+
/**
104+
* @brief Set the Application Callback
105+
*
106+
* @param callbacks pointer to the application callbacks.
107+
* The callback can be set to nullptr if the application wants to remove its callback
108+
*/
109+
void SetApplicationCallback(ApplicationCallback * callback) { mCallback = callback; }
110+
73111
/**
74112
* @brief Public API to request the Wi-Fi chip to transition to High Performance.
75113
* Function increases the HighPerformance request counter to prevent the chip from going to sleep
@@ -105,6 +143,7 @@ class WifiSleepManager
105143
* 1. If there are high performance requests, configure high performance mode.
106144
* 2. If commissioning is in progress, configure DTIM based sleep.
107145
* 3. If no commissioning is in progress and the device is unprovisioned, configure deep sleep.
146+
* 4. If the application callback allows, configure LI based sleep; otherwise, configure DTIM based sleep.
108147
*
109148
* @param event PowerEvent triggering the Verify and transition to low power mode processing
110149
*
@@ -130,6 +169,8 @@ class WifiSleepManager
130169

131170
bool mIsCommissioningInProgress = false;
132171
uint8_t mHighPerformanceRequestCounter = 0;
172+
173+
ApplicationCallback * mCallback = nullptr;
133174
};
134175

135176
} // namespace Silabs

0 commit comments

Comments
 (0)