Skip to content

Commit

Permalink
Enabling sleepy for 917soc with power manager
Browse files Browse the repository at this point in the history
  • Loading branch information
chirag-silabs committed Jul 1, 2024
1 parent 4672e1a commit 1467880
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 80 deletions.
27 changes: 14 additions & 13 deletions examples/platform/silabs/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ extern "C" {
#ifdef SLI_SI91X_MCU_INTERFACE
#include "si91x_device.h"
extern uint32_t SystemCoreClock;
#if SL_ICD_ENABLED
#include "sl_si91x_m4_ps.h"
#endif // SL_ICD_ENABLED
#else // For EFR32
#include "RTE_Components.h"
#include CMSIS_device_header
Expand Down Expand Up @@ -141,21 +144,18 @@ extern uint32_t SystemCoreClock;
/* Energy saving modes. */
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
#define configUSE_TICKLESS_IDLE 1
#elif SL_ICD_ENABLED && SI917_M4_SLEEP_ENABLED
#elif (SLI_SI91X_MCU_INTERFACE && SL_ICD_ENABLED)
#define configUSE_TICKLESS_IDLE 1
#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 70
#define configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING(x) vTaskPreSuppressTicksAndSleepProcessing(&x)
#define configPRE_SLEEP_PROCESSING(x) sl_wfx_host_si91x_sleep(&x)
#define configPOST_SLEEP_PROCESSING(x) sl_si91x_post_sleep_update_ticks(&x)
#define configPRE_SLEEP_PROCESSING(x)
#define configPOST_SLEEP_PROCESSING(x)
#define configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING(x) sl_si91x_pre_supress_ticks_and_sleep(&x)
#else
#define configUSE_TICKLESS_IDLE 0
#endif // SL_CATALOG_POWER_MANAGER_PRESENT

#if defined(SLI_SI91X_MCU_INTERFACE)
#define configTICK_RATE_HZ (1000)
#else
#define configTICK_RATE_HZ (1024)
#endif // SLI_SI91X_MCU_INTERFACE

/* Definition used by Keil to replace default system clock source. */
#define configOVERRIDE_DEFAULT_TICK_CONFIGURATION 1

Expand All @@ -175,7 +175,11 @@ extern uint32_t SystemCoreClock;

/* Software timer related definitions. */
#define configUSE_TIMERS (1)
#ifdef SLI_SI917
#define configTIMER_TASK_PRIORITY (55) /* Highest priority */
#else
#define configTIMER_TASK_PRIORITY (40) /* Highest priority */
#endif // SLI_SI917
#define configTIMER_QUEUE_LENGTH (10)
#define configTIMER_TASK_STACK_DEPTH (1024)

Expand Down Expand Up @@ -211,11 +215,8 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configUSE_PORT_OPTIMISED_TASK_SELECTION (0)
#define configUSE_TICKLESS_IDLE_SIMPLE_DEBUG (1) /* See into vPortSuppressTicksAndSleep source code for explanation */
#define configMAX_PRIORITIES (56)
#if SLI_SI91X_MCU_INTERFACE && SL_ICD_ENABLED
#define configMINIMAL_STACK_SIZE (1024) /* Number of words to use for Idle and Timer stacks */
#else // For EFR32
#define configMINIMAL_STACK_SIZE (320) /* Number of words to use for Idle and Timer stacks */
#endif // SLI_SI91X_MCU_INTERFACE && SL_ICD_ENABLED
#define configMINIMAL_STACK_SIZE (320) /* Number of words to use for Idle and Timer stacks */

#ifdef HEAP_MONITORING
#define configMAX_TASK_NAME_LEN (24)
#else
Expand Down
65 changes: 4 additions & 61 deletions examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@

#ifdef SLI_SI91X_MCU_INTERFACE
#include "wfx_rsi.h"
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SI917_M4_SLEEP_ENABLED
#include "rsi_m4.h"
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SI917_M4_SLEEP_ENABLED
#endif // SLI_SI91X_MCU_INTERFACE
#endif /* SLI_SI91X_MCU_INTERFACE */

#include <crypto/CHIPCryptoPAL.h>
// If building with the EFR32-provided crypto backend, we can use the
Expand Down Expand Up @@ -356,63 +353,9 @@ CHIP_ERROR SilabsMatterConfig::InitWiFi(void)
// ================================================================================
// FreeRTOS Callbacks
// ================================================================================
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SI917_M4_SLEEP_ENABLED
static bool is_sleep_ready = false;
void vTaskPreSuppressTicksAndSleepProcessing(uint16_t * xExpectedIdleTime)
{
// pointer check
if (xExpectedIdleTime == NULL)
{
return;
}

if (!is_sleep_ready)
{
*xExpectedIdleTime = 0;
}
else
{
// a preliminary check of the expected idle time is performed without making M4 inactive
if (*xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP)
{
// Indicate M4 is Inactive
P2P_STATUS_REG &= ~M4_is_active;
// Waiting for one more clock cycle to make sure M4 H/W Register is updated
P2P_STATUS_REG;

// TODO: This delay is added to sync between M4 and TA. It should be removed once the logic is moved to wifi SDK
for (uint8_t delay = 0; delay < 10; delay++)
{
__ASM("NOP");
}
// Checking if TA has already triggered a packet to M4
// RX_BUFFER_VALID will be cleared by TA if any packet is triggered
if ((P2P_STATUS_REG & TA_wakeup_M4) || (P2P_STATUS_REG & M4_wakeup_TA) || (!(M4SS_P2P_INTR_SET_REG & RX_BUFFER_VALID)))
{
P2P_STATUS_REG |= M4_is_active;
*xExpectedIdleTime = 0;
}
else
{
M4SS_P2P_INTR_CLR_REG = RX_BUFFER_VALID;
M4SS_P2P_INTR_CLR_REG;

TASS_P2P_INTR_MASK_SET = (TX_PKT_TRANSFER_DONE_INTERRUPT | RX_PKT_TRANSFER_DONE_INTERRUPT |
TA_WRITING_ON_COMM_FLASH | NWP_DEINIT_IN_COMM_FLASH
#ifdef SL_SI91X_SIDE_BAND_CRYPTO
| SIDE_BAND_CRYPTO_DONE
#endif
);
}
}
}
}
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SI917_M4_SLEEP_ENABLED
extern "C" void vApplicationIdleHook(void)
{
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SI917_M4_SLEEP_ENABLED
invoke_btn_press_event();
// is_sleep_ready is required since wfx_is_sleep_ready() is not FreeRTOS scheduler agnostic
is_sleep_ready = wfx_is_sleep_ready();
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SI917_M4_SLEEP_ENABLED
#if (SLI_SI91X_MCU_INTERFACE && CHIP_CONFIG_ENABLE_ICD_SERVER)
sl_si91x_invoke_btn_press_event();
#endif
}
1 change: 1 addition & 0 deletions examples/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ source_set("siwx917-common") {
public_configs = [
":siwx917-common-config",
"${efr32_sdk_build_root}:silabs_config",
":chip_examples_project_config",
]

include_dirs = [
Expand Down
7 changes: 5 additions & 2 deletions examples/platform/silabs/wfx_rsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <event_groups.h>
#include <wfx_host_events.h>
#include <app/icd/server/ICDServerConfig.h>

#ifndef RSI_BLE_ENABLE
#define RSI_BLE_ENABLE (1)
Expand Down Expand Up @@ -112,8 +113,10 @@ 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();
int32_t wfx_wifi_rsi_init(void);
#if SL_ICD_ENABLED
void sl_wfx_host_si91x_sleep_wakeup();
#if CHIP_CONFIG_ENABLE_ICD_SERVER
#if SLI_SI91X_MCU_INTERFACE
void sl_si91x_invoke_btn_press_event();
#endif // SLI_SI91X_MCU_INTERFACE
#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
Expand Down
4 changes: 4 additions & 0 deletions src/lwip/silabs/lwipopts-rs911x.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@
#define DEFAULT_UDP_RECVMBOX_SIZE 6
#define DEFAULT_TCP_RECVMBOX_SIZE 6

#if SL_ICD_ENABLED
#define SL_LWIP_MLD6_TIMERS_ONDEMAND 1
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

#ifdef LWIP_DEBUG

#define MEMP_OVERFLOW_CHECK (0)
Expand Down
4 changes: 4 additions & 0 deletions src/lwip/silabs/lwipopts-wf200.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@
#define DEFAULT_UDP_RECVMBOX_SIZE 6
#define DEFAULT_TCP_RECVMBOX_SIZE 6

#if SL_ICD_ENABLED
#define SL_LWIP_MLD6_TIMERS_ONDEMAND 1
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

#ifdef LWIP_DEBUG

#define MEMP_OVERFLOW_CHECK (0)
Expand Down
23 changes: 19 additions & 4 deletions third_party/silabs/SiWx917_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ template("siwx917_sdk") {
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/firmware_upgrade",
"${wifi_sdk_root}/components/device/silabs/si91x/mcu/hal/inc",
"${wifi_sdk_root}/components/device/silabs/si91x/mcu/drivers/systemlevel/inc",

"${wifi_sdk_root}/components/device/silabs/si91x/mcu/drivers/service/power_manager/inc",
]

if (use_system_view) {
Expand Down Expand Up @@ -307,9 +309,9 @@ 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_SI91X_MCU_WIRELESS_BASED_WAKEUP=1",
"SL_SI91X_MCU_BUTTON_BASED_WAKEUP=1",
"SL_SI91X_MCU_ALARM_BASED_WAKEUP=1",
"SL_SI91X_NPSS_GPIO_BTN_HANDLER=1",
"SL_SI91X_POWER_MANAGER_UC_AVAILABLE=1",
"SL_SI91X_TICKLESS_MODE=1",
]

if (si91x_alarm_based_periodic_wakeup) {
Expand Down Expand Up @@ -644,6 +646,7 @@ template("siwx917_sdk") {
"${wifi_sdk_root}/components/board/silabs/src/rsi_board.c",
"${wifi_sdk_root}/components/common/src/sl_utility.c",
"${wifi_sdk_root}/components/device/silabs/si91x/mcu/core/chip/src/rsi_deepsleep_soc.c",
"${wifi_sdk_root}/components/device/silabs/si91x/mcu/core/chip/src/rsi_ps_ram_func.c",
"${wifi_sdk_root}/components/device/silabs/si91x/mcu/core/chip/src/rsi_system_config.c",
"${wifi_sdk_root}/components/device/silabs/si91x/mcu/core/chip/src/system_si91x.c",
"${wifi_sdk_root}/components/device/silabs/si91x/mcu/core/common/src/rsi_debug.c",
Expand Down Expand Up @@ -769,9 +772,21 @@ template("siwx917_sdk") {

if (chip_enable_icd_server) {
sources += [
"${sdk_support_root}/matter/si91x/siwx917/BRD4338A/autogen/sl_si91x_power_manager_handler.c",
"${sdk_support_root}/matter/si91x/siwx917/BRD4338A/autogen/sl_si91x_power_manager_wakeup_handler.c",

"${wifi_sdk_root}/components/device/silabs/si91x/mcu/drivers/peripheral_drivers/src/sl_si91x_m4_ps.c",
"${wifi_sdk_root}/components/device/silabs/si91x/mcu/drivers/systemlevel/src/rsi_rtc.c",
"${wifi_sdk_root}/components/device/silabs/si91x/mcu/drivers/systemlevel/src/rsi_time_period.c",

"${wifi_sdk_root}/components/device/silabs/si91x/mcu/drivers/service/power_manager/src/sl_si91x_power_manager.c",
"${wifi_sdk_root}/components/device/silabs/si91x/mcu/drivers/service/power_manager/src/sli_si91x_power_manager.c",
"${wifi_sdk_root}/components/device/silabs/si91x/mcu/drivers/service/power_manager/src/sli_si91x_power_manager_wakeup_init.c",
"${wifi_sdk_root}/third_party/silicon_labs/freertos/src/sl_si91x_low_power_tickless_mode.c",

# "${efr32_sdk_root}/platform/service/sleeptimer/src/sl_sleeptimer.c",
# "${wifi_sdk_root}/components/device/silabs/si91x/mcu/drivers/service/sleeptimer/src/sl_sleeptimer_hal_si91x_sysrtc.c",

# "${wifi_sdk_root}/components/device/silabs/si91x/mcu/drivers/peripheral_drivers/src/rsi_sysrtc.c",
]
}

Expand Down

0 comments on commit 1467880

Please sign in to comment.