Skip to content

Commit

Permalink
enabling the sleepy device for EFR32 and rs911x combo
Browse files Browse the repository at this point in the history
  • Loading branch information
chirag-silabs committed Mar 7, 2023
1 parent 69ec3ea commit 2967ff0
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 54 deletions.
14 changes: 14 additions & 0 deletions examples/platform/silabs/efr32/rs911x/hal/efx_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
#include "sl_device_init_dpll.h"
#include "sl_device_init_hfxo.h"

#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
#include "sl_power_manager.h"
#endif

StaticSemaphore_t xEfxSpiIntfSemaBuffer;
static SemaphoreHandle_t spi_sem;

Expand Down Expand Up @@ -184,6 +188,10 @@ static bool rx_dma_complete(unsigned int channel, unsigned int sequenceNo, void
xSemaphoreGiveFromISR(spi_sem, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);

#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
sl_power_manager_remove_em_requirement(SL_POWER_MANAGER_EM1);
#endif

return true;
}

Expand All @@ -205,6 +213,9 @@ static void receiveDMA(uint8_t * rx_buf, uint16_t xlen)
* The xmit can be dummy data (no src increment for tx)
*/
dummy_data = 0;
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
sl_power_manager_add_em_requirement(SL_POWER_MANAGER_EM1);
#endif
DMADRV_PeripheralMemory(rx_dma_channel, MY_USART_RX_SIGNAL, (void *) rx_buf, (void *) &(MY_USART->RXDATA), true, xlen,
dmadrvDataSize1, rx_dma_complete, NULL);

Expand Down Expand Up @@ -248,6 +259,9 @@ static void transmitDMA(uint8_t * rx_buf, uint8_t * tx_buf, uint16_t xlen)
/* DEBUG */ rx_buf[0] = 0xAA;
rx_buf[1] = 0x55;
}
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
sl_power_manager_add_em_requirement(SL_POWER_MANAGER_EM1);
#endif
DMADRV_PeripheralMemory(rx_dma_channel, MY_USART_RX_SIGNAL, buf, (void *) &(MY_USART->RXDATA), srcinc, xlen, dmadrvDataSize1,
rx_dma_complete, buf);
// Start transmit DMA.
Expand Down
109 changes: 61 additions & 48 deletions examples/platform/silabs/efr32/rs911x/hal/rsi_hal_mcu_ioports.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#include "rsi_board_configuration.h"
#include "rsi_driver.h"

