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

Restyle Adds PSA crypto support file for SiWx917 #176

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 59 additions & 62 deletions matter/si91x/siwx917/BRD4338A/support/src/sl_si91x_m4_ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +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 \
#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
static RTC_TIME_CONFIG_T rtc_configuration, alarm_configuration, rtc_get_time;
uint8_t m4_alarm_initialization_done;
Expand All @@ -79,8 +83,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 @@ -108,8 +111,7 @@ void wakeup_source_config(void)

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

/* Get the wake up source */
Expand All @@ -122,21 +124,20 @@ void IRQ026_Handler()
return;
}
#endif /* SL_SI91X_MCU_WIRELESS_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 @@ -146,7 +147,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 @@ -202,20 +204,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 @@ -227,7 +228,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 @@ -237,8 +239,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,8 +262,7 @@ void RTC_ALARM_IRQHandler(void)
* 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 @@ -297,25 +297,22 @@ 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

/* Configure RAM Usage and Retention Size */
sl_si91x_configure_ram_retention(WISEMCU_320KB_RAM_IN_USE, WISEMCU_RETAIN_DEFAULT_RAM_DURING_SLEEP);
sl_si91x_configure_ram_retention(WISEMCU_320KB_RAM_IN_USE,
WISEMCU_RETAIN_DEFAULT_RAM_DURING_SLEEP);
/* Trigger M4 Sleep */
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
Loading