Skip to content

Commit

Permalink
Feature/wifi siwx917 factory reset long press, Increased QSPI clock, …
Browse files Browse the repository at this point in the history
…RAM and Flash sizes (#24697)

* SiWx917 : Factory reset long press change

* Increased qspi clock to improve the flash performance, RAM and flash sizes are updated for 917 SoC

* Restyler issue fixed

---------

Co-authored-by: senthil kumar E K <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Feb 13, 2024
1 parent 0891be7 commit 1021792
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 70 deletions.
2 changes: 2 additions & 0 deletions examples/light-switch-app/silabs/SiWx917/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
*********************************************************/
// Button specific defines for SiWx917
#define SL_SIMPLE_BUTTON_PRESSED 1U
#define SL_SIMPLE_BUTTON_RELEASED 0U

#define SIWx917_BTN0 0
#define SIWx917_BTN1 1

Expand Down
122 changes: 64 additions & 58 deletions examples/platform/silabs/SiWx917/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#endif // DISPLAY_ENABLED

#include "SiWx917DeviceDataProvider.h"
#include "rsi_board.h"
#include "rsi_chip.h"
#include "siwx917_utils.h"
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <app/util/attribute-storage.h>
Expand All @@ -56,8 +59,9 @@
* Defines and Constants
*********************************************************/

#define FACTORY_RESET_TRIGGER_TIMEOUT 3000
#define FACTORY_RESET_TRIGGER_TIMEOUT 7000
#define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000
#define FACTORY_RESET_LOOP_COUNT 5
#ifndef APP_TASK_STACK_SIZE
#define APP_TASK_STACK_SIZE (4096)
#endif
Expand Down Expand Up @@ -242,41 +246,22 @@ void BaseApplication::FunctionEventHandler(AppEvent * aEvent)
{
return;
}
}

// If we reached here, the button was held past FACTORY_RESET_TRIGGER_TIMEOUT,
// initiate factory reset
if (mFunctionTimerActive && mFunction == kFunction_StartBleAdv)
{
SILABS_LOG("Factory Reset Triggered. Release button within %ums to cancel.", FACTORY_RESET_CANCEL_WINDOW_TIMEOUT);

// Start timer for FACTORY_RESET_CANCEL_WINDOW_TIMEOUT to allow user to
// cancel, if required.
StartFunctionTimer(FACTORY_RESET_CANCEL_WINDOW_TIMEOUT);

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
StartStatusLEDTimer();
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED

mFunction = kFunction_FactoryReset;
void BaseApplication::FunctionFactoryReset(void)
{
SILABS_LOG("#################################################################");
SILABS_LOG("################### Factory reset triggered #####################");
SILABS_LOG("#################################################################");

#ifdef ENABLE_WSTK_LEDS
// Turn off LED before starting blink to make sure blink is
// co-ordinated.
sStatusLED.Set(false);
sStatusLED.Blink(500);
#endif // ENABLE_WSTK_LEDS
}
else if (mFunctionTimerActive && mFunction == kFunction_FactoryReset)
{
// Actually trigger Factory Reset
mFunction = kFunction_NoneSelected;
// Actually trigger Factory Reset
mFunction = kFunction_NoneSelected;

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
StopStatusLEDTimer();
StopStatusLEDTimer();
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED

chip::Server::GetInstance().ScheduleFactoryReset();
}
chip::Server::GetInstance().ScheduleFactoryReset();
}

void BaseApplication::LightEventHandler()
Expand Down Expand Up @@ -367,6 +352,8 @@ void BaseApplication::LightEventHandler()

