Skip to content

Commit

Permalink
Pull request project-chip#1534: [MATTER-3042] :Allow M4 to go to slee…
Browse files Browse the repository at this point in the history
…p when it is uncommissioned

Merge in WMN_TOOLS/matter from feature/917_sleepy_uncommissioned to RC_2.3.0-1.3

Squashed commit of the following:

commit 0d5350c7dc0468aeb1c7bcf7f8cb8833b8e1427a
Author: chbansal <chirag.bansal@silabs.com>
Date:   Thu Feb 8 15:07:37 2024 +0530

    reverting the DIC_ENABLE macro to back place

commit 5df0f689f39525889979e6e609f56b463611c3dc
Author: chbansal <chirag.bansal@silabs.com>
Date:   Wed Feb 7 23:15:22 2024 +0530

    Adding different Appdelegate to not allow the DUT go to sleep in between commissioning

commit 4bfd3a125ec5561325ee29b263479821253cc69d
Author: chbansal <chirag.bansal@silabs.com>
Date:   Wed Feb 7 21:43:01 2024 +0530

    reverting the BLEManagerImpl.cpp

... and 7 more commits
  • Loading branch information
chirag-silabs authored and jmartinez-silabs committed Feb 8, 2024
1 parent 88f0522 commit 10a0af2
Show file tree
Hide file tree
Showing 16 changed files with 179 additions and 36 deletions.
27 changes: 23 additions & 4 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "AppTask.h"
#include <app/server/Server.h>

#define APP_ACTION_BUTTON 1
#define APP_ACTION_BUTTON 1

#ifdef DISPLAY_ENABLED
#include "lcd.h"
Expand All @@ -44,9 +44,9 @@
#include <assert.h>
#include <lib/support/CodeUtils.h>
#include <platform/CHIPDeviceLayer.h>
#include <provision/ProvisionManager.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>
#include <provision/ProvisionManager.h>