#define RSI_HAL_LP_SLEEP_CONFIRM_PIN 6
/*===========================================================*/
/**
* @fn void rsi_hal_config_gpio(uint8_t gpio_number,uint8_t mode,uint8_t value)
Expand All @@ -61,15 +61,16 @@ void rsi_hal_config_gpio(uint8_t gpio_number, uint8_t mode, uint8_t value)

CMU_ClockEnable(cmuClock_GPIO, true);

// WFX_RSI_LOG ("RSI: CFG GPIO: 0x%x", gpio_number);
switch (gpio_number)
{
case RSI_HAL_RESET_PIN:
GPIO_PinModeSet(WFX_RESET_PIN.port, WFX_RESET_PIN.pin, gpioModePushPull, PINOUT_SET);
break;
default:
break;
}
switch(gpio_number)
{
case RSI_HAL_SLEEP_CONFIRM_PIN: GPIO_PinModeSet(WFX_SLEEP_CONFIRM_PIN.port, WFX_SLEEP_CONFIRM_PIN.pin, gpioModeWiredOrPullDown, 1); break;
#ifndef LOGGING_STATS
case RSI_HAL_WAKEUP_INDICATION_PIN: GPIO_PinModeSet(WAKE_INDICATOR_PIN.port, WAKE_INDICATOR_PIN.pin, gpioModeWiredOrPullDown, 0); break;
#endif
case RSI_HAL_RESET_PIN: GPIO_PinModeSet(WFX_RESET_PIN.port, WFX_RESET_PIN.pin, gpioModePushPull, 1); break;
case RSI_HAL_LP_SLEEP_CONFIRM_PIN: GPIO_PinModeSet(WFX_SLEEP_CONFIRM_PIN.port, WFX_SLEEP_CONFIRM_PIN.pin, gpioModeWiredOrPullDown, 1);break;
default: break;
}
}

/*===========================================================*/
Expand All @@ -81,19 +82,20 @@ void rsi_hal_config_gpio(uint8_t gpio_number, uint8_t mode, uint8_t value)
* @return none
* @description This API is used to drives or makes the host gpio value high.
*/
void rsi_hal_set_gpio(uint8_t gpio_number)
{
// WFX_RSI_LOG ("RSI: SET GPIO: 0x%x", gpio_number);
switch (gpio_number)
{
case RSI_HAL_RESET_PIN:
GPIO_PinModeSet(WFX_RESET_PIN.port, WFX_RESET_PIN.pin, gpioModeWiredOrPullDown, PINOUT_SET);
break;
default:
break;
}
void rsi_hal_set_gpio(uint8_t gpio_number) {
switch(gpio_number)
{
case RSI_HAL_SLEEP_CONFIRM_PIN: GPIO_PinModeSet(WFX_SLEEP_CONFIRM_PIN.port, WFX_SLEEP_CONFIRM_PIN.pin, gpioModeWiredOrPullDown, 1); break;
#ifndef LOGGING_STATS
case RSI_HAL_WAKEUP_INDICATION_PIN: GPIO_PinModeSet(WAKE_INDICATOR_PIN.port, WAKE_INDICATOR_PIN.pin, gpioModeInput, 1); break;
#else
case RSI_HAL_WAKEUP_INDICATION_PIN: GPIO_PinModeSet(LOGGING_WAKE_INDICATOR_PIN.port, LOGGING_WAKE_INDICATOR_PIN.pin, gpioModeInput, 1); break;
#endif
case RSI_HAL_RESET_PIN: GPIO_PinModeSet(WFX_RESET_PIN.port, WFX_RESET_PIN.pin, gpioModeWiredOrPullDown, 1); break;
case RSI_HAL_LP_SLEEP_CONFIRM_PIN: GPIO_PinModeSet(WFX_SLEEP_CONFIRM_PIN.port, WFX_SLEEP_CONFIRM_PIN.pin, gpioModeWiredOrPullDown, 1);break;
default: break;
}
}

/*===========================================================*/
/**
* @fn uint8_t rsi_hal_get_gpio(void)
Expand All @@ -103,22 +105,22 @@ void rsi_hal_set_gpio(uint8_t gpio_number)
* @return gpio pin value
* @description This API is used to configure get the gpio pin value.
*/
uint8_t rsi_hal_get_gpio(uint8_t gpio_number)
{
// WFX_RSI_LOG ("RSI: GET GPIO: 0x%x", gpio_number);
switch (gpio_number)
{
case RSI_HAL_RESET_PIN:
return GPIO_PinInGet(WFX_RESET_PIN.port, WFX_RESET_PIN.pin);
case RSI_HAL_MODULE_INTERRUPT_PIN:
return GPIO_PinInGet(WFX_INTERRUPT_PIN.port, WFX_INTERRUPT_PIN.pin);
default:
break;
}

return 0;
uint8_t rsi_hal_get_gpio(uint8_t gpio_number) {
switch(gpio_number)
{
case RSI_HAL_SLEEP_CONFIRM_PIN: return GPIO_PinInGet(WFX_SLEEP_CONFIRM_PIN.port, WFX_SLEEP_CONFIRM_PIN.pin);
#ifndef LOGGING_STATS
case RSI_HAL_WAKEUP_INDICATION_PIN: return GPIO_PinInGet(WAKE_INDICATOR_PIN.port, WAKE_INDICATOR_PIN.pin);
#else
case RSI_HAL_WAKEUP_INDICATION_PIN: return GPIO_PinInGet(LOGGING_WAKE_INDICATOR_PIN.port, LOGGING_WAKE_INDICATOR_PIN.pin);
#endif
case RSI_HAL_RESET_PIN: return GPIO_PinInGet(WFX_RESET_PIN.port, WFX_RESET_PIN.pin);
case RSI_HAL_MODULE_INTERRUPT_PIN: return GPIO_PinInGet(WFX_INTERRUPT_PIN.port, WFX_INTERRUPT_PIN.pin);
case RSI_HAL_LP_SLEEP_CONFIRM_PIN: return GPIO_PinInGet(WFX_SLEEP_CONFIRM_PIN.port, WFX_SLEEP_CONFIRM_PIN.pin);
default: break;
}
return 0;
}

/*===========================================================*/
/**
* @fn void rsi_hal_set_gpio(uint8_t gpio_number)
Expand All @@ -128,14 +130,25 @@ uint8_t rsi_hal_get_gpio(uint8_t gpio_number)
* @return none
* @description This API is used to drives or makes the host gpio value low.
*/
void rsi_hal_clear_gpio(uint8_t gpio_number)
{
// WFX_RSI_LOG ("RSI: CLR GPIO: 0x%x", gpio_number);
switch (gpio_number)
{
case RSI_HAL_RESET_PIN:
return GPIO_PinOutClear(WFX_RESET_PIN.port, WFX_RESET_PIN.pin);
default:
break;
}
}
void rsi_hal_clear_gpio(uint8_t gpio_number) {
switch(gpio_number)
{
case RSI_HAL_SLEEP_CONFIRM_PIN:
GPIO_PinOutClear(WFX_SLEEP_CONFIRM_PIN.port, WFX_SLEEP_CONFIRM_PIN.pin); break;
#ifndef LOGGING_STATS
//fall through
case RSI_HAL_WAKEUP_INDICATION_PIN:
GPIO_PinOutClear(WAKE_INDICATOR_PIN.port, WAKE_INDICATOR_PIN.pin); break;
#else
//fall through
case RSI_HAL_WAKEUP_INDICATION_PIN:
GPIO_PinOutClear(LOGGING_WAKE_INDICATOR_PIN.port, LOGGING_WAKE_INDICATOR_PIN.pin); break;
#endif
//fall through
case RSI_HAL_RESET_PIN: GPIO_PinOutClear(WFX_RESET_PIN.port, WFX_RESET_PIN.pin); break;
//fall through
case RSI_HAL_LP_SLEEP_CONFIRM_PIN: GPIO_PinOutClear(WFX_SLEEP_CONFIRM_PIN.port, WFX_SLEEP_CONFIRM_PIN.pin); break;
//fall through
default: break;
}
}
17 changes: 17 additions & 0 deletions examples/platform/silabs/efr32/rs911x/rsi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,15 @@ void wfx_rsi_task(void * arg)
{
wfx_dhcp_got_ipv4((uint32_t) sta_netif->ip_addr.u_addr.ip4.addr);
hasNotifiedIPV4 = true;
#if CHIP_DEVICE_CONFIG_ENABLE_SED
// enabling the power save mode for RS9116 if sleepy device is enabled
rsi_status = rsi_wlan_power_save_profile(RSI_SLEEP_MODE_2, RSI_MAX_PSP);
if (status != RSI_SUCCESS) {
WFX_RSI_LOG("Powersave Config Failed, Error Code : 0x%lX", status);
return status;
}
WFX_RSI_LOG("Powersave Config Success");
#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */
if (!hasNotifiedWifiConnectivity)
{
wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac);
Expand All @@ -673,6 +682,14 @@ void wfx_rsi_task(void * arg)
{
wfx_ipv6_notify(GET_IPV6_SUCCESS);
hasNotifiedIPV6 = true;
#if CHIP_DEVICE_CONFIG_ENABLE_SED
// enabling the power save mode for RS9116 if sleepy device is enabled
rsi_status = rsi_wlan_power_save_profile(RSI_SLEEP_MODE_2, RSI_MAX_PSP);
if (rsi_status != RSI_SUCCESS) {
WFX_RSI_LOG("Powersave Config Failed, Error Code : 0x%lX", rsi_status);
}
WFX_RSI_LOG("Powersave Config Success");
#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */
if (!hasNotifiedWifiConnectivity)
{
wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac);
Expand Down
16 changes: 12 additions & 4 deletions examples/platform/silabs/efr32/rs911x/rsi_wlan_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,23 @@
#ifdef RSI_M4_INTERFACE
#define RSI_EXT_CUSTOM_FEATURE_BIT_MAP (EXT_FEAT_256K_MODE | EXT_FEAT_IEEE_80211W)
#else
#ifdef CHIP_9117
#define RSI_EXT_CUSTOM_FEATURE_BIT_MAP (EXT_FEAT_448K_M4SS_256K | EXT_FEAT_IEEE_80211W)
#else
#define RSI_EXT_CUSTOM_FEATURE_BIT_MAP (EXT_FEAT_384K_MODE | EXT_FEAT_IEEE_80211W)
#endif
#endif /* CHIP_9117 */
#endif /* WIFI_ENABLE_SECURITY_WPA3 */
#else
#ifdef RSI_M4_INTERFACE
#define RSI_EXT_CUSTOM_FEATURE_BIT_MAP EXT_FEAT_256K_MODE
#else
#ifdef CHIP_9117
#define RSI_EXT_CUSTOM_FEATURE_BIT_MAP EXT_FEAT_448K_M4SS_256K
#else
#define RSI_EXT_CUSTOM_FEATURE_BIT_MAP EXT_FEAT_384K_MODE
#endif
#endif
#endif /* CHIP_9117 */
#endif /* RSI_M4_INTERFACE */
#endif /* WIFI_ENABLE_SECURITY_WPA3 */

//! To set Extended TCPIP feature select bit map
#define RSI_EXT_TCPIP_FEATURE_BITMAP (/*EXT_FEAT_HTTP_OTAF_SUPPORT |*/ EXT_TCP_IP_SSL_16K_RECORD)
Expand Down Expand Up @@ -309,7 +317,7 @@
//! Power save command parameters
/*=======================================================================*/
//! set handshake type of power mode
#define RSI_HAND_SHAKE_TYPE MSG_BASED
#define RSI_HAND_SHAKE_TYPE GPIO_BASED

//! 0 - LP, 1- ULP mode with RAM retention and 2 - ULP with Non RAM retention
#define RSI_SELECT_LP_OR_ULP_MODE RSI_ULP_WITH_RAM_RET
Expand Down
8 changes: 7 additions & 1 deletion src/platform/silabs/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
bool _CanStartWiFiScan();
void _OnWiFiScanDone();
void _OnWiFiStationProvisionChange();
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_SED
ConnectivityManager::SEDIntervalsConfig mIntervalsConfig;
CHIP_ERROR _GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig);
CHIP_ERROR _SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig);
CHIP_ERROR _RequestSEDActiveMode(bool onOff, bool delayIdle = false);
#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */
#endif /* CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION */
// ===== Members for internal use by the following friends.

friend ConnectivityManager & ConnectivityMgr(void);
Expand Down
24 changes: 24 additions & 0 deletions src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,30 @@ void ConnectivityManagerImpl::_OnWiFiStationProvisionChange()
DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL);
}

