Skip to content

Commit

Permalink
Restyled by clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits committed Jan 8, 2024
1 parent 9b72195 commit 9143a0e
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 108 deletions.
52 changes: 26 additions & 26 deletions matter/si91x/siwx917/BRD4338A/support/inc/sl_si91x_m4_ps.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/***************************************************************************/ /**
* @file sl_si91x_m4_ps.h
* @brief M4 power save
*******************************************************************************
* # License
* <b>Copyright 2023 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* The licenser of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
* @file sl_si91x_m4_ps.h
* @brief M4 power save
*******************************************************************************
* # License
* <b>Copyright 2023 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* The licenser of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/

#ifndef SL_SI91X_M4_POWERSAVE_H_
#define SL_SI91X_M4_POWERSAVE_H_
Expand All @@ -22,24 +22,24 @@
#include "rsi_debug.h"
#endif
#ifdef SLI_SI91X_MCU_INTERFACE
#include "rsi_rtc.h"
#include "rsi_m4.h"
#include "rsi_ds_timer.h"
#include "rsi_wisemcu_hardware_setup.h"
#include "rsi_rom_ulpss_clk.h"
#include "rsi_rom_timer.h"
#include "rsi_m4.h"
#include "rsi_rom_power_save.h"
#include "rsi_rom_timer.h"
#include "rsi_rom_ulpss_clk.h"
#include "rsi_rtc.h"
#include "rsi_wisemcu_hardware_setup.h"
#include "sl_event_handler.h"

/*=======================================================================*/
//! Power save command parameters
/*=======================================================================*/
//! set handshake type of power mode
#define RSI_HAND_SHAKE_TYPE M4_BASED
#define RSI_HAND_SHAKE_TYPE M4_BASED
#define WIRELESS_WAKEUP_IRQ_PRI 8
#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)
#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)

// -----------------------------------------------------------------------------
// Prototypes
Expand All @@ -49,8 +49,8 @@
* @param[in] none
* @return none.
* @section description
* This function is used to trigger sleep in the M4 and in the case of the retention submitting the buffer valid
* to the TA for the rx packets.
* This function is used to trigger sleep in the M4 and in the case of the
* retention submitting the buffer valid to the TA for the rx packets.
*/
void sl_si91x_m4_sleep_wakeup(void);

Expand Down
163 changes: 81 additions & 82 deletions matter/si91x/siwx917/BRD4338A/support/src/sl_si91x_m4_ps.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/***************************************************************************/ /**
* @file sl_si91x_m4_ps.h
* @brief M4 power save
*******************************************************************************
* # License
* <b>Copyright 2023 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* The licenser of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
* @file sl_si91x_m4_ps.h
* @brief M4 power save
*******************************************************************************
* # License
* <b>Copyright 2023 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* The licenser of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
#include "sl_si91x_m4_ps.h"
#include "cmsis_os2.h"
#ifdef SL_WIFI_COMPONENT_INCLUDED
Expand All @@ -27,41 +27,47 @@
#define ALARM_PERIODIC_TIME 30 /*<! periodic alarm configuration in SEC */
#endif

#define RTC_ALARM_INTR BIT(16)
#define NPSS_GPIO_2 2
#define RTC_ALARM_INTR BIT(16)
#define NPSS_GPIO_2 2
#define NPSSGPIO_PIN_MUX_MODE2 2
#define NPSS_GPIO_INTR_LOW 0
#define NPSS_GPIO_DIR_INPUT 1
#define NPSS_GPIO_2_INTR BIT(2)
#define NPSS_GPIO_INTR_LOW 0
#define NPSS_GPIO_DIR_INPUT 1
#define NPSS_GPIO_2_INTR BIT(2)