#if CHIP_ENABLE_OPENTHREAD
#include <platform/OpenThread/OpenThreadUtils.h>
Expand Down Expand Up @@ -148,6 +148,9 @@ Identify gIdentify = {
bool BaseApplication::sIsProvisioned = false;
bool BaseApplication::sIsFactoryResetTriggered = false;
LEDWidget * BaseApplication::sAppActionLed = nullptr;
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
BaseApplicationDelegate BaseApplication::sAppDelegate = BaseApplicationDelegate();
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917

#ifdef DIC_ENABLE
namespace {
Expand All @@ -165,6 +168,23 @@ void AppSpecificConnectivityEventCallback(const ChipDeviceEvent * event, intptr_
} // namespace
#endif // DIC_ENABLE

#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
void BaseApplicationDelegate::OnCommissioningSessionStarted() { isComissioningStarted = true; }
void BaseApplicationDelegate::OnCommissioningSessionStopped() { isComissioningStarted = false; }
void BaseApplicationDelegate::OnCommissioningWindowClosed()
{
ChipLogProgress(DeviceLayer, "OnCommissioningWindowClosed");
if (!BaseApplication::GetProvisionStatus() && !isComissioningStarted)
{
int32_t status = wfx_power_save(RSI_SLEEP_MODE_8, STANDBY_POWER_SAVE_WITH_RAM_RETENTION);
if (status != SL_STATUS_OK)
{
ChipLogError(DeviceLayer, "Failed to enable the TA Deep Sleep");
}
}
}
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917

/**********************************************************
* AppTask Definitions
*********************************************************/
Expand Down Expand Up @@ -263,7 +283,6 @@ CHIP_ERROR BaseApplication::Init()
#if CHIP_ENABLE_OPENTHREAD
BaseApplication::sIsProvisioned = ConnectivityMgr().IsThreadProvisioned();
#endif

return err;
}

Expand Down Expand Up @@ -741,7 +760,7 @@ void BaseApplication::ScheduleFactoryReset()
{
PlatformMgr().ScheduleWork([](intptr_t) {
// Press both buttons to request provisioning
if(GetPlatform().GetButtonState(APP_ACTION_BUTTON))
if (GetPlatform().GetButtonState(APP_ACTION_BUTTON))
{
Provision::Manager::GetInstance().RequestProvision();
}
Expand Down
16 changes: 15 additions & 1 deletion examples/platform/silabs/BaseApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "FreeRTOS.h"
#include "timers.h" // provides FreeRTOS timer support
#include <app/clusters/identify-server/identify-server.h>
#include <app/server/AppDelegate.h>
#include <app/util/config.h>
#include <ble/BLEEndPoint.h>
#include <lib/core/CHIPError.h>
Expand Down Expand Up @@ -62,10 +63,20 @@
#define APP_ERROR_START_TIMER_FAILED CHIP_APPLICATION_ERROR(0x05)
#define APP_ERROR_STOP_TIMER_FAILED CHIP_APPLICATION_ERROR(0x06)

#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
class BaseApplicationDelegate : public AppDelegate
{
public:
bool isComissioningStarted;
void OnCommissioningSessionStarted() override;
void OnCommissioningSessionStopped() override;
void OnCommissioningWindowClosed() override;
};
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917

/**********************************************************
* BaseApplication Declaration
*********************************************************/

class BaseApplication
{

Expand All @@ -75,6 +86,9 @@ class BaseApplication
static bool sIsProvisioned;
static bool sIsFactoryResetTriggered;
static LEDWidget * sAppActionLed;
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
static BaseApplicationDelegate sAppDelegate;
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917

/**
* @brief Create AppTask task and Event Queue
Expand Down
10 changes: 5 additions & 5 deletions examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "AppConfig.h"
#include "BaseApplication.h"
#include "OTAConfig.h"
#include <MatterConfig.h>

Expand Down Expand Up @@ -261,6 +262,9 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
initParams.endpointNativeParams = static_cast<void *>(&nativeParams);
#endif

#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
initParams.appDelegate = &BaseApplication::sAppDelegate;
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
// Init Matter Server and Start Event Loop
err = chip::Server::GetInstance().Init(initParams);

Expand Down Expand Up @@ -310,10 +314,6 @@ CHIP_ERROR SilabsMatterConfig::InitWiFi(void)
extern "C" void vApplicationIdleHook(void)
{
#if SIWX_917 && CHIP_CONFIG_ENABLE_ICD_SERVER
if (ConnectivityMgr().IsWiFiStationConnected())
{
// Let the M4 sleep once commissioning is done and device is in idle state
sl_wfx_host_si91x_sleep_wakeup();
}
sl_wfx_host_si91x_sleep_wakeup();
#endif
}
23 changes: 15 additions & 8 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t
SILABS_LOG("F: Join Event received with %u bytes payload\n", result_length);
callback_status = *(sl_status_t *) result;
wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTED);
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries++);
is_wifi_disconnection_event = true;
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries++);
if (is_wifi_disconnection_event || wfx_rsi.join_retries <= WFX_RSI_CONFIG_MAX_JOIN)
{
xEventGroupSetBits(wfx_rsi.events, WFX_EVT_STA_START_JOIN);
Expand Down Expand Up @@ -256,28 +256,35 @@ void sl_wfx_host_si91x_sleep_wakeup()
* @brief
* Setting the RS911x in DTIM sleep based mode
*
* @param[in] None
* @param[in] sl_si91x_ble_state : State to set for the BLE
sl_si91x_wifi_state : State to set for the WiFi
* @return
* None
*********************************************************************/
int32_t wfx_rsi_power_save()
int32_t wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state,sl_si91x_performance_profile_t sl_si91x_wifi_state)
{
int32_t status;
status = rsi_bt_power_save_profile(2, 0);

status = rsi_bt_power_save_profile(sl_si91x_ble_state, 0);
if (status != RSI_SUCCESS)
{
SILABS_LOG("BT Powersave Config Failed, Error Code : 0x%lX", status);
return status;
}

sl_wifi_performance_profile_t wifi_profile = { .profile = ASSOCIATED_POWER_SAVE };
sl_wifi_performance_profile_t wifi_profile = { .profile = sl_si91x_wifi_state };
status = sl_wifi_set_performance_profile(&wifi_profile);
if (status != RSI_SUCCESS)
{
SILABS_LOG("Powersave Config Failed, Error Code : 0x%lX", status);
return status;
}
wfx_rsi.dev_state |= WFX_RSI_ST_SLEEP_READY;
if(sl_si91x_wifi_state == HIGH_PERFORMANCE)
{
wfx_rsi.dev_state &= ~(WFX_RSI_ST_SLEEP_READY);
}
else{
wfx_rsi.dev_state |= WFX_RSI_ST_SLEEP_READY;
}
return status;
}
#endif /* SL_ICD_ENABLED */
Expand Down Expand Up @@ -630,11 +637,11 @@ static sl_status_t wfx_rsi_do_join(void)
wfx_rsi.join_retries);
wfx_rsi.join_retries += 1;
wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED);
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries);
if (is_wifi_disconnection_event || wfx_rsi.join_retries <= MAX_JOIN_RETRIES_COUNT)
{
xEventGroupSetBits(wfx_rsi.events, WFX_EVT_STA_START_JOIN);
}
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int32_t wfx_rsi_disconnect();
int32_t wfx_wifi_rsi_init(void);
#if SL_ICD_ENABLED
void sl_wfx_host_si91x_sleep_wakeup();
int32_t wfx_rsi_power_save();
int32_t wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state);
#endif /* SL_ICD_ENABLED */

