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

[Silabs] Enabling Sleepy on 917 SoC device #31299

Merged
8 changes: 7 additions & 1 deletion examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,5 +296,11 @@ CHIP_ERROR SilabsMatterConfig::InitWiFi(void)
// ================================================================================
extern "C" void vApplicationIdleHook(void)
{
// FreeRTOS Idle callback
#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();
}
#endif
}
68 changes: 65 additions & 3 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@

#include "ble_config.h"

#if SL_ICD_ENABLED && SIWX_917
#include "rsi_rom_power_save.h"
#include "sl_si91x_button_pin_config.h"
#include "sl_si91x_m4_ps.h"

// TODO: should be removed once we are getting the press interrupt for button 0 with sleep
#define BUTTON_PRESSED 1
bool btn0_pressed = false;
#endif // SL_ICD_ENABLED && SIWX_917

#include "dhcp_client.h"
#include "sl_wifi.h"
#include "wfx_host_events.h"
Expand Down Expand Up @@ -198,6 +208,44 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t
}

#if SL_ICD_ENABLED

#if SIWX_917
/******************************************************************
* @fn sl_wfx_host_si91x_sleep_wakeup()
* @brief
* M4 going to sleep
*
* @param[in] None
* @return
* None
*********************************************************************/
void sl_wfx_host_si91x_sleep_wakeup()
{
if (wfx_rsi.dev_state & WFX_RSI_ST_SLEEP_READY)
{
// TODO: should be removed once we are getting the press interrupt for button 0 with sleep
if (!RSI_NPSSGPIO_GetPin(SL_BUTTON_BTN0_PIN) && !btn0_pressed)
{
sl_button_on_change(SL_BUTTON_BTN0_NUMBER, BUTTON_PRESSED);
btn0_pressed = true;
}
if (RSI_NPSSGPIO_GetPin(SL_BUTTON_BTN0_PIN))
{
#ifdef DISPLAY_ENABLED
// if LCD is enabled, power down the lcd before setting the M4 to sleep
sl_si91x_hardware_setup();
#endif
btn0_pressed = false;
/* Configure RAM Usage and Retention Size */
sl_si91x_m4_sleep_wakeup();
#if SILABS_LOG_ENABLED
silabsInitLog();
chirag-silabs marked this conversation as resolved.
Show resolved Hide resolved
#endif
}
}
}
#endif /* SIWX_917 */

/******************************************************************
* @fn wfx_rsi_power_save()
* @brief
Expand All @@ -217,14 +265,14 @@ int32_t wfx_rsi_power_save()
return status;
}

sl_wifi_performance_profile_t wifi_profile = { ASSOCIATED_POWER_SAVE };
sl_wifi_performance_profile_t wifi_profile = { .profile = ASSOCIATED_POWER_SAVE };
status = sl_wifi_set_performance_profile(&wifi_profile);
if (status != RSI_SUCCESS)
{
SILABS_LOG("Powersave Config Failed, Error Code : 0x%lX", status);
return status;
}
SILABS_LOG("Powersave Config Success");
wfx_rsi.dev_state |= WFX_RSI_ST_SLEEP_READY;
return status;
}
#endif /* SL_ICD_ENABLED */
Expand Down Expand Up @@ -283,7 +331,17 @@ static sl_status_t wfx_rsi_init(void)
SILABS_LOG("wfx_rsi_init failed %x", status);
return status;
}
#endif
#else // For SoC
#if SL_ICD_ENABLED
uint8_t xtal_enable = 1;
status = sl_si91x_m4_ta_secure_handshake(SL_SI91X_ENABLE_XTAL, 1, &xtal_enable, 0, NULL);
if (status != SL_STATUS_OK)
{
SILABS_LOG("Failed to bring m4_ta_secure_handshake: 0x%lx\r\n", status);
return status;
}
#endif /* SL_ICD_ENABLED */
#endif /* SLI_SI91X_MCU_INTERFACE */

sl_wifi_firmware_version_t version = { 0 };
status = sl_wifi_get_firmware_version(&version);
Expand Down Expand Up @@ -500,6 +558,10 @@ static sl_status_t wfx_rsi_do_join(void)

sl_wifi_set_join_callback(join_callback_handler, NULL);

// Setting the listen interval to 0 which will set it to DTIM interval
sl_wifi_listen_interval_t sleep_interval = { .listen_interval = 0 };
status = sl_wifi_set_listen_interval(SL_WIFI_CLIENT_INTERFACE, sleep_interval);

/* Try to connect Wifi with given Credentials
* untill there is a success or maximum number of tries allowed
*/
Expand Down
2 changes: 0 additions & 2 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wlan_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
//! Disable feature
#define RSI_DISABLE 0

#define SI91X_LISTEN_INTERVAL 0