/*Update time configurations for next boundary alarm*/
#define RC_TRIGGER_TIME 5
#define RO_TRIGGER_TIME 0
#define NO_OF_HOURS_IN_A_DAY 24
#define NO_OF_MINUTES_IN_AN_HOUR 60
#define RC_TRIGGER_TIME 5
#define RO_TRIGGER_TIME 0
#define NO_OF_HOURS_IN_A_DAY 24
#define NO_OF_MINUTES_IN_AN_HOUR 60
#define NO_OF_SECONDS_IN_A_MINUTE 60
#define NO_OF_MONTHS_IN_A_YEAR 12
#define BASE_YEAR 2000
#define NO_OF_DAYS_IN_A_MONTH_1 28
#define NO_OF_DAYS_IN_A_MONTH_2 29
#define NO_OF_DAYS_IN_A_MONTH_3 30
#define NO_OF_DAYS_IN_A_MONTH_4 31
#define NO_OF_MONTHS_IN_A_YEAR 12
#define BASE_YEAR 2000
#define NO_OF_DAYS_IN_A_MONTH_1 28
#define NO_OF_DAYS_IN_A_MONTH_2 29
#define NO_OF_DAYS_IN_A_MONTH_3 30
#define NO_OF_DAYS_IN_A_MONTH_4 31

