1 /***************************************************************************/ /**
2  * @file  sl_platform.c
3  *******************************************************************************
4  * # License
5  * <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b>
6  *******************************************************************************
7  *
8  * SPDX-License-Identifier: Zlib
9  *
10  * The licensor of this software is Silicon Laboratories Inc.
11  *
12  * This software is provided 'as-is', without any express or implied
13  * warranty. In no event will the authors be held liable for any damages
14  * arising from the use of this software.
15  *
16  * Permission is granted to anyone to use this software for any purpose,
17  * including commercial applications, and to alter it and redistribute it
18  * freely, subject to the following restrictions:
19  *
20  * 1. The origin of this software must not be misrepresented; you must not
21  *    claim that you wrote the original software. If you use this software
22  *    in a product, an acknowledgment in the product documentation would be
23  *    appreciated but is not required.
24  * 2. Altered source versions must be plainly marked as such, and must not be
25  *    misrepresented as being the original software.
26  * 3. This notice may not be removed or altered from any source distribution.
27  *
28  ******************************************************************************/
29 #include "sli_siwx917_soc.h"
30 #include "sl_device.h"
31 #include "sl_si91x_constants.h"
32 #include "sl_si91x_status.h"
33 #include "sl_si91x_core_utilities.h"
34 #include "sl_status.h"
35 #include "sl_constants.h"
36 #include <stdbool.h>
37 #if defined(SL_COMPONENT_CATALOG_PRESENT)
38 #include "sl_component_catalog.h"
39 #endif
40 #include "sl_board_configuration.h"
41 #include "rsi_rom_clks.h"
42 
43 #if defined(SL_CATALOG_KERNEL_PRESENT)
44 #include "cmsis_os2.h"
45 #include "FreeRTOSConfig.h"
46 #endif
47 
48 sl_status_t sli_si91x_submit_rx_pkt(void);
49 void sl_board_enable_vcom(void);
50 sl_status_t si91x_bootup_firmware(const uint8_t select_option);
51 
sli_si91x_platform_init(void)52 void sli_si91x_platform_init(void)
53 {
54 #ifdef SLI_SI91X_MCU_COMMON_FLASH_MODE
55   /* Before NWP going to power save mode ,set m4ss_ref_clk_mux_ctrl ,tass_ref_clk_mux_ctrl,
56   AON domain power supply controls from NWP to M4 */
57   RSI_Set_Cntrls_To_M4();
58 #endif
59 
60   // Enable DWT and cycle counting
61   CoreDebug->DEMCR |= 0x01000000;
62   DWT->CTRL |= 0x1;
63 
64 #if (configUSE_TICKLESS_IDLE == 0)
65   SysTick_Config(SystemCoreClock / CONFIG_SYS_CLOCK_TICKS_PER_SEC);
66   // Set P2P Intr priority
67   NVIC_SetPriority(SysTick_IRQn, SYSTICK_INTR_PRI);
68 #endif
69   //On boot-up, verify the M4_wakeup_TA bit in the P2P status register and clearing the bit if it is set.
70   if (P2P_STATUS_REG & M4_wakeup_TA) {
71     P2P_STATUS_REG &= ~M4_wakeup_TA;
72   }
73 }
74 
sl_board_enable_vcom(void)75 void sl_board_enable_vcom(void)
76 {
77   //empty function
78 }
79 
si91x_bootup_firmware(const uint8_t select_option)80 sl_status_t si91x_bootup_firmware(const uint8_t select_option)
81 {
82   uint8_t skip_bootload_sequence = 0;
83   si91x_status_t retval          = RSI_ERROR_NONE;
84 
85   if (!(P2P_STATUS_REG & TA_is_active)) {
86     P2P_STATUS_REG |= M4_wakeup_TA;
87     skip_bootload_sequence = 1;
88   }
89   while (!(P2P_STATUS_REG & TA_is_active)) {
90     //loop is waiting for the TA to become active
91   }
92 
93   if (!skip_bootload_sequence) {
94     do {
95       retval = rsi_waitfor_boardready();
96       if (retval == RSI_ERROR_NONE) {
97         break;
98       }
99       if ((retval < 0) && (retval != RSI_ERROR_WAITING_FOR_BOARD_READY) && (retval != RSI_ERROR_IN_OS_OPERATION)) {
100         return convert_si91x_status_to_sl_status(retval);
101       }
102     } while ((retval == RSI_ERROR_WAITING_FOR_BOARD_READY) || (retval == RSI_ERROR_IN_OS_OPERATION));
103     retval = rsi_select_option(select_option);
104     VERIFY_STATUS_AND_RETURN(convert_si91x_status_to_sl_status(retval));
105   }
106 
107   // Update TX & RX DMA descriptor address
108   rsi_update_tx_dma_desc(skip_bootload_sequence);
109   rsi_update_rx_dma_desc();
110 
111 #if SL_SI91X_FAST_FW_UP
112   status = rsi_set_fast_fw_up();
113   if (status != RSI_SUCCESS) {
114     SL_PRINTF(SL_DEVICE_INIT_SET_FAST_FIRMWARE_UP_ERROR, COMMON, LOG_ERROR, "status: %4x", status);
115     return status;
116   }
117 #endif
118 
119   sli_m4_ta_interrupt_init();
120   if (!(M4SS_P2P_INTR_SET_REG & RX_BUFFER_VALID)) {
121     sli_si91x_submit_rx_pkt();
122   }
123 
124 #if defined(SL_CATALOG_KERNEL_PRESENT)
125   osKernelInitialize();
126 #endif
127 
128   return SL_STATUS_OK;
129 }
130