Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SL-ONLY] Add selective listening framework to WifiSleepManager #284

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/platform/silabs/wifi/icd/WifiSleepManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ namespace {
// TODO: Once the platform sleep calls are unified, we can removed this ifdef
#if SLI_SI917 // 917 SoC & NCP

/**
* @brief Configures the Wi-Fi Chip to go to LI based sleep.
* Function sets the listen interval the ICD Transort Slow Poll configuration and enables the broadcast filter.
*
* @return CHIP_ERROR CHIP_NO_ERROR if the configuration of the Wi-Fi chip was successful; otherwise CHIP_ERROR_INTERNAL
*/
CHIP_ERROR ConfigureLIBasedSleep()
{
ReturnLogErrorOnFailure(ConfigureBroadcastFilter(true));

// Allowing the device to go to sleep must be the last actions to avoid configuration failures.
ReturnLogErrorOnFailure(ConfigurePowerSave(RSI_SLEEP_MODE_2, ASSOCIATED_POWER_SAVE,
chip::ICDConfigurationData::GetInstance().GetSlowPollingInterval().count()));

return CHIP_NO_ERROR;
}

/**
* @brief Configures the Wi-Fi Chip to go to DTIM based sleep.
* Function sets the listen interval to be synced with the DTIM beacon and disables the broadcast filter.
Expand Down Expand Up @@ -157,6 +174,11 @@ CHIP_ERROR WifiSleepManager::VerifyAndTransitionToLowPowerMode(PowerEvent event)
return ConfigureDeepSleep();
}

if (mCallback && mCallback->CanGoToLIBasedSleep())
{
return ConfigureLIBasedSleep();
}

return ConfigureDTIMBasedSleep();

#else
Expand Down
41 changes: 41 additions & 0 deletions src/platform/silabs/wifi/icd/WifiSleepManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,36 @@ class WifiSleepManager
kConnectivityChange = 2,
};

/**
* @brief Class implements the callbacks that the application can implement
* to alter the WifiSleepManager behaviors.
*/
class ApplicationCallback
{
public:
virtual ~ApplicationCallback() = default;

/**
* @brief Function informs the WifiSleepManager in which Low Power mode the device can go to.
* The two supported sleep modes are DTIM based sleep and LI based sleep.
*
* When the function is called, the WifiSleepManager is about to go to sleep and using this function to make decision
* as too wether it can go LI based sleep, lowest power mode, or DTIM based sleep.
*
* DTIM based sleep requires the Wi-Fi devices to be synced with the DTIM beacon.
* In this mode, the broadcast filter is disabled and the device will process multicast and
* broadcast messages.
*
* LI based sleep allows the Wi-Fi devices to sleep for configurable amounts of time without needing to be synced
* with the DTIM beacon. The sleep time is configurable trough the ICD Manager feature-set.
* In the LI based sleep, the broadcast filter is enabled.
*
* @return true The Wi-Fi Sleep Manager can go to LI based sleep
* @return false The Wi-Fi Sleep Manager cannot go to LI based sleep or an error occured in the processing.
*/
virtual bool CanGoToLIBasedSleep() = 0;
};

/**
* @brief Init function that configure the SleepManager APIs based on the type of ICD.
* Function validates that the SleepManager configuration were correctly set as well.
Expand Down Expand Up @@ -70,6 +100,14 @@ class WifiSleepManager
WifiSleepManager::GetInstance().RemoveHighPerformanceRequest();
}

/**
* @brief Set the Application Callback
*
* @param callbacks pointer to the application callbacks.
* The callback can be set to nullptr if the application wants to remove its callback
*/
void SetApplicationCallback(ApplicationCallback * callback) { mCallback = callback; }

/**
* @brief Public API to request the Wi-Fi chip to transition to High Performance.
* Function increases the HighPerformance request counter to prevent the chip from going to sleep
Expand Down Expand Up @@ -105,6 +143,7 @@ class WifiSleepManager
* 1. If there are high performance requests, configure high performance mode.
* 2. If commissioning is in progress, configure DTIM based sleep.
* 3. If no commissioning is in progress and the device is unprovisioned, configure deep sleep.
* 4. If the application callback allows, configure LI based sleep; otherwise, configure DTIM based sleep.
*
* @param event PowerEvent triggering the Verify and transition to low power mode processing
*
Expand All @@ -130,6 +169,8 @@ class WifiSleepManager

bool mIsCommissioningInProgress = false;
uint8_t mHighPerformanceRequestCounter = 0;

ApplicationCallback * mCallback = nullptr;
};

} // namespace Silabs
Expand Down
Loading