#if CHIP_DEVICE_CONFIG_ENABLE_SED
CHIP_ERROR ConnectivityManagerImpl::_GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & SEDIntervalsConfig)
{
// For now Wi-Fi uses DTIM power save mode
SEDIntervalsConfig.ActiveIntervalMS =
chip::System::Clock::Milliseconds32(50);
SEDIntervalsConfig.IdleIntervalMS =
chip::System::Clock::Milliseconds32(300);
return CHIP_NO_ERROR;
}

CHIP_ERROR ConnectivityManagerImpl::_SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig)
{
// not required
return CHIP_NO_ERROR;
}

CHIP_ERROR ConnectivityManagerImpl::_RequestSEDActiveMode(bool onOff, bool delayIdle)
{
// not required
return CHIP_NO_ERROR;
}
#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */

// == == == == == == == == == == ConnectivityManager Private Methods == == == == == == == == == ==

void ConnectivityManagerImpl::DriveStationState()
Expand Down
6 changes: 5 additions & 1 deletion third_party/silabs/efr32_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ template("efr32_sdk") {
if (use_SiWx917) {
#Added this flag only for SiwX917 NCP board
#TODO: Remove when rsi_wlan_ext_stats gets implemented using Wisemcu SDK
defines += [ "SiWx917_WIFI" ]
defines += [
"SiWx917_WIFI",
"EXP_BOARD=1",
"CHIP_9117=1",
]
} else if (use_wf200) {
defines += [
"SL_HEAP_SIZE=24576",
Expand Down

0 comments on commit 2967ff0

Please sign in to comment.