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-UP] Add application callback to allow the application to inject logic #116

Merged
merged 10 commits into from
Nov 20, 2024
19 changes: 16 additions & 3 deletions src/platform/silabs/wifi/SiWx/WifiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,9 +865,8 @@ void wfx_dhcp_got_ipv4(uint32_t ip)
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */

#if CHIP_CONFIG_ENABLE_ICD_SERVER

sl_status_t wfx_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state,
uint32_t listenInterval)
sl_status_t CofigurePowerSave(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state,
uint32_t listenInterval)
{
int32_t error = rsi_bt_power_save_profile(sl_si91x_ble_state, 0);
VerifyOrReturnError(error == RSI_SUCCESS, SL_STATUS_FAIL,
Expand All @@ -885,4 +884,18 @@ sl_status_t wfx_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_

return status;
}

sl_status_t ConfigureBroadcastFilter(bool enableBroadcastFilter)
{
sl_status_t status = SL_STATUS_OK;

uint16_t beaconDropThreshold = (enableBroadcastFilter) ? kTimeToFullBeaconReception : 0;
uint8_t filterBcastInTim = (enableBroadcastFilter) ? 1 : 0;

status = sl_wifi_filter_broadcast(beaconDropThreshold, filterBcastInTim, 1 /* valid till next update*/);
VerifyOrReturnError(status == SL_STATUS_OK, status,
ChipLogError(DeviceLayer, "sl_wifi_filter_broadcast failed: 0x%lx", static_cast<uint32_t>(status)));

return status;
}
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
14 changes: 11 additions & 3 deletions src/platform/silabs/wifi/WifiInterfaceAbstraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,20 @@ bool wfx_hw_ready(void);
#ifdef RS911X_WIFI // for RS9116, 917 NCP and 917 SoC
/* RSI Power Save */
#if (SLI_SI91X_MCU_INTERFACE | EXP_BOARD)
sl_status_t wfx_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state,
uint32_t listenInterval);
sl_status_t CofigurePowerSave(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state,
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
uint32_t listenInterval);
#else
sl_status_t wfx_power_save();
sl_status_t CofigurePowerSave();
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
#endif /* (SLI_SI91X_MCU_INTERFACE | EXP_BOARD) */
#endif /* RS911X_WIFI */

/**
* @brief Configures the broadcast filter.
*
* @param[in] enableBroadcastFilter Boolean to enable or disable the broadcast filter.
* @return sl_status_t Returns the status of the operation.
*/
sl_status_t ConfigureBroadcastFilter(bool enableBroadcastFilter);
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

