Skip to content

Commit

Permalink
m4 sleep changes for 917 soc
Browse files Browse the repository at this point in the history
  • Loading branch information
chirag-silabs committed Nov 8, 2023
1 parent 155917e commit a7e166c
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 35 deletions.
11 changes: 10 additions & 1 deletion examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@

#ifdef SIWX_917
#include "wfx_rsi.h"
#if SL_ICD_ENABLED
extern "C" void M4_sleep_wakeup(void);
#endif /* SL_ICD_ENABLED */
#endif /* SIWX_917 */

using namespace ::chip;
Expand Down Expand Up @@ -294,7 +297,13 @@ CHIP_ERROR SilabsMatterConfig::InitWiFi(void)
// ================================================================================
// FreeRTOS Callbacks
// ================================================================================
extern "C" uint8_t test;
extern "C" void vApplicationIdleHook(void)
{
// FreeRTOS Idle callback
#if ((SIWX_917 == 1) && (SL_ICD_ENABLED == 1))
if(ConnectivityMgr().IsWiFiStationConnected()) {
// Let the M4 sleep once commissioning is done and device is in idle state
M4_sleep_wakeup();
}
#endif
}
111 changes: 109 additions & 2 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
#include "task.h"
#include "wfx_host_events.h"

#include "rsi_m4.h"
#include "rsi_board.h"

#include "ble_config.h"
#include "rsi_rom_power_save.h"
#include "sl_si91x_button_config.h"

#if (EXP_BOARD)
#include "rsi_bt_common_apis.h"
#endif
Expand Down Expand Up @@ -194,6 +201,90 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t
}

#if SL_ICD_ENABLED
void IRQ026_Handler()
{
RSI_PS_GetWkpUpStatus();

/*Clear interrupt */
RSI_PS_ClrWkpUpStatus(NPSS_TO_MCU_WIRELESS_INTR);

return;
}

void wakeup_source_config(void)
{
/*Configure the NPSS GPIO mode to wake up  */
RSI_NPSSGPIO_SetPinMux(NPSS_GPIO_2, NPSSGPIO_PIN_MUX_MODE2);

/*Configure the NPSS GPIO direction to input */
RSI_NPSSGPIO_SetDir(NPSS_GPIO_2, NPSS_GPIO_DIR_INPUT);

/*Configure the NPSS GPIO interrupt polarity */
RSI_NPSSGPIO_SetPolarity(NPSS_GPIO_2, NPSS_GPIO_INTR_LOW);

/*Enable the REN*/
RSI_NPSSGPIO_InputBufferEn(NPSS_GPIO_2, 1);

/* Set the GPIO to wake from deep sleep */
RSI_NPSSGPIO_SetWkpGpio(NPSS_GPIO_2_INTR);

/* Un mask the NPSS GPIO interrupt*/
RSI_NPSSGPIO_IntrUnMask(NPSS_GPIO_2_INTR);

/*Select wake up sources */
RSI_PS_SetWkpSources(GPIO_BASED_WAKEUP);

/*Enable the NPSS GPIO interrupt slot*/
NVIC_EnableIRQ(NPSS_TO_MCU_GPIO_INTR_IRQn);
}

/******************************************************************
* @fn M4_sleep_wakeup()
* @brief
* Setting the M4 to sleep
*
* @param[in] None
* @return
* None
*********************************************************************/
void M4_sleep_wakeup() {
if (RSI_NPSSGPIO_GetPin(SL_BUTTON_BTN0_PIN))
{
/* Configure RAM Usage and Retention Size */
sl_si91x_configure_ram_retention(WISEMCU_256KB_RAM_IN_USE, WISEMCU_RETAIN_DEFAULT_RAM_DURING_SLEEP);
SILABS_LOG("M4 going to sleep");
sl_si91x_trigger_sleep(SLEEP_WITH_RETENTION,
DISABLE_LF_MODE,
WKP_RAM_USAGE_LOCATION,
(uint32_t)RSI_PS_RestoreCpuContext,
IVT_OFFSET_ADDR,
RSI_WAKEUP_FROM_FLASH_MODE);
sli_m4_ta_interrupt_init();
fpuInit();
wakeup_source_config();
silabsInitLog();
/*Start of M4 init after wake up */
SILABS_LOG("M4 wakeup successful");
}
}