#define RTC_ALARM_IRQHandler IRQ028_Handler
#define NVIC_RTC_ALARM MCU_CAL_ALARM_IRQn
#define NVIC_RTC_ALARM MCU_CAL_ALARM_IRQn
#ifdef SLI_SI91X_MCU_COMMON_FLASH_MODE
#ifdef SLI_SI917B0
#define IVT_OFFSET_ADDR 0x8202000 /*<!Application IVT location VTOR offset for B0> */
#define IVT_OFFSET_ADDR \
0x8202000 /*<!Application IVT location VTOR offset for B0> */
#else
#define IVT_OFFSET_ADDR 0x8212000 /*<!Application IVT location VTOR offset for A0> */
#define IVT_OFFSET_ADDR \
0x8212000 /*<!Application IVT location VTOR offset for A0> */
#endif
#else
#define IVT_OFFSET_ADDR 0x8012000 /*<!Application IVT location VTOR offset for dual flash A0 and B0> */
#define IVT_OFFSET_ADDR \
0x8012000 /*<!Application IVT location VTOR offset for dual flash A0 and B0> \
*/
#endif
#ifdef SLI_SI917B0
#define WKP_RAM_USAGE_LOCATION 0x24061EFC /*<!Bootloader RAM usage location upon wake up for B0 */
#define WKP_RAM_USAGE_LOCATION \
0x24061EFC /*<!Bootloader RAM usage location upon wake up for B0 */
#else
#define WKP_RAM_USAGE_LOCATION 0x24061000 /*<!Bootloader RAM usage location upon wake up for A0 */
#define WKP_RAM_USAGE_LOCATION \
0x24061000 /*<!Bootloader RAM usage location upon wake up for A0 */
#endif
#if SL_SI91X_MCU_ALARM_BASED_WAKEUP
static RTC_TIME_CONFIG_T rtc_configuration, alarm_configuration, rtc_get_time;
Expand All @@ -80,8 +86,7 @@ void vPortSetupTimerInterrupt(void);
* @param none
* @return none
*/
void wakeup_source_config(void)
{
void wakeup_source_config(void) {
/*Configure the NPSS GPIO mode to wake up  */
RSI_NPSSGPIO_SetPinMux(NPSS_GPIO_2, NPSSGPIO_PIN_MUX_MODE2);

Expand Down Expand Up @@ -109,36 +114,34 @@ void wakeup_source_config(void)

#endif /* SL_SI91X_MCU_BUTTON_BASED_WAKEUP */
#ifdef SL_SI91X_MCU_WIRELESS_BASED_WAKEUP
void IRQ026_Handler()
{
//volatile uint32_t wakeUpSrc = 0;
void IRQ026_Handler() {
// volatile uint32_t wakeUpSrc = 0;

/*Get the wake up source */
//wakeUpSrc = RSI_PS_GetWkpUpStatus();
// wakeUpSrc = RSI_PS_GetWkpUpStatus();
RSI_PS_GetWkpUpStatus();

/*Clear interrupt */
RSI_PS_ClrWkpUpStatus(NPSS_TO_MCU_WIRELESS_INTR);
//LOG_PRINT("\r\n received packet from sleep \r\n");
// LOG_PRINT("\r\n received packet from sleep \r\n");
return;
}
#endif /* SL_SI91X_MCU_WIRELESS_BASED_WAKEUP */
#if SL_SI91X_MCU_ALARM_BASED_WAKEUP
void set_alarm_interrupt_timer(uint16_t interval)
{
void set_alarm_interrupt_timer(uint16_t interval) {
/* Get the RTC time,which is used to update alarm time as per RTC time */
RSI_RTC_GetDateTime(RTC, &rtc_get_time);

/*RTC alarm configuration */
alarm_configuration.DayOfWeek = rtc_get_time.DayOfWeek;
alarm_configuration.Month = rtc_get_time.Month;
alarm_configuration.Century = rtc_get_time.Century;
alarm_configuration.DayOfWeek = rtc_get_time.DayOfWeek;
alarm_configuration.Month = rtc_get_time.Month;
alarm_configuration.Century = rtc_get_time.Century;
alarm_configuration.MilliSeconds = rtc_get_time.MilliSeconds;
alarm_configuration.Day = rtc_get_time.Day;
alarm_configuration.Year = rtc_get_time.Year;
alarm_configuration.Minute = rtc_get_time.Minute;
alarm_configuration.Hour = rtc_get_time.Hour;
alarm_configuration.Second = rtc_get_time.Second;
alarm_configuration.Day = rtc_get_time.Day;
alarm_configuration.Year = rtc_get_time.Year;
alarm_configuration.Minute = rtc_get_time.Minute;
alarm_configuration.Hour = rtc_get_time.Hour;
alarm_configuration.Second = rtc_get_time.Second;

/*Update seconds for next boundary alarm */
alarm_configuration.Second = alarm_configuration.Second + (interval % 60);
Expand All @@ -148,7 +151,8 @@ void set_alarm_interrupt_timer(uint16_t interval)
}

/*Update minutes for next boundary alarm */
alarm_configuration.Minute = alarm_configuration.Minute + ((interval / 60) % 60);
alarm_configuration.Minute =
alarm_configuration.Minute + ((interval / 60) % 60);
if (alarm_configuration.Minute >= (NO_OF_MINUTES_IN_AN_HOUR)) {
alarm_configuration.Minute -= NO_OF_MINUTES_IN_AN_HOUR;
alarm_configuration.Hour += 1;
Expand Down Expand Up @@ -204,20 +208,19 @@ void set_alarm_interrupt_timer(uint16_t interval)
RSI_RTC_SetAlarmDateTime(RTC, &alarm_configuration);
}

void initialize_m4_alarm(void)
{
void initialize_m4_alarm(void) {
/*Init RTC*/
RSI_RTC_Init(RTC);

/*RTC configuration with some default time */
rtc_configuration.DayOfWeek = Saturday;
rtc_configuration.Month = March;
rtc_configuration.Day = 19;
rtc_configuration.Century = 0;
rtc_configuration.Year = 19;
rtc_configuration.Hour = 23;
rtc_configuration.Minute = 59;
rtc_configuration.Second = 50;
rtc_configuration.DayOfWeek = Saturday;
rtc_configuration.Month = March;
rtc_configuration.Day = 19;
rtc_configuration.Century = 0;
rtc_configuration.Year = 19;
rtc_configuration.Hour = 23;
rtc_configuration.Minute = 59;
rtc_configuration.Second = 50;
rtc_configuration.MilliSeconds = 0;

/*Set the RTC configuration*/
Expand All @@ -229,7 +232,8 @@ void initialize_m4_alarm(void)
/*Initialization of RTC CALIBRATION*/
RSI_RTC_CalibInitilization();
/*To calibrate rc and ro */
RSI_RTC_ROCLK_Calib(TIME_PERIOD, ENABLE, ENABLE, RC_TRIGGER_TIME, ENABLE, ENABLE, RO_TRIGGER_TIME);
RSI_RTC_ROCLK_Calib(TIME_PERIOD, ENABLE, ENABLE, RC_TRIGGER_TIME, ENABLE,
ENABLE, RO_TRIGGER_TIME);
/*Set Alarm as a wake up source to wake up from deep sleep */
RSI_PS_SetWkpSources(ALARM_BASED_WAKEUP);
/*Enable the RTC alarm interrupts */
Expand All @@ -239,8 +243,7 @@ void initialize_m4_alarm(void)
m4_alarm_initialization_done = 1;
}
/*RTC Alarm interrupt*/
void RTC_ALARM_IRQHandler(void)
{
void RTC_ALARM_IRQHandler(void) {
volatile uint32_t statusRead = 0;
/*Get the interrupt status */
statusRead = RSI_RTC_GetIntrStatus();
Expand All @@ -261,11 +264,10 @@ void RTC_ALARM_IRQHandler(void)
* @param[in] none
* @return none.
* @section description
* This function is used to trigger sleep in the M4 and in the case of the retention submitting the buffer valid
* to the TA for the rx packets.
* This function is used to trigger sleep in the M4 and in the case of the
* retention submitting the buffer valid to the TA for the rx packets.
*/
void sl_si91x_m4_sleep_wakeup(void)
{
void sl_si91x_m4_sleep_wakeup(void) {

#if SL_SI91X_MCU_ALARM_BASED_WAKEUP
/* Initialize the M4 alarm for the first time*/
Expand Down Expand Up @@ -300,29 +302,26 @@ void sl_si91x_m4_sleep_wakeup(void)
sl_si91x_disable_flash_ldo();

/* Configure RAM Usage and Retention Size */
sl_si91x_configure_ram_retention(WISEMCU_48KB_RAM_IN_USE, WISEMCU_RETAIN_DEFAULT_RAM_DURING_SLEEP);
sl_si91x_configure_ram_retention(WISEMCU_48KB_RAM_IN_USE,
WISEMCU_RETAIN_DEFAULT_RAM_DURING_SLEEP);

/* Trigger M4 Sleep */
sl_si91x_trigger_sleep(SLEEP_WITH_RETENTION,
DISABLE_LF_MODE,
0,
(uint32_t)RSI_PS_RestoreCpuContext,
0,
sl_si91x_trigger_sleep(SLEEP_WITH_RETENTION, DISABLE_LF_MODE, 0,
(uint32_t)RSI_PS_RestoreCpuContext, 0,
RSI_WAKEUP_WITH_RETENTION_WO_ULPSS_RAM);
#else

#ifdef SLI_SI91X_MCU_COMMON_FLASH_MODE
M4SS_P2P_INTR_SET_REG &= ~BIT(3);
#endif
/* Configure RAM Usage and Retention Size */
sl_si91x_configure_ram_retention(WISEMCU_256KB_RAM_IN_USE, WISEMCU_RETAIN_DEFAULT_RAM_DURING_SLEEP);
sl_si91x_configure_ram_retention(WISEMCU_256KB_RAM_IN_USE,
WISEMCU_RETAIN_DEFAULT_RAM_DURING_SLEEP);
/* Trigger M4 Sleep*/
MCU_RET->NPSS_GPIO_CNTRL[0].NPSS_GPIO_CTRLS_b.NPSS_GPIO_OUT = 0;
sl_si91x_trigger_sleep(SLEEP_WITH_RETENTION,
DISABLE_LF_MODE,
sl_si91x_trigger_sleep(SLEEP_WITH_RETENTION, DISABLE_LF_MODE,
WKP_RAM_USAGE_LOCATION,
(uint32_t)RSI_PS_RestoreCpuContext,
IVT_OFFSET_ADDR,
(uint32_t)RSI_PS_RestoreCpuContext, IVT_OFFSET_ADDR,
RSI_WAKEUP_FROM_FLASH_MODE);
#endif

Expand Down

0 comments on commit 9143a0e

Please sign in to comment.