void BaseApplication::ButtonHandler(AppEvent * aEvent)
{
uint8_t count = FACTORY_RESET_LOOP_COUNT;

// To trigger software update: press the APP_FUNCTION_BUTTON button briefly (<
// FACTORY_RESET_TRIGGER_TIMEOUT) To initiate factory reset: press the
// APP_FUNCTION_BUTTON for FACTORY_RESET_TRIGGER_TIMEOUT +
Expand All @@ -376,44 +363,63 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
// start blinking within the FACTORY_RESET_CANCEL_WINDOW_TIMEOUT
if (aEvent->ButtonEvent.Action == SL_SIMPLE_BUTTON_PRESSED)
{
if (!mFunctionTimerActive && mFunction == kFunction_NoneSelected)
if ((!mFunctionTimerActive) && (mFunction == kFunction_NoneSelected))
{
StartFunctionTimer(FACTORY_RESET_TRIGGER_TIMEOUT);
mFunction = kFunction_StartBleAdv;
mFunction = kFunction_FactoryReset;

// Wait for sometime to determine button is pressed for Factory reset
// other functionality
vTaskDelay(1000); // Delay of 1sec before we check the button status
}
}
else

while (!(RSI_NPSSGPIO_GetPin(NPSS_GPIO_0)))
{
// If the button was released before factory reset got initiated, start BLE advertissement in fast mode
if (mFunctionTimerActive && mFunction == kFunction_StartBleAdv)
if (count == 0)
{
CancelFunctionTimer();
mFunction = kFunction_NoneSelected;

#ifdef SL_WIFI
if (!ConnectivityMgr().IsWiFiStationProvisioned())
#else
if (!ConnectivityMgr().IsThreadProvisioned())
#endif /* !SL_WIFI */
{
// Enable BLE advertisements
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
ConnectivityMgr().SetBLEAdvertisingMode(ConnectivityMgr().kFastAdvertising);
}
else { SILABS_LOG("Network is already provisioned, Ble advertissement not enabled"); }
FunctionFactoryReset();
break;
}
else if (mFunctionTimerActive && mFunction == kFunction_FactoryReset)
{
CancelFunctionTimer();

#ifdef ENABLE_WSTK_LEDS
// Turn off status LED before starting blink to make sure blink is
// co-ordinated.
sStatusLED.Set(false);
sStatusLED.Blink(500);
#endif // ENABLE_WSTK_LEDS

SILABS_LOG("Factory reset triggering in %d sec release button to cancel", count--);

// Delay of 1sec before checking the button status again
vTaskDelay(1000);
}

if (count > 0)
{
#ifdef ENABLE_WSTK_LEDS
sStatusLED.Set(false);
#endif
SILABS_LOG("Factory Reset has been Canceled"); // button held past Timeout wait till button is released
}

// If the button was released before factory reset got initiated, start BLE advertissement in fast mode
if (mFunction == kFunction_FactoryReset)
{
mFunction = kFunction_NoneSelected;

#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1
StopStatusLEDTimer();
StopStatusLEDTimer();
#endif

// Change the function to none selected since factory reset has been
// canceled.
mFunction = kFunction_NoneSelected;
SILABS_LOG("Factory Reset has been Canceled");
if (!ConnectivityMgr().IsWiFiStationProvisioned())
{
// Enable BLE advertisements
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
ConnectivityMgr().SetBLEAdvertisingMode(ConnectivityMgr().kFastAdvertising);
}
else
{
SILABS_LOG("Network is already provisioned, Ble advertissement not enabled");
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions examples/platform/silabs/SiWx917/BaseApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ class BaseApplication
*/
static void FunctionTimerEventHandler(TimerHandle_t xTimer);

/**
* @brief Factory reset trigger function
* Trigger factory if called
*
*/
static void FunctionFactoryReset(void);

/**
* @brief Timer Event processing function
* Trigger factory if Press and Hold duration is respected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#define ICACHE_DISABLE
#define DEBUG_DISABLE

/* QSPI clock config params */
#define INTF_PLL_500_CTRL_VALUE 0xD900
#define INTF_PLL_CLK 160000000 /* PLL out clock 160MHz */

#define PMU_GOOD_TIME 31 /*Duration in us*/
#define XTAL_GOOD_TIME 31 /*Duration in us*/

Expand All @@ -55,6 +59,8 @@
*/
int soc_pll_config(void)
{
int32_t status = RSI_OK;

RSI_CLK_SocPllLockConfig(1, 1, 7);

RSI_CLK_SocPllRefClkConfig(2);
Expand All @@ -77,7 +83,19 @@ int soc_pll_config(void)
RSI_CLK_M4SocClkConfig(M4CLK, M4_SOCPLLCLK, 0);

#ifdef SWITCH_QSPI_TO_SOC_PLL
RSI_CLK_QspiClkConfig(M4CLK, QSPI_INTFPLLCLK, 0, 0, 0);
/* program intf pll to 160Mhz */
SPI_MEM_MAP_PLL(INTF_PLL_500_CTRL_REG9) = INTF_PLL_500_CTRL_VALUE;
status = RSI_CLK_SetIntfPllFreq(M4CLK, INTF_PLL_CLK, SOC_PLL_REF_FREQUENCY);
if (status != RSI_OK)
{
SILABS_LOG("Failed to Config Interface PLL Clock, status:%d", status);
}
else
{
SILABS_LOG("Configured Interface PLL Clock to %d", INTF_PLL_CLK);
}

RSI_CLK_QspiClkConfig(M4CLK, QSPI_INTFPLLCLK, 0, 0, 1);
#endif /* SWITCH_QSPI_TO_SOC_PLL */

return 0;
Expand All @@ -100,13 +118,13 @@ void RSI_Wakeupsw_config(void)
RSI_NPSSGPIO_InputBufferEn(NPSS_GPIO_2, 1);

/*Configure the NPSS GPIO mode to wake up */
RSI_NPSSGPIO_SetPinMux(NPSS_GPIO_2, 2);
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_OUTPUT);

/* Enables rise edge interrupt detection for UULP_VBAT_GPIO_0 */
RSI_NPSSGPIO_SetIntLevelLowEnable(NPSS_GPIO_2_INTR);
/* Enables fall edge interrupt detection for UULP_VBAT_GPIO_0 */
RSI_NPSSGPIO_SetIntFallEdgeEnable(NPSS_GPIO_2_INTR);

/* Un mask the NPSS GPIO interrupt*/
RSI_NPSSGPIO_IntrUnMask(NPSS_GPIO_2_INTR);
Expand All @@ -118,9 +136,9 @@ void RSI_Wakeupsw_config(void)
RSI_NPSSGPIO_ClrIntr(NPSS_GPIO_2_INTR);

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

NVIC_SetPriority(21, 7);
NVIC_SetPriority(NPSS_TO_MCU_GPIO_INTR_IRQn, 7);
}

void RSI_Wakeupsw_config_gpio0(void)
Expand All @@ -140,8 +158,8 @@ void RSI_Wakeupsw_config_gpio0(void)
/* Set the GPIO to wake from deep sleep */
RSI_NPSSGPIO_SetWkpGpio(NPSS_GPIO_0_INTR);

/* Enables rise edge interrupt detection for UULP_VBAT_GPIO_0 */
RSI_NPSSGPIO_SetIntLevelLowEnable(NPSS_GPIO_0_INTR);
/* Enables fall edge interrupt detection for UULP_VBAT_GPIO_0 */
RSI_NPSSGPIO_SetIntFallEdgeEnable(NPSS_GPIO_0_INTR);

/* Un mask the NPSS GPIO interrupt*/
RSI_NPSSGPIO_IntrUnMask(NPSS_GPIO_0_INTR);
Expand All @@ -153,8 +171,8 @@ void RSI_Wakeupsw_config_gpio0(void)
RSI_NPSSGPIO_ClrIntr(NPSS_GPIO_0_INTR);

// 21 being the NPSS_TO_MCU_GPIO_INTR_IRQn
NVIC_EnableIRQ(21);
NVIC_SetPriority(21, 7);
NVIC_EnableIRQ(NPSS_TO_MCU_GPIO_INTR_IRQn);
NVIC_SetPriority(NPSS_TO_MCU_GPIO_INTR_IRQn, 7);
}

/*==============================================*/
Expand Down
4 changes: 2 additions & 2 deletions examples/platform/silabs/SiWx917/ldscripts/SiWx917.ld
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

MEMORY
{
FLASH (rx) : ORIGIN = 0x08012000, LENGTH = 0x200000
RAM (rwx) : ORIGIN = 0xC, LENGTH = 262144
FLASH (rx) : ORIGIN = 0x08012000, LENGTH = 0x400000
RAM (rwx) : ORIGIN = 0xC, LENGTH = 0x4FC00
}

/* Linker script to place sections and symbol values. Should be used together
Expand Down

0 comments on commit 1021792

Please sign in to comment.