static const sl_wifi_device_configuration_t config = {
.boot_option = LOAD_NWP_FW,
.mac_address = NULL,
Expand Down
5 changes: 5 additions & 0 deletions examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#define WFX_RSI_ST_STA_READY (WFX_RSI_ST_STA_CONNECTED | WFX_RSI_ST_STA_DHCP_DONE)
#define WFX_RSI_ST_STARTED (0x200) /* RSI task started */
#define WFX_RSI_ST_SCANSTARTED (0x400) /* Scan Started */
#define WFX_RSI_ST_SLEEP_READY (0x800) /* Notify the M4 to go to sleep*/

struct wfx_rsi
{
Expand Down Expand Up @@ -92,6 +93,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();
int32_t wfx_rsi_power_save();
#endif /* SL_ICD_ENABLED */

#ifdef __cplusplus
}
Expand Down
4 changes: 4 additions & 0 deletions examples/platform/silabs/display/demo-ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "dmd/dmd.h"
#include "em_types.h"
#include "glib.h"
#include "sl_memlcd.h"
#if SL_WIFI && !SIWX_917
#include "spi_multiplex.h"
#endif // SL_WIFI && !SIWX_917
Expand Down Expand Up @@ -102,6 +103,9 @@ void demoUIInit(GLIB_Context_t * context)

sl_status_t updateDisplay(void)
{
#if SIWX_917 && SL_ICD_ENABLED && DISPLAY_ENABLED
sl_memlcd_post_wakeup_init();
#endif // SIWX_917 && SL_ICD_ENABLED && DISPLAY_ENABLED
#if SL_LCDCTRL_MUX
sl_wfx_host_pre_lcd_spi_transfer();
#endif // SL_LCDCTRL_MUX
Expand Down
4 changes: 4 additions & 0 deletions scripts/examples/gn_silabs_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ if [ "$#" == "0" ]; then
Use provided hardware version at build time
siwx917_commissionable_data
Build with the commissionable data given in DeviceConfig.h (only for SiWx917)
si91x_alarm_based_wakeup
Enable the Alarm Based Wakeup for 917 SoC when sleep is enabled (Default false)
si91x_alarm_periodic_time
Periodic time at which the 917 SoC should wakeup (Default: 30sec)
Presets
--icd
enable ICD features, set thread mtd
Expand Down
6 changes: 6 additions & 0 deletions src/platform/silabs/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,15 @@ void KeyValueStoreManagerImpl::ScheduleKeyMapSave(void)
During commissioning, the key map will be modified multiples times subsequently.
Commit the key map in nvm once it as stabilized.
*/
#if SIWX_917 && CHIP_CONFIG_ENABLE_ICD_SERVER
// TODO: Remove this when RTC timer is added MATTER-2705
SilabsConfig::WriteConfigValueBin(SilabsConfig::kConfigKey_KvsStringKeyMap, reinterpret_cast<const uint8_t *>(mKvsKeyMap),
sizeof(mKvsKeyMap));
#else
SystemLayer().StartTimer(
std::chrono::duration_cast<System::Clock::Timeout>(System::Clock::Seconds32(SILABS_KVS_SAVE_DELAY_SECONDS)),
KeyValueStoreManagerImpl::OnScheduledKeyMapSave, NULL);
#endif // defined(SIWX_917) && CHIP_CONFIG_ENABLE_ICD_SERVER
}

CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size,
Expand Down
7 changes: 7 additions & 0 deletions src/platform/silabs/rs911x/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ void sl_ble_event_handling_task(void)
default:
break;
}

if (chip::DeviceLayer::ConnectivityMgr().IsWiFiStationConnected())
{
// Once DUT is connected adding a 500ms delay
// TODO: Fix this with a better event handling
vTaskDelay(pdMS_TO_TICKS(500));
}
}
}

Expand Down
79 changes: 54 additions & 25 deletions third_party/silabs/SiWx917_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ import("silabs_board.gni")

examples_plat_dir = "${chip_root}/examples/platform/silabs/SiWx917"

declare_args() {
# Enable the Alarm Based Wakeup for 917 SoC when sleep is enabled
si91x_alarm_based_wakeup = false

# Periodic time at which the 917 SoC should wakeup
si91x_alarm_periodic_time = 30
}