/******************************************************************
* @fn InitWakeupSource()
* @brief
* Setting the Wakeup Source of the M4
*
* @param[in] None
* @return
* None
*********************************************************************/
void InitWakeupSource() {
/* Configure Wakeup-Source */
RSI_PS_SetWkpSources(WIRELESS_BASED_WAKEUP);
NVIC_SetPriority(WIRELESS_WAKEUP_IRQHandler, WIRELESS_WAKEUP_IRQHandler_Priority);

/* Enable NVIC */
NVIC_EnableIRQ(WIRELESS_WAKEUP_IRQHandler);
}
/******************************************************************
* @fn wfx_rsi_power_save()
* @brief
Expand All @@ -213,7 +304,7 @@ 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)
{
Expand Down Expand Up @@ -264,7 +355,19 @@ 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(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;
}
SILABS_LOG("m4_ta_secure_handshake Success\r\n");
InitWakeupSource();
#endif /* SL_ICD_ENABLED */
#endif /* !RSI_M4_INTERFACE */

status = sl_wifi_get_mac_address(SL_WIFI_CLIENT_INTERFACE, (sl_mac_address_t *) &wfx_rsi.sta_mac.octet[0]);
if (status != SL_STATUS_OK)
{
Expand Down Expand Up @@ -474,6 +577,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
34 changes: 25 additions & 9 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wlan_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,22 @@
//! Disable feature
#define RSI_DISABLE 0

#define SI91X_LISTEN_INTERVAL 0
//#define SI91X_LISTEN_INTERVAL 0
#if COMMON_FLASH_EN
#define IVT_OFFSET_ADDR 0x81C2000 //0x8012000 /*<!Application IVT location VTOR offset> */
#define WKP_RAM_USAGE_LOCATION 0x24061EFC //0x24061000 /*<!Bootloader RAM usage location upon wake up */
#else // For Dual Flash
#define IVT_OFFSET_ADDR 0x8012000 /*<!Application IVT location VTOR offset> */
#define WKP_RAM_USAGE_LOCATION 0x24061000 /*<!Bootloader RAM usage location upon wake up */
#endif // COMMON_FLASH_EN

#define WIRELESS_WAKEUP_IRQHandler NPSS_TO_MCU_WIRELESS_INTR_IRQn
#define WIRELESS_WAKEUP_IRQHandler_Priority 17

/* Constants required to manipulate the NVIC. */
#define portNVIC_SHPR3_REG (*((volatile uint32_t *)0xe000ed20))
#define portNVIC_PENDSV_PRI (((uint32_t)(0x3f << 4)) << 16UL)
#define portNVIC_SYSTICK_PRI (((uint32_t)(0x3f << 4)) << 24UL)

static const sl_wifi_device_configuration_t config = {
.boot_option = LOAD_NWP_FW,
Expand Down Expand Up @@ -76,14 +91,15 @@ static const sl_wifi_device_configuration_t config = {
#else
.ext_tcp_ip_feature_bit_map = (RSI_EXT_TCPIP_FEATURE_BITMAP | SL_SI91X_CONFIG_FEAT_EXTENTION_VALID),
#endif
//! ENABLE_BLE_PROTOCOL in bt_feature_bit_map
//!ENABLE_BLE_PROTOCOL in bt_feature_bit_map
.ble_feature_bit_map =
((SL_SI91X_BLE_MAX_NBR_PERIPHERALS(RSI_BLE_MAX_NBR_PERIPHERALS) |
SL_SI91X_BLE_MAX_NBR_CENTRALS(RSI_BLE_MAX_NBR_CENTRALS) |
SL_SI91X_BLE_MAX_NBR_ATT_SERV(RSI_BLE_MAX_NBR_ATT_SERV) |
SL_SI91X_BLE_MAX_NBR_ATT_REC(RSI_BLE_MAX_NBR_ATT_REC)) |
SL_SI91X_FEAT_BLE_CUSTOM_FEAT_EXTENTION_VALID | SL_SI91X_BLE_PWR_INX(RSI_BLE_PWR_INX) |
SL_SI91X_BLE_PWR_SAVE_OPTIONS(RSI_BLE_PWR_SAVE_OPTIONS) | SL_SI91X_916_BLE_COMPATIBLE_FEAT_ENABLE
((SL_SI91X_BLE_MAX_NBR_PERIPHERALS(RSI_BLE_MAX_NBR_PERIPHERALS)
| SL_SI91X_BLE_MAX_NBR_CENTRALS(RSI_BLE_MAX_NBR_CENTRALS)
| SL_SI91X_BLE_MAX_NBR_ATT_SERV(RSI_BLE_MAX_NBR_ATT_SERV)
| SL_SI91X_BLE_MAX_NBR_ATT_REC(RSI_BLE_MAX_NBR_ATT_REC))
| SL_SI91X_FEAT_BLE_CUSTOM_FEAT_EXTENTION_VALID | SL_SI91X_BLE_PWR_INX(RSI_BLE_PWR_INX)
| SL_SI91X_BLE_PWR_SAVE_OPTIONS(RSI_BLE_PWR_SAVE_OPTIONS)
| SL_SI91X_916_BLE_COMPATIBLE_FEAT_ENABLE
#if RSI_BLE_GATT_ASYNC_ENABLE
| SL_SI91X_BLE_GATT_ASYNC_ENABLE
#endif
Expand All @@ -110,4 +126,4 @@ static const sl_wifi_device_configuration_t config = {
.config_feature_bit_map = (SL_SI91X_FEAT_SLEEP_GPIO_SEL_BITMAP | RSI_CONFIG_FEATURE_BITMAP) }
};

#endif
#endif
3 changes: 3 additions & 0 deletions examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ 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
int32_t wfx_rsi_power_save();
#endif /* SL_ICD_ENABLED */

#ifdef __cplusplus
}
Expand Down
17 changes: 14 additions & 3 deletions examples/platform/silabs/ldscripts/SiWx917-common.ld
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ SECTIONS
{
KEEP(*(.isr_vector))
KEEP(*(.reset_handler))
*(EXCLUDE_FILE(*sl_si91x_bus.o *sl_si91x_driver.o *sli_si91x_multithreaded.o *rsi_hal_mcu_m4_ram.o ) .text*)
*(EXCLUDE_FILE(*sl_si91x_bus.o *sl_si91x_driver.o *sli_si91x_multithreaded.o *rsi_deepsleep_soc.o *rsi_hal_mcu_m4_ram.o *croutine.o *event_groups.o *list.o *queue.o *stream_buffer.o *tasks.o *timers.o *cmsis_os2.o *freertos_umm_malloc_host.o *port.o *heap_*.o) .text*)

/* .ctors */
*crtbegin.o(.ctors)
Expand Down Expand Up @@ -131,6 +131,18 @@ SECTIONS
*sl_si91x_driver.o(.text*)
*sli_si91x_multithreaded.o(.text*)
*rsi_hal_mcu_m4_ram.o(.text*)
*rsi_deepsleep_soc.o(.text*)
*croutine.o(.text*)
*event_groups.o(.text*)
*list.o(.text*)
*queue.o(.text*)
*cmsis_os2.o(.text*)
*stream_buffer.o(.text*)
*tasks.o(.text*)
*timers.o(.text*)
*freertos_umm_malloc_host.o(.text*)
*port.o(.text*)
*heap_*.o(.text*)

. = ALIGN(4);
/* preinit data */
Expand Down Expand Up @@ -224,7 +236,7 @@ SECTIONS
KEEP(*(.simee*))
} > rom

linker_nvm_end = __main_flash_end__;
linker_nvm_end = __main_flash_end__ - 4096;
linker_nvm_begin = linker_nvm_end - SIZEOF(.nvm);
linker_nvm_size = SIZEOF(.nvm);
linker_storage_end = linker_nvm_begin;
Expand All @@ -237,4 +249,3 @@ SECTIONS
app_flash_end = 0x81c2000 + 0x200000;
ASSERT( (linker_nvm_begin + SIZEOF(.nvm)) <= app_flash_end, "NVM3 is excessing the flash size !")
}

6 changes: 6 additions & 0 deletions src/platform/silabs/rs911x/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ 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
48 changes: 30 additions & 18 deletions third_party/silabs/SiWx917_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ template("siwx917_sdk") {
"SILABS_LOG_ENABLED=${silabs_log_enabled}",
"SL_HEAP_SIZE=32768",
"SL_WIFI=1",
"CCP_SI917_BRINGUP",
"SL_COMPONENT_CATALOG_PRESENT",
"RS911X_WIFI",
"CCP_SI917_BRINGUP=1",
"SL_COMPONENT_CATALOG_PRESENT=1",
"RS911X_WIFI=1",
"RSI_WLAN_ENABLE",
"RSI_WITH_OS",
"RSI_M4_INTERFACE", #Enable CCP bus Interface
"RSI_M4_INTERFACE=1", #Enable CCP bus Interface
"RSI_WLAN_API_ENABLE",
"LITTLE_ENDIAN_ORDER",
"_CHIP_9118",
Expand All @@ -167,31 +167,39 @@ template("siwx917_sdk") {
"PLATFORM_HEADER=\"platform-header.h\"",
"USE_NVM3=1",
"RSI_ARM_CM4F",
"SIWX_917",
"CHIP_9117",
"SIWX_917=1",
"CHIP_9117=1",
"BLE_ENABLE=1",
"RSI_LITTLE_ENDIAN=1",
"TINYCRYPT_PRIMITIVES",
"OPTIMIZE_TINYCRYPT_ASM",
"__error_t_defined",
"RSI_SAMPLE_HAL",
"ENABLE_IPMU_APIS",
"RSI_SAMPLE_HAL=1",
"ENABLE_IPMU_APIS=1",
"ROM_BYPASS",
"DEBUG_UART",
"FLASH_BASED_EXECUTION_ENABLE",
"TA_DEEP_SLEEP_COMMON_FLASH",
"SL_WIFI_COMPONENT_INCLUDED",
"DEBUG_UART=1",
"FLASH_BASED_EXECUTION_ENABLE=1",
"TA_DEEP_SLEEP_COMMON_FLASH=1",
"SL_WIFI_COMPONENT_INCLUDED=1",
"CHIP_917=1",
"ROMDRIVER_PRESENT=1",
"SL_CATALOG_FREERTOS_KERNEL_PRESENT=1",
"SL_PLATFORM_EXAMPLES_ENABLE",
"SI91X_DEVICE=1",
"SI917_RADIO_BOARD=1",
"FLASH_PAGE_SIZE",
"SL_NVM3_PRESENT",
"FLASH_PAGE_SIZE=1",
"SL_NVM3_PRESENT=1",
"ROM_WIRELESS",
"BRD4325A", #TODO: should be removed after SoC macro clean-up
"CONNECTIVITY_PLATFORM",
"BRD4325A=1", #TODO: should be removed after SoC macro clean-up
"SI917_SOC=1",
"EXT_IRQ_COUNT=75",
"FLASH_PAGE_SIZE=1",
"SI917_COMMON_FLASH=1",
"SRAM_BASE=0x0c",
"SRAM_SIZE=0x00040000",
"DEBUG_ENABLE=1",
"ENABLE_DEBUG_MODULE=1",
"SI917=1",
]

if (silabs_board == "BRD4325B") {
Expand Down Expand Up @@ -271,8 +279,12 @@ template("siwx917_sdk") {

if (chip_enable_icd_server) {
defines += [
"SL_CATALOG_POWER_MANAGER_PRESENT",
"SL_CATALOG_SLEEPTIMER_PRESENT",
"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}",
]
}

Expand Down
4 changes: 2 additions & 2 deletions third_party/silabs/silabs_board.gni
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ if (silabs_board == "BRD4304A") {
} else if (silabs_board == "BRD4338A") {
silabs_family = "SiWx917-common"
silabs_mcu = "SiWG917M111MGTBA"
disable_lcd = false
show_qr_code = true
disable_lcd = true
show_qr_code = false
wifi_soc = true
wifi_soc_common_flash = true
silabs_board_lower = "brd4338a"
Expand Down

0 comments on commit a7e166c

Please sign in to comment.