#ifdef __cplusplus
Expand Down
7 changes: 4 additions & 3 deletions examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,14 @@ sl_status_t wfx_connect_to_ap(void)
* @fn sl_status_t wfx_power_save()
* @brief
* Implements the power save in sleepy application
* @param[in] None
* @param[in] sl_si91x_ble_state : State to set for the BLE
sl_si91x_wifi_state : State to set for the WiFi
* @return SL_STATUS_OK if successful,
* SL_STATUS_FAIL otherwise
***********************************************************************/
sl_status_t wfx_power_save()
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)
{
if (wfx_rsi_power_save() != SL_STATUS_OK)
if (wfx_rsi_power_save(sl_si91x_ble_state, sl_si91x_wifi_state) != SL_STATUS_OK)
{
return SL_STATUS_FAIL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,4 @@ typedef struct
#define INTERRUPT_PIN PIN(A, 7)
#define SLEEP_CONFIRM_PIN PIN(A, 5) /* Exp hdr 7 */
#endif

#define NETWORK_INTERFACE_VALID(x) (x == SL_NET_DEFAULT_WIFI_CLIENT_INTERFACE) || (x == SL_NET_DEFAULT_WIFI_AP_INTERFACE)
#endif /* _RSI_BOARD_CONFIGURATION_H_ */
4 changes: 4 additions & 0 deletions examples/platform/silabs/efr32/rs911x/wfx_rsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info);
int32_t wfx_rsi_reset_count();
int32_t wfx_rsi_disconnect();
#if SL_ICD_ENABLED
#if SLI_SI917
int32_t wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state);
#else
int32_t wfx_rsi_power_save();
#endif /* SLI_SI917 */
#endif /* SL_ICD_ENABLED */

#ifdef __cplusplus
Expand Down
16 changes: 16 additions & 0 deletions examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ sl_status_t wfx_connect_to_ap(void)
}

#if SL_ICD_ENABLED
#if SLI_SI917
/*********************************************************************
* @fn sl_status_t wfx_power_save()
* @brief
* Implements the power save in sleepy application
* @param[in] sl_si91x_ble_state : State to set for the BLE
sl_si91x_wifi_state : State to set for the WiFi
* @return SL_STATUS_OK if successful,
* SL_STATUS_FAIL otherwise
***********************************************************************/
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)
{
return (wfx_rsi_power_save(sl_si91x_ble_state, sl_si91x_wifi_state) ? SL_STATUS_FAIL : SL_STATUS_OK);
}
#else // For RS9116
/*********************************************************************
* @fn sl_status_t wfx_power_save()
* @brief
Expand All @@ -204,6 +219,7 @@ sl_status_t wfx_power_save()
{
return (wfx_rsi_power_save() ? SL_STATUS_FAIL : SL_STATUS_OK);
}
#endif /* SLI_SI917 */
#endif /* SL_ICD_ENABLED */

/*********************************************************************
Expand Down
4 changes: 4 additions & 0 deletions src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,11 @@ void ConnectivityManagerImpl::OnStationConnected()
(void) PlatformMgr().PostEvent(&event);
// Setting the rs911x in the power save mode
#if (CHIP_CONFIG_ENABLE_ICD_SERVER && RS911X_WIFI)
#if SLI_SI917
sl_status_t err = wfx_power_save(RSI_SLEEP_MODE_2, ASSOCIATED_POWER_SAVE);
#else
sl_status_t err = wfx_power_save();
#endif /* SLI_SI917 */
if (err != SL_STATUS_OK)
{
ChipLogError(DeviceLayer, "Power save config for Wifi failed");
Expand Down
Loading

0 comments on commit 10a0af2

Please sign in to comment.