void sl_matter_wifi_task(void * arg);
Expand Down
30 changes: 24 additions & 6 deletions src/platform/silabs/wifi/icd/WifiSleepManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ CHIP_ERROR WifiSleepManager::RequestHighPerformance()
if (mHighPerformanceRequestCounter == 0)
{
#if SLI_SI917 // 917 SoC & NCP
VerifyOrReturnError(wfx_power_save(RSI_ACTIVE, HIGH_PERFORMANCE, 0) == SL_STATUS_OK, CHIP_ERROR_INTERNAL,
VerifyOrReturnError(CofigurePowerSave(RSI_ACTIVE, HIGH_PERFORMANCE, 0) == SL_STATUS_OK, CHIP_ERROR_INTERNAL,
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
ChipLogError(DeviceLayer, "Failed to set Wi-FI configuration to HighPerformance"));
#endif // SLI_SI917
}
Expand Down Expand Up @@ -102,16 +102,34 @@ CHIP_ERROR WifiSleepManager::VerifyAndTransitionToLowPowerMode()

if (!(wifiConfig.ssid[0] != 0) && !isCommissioningInProgress)
{
VerifyOrReturnError(wfx_power_save(RSI_SLEEP_MODE_8, DEEP_SLEEP_WITH_RAM_RETENTION, 0) != SL_STATUS_OK, CHIP_ERROR_INTERNAL,
ChipLogError(DeviceLayer, "Failed to enable Deep Sleep."));
VerifyOrReturnError(CofigurePowerSave(RSI_SLEEP_MODE_8, DEEP_SLEEP_WITH_RAM_RETENTION, 0) != SL_STATUS_OK,
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
CHIP_ERROR_INTERNAL, ChipLogError(DeviceLayer, "Failed to enable Deep Sleep."));
}
else
{
VerifyOrReturnError(wfx_power_save(RSI_SLEEP_MODE_2, ASSOCIATED_POWER_SAVE, 0) != SL_STATUS_OK, CHIP_ERROR_INTERNAL,
ChipLogError(DeviceLayer, "Failed to enable to go to sleep."));

if (mCallbacks && mCallbacks->CanGoToLIBasedSleep())
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
{
VerifyOrReturnError(CofigurePowerSave(RSI_SLEEP_MODE_2, ASSOCIATED_POWER_SAVE,
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
ICDConfigurationData::GetInstance().GetSlowPollingInterval().count()) !=
SL_STATUS_OK,
CHIP_ERROR_INTERNAL, ChipLogError(DeviceLayer, "Failed to enable to go to sleep."));

VerifyOrReturnError(ConfigureBroadcastFilter(true), CHIP_ERROR_INTERNAL,
ChipLogError(DeviceLayer, "Failed to configure broadcasts filter."));
}
else
{

VerifyOrReturnError(CofigurePowerSave(RSI_SLEEP_MODE_2, ASSOCIATED_POWER_SAVE, 0) != SL_STATUS_OK, CHIP_ERROR_INTERNAL,
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
ChipLogError(DeviceLayer, "Failed to enable to go to sleep."));

VerifyOrReturnError(ConfigureBroadcastFilter(false), CHIP_ERROR_INTERNAL,
ChipLogError(DeviceLayer, "Failed to configure broadcasts filter."));
}
}
#elif RS911X_WIFI // rs9116
VerifyOrReturnError(wfx_power_save() != SL_STATUS_OK, CHIP_ERROR_INTERNAL,
VerifyOrReturnError(CofigurePowerSave() != SL_STATUS_OK, CHIP_ERROR_INTERNAL,
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
ChipLogError(DeviceLayer, "Failed to enable to go to sleep."));
#endif

Expand Down
42 changes: 41 additions & 1 deletion src/platform/silabs/wifi/icd/WifiSleepManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ class WifiSleepManager

static WifiSleepManager & GetInstance() { return mInstance; }

/**
* @brief Class implements the callbacks that the application can implement
* to alter the WifiSleepManager behaviors.
*/
class ApplicationCallbacks
{
public:
virtual ~ApplicationCallbacks() = 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 @@ -63,6 +93,14 @@ class WifiSleepManager
*/
CHIP_ERROR RemoveHighPerformanceRequest();

/**
* @brief Set the Application Callbacks
*
* @param callbacks pointer to the application callbacks.
* The callbacks can be set to nullptr if the application wants to remove its callbacks
*/
void SetApplicationCallbacks(ApplicationCallbacks * callbacks);

void HandleCommissioningComplete();
void HandleInternetConnectivityChange();
void HandleCommissioningWindowClose();
Expand All @@ -85,9 +123,11 @@ class WifiSleepManager
CHIP_ERROR VerifyAndTransitionToLowPowerMode();

static WifiSleepManager mInstance;
bool isCommissioningInProgress = false;

bool isCommissioningInProgress = false;
uint8_t mHighPerformanceRequestCounter = 0;

ApplicationCallbacks * mCallbacks = nullptr;
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace Silabs
Expand Down
4 changes: 2 additions & 2 deletions src/platform/silabs/wifi/rs911x/WifiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -926,14 +926,14 @@ int32_t wfx_rsi_send_data(void * p, uint16_t len)

#if SL_ICD_ENABLED
/*********************************************************************
* @fn sl_status_t wfx_power_save(void)
* @fn sl_status_t CofigurePowerSave(void)
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
* @brief
* Implements the power save in sleepy application
* @param[in] None
* @return SL_STATUS_OK if successful,
* SL_STATUS_FAIL otherwise
***********************************************************************/
sl_status_t wfx_power_save(void)
sl_status_t CofigurePowerSave(void)
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
{
int32_t status;
#ifdef RSI_BLE_ENABLE
Expand Down
2 changes: 2 additions & 0 deletions third_party/silabs/SiWx917_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ template("siwx917_sdk") {
"SL_ACTIVE_MODE_DURATION_MS=${sl_active_mode_duration_ms}",
"SL_IDLE_MODE_DURATION_S=${sl_idle_mode_duration_s}",
"SL_ICD_SUPPORTED_CLIENTS_PER_FABRIC=${sl_icd_supported_clients_per_fabric}",
"SL_TRANSPORT_IDLE_INTERVAL=${sl_transport_idle_interval_ms}",
"SL_TRANSPORT_ACTIVE_INTERVAL=${sl_transport_active_interval_ms}",
"SL_SI91X_POWER_MANAGER_UC_AVAILABLE=1",
"SL_SI91X_TICKLESS_MODE=1",

Expand Down
Loading