# Defines an siwx917 SDK build target.
#
# Parameters:
Expand Down Expand Up @@ -143,12 +151,12 @@ template("siwx917_sdk") {
"SILABS_LOG_ENABLED=${silabs_log_enabled}",
"SL_HEAP_SIZE=32768",
"SL_WIFI=1",
"CCP_SI917_BRINGUP",
"CCP_SI917_BRINGUP=1",
"SL_COMPONENT_CATALOG_PRESENT",
"RS911X_WIFI",
"RS911X_WIFI=1",
"RSI_WLAN_ENABLE",
"SLI_SI91X_ENABLE_OS",
"SLI_SI91X_MCU_INTERFACE", #Enable CCP bus Interface
"SLI_SI91X_ENABLE_OS=1",
"SLI_SI91X_MCU_INTERFACE=1", #Enable CCP bus Interface
"RSI_WLAN_API_ENABLE",
"NVM3_DEFAULT_NVM_SIZE=40960",
"NVM3_DEFAULT_MAX_OBJECT_SIZE=4092",
Expand All @@ -159,43 +167,46 @@ template("siwx917_sdk") {
"__HEAP_SIZE=0",
"PLATFORM_HEADER=\"platform-header.h\"",
"USE_NVM3=1",
"RSI_ARM_CM4F",
"SIWX_917",
"CHIP_9117",
"SIWX_917=1",
"CHIP_9117=1",
"SLI_SI91X_ENABLE_BLE=1",
"SL_SI91X_ENABLE_LITTLE_ENDIAN=1",
"TINYCRYPT_PRIMITIVES",
"OPTIMIZE_TINYCRYPT_ASM",
"__error_t_defined",
"RSI_SAMPLE_HAL",
"ENABLE_IPMU_APIS",
"SLI_SI91X_MCU_MOV_ROM_API_TO_FLASH",
"DEBUG_UART",
"SLI_SI91X_MCU_ENABLE_FLASH_BASED_EXECUTION",
"SL_WIFI_COMPONENT_INCLUDED",
"DEBUG_UART=1",
"SLI_SI91X_MCU_ENABLE_FLASH_BASED_EXECUTION=1",
"SL_WIFI_COMPONENT_INCLUDED=1",
"SLI_SI917=1",
"SI917=1",
"ROMDRIVER_PRESENT=1",
"SL_CATALOG_FREERTOS_KERNEL_PRESENT=1",
"SL_PLATFORM_EXAMPLES_ENABLE",
"SLI_SI91X_MCU_CONFIG_RADIO_BOARD_BASE_VER=1",
"FLASH_PAGE_SIZE",
"SL_NVM3_PRESENT",
"ROM_WIRELESS",
"BRD4325A", #TODO: should be removed after SoC macro clean-up
"CONNECTIVITY_PLATFORM",
"SLI_SI917B0 = 1",
"SLI_SI917B0=1",
"SLI_SI91X_MCU_COMMON_FLASH_MODE=1",
"EXECUTION_FROM_RAM",
"SLI_SI91X_MCU_CONFIG_RADIO_BOARD_VER2=1",
"SL_BOARD_REV=\"A00\"",
"SPI_MULTI_SLAVE=1",
"SYSCALLS_WRITE=1",
"SI91X_SYSRTC_COUNT=1",
"SSI_ULP_MASTER=1",
"SL_MEMLCD_EXTCOMIN_PORT=0",
"__STATIC_INLINE=static inline",
"SL_SI91X_SI917_RAM_MEM_CONFIG=3",
"SL_SI91X_SI917_RAM_MEM_CONFIG=2",
"SL_SI91x_DUAL_INTERRUPTS_ERRATA=1",
"EXT_IRQ_COUNT=75",
"FLASH_PAGE_SIZE=1",
"DEBUG_ENABLE=1",
"ENABLE_DEBUG_MODULE=1",
"SI91X_SYSRTC_PRESENT=1",
"TA_DEEP_SLEEP_COMMON_FLASH=1",
"SI917_SOC=1",
"SI91X_PLATFORM=1",
"SL_NET_COMPONENT_INCLUDED=1",
"SRAM_BASE=0x0cUL",
"SRAM_SIZE=0x4fc00UL",
"SLI_SI91X_MCU_ENABLE_IPMU_APIS=1",
"RADIO_CONFIG_DMP_SUPPORT=1",
"configUSE_POSIX_ERRNO=1",
]

if (chip_build_libshell) {
Expand Down Expand Up @@ -250,13 +261,21 @@ template("siwx917_sdk") {

if (chip_enable_icd_server) {
defines += [
"WIFI_DEBUG_ENABLED=1",
"SL_ICD_ENABLED=1",
"SL_ACTIVE_MODE_THRESHOLD=${sl_active_mode_threshold_ms}",
"SL_ACTIVE_MODE_INTERVAL=${sl_active_mode_interval_ms}",
"SL_IDLE_MODE_INTERVAL=${sl_idle_mode_interval_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",
]

if (si91x_alarm_based_wakeup) {
defines += [
"SL_SI91X_MCU_ALARM_BASED_WAKEUP=1",
"ALARM_PERIODIC_TIME=${si91x_alarm_periodic_time}",
]
}
}

if (chip_build_libshell) { # matter shell
Expand Down Expand Up @@ -472,6 +491,13 @@ template("siwx917_sdk") {
]
}

if (chip_enable_icd_server) {
sources += [
"${sdk_support_root}/matter/si91x/siwx917/BRD4338A/support/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",
]
}
public_deps = [
":siwx917_mbedtls_config",
"${segger_rtt_root}:segger_rtt",
Expand Down Expand Up @@ -501,6 +527,9 @@ template("siwx917_sdk") {
]
}

public_configs = [ ":${sdk_target_name}_config" ]
public_configs = [
":${sdk_target_name}_config",
"${examples_plat_dir}:siwx917-common-config",
]
}
}
2 changes: 0 additions & 2 deletions third_party/silabs/silabs_board.gni
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ if (silabs_board == "BRD4304A") {
} else if (silabs_board == "BRD4338A") {
silabs_family = "SiWx917-common"
silabs_mcu = "SiWG917M111MGTBA"
disable_lcd = false
show_qr_code = true
wifi_soc = true
} else if (silabs_board == "BRD4180A") {
assert(
Expand Down
Loading