1 /*******************************************************************************
2 * @file  rsi_power_save.h
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 
30 /**
31  * Includes
32  */
33 
34 #ifndef __RSI_POWER_SAVE_H__
35 #define __RSI_POWER_SAVE_H__
36 
37 #include "rsi_error.h"
38 #include "base_types.h"
39 #include "rsi_ccp_common.h"
40 #include "rsi_reg_spi.h"
41 #include "rsi_ipmu.h"
42 #include "rsi_system_config.h"
43 #include "rsi_ccp_user_config.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 /*M4SS peripheral power gates */
50 /* M4SS_PWRCTRL_SET_REG Bits ((NPSS MCU(MCU DM POWER CTRL FF's Domain))*/
51 #define M4SS_PWRGATE_ULP_EXT_ROM  BIT(22)
52 #define M4SS_PWRGATE_ULP_M4_CORE  BIT(18)
53 #define M4SS_PWRGATE_ULP_IID      BIT(14)
54 #define M4SS_PWRGATE_ULP_SDIO_SPI BIT(11)
55 #define M4SS_PWRGATE_ULP_RPDMA    BIT(9)
56 #if defined(SLI_SI917) || defined(SLI_SI915)
57 #define M4SS_PWRGATE_ULP_EFUSE_PERI   BIT(4)
58 #define M4SS_PWRGATE_ULP_QSPI_ICACHE  BIT(13)
59 #define M4SS_PWRGATE_ULP_M4_DEBUG_FPU BIT(17)
60 #else
61 #define M4SS_PWRGATE_ULP_EFUSE    BIT(4)
62 #define M4SS_PWRGATE_ULP_QSPI     BIT(13)
63 #define M4SS_PWRGATE_ULP_M4_DEBUG BIT(17)
64 #endif
65 #if defined(CHIP_9118)
66 #define M4SS_PWRGATE_ULP_M4_FPU   BIT(16)
67 #define M4SS_PWRGATE_ULP_ICACHE   BIT(15)
68 #define M4SS_PWRGATE_ULP_ETHERNET BIT(12)
69 #define M4SS_PWRGATE_ULP_USB      BIT(10)
70 #define M4SS_PWRGATE_ULP_PERI1    BIT(8)
71 #define M4SS_PWRGATE_ULP_PERI2    BIT(7)
72 #define M4SS_PWRGATE_ULP_PERI3    BIT(6)
73 #define M4SS_PWRGATE_ULP_CCI      BIT(5)
74 #define M4SS_PWRGATE_ULP_SD_MEM   BIT(2)
75 #endif
76 
77 /*ULPSS Peripheral power gate */
78 /* ULPSS_PWRCTRL_SET_REG bits (NPSS MCU(MCU DM POWER CTRL FF's Domain))*/
79 #define ULPSS_PWRGATE_ULP_MISC BIT(18)
80 #define ULPSS_PWRGATE_ULP_CAP  BIT(19)
81 #if defined(CHIP_9118)
82 #define ULPSS_PWRGATE_ULP_VAD BIT(20)
83 #endif
84 #define ULPSS_PWRGATE_ULP_UART BIT(21)
85 #define ULPSS_PWRGATE_ULP_SSI  BIT(22)
86 #define ULPSS_PWRGATE_ULP_I2S  BIT(23)
87 #define ULPSS_PWRGATE_ULP_I2C  BIT(24)
88 #define ULPSS_PWRGATE_ULP_AUX  BIT(25)
89 #define ULPSS_PWRGATE_ULP_IR   BIT(26)
90 #define ULPSS_PWRGATE_ULP_UDMA BIT(27)
91 #define ULPSS_PWRGATE_ULP_FIM  BIT(28)
92 
93 /*NPSS Peripheral power gates */
94 /*MCUAON_NPSS_PWRCTRL_SET_REG Bits (MCU AON Domain)*/
95 #define SLPSS_PWRGATE_ULP_NWPAPB_MCU_CTRL BIT(16)
96 #define SLPSS_PWRGATE_ULP_TIMEPERIOD      BIT(10)
97 #define SLPSS_PWRGATE_ULP_MCUSTORE3       BIT(9)
98 #define SLPSS_PWRGATE_ULP_MCUSTORE2       BIT(8)
99 #define SLPSS_PWRGATE_ULP_MCUSTORE1       BIT(7)
100 #define SLPSS_PWRGATE_ULP_MCUTS           BIT(6)
101 #define SLPSS_PWRGATE_ULP_MCUPS           BIT(5)
102 #define SLPSS_PWRGATE_ULP_MCUWDT          BIT(4)
103 #define SLPSS_PWRGATE_ULP_MCURTC          BIT(3)
104 #define SLPSS_PWRGATE_ULP_MCUFSM          BIT(2)
105 #define SLPSS_PWRGATE_ULP_MCUBFFS         BIT(1)
106 
107 /*Power supply controls*/
108 /*MCU_FSM_CRTL_PDM_AND_ENABLES_b(0x24) Reg Bits (MCU FSM )*/
109 #define ENABLE_WDT_IN_SLEEP          BIT(0)
110 #define ENABLE_WURX_DETECTION        BIT(1)
111 #define RESET_MCU_BBF_DM_EN          BIT(2)
112 #define DISABLE_TURNOFF_SRAM_PERI    BIT(3)
113 #define ENABLE_SRAM_DS_CTRL          BIT(4)
114 #define POWER_ENABLE_FSM_PERI        BIT(16)
115 #define POWER_ENABLE_TIMESTAMPING    BIT(17)
116 #define POWER_ENABLE_DEEPSLEEP_TIMER BIT(18)
117 #define POWER_ENABLE_RETENTION_DM    BIT(19)
118 
119 /*Wake up sources configuration*/
120 /*MCU_FSM_CRTL_PDM_AND_ENABLES_b(0x24) Reg Bits (MCU FSM )*/
121 #define WDT_INTR_BASED_WAKEUP BIT(29)
122 #define MSEC_BASED_WAKEUP     BIT(28)
123 #define SEC_BASED_WAKEUP      BIT(27)
124 #define ALARM_BASED_WAKEUP    BIT(26)
125 #define SDCSS_BASED_WAKEUP    BIT(25)
126 #define ULPSS_BASED_WAKEUP    BIT(24)
127 #if !defined(SLI_SI917B0) && !defined(SLI_SI915)
128 #define WAKEIF_BASED_WAKEUP BIT(22)
129 #else
130 #define SYSRTC_BASED_WAKEUP BIT(22)
131 #endif
132 #define COMPR_BASED_WAKEUP    BIT(21)
133 #define GPIO_BASED_WAKEUP     BIT(20)
134 #define M4_PROCS_BASED_WAKEUP BIT(19)
135 #define WIRELESS_BASED_WAKEUP BIT(18)
136 #define HOST_BASED_WAKEUP     BIT(17)
137 #define DST_BASED_WAKEUP      BIT(16)
138 #define WIC_BASED_WAKEUP      BIT(23)
139 
140 /*RAM retention controls */
141 /*MCU FSM SLEEP CTRLS AND WAKEUP MODE Reg(0x0) (MCU FSM)*/
142 #define M4ULP_RAM16K_RETENTION_MODE_EN BIT(7)
143 #define ULPSS_RAM_RETENTION_MODE_EN    BIT(6)
144 #define TA_RAM_RETENTION_MODE_EN       BIT(5)
145 #define M4ULP_RAM_RETENTION_MODE_EN    BIT(4)
146 #define M4SS_RAM_RETENTION_MODE_EN     BIT(3) /* reserved in 917 */
147 #define HPSRAM_RET_ULP_MODE_EN         BIT(2)
148 
149 /*RAM banks power gate controls*/
150 /* M4_SRAM_PWRCTRL_SET_REG1 reg bits((NPSS MCU(MCU DM POWER CTRL FF's Domain)) */
151 #if defined(CHIP_9118)
152 /*These banks typically used in M4SS high power mode */
153 #define RAM_BANK_0 BIT(0) /*!< RAM BANK 0 SIZE : 16K*/
154 #define RAM_BANK_1 BIT(1) /*!< RAM BANK 1 SIZE : 32K*/
155 #define RAM_BANK_2 BIT(2) /*!< RAM BANK 2 SIZE : 16K*/
156 /*Typically used in M4 ULP mode*/
157 /*m4ulp_ram16k_retention_mode_en*/
158 #define RAM_BANK_3 BIT(3) /*!< RAM BANK 3 SIZE : 4K*/
159 #define RAM_BANK_4 BIT(4) /*!< RAM BANK 4 SIZE : 4K*/
160 #define RAM_BANK_5 BIT(5) /*!< RAM BANK 4 SIZE : 4K*/
161 #define RAM_BANK_6 BIT(6) /*!< RAM BANK 4 SIZE : 4K*/
162 #define RAM_BANK_7 BIT(7) /*!< RAM BANK 4 SIZE : 32K*/
163 #define RAM_BANK_8 BIT(8) /*!< RAM BANK 4 SIZE : 64K*/
164 #define RAM_BANK_9 BIT(9) /*!< RAM BANK 4 SIZE : 16K*/
165 /*typically these banks are used in TASS */
166 #define RAM_BANK_10 BIT(16) /*!< RAM BANK 4 SIZE : 16K*/
167 #define RAM_BANK_11 BIT(17) /*!< RAM BANK 4 SIZE : 32K*/
168 #define RAM_BANK_12 BIT(18) /*!< RAM BANK 4 SIZE : 80K*/
169 #define RAM_BANK_13 BIT(19) /*!< RAM BANK 4 SIZE : 64K*/
170 #else
171 /*These banks typically used in M4SS high power mode */
172 #define RAM_BANK_0 BIT(0) /*!< 4KB (Bank1 of first 192k chunk)*/
173 #define RAM_BANK_1 BIT(1) /*!< 4KB (Bank2 of first 192k chunk)*/
174 #define RAM_BANK_2 BIT(2) /*!< 4KB (Bank3 of first 192k chunk)*/
175 #define RAM_BANK_3 BIT(3) /*!< 4KB (Bank4 of first 192k chunk)*/
176 #define RAM_BANK_4 BIT(4) /*!< 16KB (Bank 5 of first 192k chunk)*/
177 #define RAM_BANK_5 BIT(5) /*!< 32KB (Bank 6-7 of first 192k chunk*/
178 #define RAM_BANK_6 BIT(6) /*!< 64KB (Bank 8-11 of first 192k chunk)*/
179 #define RAM_BANK_7 BIT(7) /*!< 64KB (Bank 12-15 of first 192k chunk)*/
180 #define RAM_BANK_8 BIT(8) /*!< 64KB (Bank 1-4 of second 64k chunk)*/
181 #define RAM_BANK_9 BIT(9) /*!< 64KB (Bank 1-4 of third 64k chunk)*/
182 #endif
183 
184 /*ULPSS RAM banks power gates */
185 /*ULPSS _RAM_PWRCTRL_SET_REG1 bits (NPSS MCU(MCU DM POWER CTRL FF's Domain)*/
186 #define ULPSS_2K_BANK_0 BIT(0)
187 #define ULPSS_2K_BANK_1 BIT(1)
188 #define ULPSS_2K_BANK_2 BIT(2)
189 #define ULPSS_2K_BANK_3 BIT(3)
190 #if defined(CHIP_9118)
191 #define ULPSS_2K_BANK_4 BIT(4)
192 #define ULPSS_2K_BANK_5 BIT(5)
193 #define ULPSS_2K_BANK_6 BIT(6)
194 #define ULPSS_2K_BANK_7 BIT(7)
195 #endif
196 
197 /*Controls the PMU off delay time*/
198 #define PMU_LDO_OFF_DELAY 31U
199 
200 /*LP control reg */
201 #define M4LP_CTRL_REG          *((volatile uint32_t *)(0x24041424))
202 #define ULP_M4_CORE_CLK_ENABLE BIT(2)
203 
204 /*NPSS INTERRUPT */
205 #ifndef NPSS_INTR_BASE
206 #define NPSS_INTR_BASE 0x12080000
207 #endif // NPSS_INTR_BASE
208 #ifndef NPSS_INTR_MASK_SET_REG
209 #define NPSS_INTR_MASK_SET_REG (*(volatile uint32_t *)(NPSS_INTR_BASE + 0x00))
210 #endif // NPSS_INTR_MASK_SET_REG
211 #ifndef NPSS_INTR_MASK_CLR_REG
212 #define NPSS_INTR_MASK_CLR_REG (*(volatile uint32_t *)(NPSS_INTR_BASE + 0x04))
213 #endif // NPSS_INTR_MASK_CLR_REG
214 #ifndef NPSS_INTR_CLEAR_REG
215 #define NPSS_INTR_CLEAR_REG (*(volatile uint32_t *)(NPSS_INTR_BASE + 0x08))
216 #endif // NPSS_INTR_CLEAR_REG
217 #ifndef NPSS_INTR_STATUS_REG
218 #define NPSS_INTR_STATUS_REG (*(volatile uint32_t *)(NPSS_INTR_BASE + 0x0C))
219 #endif // NPSS_INTR_STATUS_REG
220 #define M4_ULP_SLP_STATUS_REG (*(volatile uint32_t *)(NPSS_INTR_BASE + 0x1C))
221 #define MCU_ULP_WAKEUP        BIT(0) /*	To check whether it is first boot up or Wake up */
222 #define NWPAON_POR_CTRL_BITS  *(volatile uint32_t *)(0x41300000 + 0x3C)
223 #define POC_CNTRL_REG_0       BIT(0)
224 
225 /*NPSS interrupt numbers*/
226 #define NPSS_TO_MCU_WDT_INTR    BIT(0)
227 #define NPSS_TO_MCU_GPIO_INTR_0 BIT(1)
228 #define NPSS_TO_MCU_GPIO_INTR_1 BIT(2)
229 #define NPSS_TO_MCU_GPIO_INTR_2 BIT(3)
230 #define NPSS_TO_MCU_GPIO_INTR_3 BIT(4)
231 #define NPSS_TO_MCU_GPIO_INTR_4 BIT(5)
232 
233 #define NPSS_TO_MCU_CMP_INTR_1 BIT(6)
234 #define NPSS_TO_MCU_CMP_INTR_2 BIT(7)
235 #define NPSS_TO_MCU_CMP_INTR_3 BIT(8)
236 #define NPSS_TO_MCU_CMP_INTR_4 BIT(9)
237 
238 #define NPSS_TO_MCU_RFWAKEUP_INTR BIT(10)
239 
240 #define NPSS_TO_MCU_BOD_INTR    BIT(11)
241 #define NPSS_TO_MCU_BUTTON_INTR BIT(12)
242 
243 #define NPSS_TO_MCU_SDC_INTR       BIT(13)
244 #define NPSS_TO_MCU_WIRELESS_INTR  BIT(14)
245 #define NPSS_TO_MCU_WAKEUP_INTR    BIT(15)
246 #define NPSS_TO_MCU_ALARM_INTR     BIT(16)
247 #define NPSS_TO_MCU_SEC_INTR       BIT(17)
248 #define NPSS_TO_MCU_MSEC_INTR      BIT(18)
249 #define NPSS_TO_MCU_PROCESSOR_INTR BIT(19)
250 #define NPSS_TO_MCU_HOST_INTR      BIT(20)
251 #define NPSS_TO_MCU_DST_INTR       BIT(21)
252 
253 #define ENABLE_NEGEDGE_ULP     BIT(1)
254 #define ULP_MODE_SWITCHED_NPSS BIT(3)
255 #define ULP_MODE_AFTR_CLK_SW   BIT(2)
256 
257 /*wake up status register */
258 /*MCU_FSM_WAKEUP_STATUS_REG Reg(0x38) (MCU FSM)*/
259 #define CDBG_POWER_UP_REQUEST_WAKEUP     BIT(6)
260 #define WATCH_DOG_WINDOW_RESET_INTERRUPT BIT(5)
261 #define WWD_RESET_LOOKUP_WAKEUP          BIT(4)
262 #define WATCHDOG_RESET_INTERRUPT         BIT(3)
263 #define HOST_BASED_WAKEUP_S              BIT(2)
264 #define TIMEOUT_WAKEUP                   BIT(1)
265 #define WAKEUP_INDICATION                BIT(0)
266 
267 /*wake up status clear register */
268 /*MCU_FSM_WAKEUP_STATUS_CLEAR Reg(0x3C) (MCU FSM)*/
269 #define MCU_WAKEUP_INTERRUPT                BIT(11)
270 #define RF_WAKEUP_CLEAR                     BIT(10)
271 #define COMP6_BASED_WAKEUP_STATUS_CLEAR     BIT(9)
272 #define COMP5_BASED_WAKEUP_STATUS_CLEAR     BIT(8)
273 #define COMP4_BASED_WAKEUP_STATUS_CLEAR     BIT(7)
274 #define COMP3_BASED_WAKEUP_STATUS_CLEAR     BIT(6)
275 #define COMP2_BASED_WAKEUP_STATUS_CLEAR     BIT(5)
276 #define COMP1_BASED_WAKEUP_STATUS_CLEAR     BIT(4)
277 #define RTC_ALARM_BASED_WAKEUP_STATUS_CLEAR BIT(3)
278 #define RTC_SEC_BASED_STATUS_CLEAR          BIT(2)
279 #define MILLI_SEC_BASED_STATUS_CLEAR        BIT(1)
280 #define WWD_INTERRUPT_STATUS_CLEAR          BIT(0)
281 
282 /*PMU status configuration bits */
283 /* MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE Reg bits (0x0)(MCU FSM)*/
284 #define PMU_STS_DCDC_ON      BIT(10)
285 #define PMU_STS_FLASH_LDO_ON BIT(9)
286 #define PMU_STS_SOC_LDO_ON   BIT(8)
287 
288 /*PMU  */
289 #define STANDBY_LDOSOC_R BIT(18)
290 #define STANDBY_LDORF_R  BIT(17)
291 #define BGPMU_SLEEP_EN_R BIT(16)
292 
293 /*Retention sleep configurations*/
294 #if defined(SLI_SI917B0) || defined(SLI_SI915)
295 
296 //!PSRAM only initialized upon wakeup and it branches to PSRAM
297 #define SL_SI91X_MCU_WAKEUP_PSRAM_MODE 1
298 
299 //!PSRAM and FLASH both will be initialized upon wake up,BIT4 refers to program flash upon wakeup
300 #define RSI_WAKEUP_FROM_FLASH_MODE (0x1 | (BIT(4)))
301 #else
302 #define RSI_WAKEUP_FROM_FLASH_MODE 1
303 #endif
304 #define RSI_WAKEUP_WITH_OUT_RETENTION          2
305 #define RSI_WAKEUP_WITH_RETENTION              3
306 #define RSI_WAKEUP_WITH_RETENTION_WO_ULPSS_RAM 4
307 #define RSI_WAKEUP_WO_RETENTION_WO_ULPSS_RAM   5
308 
309 //!Retention ram content ulp memory start ,end addresses for power save retention sleep cases
310 #define RETEN_RAM_CONTENT_START_LOCATION            (*(volatile uint32_t *)(0x24061F00))
311 #define RETEN_RAM_CONTENT_END_LOCATION              (*(volatile uint32_t *)(0x24061FCC))
312 #define RETEN_RAM_CONTENT_WAKEUP_FLASH_BIT_LOCATION (*(volatile uint32_t *)(0x24061FC8))
313 
314 #define ICACHE2_ADDR_TRANSLATE_1_REG *(volatile uint32_t *)(0x20280000 + 0x24) // ICACHE address register
315 #ifndef MISC_CFG_SRAM_REDUNDANCY_CTRL
316 #define MISC_CFG_SRAM_REDUNDANCY_CTRL *(volatile uint32_t *)(0x46008000 + 0x18) // Misc config register
317 #endif
318 #ifndef MISC_CONFIG_MISC_CTRL1
319 #define MISC_CONFIG_MISC_CTRL1 *(volatile uint32_t *)(0x46008000 + 0x44) // Misc control register
320 #endif
321 #define P2P_STATUS_REGISTER        *(volatile uint32_t *)(0x46008000 + 0x174) // P2P status register
322 #define M4SS_P2P_INTR_SET_REGISTER *(volatile uint32_t *)(0x46008000 + 0x16C) // P2P interrupt set register
323 
324 typedef enum FSM_CLK { FSM_NO_CLOCK = 0, FSM_20MHZ_RO = 1, FSM_MHZ_RC = 2, FSM_40MHZ_XTAL = 4 } FSM_CLK_T;
325 
326 typedef enum AON_CLK { KHZ_RO_CLK_SEL = 1, KHZ_RC_CLK_SEL = 2, KHZ_XTAL_CLK_SEL = 4 } AON_CLK_T;
327 
328 /*Ship modes*/
329 typedef enum SHUT_DOWN_WKP_MODE {
330   NPSS_GPIO_2_BASED       = 0,
331   NPSS_GPIO_1_BASED       = 1,
332   NPSS_GPIO_2_AND_3_BASED = 2,
333   NPSS_GPIO_2_OR_3_BASED  = 3,
334 } SHUT_DOWN_WKP_MODE_T;
335 
336 /// @brief Peri efuse power state
337 typedef enum { POWER_DOWN, POWER_UP } peri_efuse_power_state_t;
338 
339 /*m4ss context switch top ULP mode selection */
340 typedef enum ULP_MODE { ULP_MCU_MODE = 1, UULP_MCU_MODE = 3 } ULP_MODE_T;
341 
342 /*NPSS Comparator selection*/
343 typedef enum NPSS_COMPARATOR {
344   NPSS_CMP_1,
345   NPSS_CMP_2,
346   NPSS_CMP_3,
347   NPSS_CMP_4,
348   NPSS_CMP_5,
349 } NPSS_COMPARATOR_T;
350 
351 #define _SOC_LDO        3
352 #define MCU_SOC_LDO_LVL BIT(17)
353 #define MCU_DCDC_LVL    BIT(18)
354 
355 /*Select value for ULPSS RAM Power MUX*/
356 #define PWR_MUX_SEL_ULPSSRAM_SOC_LDO  3
357 #define PWR_MUX_SEL_ULPSSRAM_SCDC_0_9 1
358 #define PWR_MUX_SEL_ULPSSRAM_SCDC_0_6 0
359 
360 /*Select value for M4 ULP RAM Power MUX*/
361 #define PWR_MUX_SEL_M4_ULP_RAM_SOC_LDO  3
362 #define PWR_MUX_SEL_M4_ULP_RAM_SCDC_0_9 1
363 #define PWR_MUX_SEL_M4_ULP_RAM_SCDC_0_6 0
364 
365 /*Select value for M4 ULP RAM 16K Power MUX*/
366 #define PWR_MUX_SEL_M4_ULP_RAM16K_SOC_LDO  3
367 #define PWR_MUX_SEL_M4_ULP_RAM16K_SCDC_0_9 1
368 #define PWR_MUX_SEL_M4_ULP_RAM16K_SCDC_0_6 0
369 
370 /*Select value for M4 ULP (Cortex Core)Power MUX*/
371 #define PWR_MUX_SEL_M4ULP_SOC_LDO  3
372 #define PWR_MUX_SEL_M4ULP_SCDC_0_9 1
373 #define PWR_MUX_SEL_M4ULP_SCDC_0_6 0
374 
375 /*Select value for ULPSS (Peripherals)Power MUX*/
376 #define PWR_MUX_SEL_ULPSS_SOC_LDO  1
377 #define PWR_MUX_SEL_ULPSS_SCDC_0_9 0
378 
379 /*BG SAMPLE ENABLE AND DISABLE /ENABLE MACROS*/
380 #define ENABLE_BG_SAMPLE_ENABLE  1
381 #define DISABLE_BG_SAMPLE_ENABLE 0
382 
383 /*DC DC ENABLE AND DISABLE /ENABLE MACROS*/
384 #define ENABLE_DC_DC_ENABLE  1
385 #define DISABLE_DC_DC_ENABLE 0
386 
387 /*SOC LDO ENABLE AND DISABLE /ENABLE MACROS*/
388 #define ENABLE_SOCLDO_ENABLE  1
389 #define DISABLE_SOCLDO_ENABLE 0
390 
391 /*STAND BY ENABLE AND DISABLE /ENABLE MACROS*/
392 #define ENABLE_STANDBYDC  1
393 #define DISABLE_STANDBYDC 0
394 
395 /* NWP 192K RAM RETENTION MODE ENABLE in PS2 */
396 #define ENABLE_TA192K_RAM_RET  1
397 #define DISABLE_TA192K_RAM_RET 0
398 
399 /* M4 64K RAM RETENTION MODE ENABLE in PS2  */
400 #define ENABLE_M464K_RAM_RET  1
401 #define DISABLE_M464K_RAM_RET 0
402 
403 #define NWP_FSM_CLOCKS_SELECT      *(volatile uint32_t *)0x41300114
404 #define ENABLE_RO_32KHz_N_RO_20MHz 0x9
405 
406 #define NWP_FSM_CLK_EN_AND_FIRST_BOOTUP *(volatile uint32_t *)0x41300120
407 #define DISABLE_ULP_CLKS                0x790000
408 
409 #define NWPAON_NPSS_PWRCTRL_CLEAR_REG *(volatile uint32_t *)0x4130000C
410 #define PWRGATE_EN_N_ULP_NWPDOMAINS   0x78
411 
412 #define STANDBY_DC1P3     BIT(19)
413 #define BGPMU_SLEEP_EN    BIT(1)
414 #define SCDCDC_LP_MODE_EN BIT(0)
415 #define NWP_PMU_CTRLS     *(volatile uint32_t *)0x41300140
416 
417 #define TASS_REF_CLOCK_SELECT    *(volatile uint32_t *)0x41300110
418 #define TASS_REF_CLK_CLEANER_OFF BIT(22)
419 #define TASS_REF_CLK_CLEANER_ON  BIT(23)
420 
421 #define TASS_PMU_LDO_CTRL_CLEAR *(volatile uint32_t *)0x41300424
422 #define TASS_SOC_LDO_LVL        BIT(17)
423 #define TASS_DCDC_LVL           BIT(18)
424 
425 #define RF_AFE_PWR_CTRL_REG *(volatile uint32_t *)0x41300480
426 #define RF2G_SHUTDOWN       BIT(5)
427 
428 #define RF_AFE_PWR_CTRL_REG *(volatile uint32_t *)0x41300480
429 #define RF2G_PG_EN          BIT(7)
430 #define AFE_PG_EN           BIT(1)
431 
432 #define TASS_M4SS_CRTL_SET_REG     *(volatile uint32_t *)0x41300470
433 #define TASS_CTRL_SOCPLL_SPI_PG_EN BIT(20)
434 
435 #define MODEM_BAND1_PWRCTRL_CLEAR_REG               *(volatile uint32_t *)0x41300408
436 #define MODEM_EXT_PWRGATE_EN_N_ULP_BBP_WLAN_GAINLUT BIT(28)
437 #define MODEM_EXT_PWRGATE_EN_N_ULP_BBP_TXPPLUT      BIT(24)
438 #define MODEM_EXT_PWRGATE_EN_N_ULP_PPE_SHARED       BIT(20)
439 #define MODEM_EXT_PWRGATE_EN_N_ULP_PPE_IMDM         BIT(16)
440 
441 #define MODEM_ZBBT_PWRCTRL_CLEAR_REG                *(volatile uint32_t *)0x41300418
442 #define MODEM_EXT_PWRGATE_EN_N_ULP_BBP_ZBBT_GAINLUT BIT(4)
443 
444 #define NWP_RTC_TIMER_CLOCK_PERIOD_SOC *(volatile uint32_t *)(0x41300204)
445 #define RTC_TIMER_CLK_PERIOD_VALUE     0x003E7FFF
446 
447 #define SPI_RTC_TIMER_CLK_PERIOD_APPLIED BIT(31)
448 
449 #define NWP_FSM_SLEEP_WAKEUP_MODES *(volatile uint32_t *)0x41300100
450 #define COUNT_TICK_ENABLE          0x1
451 #if defined(SLI_SI917B0) || defined(SLI_SI915)
452 #define MCURET_BOOTSTATUS_REG *(volatile uint32_t *)(MCU_NPSS_BASE_ADDR + 0x604)
453 #define KEY_SIZE_IN_DWORDS    8
454 
455 #define RSI_WAKE_FROM_FLASH_CB_START_ADDR 0x24061F00
456 
457 #define STACK_AND_CB_ADDR_PRESENT_IN_BBFF BIT(20)
458 
459 #define RSI_WAKE_FROM_FLASH_JUMP_ADDR 0x24061F28
460 
461 #define STACK_AND_CB_ADDR_BIT_NO     12
462 #define QSPI_KEY_SIZE_256            BIT(16)
463 #define PSRAM_SEC_EN                 BIT(23)
464 #define KEY_LENGTH                   BIT(11)
465 #define PSRAM_SEC_EN                 BIT(23)
466 #define M4SS_PSRAM_QSPI_BASE_ADDRESS 0x12040000
467 #endif
468 
469 #define MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE_REG *(volatile uint32 *)(0x24048100 + 0x0)
470 #define LDO_FLASH_ON                            BIT(9)
471 #define PMU_DCDC_ON                             BIT(10)
472 
473 /** @addtogroup SOC2
474 * @{
475 */
476 /**
477  * @fn            STATIC INLINE rsi_error_t ps_power_state_change_ps4tops2( ULP_MODE_T enCtxSel          ,
478  *                                                          uint8_t PwrMuxSelUlpssRam    ,
479  *                                                          uint8_t pwrMuxSelM4UlpRam    ,
480  *                                                          uint8_t pwrMuxSelM4UlpRam16K ,
481  *                                                          uint8_t pwrMuxSelM4Ulp       ,
482  *                                                          uint8_t pwrMuxSelUlpss       ,
483  *                                                          uint8_t bgSampleEnable       ,
484  *                                                          uint8_t dcDcEnable           ,
485  *                                                          uint8_t socLdoEnable         ,
486  *                                                          uint8_t standByDc
487  *                                                        )
488  * @brief         This API is used to used to change the power transition state from Power save state 4/3 to power save state 2
489  * @param[in]     enCtxSel : is Select enum for the context top ULP mode
490  *                \n  00, 10 - \ref HP-MCU/LP-MCU Mode
491  *                \n  01 - \ref ULP-MCU Mode
492  *                \n  11 - \ref UULP-MCU Mode
493  *                \n  (1st 16K of M4 RAM is dedicated to IM,
494  *                \n  2nd 16K of M4 RAM is dedicated to DM)
495  * @param[in]     pwrMuxSelM4UlpRam : Select value for M4 ULP RAM Power MUX
496  *                \n  3 \ref  SOC LDO
497  *                \n  1 \ref  SCDCDC 0.9
498  *                \n  0 \ref  SCDCDC 0.6
499  * @param[in]    PwrMuxSelUlpssRam :Select value for ULPSS RAM Power MUX
500  *                \n  3 \ref  SOC LDO
501  *                \n  1 \ref  SCDCDC 0.9
502  *                \n  0 \ref  SCDCDC 0.6
503  * @param[in]     pwrMuxSelM4UlpRam16K : is Select value for M4 ULP RAM 16K Power MUX
504  *                \n  3 \ref  SOC LDO
505  *                \n  1 \ref  SCDCDC 0.9
506  *                \n  0  \ref SCDCDC 0.6
507  * @param[in]     pwrMuxSelM4Ulp : is Select value for M4 ULP (Peripherals + CORTEX Core )Power MUX
508  *                \n  3 \ref SOC LDO
509  *                \n  1 \ref SCDCDC 0.9
510  *                \n  0 \ref SCDCDC 0.6
511  * @param[in]     pwrMuxSelUlpss : is Select value for ULPSS(Peripherals) Power MUX
512  *                \n  1 \ref SOC LDO
513  *                \n  0 \ref SCDCDC 0.9
514  * @param[in]     bgSampleEnable  : Value to enable or disable the bg Sample
515  *                                  \n 0 :Disable
516  *                                  \n 1 :Enale
517  * @param[in]     dcDcEnable      : Value to enable or disable the dcDcEnable
518  *                                  \n 0 :Disable
519  *                                  \n 1 :Enale
520  * @param[in]     socLdoEnable    : Value to enable or disable the socLdoEnable
521  *                                  \n 0 :Disable
522  *                                  \n 1 :Enale
523  * @param[in]     standByDc       : Value to enable or disable the standByDc
524  *                                  \n 0 :Disable
525  *                                  \n 1 :Enale
526  * @return        returns 0 \ref RSI_OK on success,return error code on error
527  */
ps_power_state_change_ps4tops2(ULP_MODE_T enCtxSel,uint8_t PwrMuxSelUlpssRam,uint8_t pwrMuxSelM4UlpRam,uint8_t pwrMuxSelM4UlpRam16K,uint8_t pwrMuxSelM4Ulp,uint8_t pwrMuxSelUlpss,uint8_t bgSampleEnable,uint8_t dcDcEnable,uint8_t socLdoEnable,uint8_t standByDc)528 STATIC INLINE rsi_error_t ps_power_state_change_ps4tops2(ULP_MODE_T enCtxSel,
529                                                          uint8_t PwrMuxSelUlpssRam,
530                                                          uint8_t pwrMuxSelM4UlpRam,
531                                                          uint8_t pwrMuxSelM4UlpRam16K,
532                                                          uint8_t pwrMuxSelM4Ulp,
533                                                          uint8_t pwrMuxSelUlpss,
534                                                          uint8_t bgSampleEnable,
535                                                          uint8_t dcDcEnable,
536                                                          uint8_t socLdoEnable,
537                                                          uint8_t standByDc)
538 {
539   volatile int x = 0;
540 
541   /*return error if this function is called from PS2*/
542   if (M4_ULP_SLP_STATUS_REG & ULP_MODE_SWITCHED_NPSS) {
543     return ERROR_PS_INVALID_STATE;
544   }
545 
546   /*Static clock enable m4 core in ULP mode*/
547   M4LP_CTRL_REG |= ULP_M4_CORE_CLK_ENABLE;
548 
549   /*flushes the transactions in the Bridge before transition to PS2 state*/
550   x = (int)ULPCLK->ULP_TA_CLK_GEN_REG;
551   /*Select the MCU mode*/
552   MCU_FSM->MCU_FSM_PERI_CONFIG_REG_b.M4SS_CONTEXT_SWITCH_TOP_ULP_MODE = enCtxSel;
553 
554   /*Avoid the junk system bus access*/
555   for (x = 0; x < 10; x++) {
556     __ASM("NOP");
557   }
558   /*
559   Indicates the status of functional switching to ULP Mode operation
560   0 - PS4 state
561   1 - PS2 state
562    */
563   do {
564     /*wait for status of functional switching to ULP Mode operation*/
565     x++;
566   } while ((M4_ULP_SLP_STATUS_REG & ULP_MODE_AFTR_CLK_SW) != ULP_MODE_AFTR_CLK_SW);
567 
568   /*Select value for ULPSS RAM Power Mux*/
569   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.POWER_MUX_SEL_ULPSS_RAM = (unsigned int)(PwrMuxSelUlpssRam & 0x3);
570   /*Select value for M4 ULP RAM Power Mux*/
571   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.POWER_MUX_SEL_M4_ULP_RAM = (unsigned int)(pwrMuxSelM4UlpRam & 0x3);
572   /*Select value for M4 ULP RAM 16K Power Mux*/
573   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.POWER_MUX_SEL_M4_ULP_RAM_16K = (unsigned int)(pwrMuxSelM4UlpRam16K & 0x3);
574   /*Select value for M4 ULP (Peripherals + Cortex Core )Power Mux*/
575   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.POWER_MUX_SEL_M4_ULP = (unsigned int)(pwrMuxSelM4Ulp & 0x3);
576   /*Select value for ULPSS(Peripherals) Power Mux*/
577   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.POWER_MUX_SEL_ULPSS = (unsigned int)(pwrMuxSelUlpss & 0x1);
578 
579   /*update the SOC LDO*/
580   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.FSM_PERI_SOC_LDO_EN = (unsigned int)(socLdoEnable & 0x1);
581 
582   if (socLdoEnable == 1) {
583     MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.FSM_PERI_DCDC_EN = 1;
584     MCU_FSM->MCU_FSM_PERI_CONFIG_REG_b.BGPMU_SAMPLING_EN_R   = 0;
585   }
586 
587   else {
588     MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.FSM_PERI_DCDC_EN = (unsigned int)(socLdoEnable & 0x1);
589   }
590 
591   if (dcDcEnable == 1) {
592     MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.FSM_PERI_DCDC_EN = (unsigned int)(dcDcEnable & 0x1);
593     MCU_FSM->MCU_FSM_PERI_CONFIG_REG_b.BGPMU_SAMPLING_EN_R   = 0;
594   } else {
595     MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.FSM_PERI_DCDC_EN = (unsigned int)(dcDcEnable & 0x1);
596     MCU_FSM->MCU_FSM_PERI_CONFIG_REG_b.BGPMU_SAMPLING_EN_R   = (unsigned int)(bgSampleEnable & 0x1);
597   }
598 
599   if ((socLdoEnable == 0) && (dcDcEnable == 1)) {
600     MCU_FSM->MCU_FSM_PMU_STATUS_REG_b.STANDBY_DC1P3_R = (unsigned int)(standByDc & 0x1);
601   }
602   /*Set the LDO turn off delay*/
603 
604   /*PMU off delay */
605   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.PS2_PMU_LDO_OFF_DELAY = PMU_LDO_OFF_DELAY;
606 
607 #if !defined(SLI_SI917) && !defined(SLI_SI915)
608   /*Bridge clock disable*/
609   ULPCLK->ULP_TA_CLK_GEN_REG_b.ULP2M4_A2A_BRDG_CLK_EN_b = 0;
610 #endif
611 
612   /*Set ulp mode isolation */
613   BATT_FF->M4_ULP_MODE_CONFIG = (BATT_FF->M4_ULP_MODE_CONFIG | 0x3F);
614 
615   /* Setting RETN_LDO voltage to 0.75V */
616   RSI_IPMU_RetnLdo0p75();
617 
618   /* enabling the RETN_LDO HP MODE */
619   RSI_IPMU_RetnLdoHpmode();
620 
621   /*Enable the ULP mode */
622   MCU_FSM->MCU_FSM_PERI_CONFIG_REG_b.ULP_MCU_MODE_EN = 1;
623 
624   /*  Wait for Status bit indicating Physical transition from PS2 to PS4*/
625   do {
626     /*wait for  status of Physical switching to ULP Mode operation*/
627     x++;
628   } while ((M4_ULP_SLP_STATUS_REG & ULP_MODE_SWITCHED_NPSS) != ULP_MODE_SWITCHED_NPSS);
629 
630   return RSI_OK;
631 }
632 
633 /**
634  * @fn          STATIC INLINE rsi_error_t ps_power_state_change_ps2_to_Ps4(uint32_t PmuBuckTurnOnWaitTime , uint32_t SocLdoTurnOnWaitTime)
635  * @brief       This API is used to change the power state from PS2 to PS4
636  * @param[in]   PmuBuckTurnOnWaitTime :  PMU buck time
637  * @param[in]   SocLdoTurnOnWaitTime : soc ldo turn on time
638  * @return       returns 0 \ref RSI_OK on success,return error code on error
639  */
ps_power_state_change_ps2_to_Ps4(uint32_t PmuBuckTurnOnWaitTime,uint32_t SocLdoTurnOnWaitTime)640 STATIC INLINE rsi_error_t ps_power_state_change_ps2_to_Ps4(uint32_t PmuBuckTurnOnWaitTime,
641                                                            uint32_t SocLdoTurnOnWaitTime)
642 {
643   uint8_t x;
644   /*Return if this is issues in PS4 state */
645   if (!(M4_ULP_SLP_STATUS_REG & ULP_MODE_SWITCHED_NPSS)) {
646     return ERROR_PS_INVALID_STATE;
647   }
648 #ifdef CHIP_9118
649   /*Disables clock to ULP-M4SS AHB-AHB Bridge since the MCU is in PS2 state logically*/
650   ULPCLK->ULP_TA_CLK_GEN_REG_b.ULP2M4_A2A_BRDG_CLK_EN_b = 0;
651 #endif
652   /*Select value for ULPSS RAM Power Mux*/
653   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.POWER_MUX_SEL_ULPSS_RAM = _SOC_LDO;
654   /*Select value for M4 ULP RAM Power Mux*/
655   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.POWER_MUX_SEL_M4_ULP_RAM = _SOC_LDO;
656   /*Select value for M4 ULP RAM 16K Power Mux*/
657   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.POWER_MUX_SEL_M4_ULP_RAM_16K = _SOC_LDO;
658   /*Select value for M4 ULP (Peripherals + Cortex Core )Power Mux*/
659   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.POWER_MUX_SEL_M4_ULP = _SOC_LDO;
660   /*Select value for ULPSS(Peripherals) Power Mux*/
661   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.POWER_MUX_SEL_ULPSS = 0x01;
662 
663   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.PG4_BUCK_ON_DELAY   = (unsigned int)(PmuBuckTurnOnWaitTime & 0xF);
664   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.PS4_SOCLDO_ON_DELAY = (unsigned int)(SocLdoTurnOnWaitTime & 0xF);
665 
666   MCU_FSM->MCU_FSM_PMU_STATUS_REG_b.STANDBY_DC1P3_R = 0;
667 
668   /*Disable the ULP mode */
669   MCU_FSM->MCU_FSM_PERI_CONFIG_REG_b.ULP_MCU_MODE_EN = 0;
670   // NOTE :  nopes issue issue is fixed by adding this bit
671   /*  Wait for Status bit indicating Physical transition from PS2 to PS4*/
672   /*Avoid the junk system bus access*/
673   for (x = 0; x < 10; x++) {
674     __ASM("NOP");
675   }
676 
677   while (M4_ULP_SLP_STATUS_REG & ULP_MODE_SWITCHED_NPSS)
678     ;
679 
680   /*Disable ulp mode isolation */
681   BATT_FF->M4_ULP_MODE_CONFIG &= ~(0x3F);
682 
683 #if !defined(SLI_SI917) && !defined(SLI_SI915)
684   /*Disables clock to ULP-M4SS AHB-AHB Bridge since the MCU is in PS2 state logically*/
685   ULPCLK->ULP_TA_CLK_GEN_REG_b.ULP2M4_A2A_BRDG_CLK_EN_b = 1;
686 #endif
687 
688   /*Select the MCU mode*/
689   MCU_FSM->MCU_FSM_PERI_CONFIG_REG_b.M4SS_CONTEXT_SWITCH_TOP_ULP_MODE = 0;
690   // NOTE :  nopes issue issue is fixed by adding this bit
691   /*  Wait for Status bit indicating Functional transition from PS4 to PS2*/
692   while (M4_ULP_SLP_STATUS_REG & ULP_MODE_AFTR_CLK_SW)
693     ;
694 
695   /* Setting RETN_LDO voltage to 0.7V */
696   RSI_IPMU_RetnLdoVoltsel();
697 
698   /* enabling the RETN_LDO LP MODE  */
699   RSI_IPMU_RetnLdoLpmode();
700 #if !defined(SLI_SI917) && !defined(SLI_SI915)
701   M4CLK->CLK_ENABLE_SET_REG1_b.M4SS_UM_CLK_STATIC_EN_b = 0x1;
702 #endif
703   for (x = 0; x < 200; x++) {
704     __ASM("NOP");
705   }
706 #if !defined(SLI_SI917) && !defined(SLI_SI915)
707   M4CLK->CLK_ENABLE_CLR_REG1_b.M4SS_UM_CLK_STATIC_EN_b = 0x1;
708 #endif
709   return RSI_OK;
710 }
711 /**
712  * \ingroup   RSI_SPECIFIC_DRIVERS
713  * \defgroup RSI_POWER_SAVE
714  *  @{
715  *
716  */
717 /**
718  * @fn            STATIC INLINE void RSI_PS_PowerStateChangePs4toPs3(void)
719  * @brief         This API is used to Change the power state from PS4 to PS3
720  *                \n
721  *                \ref MCU_PMU_LDO_CTRL_CLEAR
722  */
RSI_PS_PowerStateChangePs4toPs3(void)723 STATIC INLINE void RSI_PS_PowerStateChangePs4toPs3(void)
724 {
725   /*Clear the MCU_SOC_LDO_LVL */
726   BATT_FF->MCU_PMU_LDO_CTRL_CLEAR = MCU_SOC_LDO_LVL;
727 }
728 
729 /**
730  * @fn            STATIC INLINE void RSI_PS_SetDcDcToHigerVoltage(void)
731  * @brief         This API is used configure DCDC to give higher output voltage.
732  *                \n
733  *                \ref MCU_PMU_LDO_CTRL_SET
734  */
RSI_PS_SetDcDcToHigerVoltage(void)735 STATIC INLINE void RSI_PS_SetDcDcToHigerVoltage(void)
736 {
737   BATT_FF->MCU_PMU_LDO_CTRL_SET = MCU_DCDC_LVL;
738 }
739 
740 /**
741  * @fn            STATIC INLINE void RSI_PS_SetDcDcToLowerVoltage(void)
742  * @brief         This API is used configure DCDC to give lower output voltage.
743  *                \n
744  *                \ref MCU_PMU_LDO_CTRL_CLEAR
745  */
RSI_PS_SetDcDcToLowerVoltage(void)746 STATIC INLINE void RSI_PS_SetDcDcToLowerVoltage(void)
747 {
748   BATT_FF->MCU_PMU_LDO_CTRL_CLEAR = MCU_DCDC_LVL;
749 }
750 
751 /**
752  * @fn            STATIC INLINE void RSI_PS_PowerStateChangePs3toPs4(void)
753  * @brief         This API is used to Change the power state from PS3 to PS4
754  *                \n
755  *                \ref MCU_PMU_LDO_CTRL_SET
756  */
RSI_PS_PowerStateChangePs3toPs4(void)757 STATIC INLINE void RSI_PS_PowerStateChangePs3toPs4(void)
758 {
759   BATT_FF->MCU_PMU_LDO_CTRL_SET = MCU_SOC_LDO_LVL;
760   return;
761 }
762 
763 /**
764  * @fn            STATIC INLINE void RSI_PS_M4ssPeriPowerDown(uint32_t mask)
765  * @brief         This API is used to power gate the M4SS peripherals
766  * @param[in]     mask  OR'ed value of the power gates
767  *                \n
768  *                \ref M4SS_PWRCTRL_CLEAR_REG
769  * @return    none
770  */
RSI_PS_M4ssPeriPowerDown(uint32_t mask)771 STATIC INLINE void RSI_PS_M4ssPeriPowerDown(uint32_t mask)
772 {
773   BATT_FF->M4SS_PWRCTRL_CLEAR_REG = mask;
774 }
775 
776 /**
777  * @fn            STATIC INLINE void RSI_PS_M4ssPeriPowerUp(uint32_t mask)
778  * @brief         This API is used to un power gate the M4SS peripherals
779  * @param[in]     mask  OR'ed value of the power gates
780  *                \n
781  *                \ref M4SS_PWRCTRL_SET_REG
782  * @return    none
783  */
RSI_PS_M4ssPeriPowerUp(uint32_t mask)784 STATIC INLINE void RSI_PS_M4ssPeriPowerUp(uint32_t mask)
785 {
786   BATT_FF->M4SS_PWRCTRL_SET_REG = mask;
787 }
788 
789 /**
790  * @fn            STATIC INLINE void sl_si91x_peri_efuse_power_control(bool power_up)
791  * @brief         This API is used to power gate the PERI_EFUSE power domain, This power domain contains the different M4SS peripherals those are
792  *                SPI/SSI Master, I2C, USART, Micro-DMA Controller,  UART, SPI/SSI Slave, Generic-SPI Master, Config Timer, Random-Number Generator,
793  *                CRC Accelerator, SIO, I2C, I2S Master/Slave, QEI, MCPWM ,EFUSE and MVP
794  * @param[in]     power_up   1 - Power Up the EFUSE Peri Power domain
795  *                           0 - Power Down the EFUSE Peri power domain
796  * @return    none
797  */
sl_si91x_peri_efuse_power_state_control(peri_efuse_power_state_t power_up)798 STATIC INLINE void sl_si91x_peri_efuse_power_state_control(peri_efuse_power_state_t power_up)
799 {
800   if (power_up) {
801     RSI_PS_M4ssPeriPowerUp(M4SS_PWRGATE_ULP_EFUSE_PERI);
802   } else {
803     RSI_PS_M4ssPeriPowerDown(M4SS_PWRGATE_ULP_EFUSE_PERI);
804   }
805 }
806 
807 /**
808  * @fn            STATIC INLINE void RSI_PS_M4ss_Tass_Ctrl_Clear(uint32_t mask)
809  * @brief        This API is used to clear the M4SS TASS controls
810  * @param[in]     mask  OR'ed value of the power gates
811  *                \n
812  *                \ref M4SS_TASS_CTRL_CLEAR_REG
813  * @return    none
814  */
RSI_PS_M4ss_Tass_Ctrl_Clear(uint32_t mask)815 STATIC INLINE void RSI_PS_M4ss_Tass_Ctrl_Clear(uint32_t mask)
816 {
817   BATT_FF->M4SS_TASS_CTRL_CLEAR_REG = mask;
818 }
819 
820 /**
821  * @fn            STATIC INLINE void RSI_PS_UlpssPeriPowerDown(uint32_t mask)
822  * @brief         This API is used to  power gate the ULPSS peripherals
823  * @param[in]     mask  OR'ed value of the power gates
824  *                \n
825  *                \ref  ULPSS_PWRCTRL_CLEAR_REG
826  * @return    none
827  */
RSI_PS_UlpssPeriPowerDown(uint32_t mask)828 STATIC INLINE void RSI_PS_UlpssPeriPowerDown(uint32_t mask)
829 {
830   BATT_FF->ULPSS_PWRCTRL_CLEAR_REG = mask;
831 }
832 
833 /**
834  * @fn            STATIC INLINE void RSI_PS_UlpssPeriPowerUp(uint32_t mask)
835  * @brief         This API is used to un power gate the ULPSS peripherals
836  * @param[in]     mask  OR'ed value of the power domains
837  *                \n
838  *                \ref ULPSS_PWRCTRL_SET_REG
839  * @return    none
840  */
RSI_PS_UlpssPeriPowerUp(uint32_t mask)841 STATIC INLINE void RSI_PS_UlpssPeriPowerUp(uint32_t mask)
842 {
843   BATT_FF->ULPSS_PWRCTRL_SET_REG = mask;
844 }
845 
846 /**
847  * @fn            STATIC INLINE void RSI_PS_NpssPeriPowerUp(uint32_t mask)
848  * @brief         This API is used to un power gate the NPSS peripherals
849  * @param[in]     mask  OR'ed value of the power domains
850  *                \n
851  *                \ref MCUAON_NPSS_PWRCTRL_SET_REG
852  * @return    none
853  */
RSI_PS_NpssPeriPowerUp(uint32_t mask)854 STATIC INLINE void RSI_PS_NpssPeriPowerUp(uint32_t mask)
855 {
856   MCU_AON->MCUAON_NPSS_PWRCTRL_SET_REG = mask;
857 }
858 
859 /**
860  * @fn            STATIC INLINE void RSI_PS_NpssPeriPowerDown(uint32_t mask)
861  * @brief          This API is used to power gate the NPSS peripherals
862  * @param[in]     mask  OR'ed value of the power domains
863  *                \n
864  *                \ref MCUAON_NPSS_PWRCTRL_CLEAR_REG
865  * @return    none
866  */
RSI_PS_NpssPeriPowerDown(uint32_t mask)867 STATIC INLINE void RSI_PS_NpssPeriPowerDown(uint32_t mask)
868 {
869   MCU_AON->MCUAON_NPSS_PWRCTRL_CLEAR_REG = mask;
870 }
871 
872 /**
873  * @fn            STATIC INLINE void RSI_PS_M4ssRamBanksPowerDown(uint32_t mask)
874  * @brief        This API is used to power gate the M4SS RAM Banks
875  * @param[in]     mask  OR'ed value of the RAM power gates
876  *                \n
877  *                \ref M4_SRAM_PWRCTRL_CLEAR_REG1
878  * @return    none
879  */
RSI_PS_M4ssRamBanksPowerDown(uint32_t mask)880 STATIC INLINE void RSI_PS_M4ssRamBanksPowerDown(uint32_t mask)
881 {
882   BATT_FF->M4_SRAM_PWRCTRL_CLEAR_REG1 = mask;
883 }
884 
885 /**
886  * @fn            STATIC INLINE void RSI_PS_M4ssRamBanksPowerUp(uint32_t mask)
887  * @brief        This API is used to un power gate the M4SS RAM Banks
888  * @param[in]     mask  OR'ed value of the RAM power gates
889  *                \n
890  *                \ref M4_SRAM_PWRCTRL_SET_REG1
891  * @return        none
892  */
RSI_PS_M4ssRamBanksPowerUp(uint32_t mask)893 STATIC INLINE void RSI_PS_M4ssRamBanksPowerUp(uint32_t mask)
894 {
895   BATT_FF->M4_SRAM_PWRCTRL_SET_REG1 = mask;
896 }
897 
898 /**
899  * @fn            STATIC INLINE uint32_t RSI_PS_M4ssRamBanksGetPowerSts(void)
900  * @brief         This API is used to get the power gate status of M4SS RAM Banks
901  *                \ref M4_SRAM_PWRCTRL_SET_REG1
902  * @return        Ored bits of M4_SRAM_PWRCTRL_SET_REG1 reg
903  */
RSI_PS_M4ssRamBanksGetPowerSts(void)904 STATIC INLINE uint32_t RSI_PS_M4ssRamBanksGetPowerSts(void)
905 {
906   return BATT_FF->M4_SRAM_PWRCTRL_SET_REG1;
907 }
908 
909 /**
910  * @fn            STATIC INLINE void RSI_PS_M4ssRamBanksPeriPowerDown(uint32_t mask)
911  * @brief         This API is used to power gate the M4SS RAM Banks periphery domain
912  * @param[in]     mask  OR'ed value of the RAM power gates
913  *                \n
914  *                \ref M4_SRAM_PWRCTRL_CLEAR_REG1
915  * @return    none
916  */
RSI_PS_M4ssRamBanksPeriPowerDown(uint32_t mask)917 STATIC INLINE void RSI_PS_M4ssRamBanksPeriPowerDown(uint32_t mask)
918 {
919   BATT_FF->M4_SRAM_PWRCTRL_CLEAR_REG2 = mask;
920 }
921 
922 /**
923  * @fn           STATIC INLINE void RSI_PS_M4ssRamBanksPeriPowerUp(uint32_t mask)
924  * @brief         This API is used to un-power gate the M4SS RAM Banks periphery domain
925  * @param[in]     mask  OR'ed value of the RAM power gates
926  *                \n
927  *                \ref M4_SRAM_PWRCTRL_SET_REG1
928  * @return        none
929  */
RSI_PS_M4ssRamBanksPeriPowerUp(uint32_t mask)930 STATIC INLINE void RSI_PS_M4ssRamBanksPeriPowerUp(uint32_t mask)
931 {
932   BATT_FF->M4_SRAM_PWRCTRL_SET_REG2 = mask;
933 }
934 
935 /**
936  * @fn           STATIC INLINE uint32_t RSI_PS_M4ssRamBanksGetPeriPowerSts(void)
937  * @brief        This API is used to get the power gate status of M4SS RAM Banks periphery domain
938  *                \ref M4_SRAM_PWRCTRL_SET_REG1
939  * @return        Ored bits of M4_SRAM_PWRCTRL_SET_REG2 register.
940  */
RSI_PS_M4ssRamBanksGetPeriPowerSts(void)941 STATIC INLINE uint32_t RSI_PS_M4ssRamBanksGetPeriPowerSts(void)
942 {
943   return BATT_FF->M4_SRAM_PWRCTRL_SET_REG2;
944 }
945 /**
946  * @fn            STATIC INLINE void RSI_PS_UlpssRamBanksPeriPowerDown(uint32_t mask)
947  * @brief         This API is used to power gate the ULPSS RAM Banks periphery domain
948  * @param[in]     mask  OR'ed value of the RAM power gates
949  *                \n
950  *                \ref M4_SRAM_PWRCTRL_CLEAR_REG1
951  * @return    none
952  */
RSI_PS_UlpssRamBanksPeriPowerDown(uint32_t mask)953 STATIC INLINE void RSI_PS_UlpssRamBanksPeriPowerDown(uint32_t mask)
954 {
955   BATT_FF->ULPSS_RAM_PWRCTRL_CLEAR_REG3 = mask;
956 }
957 
958 /**
959  * @fn           STATIC INLINE void RSI_PS_UlpssRamBanksPeriPowerUp(uint32_t mask)
960  * @brief        This API is used to un-power gate the ULPSS RAM Banks periphery domain
961  * @param[in]     mask  OR'ed value of the RAM power gates
962  *                \n
963  *                \ref M4_SRAM_PWRCTRL_SET_REG1
964  * @return        none
965  */
RSI_PS_UlpssRamBanksPeriPowerUp(uint32_t mask)966 STATIC INLINE void RSI_PS_UlpssRamBanksPeriPowerUp(uint32_t mask)
967 {
968   BATT_FF->ULPSS_RAM_PWRCTRL_SET_REG3 = mask;
969 }
970 
971 /**
972  * @fn            STATIC INLINE void RSI_PS_SetRamRetention(uint32_t ramRetention)
973  * @brief         This API is used to set the RAM retention enable for the RAM during sleep
974  * @param[in]     ramRetention OR'ed value of the RAM retention bits
975  *                \n
976  *                \ref MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE
977  * @return    none
978  */
RSI_PS_SetRamRetention(uint32_t ramRetention)979 STATIC INLINE void RSI_PS_SetRamRetention(uint32_t ramRetention)
980 {
981   MCU_FSM->MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE |= ramRetention;
982 }
983 
984 /**
985  * @fn            STATIC INLINE void RSI_PS_ClrRamRetention(uint32_t ramRetention)
986  * @brief         This API is used to clear the RAM retention enable for the RAM during sleep
987  * @param[in]     ramRetention  OR'ed value of the RAM retention bits
988  *                \n
989  *                \ref MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE
990  * @return    none
991  */
RSI_PS_ClrRamRetention(uint32_t ramRetention)992 STATIC INLINE void RSI_PS_ClrRamRetention(uint32_t ramRetention)
993 {
994   MCU_FSM->MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE &= ~ramRetention;
995 }
996 
997 /**
998  * @fn            STATIC INLINE void RSI_PS_UlpssRamBanksPowerDown(uint32_t mask)
999  * @brief         This API is used to  power gate the ULPSS RAM Banks
1000  * @param[in]     mask  OR'ed value of the RAM power gates
1001  *                \n
1002  *                \ref ULPSS_RAM_PWRCTRL_CLEAR_REG1
1003  * @return    none
1004  */
RSI_PS_UlpssRamBanksPowerDown(uint32_t mask)1005 STATIC INLINE void RSI_PS_UlpssRamBanksPowerDown(uint32_t mask)
1006 {
1007   BATT_FF->ULPSS_RAM_PWRCTRL_CLEAR_REG1 = mask;
1008 }
1009 
1010 /**
1011  * @fn            STATIC INLINE void RSI_PS_UlpssRamBanksPowerUp(uint32_t mask)
1012  * @brief         This API is used to  un power gate the ULPSS RAM Banks
1013  * @param[in]     mask  OR'ed value of the RAM power gates
1014  *                \n
1015  *                \ref ULPSS_RAM_PWRCTRL_SET_REG1
1016  * @return    none
1017  */
RSI_PS_UlpssRamBanksPowerUp(uint32_t mask)1018 STATIC INLINE void RSI_PS_UlpssRamBanksPowerUp(uint32_t mask)
1019 {
1020   BATT_FF->ULPSS_RAM_PWRCTRL_SET_REG1 = mask;
1021 }
1022 
1023 /**
1024  * @fn            STATIC INLINE void RSI_PS_SetWkpSources(uint32_t wakeUpsrcMask)
1025  * @brief        This API is used to set the wake up source to wake up from deep sleep
1026  * @param[in]     wakeUpsrcMask OR'ed value of the wake up sources
1027  *                \n
1028  *                \ref MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE
1029  * @return    none
1030  */
RSI_PS_SetWkpSources(uint32_t wakeUpsrcMask)1031 STATIC INLINE void RSI_PS_SetWkpSources(uint32_t wakeUpsrcMask)
1032 {
1033   MCU_FSM->MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE |= wakeUpsrcMask;
1034 }
1035 
1036 /**
1037  * @fn            STATIC INLINE void RSI_PS_ClrWkpSources(uint32_t wakeUpsrcMask)
1038  * @brief         This API is used to clear the wake up source
1039  * @param[in]     wakeUpsrcMask OR'ed value of the wake up sources
1040  *                \ref MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE
1041  * @return    none
1042  */
RSI_PS_ClrWkpSources(uint32_t wakeUpsrcMask)1043 STATIC INLINE void RSI_PS_ClrWkpSources(uint32_t wakeUpsrcMask)
1044 {
1045   MCU_FSM->MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE &= ~wakeUpsrcMask;
1046 }
1047 
1048 /**
1049  * @fn            STATIC INLINE uint32_t RSI_PS_GetWkpSources(void)
1050  * @brief   This API is used to get the wake up source
1051  * @return    register bits of wake up sources
1052  */
RSI_PS_GetWkpSources(void)1053 STATIC INLINE uint32_t RSI_PS_GetWkpSources(void)
1054 {
1055   return MCU_FSM->MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE;
1056 }
1057 
1058 /**
1059  * @fn            STATIC INLINE void RSI_PS_EnableFirstBootUp(boolean_t enable)
1060  * @brief   This API is used to SET and CLEAR the First boot up bit
1061  * @param[in]     enable :
1062  *                \ref MCU_FSM_CLK_ENS_AND_FIRST_BOOTUP_b  0: disable the first boot ,
1063  *                \ref MCU_FSM_CLK_ENS_AND_FIRST_BOOTUP_b  1: enable the first boot up
1064  * @return    none
1065  */
RSI_PS_EnableFirstBootUp(boolean_t enable)1066 STATIC INLINE void RSI_PS_EnableFirstBootUp(boolean_t enable)
1067 {
1068   MCU_FSM->MCU_FSM_CLK_ENS_AND_FIRST_BOOTUP_b.FIRST_BOOTUP_MCU_N_b = (unsigned int)(enable & 0x01);
1069 }
1070 
1071 /**
1072  * @fn            STATIC INLINE void RSI_PS_PowerSupplyEnable(uint32_t mask)
1073  * @brief   This API is used to enable the supply to some NPSS peripherals
1074  * @param[in]     mask 0: disable the first boot ,  1: enable the first boot up
1075  * @return    none
1076  */
RSI_PS_PowerSupplyEnable(uint32_t mask)1077 STATIC INLINE void RSI_PS_PowerSupplyEnable(uint32_t mask)
1078 {
1079   MCU_FSM->MCU_FSM_CRTL_PDM_AND_ENABLES |= mask;
1080 }
1081 
1082 /**
1083  * @fn            STATIC INLINE void RSI_PS_PowerSupplyDisable(uint32_t mask)
1084  * @brief   This API is used to disable the supply to some NPSS peripherals
1085  * @param[in]     mask  0: disable the first boot ,  1: enable the first boot up
1086  *                \ref MCU_FSM_CRTL_PDM_AND_ENABLES
1087  * @return    none
1088  */
RSI_PS_PowerSupplyDisable(uint32_t mask)1089 STATIC INLINE void RSI_PS_PowerSupplyDisable(uint32_t mask)
1090 {
1091   MCU_FSM->MCU_FSM_CRTL_PDM_AND_ENABLES &= ~mask;
1092 }
1093 
1094 /**
1095  * @fn            STATIC INLINE void RSI_PS_FsmHfClkSel(FSM_CLK_T fsmHfClk)
1096  * @brief   This API is used to  configure the FSM high frequency clock
1097  * @param[in]     fsmHfClk : enum value of the high frequency clock sources
1098  *                \ref MCU_FSM_CLKS_REG_b
1099  * @return    none
1100  */
RSI_PS_FsmHfClkSel(FSM_CLK_T fsmHfClk)1101 STATIC INLINE void RSI_PS_FsmHfClkSel(FSM_CLK_T fsmHfClk)
1102 {
1103   MCU_FSM->MCU_FSM_CLKS_REG_b.HF_FSM_CLK_SELECT = fsmHfClk;
1104   while (MCU_FSM->MCU_FSM_CLKS_REG_b.HF_FSM_CLK_SWITCHED_SYNC != 1)
1105     ;
1106 }
1107 
1108 /**
1109  * @fn            STATIC INLINE void RSI_PS_FsmHfFreqConfig(uint32_t freq)
1110  * @brief   This API is used to  configure the FSM high frequency clock range
1111  * @param[in]     freq : frequency in MHz pass 2 if it is 2MHz
1112  * @return    none
1113  */
RSI_PS_FsmHfFreqConfig(uint32_t freq)1114 STATIC INLINE void RSI_PS_FsmHfFreqConfig(uint32_t freq)
1115 {
1116   MCU_FSM->MCU_FSM_CLKS_REG_b.HF_FSM_CLK_FREQ = (unsigned int)(freq & 0x3F);
1117 }
1118 
1119 /**
1120  * @fn            STATIC INLINE void RSI_PS_FsmLfClkSel(AON_CLK_T fsmLfClk)
1121  * @brief   This API is used to configure the FSM low frequency clock
1122  * @param[in]     fsmLfClk enum value of the low frequency clock sources
1123  *                \ref MCUAON_KHZ_CLK_SEL_POR_RESET_STATUS_b
1124  * @return    none
1125  */
RSI_PS_FsmLfClkSel(AON_CLK_T fsmLfClk)1126 STATIC INLINE void RSI_PS_FsmLfClkSel(AON_CLK_T fsmLfClk)
1127 {
1128   MCU_AON->MCUAON_KHZ_CLK_SEL_POR_RESET_STATUS_b.AON_KHZ_CLK_SEL = fsmLfClk;
1129   while (MCU_AON->MCUAON_KHZ_CLK_SEL_POR_RESET_STATUS_b.AON_KHZ_CLK_SEL_CLOCK_SWITCHED != 1)
1130     ;
1131 }
1132 
1133 /**
1134  * @fn            STATIC INLINE void RSI_PS_PmuGoodTimeDurationConfig(uint8_t pmuDuration)
1135  * @brief   This API is used to  configure the PMU good time.
1136  * @param[in]     pmuDuration  (0 to 31) are possible value is applied in power of 2.
1137  * @return    none
1138  */
RSI_PS_PmuGoodTimeDurationConfig(uint8_t pmuDuration)1139 STATIC INLINE void RSI_PS_PmuGoodTimeDurationConfig(uint8_t pmuDuration)
1140 {
1141 #ifdef CHIP_9118
1142   MCU_FSM->MCU_FSM_XTAL_AND_PMU_GOOD_COUNT_REG_b.MCUFSM_PMU_POWERGOOD_DURATION_COUNT =
1143     (unsigned int)(pmuDuration & 0x1F);
1144 #endif
1145 #if defined(SLI_SI917) || defined(SLI_SI915)
1146   MCU_FSM->MCU_FSM_XTAL_AND_PMU_GOOD_COUNT_REG_b.MCUFSM_PMU_POWERGOOD_DURATION_COUNT =
1147     (unsigned int)(pmuDuration & 0x7F);
1148 #endif
1149 }
1150 
1151 /**
1152  * @fn            STATIC INLINE void  RSI_PS_XtalGoodTimeDurationConfig(uint8_t xtalDuration)
1153  * @brief   This API is used to  configure the XTAL good time.
1154  * @param[in]     xtalDuration  (0 to 31) are possible value is applied in power of 2.
1155  *                \ref MCU_FSM_XTAL_AND_PMU_GOOD_COUNT_REG_b
1156  * @return    none
1157  */
RSI_PS_XtalGoodTimeDurationConfig(uint8_t xtalDuration)1158 STATIC INLINE void RSI_PS_XtalGoodTimeDurationConfig(uint8_t xtalDuration)
1159 {
1160 #ifdef CHIP_9118
1161   MCU_FSM->MCU_FSM_XTAL_AND_PMU_GOOD_COUNT_REG_b.MCUFSM_XTAL_GOODTIME_DURATION_COUNT =
1162     (unsigned int)(xtalDuration & 0x1F);
1163 #endif
1164 #if defined(SLI_SI917) || defined(SLI_SI915)
1165   MCU_FSM->MCU_FSM_XTAL_AND_PMU_GOOD_COUNT_REG_b.MCUFSM_XTAL_GOODTIME_DURATION_COUNT =
1166     (unsigned int)(xtalDuration & 0x7F);
1167 #endif
1168 }
1169 
1170 /**
1171  * @fn            STATIC INLINE void RSI_PS_Ps2PmuLdoOffDelayConfig(uint8_t ldoOffDelay)
1172  * @brief   This API is used to  configure LDO off delay
1173  * @param[in]     ldoOffDelay  (0 to 31) are possible value is applied in power of 2.
1174  * @return    none
1175  */
RSI_PS_Ps2PmuLdoOffDelayConfig(uint8_t ldoOffDelay)1176 STATIC INLINE void RSI_PS_Ps2PmuLdoOffDelayConfig(uint8_t ldoOffDelay)
1177 {
1178   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.PS2_PMU_LDO_OFF_DELAY = (unsigned int)(ldoOffDelay & 0x1F);
1179 }
1180 
1181 /**
1182  * @fn            STATIC INLINE void RSI_PS_Ps4PmuLdoOnDelayConfig(uint8_t ldoOnDelay)
1183  * @brief   This API is used to  configure LDO on delay
1184  * @param[in]     ldoOnDelay  (0 to 31) are possible value is applied in power of 2.
1185  *                \ref MCU_FSM_POWER_CTRL_AND_DELAY_b
1186  * @return    none
1187  */
RSI_PS_Ps4PmuLdoOnDelayConfig(uint8_t ldoOnDelay)1188 STATIC INLINE void RSI_PS_Ps4PmuLdoOnDelayConfig(uint8_t ldoOnDelay)
1189 {
1190   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.PS4_SOCLDO_ON_DELAY = (unsigned int)(ldoOnDelay & 0xF);
1191 }
1192 
1193 /**
1194  * @fn            STATIC INLINE void RSI_PS_Ps4PmuBuckOnDelayConfig(uint8_t pmuBuckOnDelay)
1195  * @brief   This API is used to  configure buck on delay
1196  * @param[in]     pmuBuckOnDelay  (0 to 31) are possible value is applied in power of 2.
1197  *                \ref MCU_FSM_POWER_CTRL_AND_DELAY_b
1198  * @return    none
1199  */
RSI_PS_Ps4PmuBuckOnDelayConfig(uint8_t pmuBuckOnDelay)1200 STATIC INLINE void RSI_PS_Ps4PmuBuckOnDelayConfig(uint8_t pmuBuckOnDelay)
1201 {
1202   MCU_FSM->MCU_FSM_POWER_CTRL_AND_DELAY_b.PG4_BUCK_ON_DELAY = (unsigned int)(pmuBuckOnDelay & 0xF);
1203 }
1204 
1205 /**
1206  * @fn            STATIC INLINE uint32_t RSI_PS_GetWkpUpStatus(void)
1207  * @brief   This API is used to  get the wake up/ NPSS interrupt status
1208  *                \ref NPSS_INTR_STATUS_REG
1209  * @return        register bits of NPSS interrupt status register
1210  * @return      wakeup/NPSS intr status
1211  */
RSI_PS_GetWkpUpStatus(void)1212 STATIC INLINE uint32_t RSI_PS_GetWkpUpStatus(void)
1213 {
1214   return NPSS_INTR_STATUS_REG;
1215 }
1216 
1217 /**
1218  * @fn            STATIC INLINE uint32_t RSI_PS_GetComnIntrSts(void)
1219  * @brief   This API is used to  get the wake up/ NPSS common interrupt status
1220  * @return    register bits of NPSS interrupt status register
1221  *                \ref MCU_FSM_WAKEUP_STATUS_REG
1222  * @return    wake up/NPSS common inrerrupt status
1223  */
RSI_PS_GetComnIntrSts(void)1224 STATIC INLINE uint32_t RSI_PS_GetComnIntrSts(void)
1225 {
1226   return MCU_FSM->MCU_FSM_WAKEUP_STATUS_REG;
1227 }
1228 
1229 /**
1230  * @fn            STATIC INLINE void RSI_PS_NpssIntrUnMask(uint32_t mask)
1231  * @brief   This API is used to  un mask the NPSS interrupts
1232  * @param[in]     mask  is OR'ed value of the NPSS interrupt bits
1233  *                \ref NPSS_INTR_MASK_CLR_REG
1234  * @return    none
1235  */
RSI_PS_NpssIntrUnMask(uint32_t mask)1236 STATIC INLINE void RSI_PS_NpssIntrUnMask(uint32_t mask)
1237 {
1238   NPSS_INTR_MASK_CLR_REG = mask;
1239 }
1240 
1241 /**
1242  * @fn            STATIC INLINE void RSI_PS_NpssIntrMask(uint32_t mask)
1243  * @brief   This API is used to  mask the NPSS interrupts
1244  * @param[in]     mask  is OR'ed value of the NPSS interrupt bits
1245  *                \ref NPSS_INTR_MASK_SET_REG
1246  * @return    none
1247  */
RSI_PS_NpssIntrMask(uint32_t mask)1248 STATIC INLINE void RSI_PS_NpssIntrMask(uint32_t mask)
1249 {
1250   NPSS_INTR_MASK_SET_REG = mask;
1251 }
1252 
1253 /**
1254  * @fn            STATIC INLINE void RSI_PS_EnableLpSleep(boolean_t lpSleep)
1255  * @brief   This API is used to  enable/disable the lp sleep mode
1256  * @param[in]     lpSleep  1:enable lp sleep , 0 : disable lp sleep
1257  *                \ref MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE_b
1258  * @return    none
1259  */
RSI_PS_EnableLpSleep(boolean_t lpSleep)1260 STATIC INLINE void RSI_PS_EnableLpSleep(boolean_t lpSleep)
1261 {
1262   MCU_FSM->MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE_b.LP_SLEEP_MODE_b = (unsigned int)(lpSleep & 0x1);
1263 }
1264 
1265 /**
1266  *@fn              STATIC INLINE void RSI_PS_SkipXtalWaitTime(boolean_t val)
1267  *@brief           This API is used to  skip the XTAL wait time
1268  *@param[in]       val 1: skip XTAL wait time
1269  *                 0 Do not skip XTAL wait time
1270  *                 \ref MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE_b
1271  * @return    none
1272  */
RSI_PS_SkipXtalWaitTime(boolean_t val)1273 STATIC INLINE void RSI_PS_SkipXtalWaitTime(boolean_t val)
1274 {
1275   /*if package_type value is 5(M7DB) then don't skip xtal wait time   */
1276   if (package_type != 0x5) {
1277     MCU_FSM->MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE_b.SKIP_XTAL_WAIT_TIME = (unsigned int)(val & 0x1);
1278   }
1279 }
1280 /**
1281  *@fn              STATIC INLINE void RSI_PS_UlpToDcDcMode(void)
1282  *@brief           This API is configures SC-DCDC from LDO to DCDC Mode
1283  * @return    none
1284  */
RSI_PS_UlpToDcDcMode(void)1285 STATIC INLINE void RSI_PS_UlpToDcDcMode(void)
1286 {
1287   ULP_SPI_MEM_MAP(0x126) = 0x3E002F;
1288   ULP_SPI_MEM_MAP(0x128) = 0x200020;
1289 }
1290 
1291 /**
1292  *@fn              STATIC INLINE void RSI_PS_LatchCntrlSet(uint32_t val)
1293  *@brief           This API is used to set the latch configurations
1294  * @return    none
1295  */
RSI_PS_LatchCntrlSet(uint32_t val)1296 STATIC INLINE void RSI_PS_LatchCntrlSet(uint32_t val)
1297 {
1298   ULP_SPI_MEM_MAP(SELECT_BG_CLK) |= val;
1299 }
1300 
1301 /**
1302  *@fn              STATIC INLINE void RSI_PS_LatchCntrlClr(uint32_t val)
1303  *@brief           This API is used to clear the latch configurations
1304  * @return    none
1305  */
RSI_PS_LatchCntrlClr(uint32_t val)1306 STATIC INLINE void RSI_PS_LatchCntrlClr(uint32_t val)
1307 {
1308   ULP_SPI_MEM_MAP(SELECT_BG_CLK) &= ~val;
1309 }
1310 
1311 /**
1312  *@fn              STATIC INLINE void RSI_PS_BodPwrGateButtonCalibEnable(void)
1313  *@brief           This API is used to enable the power-gate enable signal for button calib and vbatt status checking block
1314  * @return    none
1315  */
RSI_PS_BodPwrGateButtonCalibEnable(void)1316 STATIC INLINE void RSI_PS_BodPwrGateButtonCalibEnable(void)
1317 {
1318   ULP_SPI_MEM_MAP(0x1E3) |= (BIT(15));
1319 }
1320 
1321 /**
1322  *@fn              STATIC INLINE void RSI_PS_BodPwrGateButtonCalibDisable(void)
1323  *@brief           This API is used to disable the power-gate enable signal for button calib and vbatt status checking block
1324  * @return    none
1325  */
RSI_PS_BodPwrGateButtonCalibDisable(void)1326 STATIC INLINE void RSI_PS_BodPwrGateButtonCalibDisable(void)
1327 {
1328   ULP_SPI_MEM_MAP(0x1E3) &= ~(BIT(15));
1329 }
1330 
1331 /**
1332  *@fn              STATIC INLINE void RSI_PS_XtalEnable(void)
1333  *@brief           This API is used to enable the XTAL
1334  *@return     none
1335  */
RSI_PS_XtalEnable(void)1336 STATIC INLINE void RSI_PS_XtalEnable(void)
1337 {
1338   *(volatile uint32_t *)0x41300480 |= (BIT(10));
1339 }
1340 
1341 /**
1342  *@fn              STATIC INLINE void RSI_PS_XtalDisable(void)
1343  *@brief           This API is used to disable the XTAL
1344  *@return     none
1345  */
RSI_PS_XtalDisable(void)1346 STATIC INLINE void RSI_PS_XtalDisable(void)
1347 {
1348   *(volatile uint32_t *)0x41300480 &= ~(BIT(10));
1349 }
1350 
1351 /**
1352  *@fn              STATIC INLINE void RSI_PS_QspiDllDomainEnable(void)
1353  *@brief           This API is used to enable the power to the QSPI-DLL module
1354  *@return     none
1355  */
RSI_PS_QspiDllDomainEnable(void)1356 STATIC INLINE void RSI_PS_QspiDllDomainEnable(void)
1357 {
1358   *(volatile uint32_t *)0x24048484 |= (BIT(2) | BIT(6));
1359 }
1360 
1361 /**
1362  *@fn              STATIC INLINE void RSI_PS_QspiDllDomainDisable(void)
1363  *@brief           This API is used to disable the power to the QSPI-DLL module
1364  *@return     none
1365  */
RSI_PS_QspiDllDomainDisable(void)1366 STATIC INLINE void RSI_PS_QspiDllDomainDisable(void)
1367 {
1368   *(volatile uint32_t *)0x24048484 &= ~(BIT(2) | BIT(6));
1369 }
1370 
1371 /**
1372  *@fn              STATIC INLINE void RSI_PS_LdoSocDefaultModeEnable(void)
1373  *@brief           This API is used to enable the SOC LDO default mode (Set high for 1.1 V (default mode))
1374  *@return     none
1375  */
RSI_PS_LdoSocDefaultModeEnable(void)1376 STATIC INLINE void RSI_PS_LdoSocDefaultModeEnable(void)
1377 {
1378   PMU_SPI_MEM_MAP(0x1D6) |= (BIT(5));
1379 }
1380 
1381 /**
1382  *@fn              STATIC INLINE void RSI_PS_LdoSocDefaultModeDisable(void)
1383  *@brief           This API is used to disable the SOC LDO default mode
1384  *@return     none
1385  */
RSI_PS_LdoSocDefaultModeDisable(void)1386 STATIC INLINE void RSI_PS_LdoSocDefaultModeDisable(void)
1387 {
1388   PMU_SPI_MEM_MAP(0x1D6) &= ~(BIT(5));
1389 }
1390 
1391 /**
1392  *@fn              void RSI_PS_BypassLdoRfEnable(void)
1393  *@brief           This API is used to enable bypass of LDO-RF enable and control bits to control from outside
1394  *@return     none
1395  */
RSI_PS_BypassLdoRfEnable(void)1396 STATIC INLINE void RSI_PS_BypassLdoRfEnable(void)
1397 {
1398   PMU_SPI_MEM_MAP(0x1D8) |= BIT(2);
1399 }
1400 
1401 /**
1402  *@fn              STATIC INLINE void RSI_PS_FlashLdoEnable(void)
1403  *@brief           This API is used to flash LDO enable.
1404  *@return     none
1405  */
RSI_PS_FlashLdoEnable(void)1406 STATIC INLINE void RSI_PS_FlashLdoEnable(void)
1407 {
1408   BATT_FF->MCU_PMU_LDO_CTRL_SET = BIT(0);
1409 }
1410 
1411 /**
1412  *@fn              STATIC INLINE void RSI_PS_FlashLdoDisable(void)
1413  *@brief           This API is used to disable flash LDO.
1414  *@return     none
1415  */
RSI_PS_FlashLdoDisable(void)1416 STATIC INLINE void RSI_PS_FlashLdoDisable(void)
1417 {
1418   BATT_FF->MCU_PMU_LDO_CTRL_CLEAR = BIT(0);
1419 }
1420 
1421 /**
1422  *@fn              void RSI_PS_BypassLdoRfDisable(void)
1423  *@brief           This API is used to disable bypass of LDO-RF enable and control bits to control from outside(i.e internal logic)
1424  *@return     none
1425  */
RSI_PS_BypassLdoRfDisable(void)1426 STATIC INLINE void RSI_PS_BypassLdoRfDisable(void)
1427 {
1428   PMU_SPI_MEM_MAP(0x1D8) &= ~BIT(2);
1429 }
1430 
1431 /**
1432  *@fn              STATIC INLINE void RSI_PS_SocPllSpiDisable(void)
1433  *@brief           This API is used to disable the Soc-PLL SPI PG
1434  *@return     none
1435  */
RSI_PS_SocPllSpiDisable(void)1436 STATIC INLINE void RSI_PS_SocPllSpiDisable(void)
1437 {
1438   BATT_FF->PLLCCI_PWRCTRL_REG_b.SOCPLL_SPI_PG_EN = 0U;
1439 }
1440 
1441 /**
1442  *@fn              STATIC INLINE void RSI_PS_SocPllVddIsoEnable(void)
1443  *@brief           This API is used to enable the Soc-PLL ISO VDD
1444  *@return     none
1445  */
RSI_PS_SocPllVddIsoEnable(void)1446 STATIC INLINE void RSI_PS_SocPllVddIsoEnable(void)
1447 {
1448   BATT_FF->PLLCCI_PWRCTRL_REG_b.SOCPLL_ISO_ENABLE = 1U;
1449 }
1450 
1451 /**
1452  *@fn              STATIC INLINE void RSI_PS_SocPllVddIsoDiable(void)
1453  *@brief           This API is used to disable the Soc-PLL ISO VDD
1454  *@return     none
1455  */
RSI_PS_SocPllVddIsoDiable(void)1456 STATIC INLINE void RSI_PS_SocPllVddIsoDiable(void)
1457 {
1458   BATT_FF->PLLCCI_PWRCTRL_REG_b.SOCPLL_ISO_ENABLE = 0U;
1459 }
1460 
1461 /**
1462  *@fn              STATIC INLINE void RSI_PS_SocPllSpiEnable(void)
1463  *@brief           This API is used to enable the Soc-PLL SPI PG
1464  *@return     none
1465  */
RSI_PS_SocPllSpiEnable(void)1466 STATIC INLINE void RSI_PS_SocPllSpiEnable(void)
1467 {
1468   BATT_FF->PLLCCI_PWRCTRL_REG_b.SOCPLL_SPI_PG_EN = 1U;
1469 }
1470 
1471 /**
1472  *@fn              STATIC INLINE void RSI_ConfigBuckBoost(uint8_t cntrl , uint8_t enable)
1473  *@brief           This API is used to control the buck boost
1474  *@param[in]       cntrl 0: Software controlled 1: Hardware controlled.
1475  *@param[in]       enable 0: Disabled if controlled by software(cntrl = 0) 1: Enabled if controlled by software(cntrl = 1)
1476  *@return     none
1477  */
RSI_ConfigBuckBoost(uint8_t cntrl,uint8_t enable)1478 STATIC INLINE void RSI_ConfigBuckBoost(uint8_t cntrl, uint8_t enable)
1479 {
1480   BATT_FF->MCU_FSM_CTRL_BYPASS_b.MCU_BUCK_BOOST_ENABLE_BYPASS      = (unsigned int)((enable & 0x1) & 0x01);
1481   BATT_FF->MCU_FSM_CTRL_BYPASS_b.MCU_BUCK_BOOST_ENABLE_BYPASS_CTRL = (unsigned int)((cntrl & 0x1) & 0x01);
1482 }
1483 
1484 /**
1485  *@fn              STATIC INLINE void RSI_ConfigPmuShutDown(uint8_t cntrl , uint8_t enable)
1486  *@brief           This API is used to control the pmu shut down mode
1487  *@param[in]       cntrl 0: Software controlled 1: Hardware controlled.
1488  *@param[in]       enable 0: Disabled if controlled by software(cntrl = 0) 1: Enabled if controlled by software(cntrl = 1)
1489  *@return     none
1490  */
RSI_ConfigPmuShutDown(uint8_t cntrl,uint8_t enable)1491 STATIC INLINE void RSI_ConfigPmuShutDown(uint8_t cntrl, uint8_t enable)
1492 {
1493   BATT_FF->MCU_FSM_CTRL_BYPASS_b.MCU_PMU_SHUT_DOWN_BYPASS      = (unsigned int)((enable & 0x1) & 0x01);
1494   BATT_FF->MCU_FSM_CTRL_BYPASS_b.MCU_PMU_SHUT_DOWN_BYPASS_CTRL = (unsigned int)((cntrl & 0x1) & 0x01);
1495 }
1496 
1497 /**
1498  *@fn              STATIC INLINE void RSI_ChangeTassRefClock(void)
1499  *@brief           This API is used to change the TASS reference clock to MHz RC , This API is used only in MCU mode , should not be used in WiSeMCU mode.
1500  *@return     none
1501  */
RSI_ChangeTassRefClock(void)1502 STATIC INLINE void RSI_ChangeTassRefClock(void)
1503 {
1504   *(volatile uint32_t *)0x41300110 = (1 << 23) | (1 << 16) | (1 << 4) | 1;
1505 }
1506 
1507 /**
1508  *@fn              STATIC INLINE void RSI_SetRegSpiDivision(uint8_t div)
1509  *@brief           This API is used to change the reg access SPI clock division factor.
1510  *@return     none
1511  */
RSI_SetRegSpiDivision(uint8_t div)1512 STATIC INLINE void RSI_SetRegSpiDivision(uint8_t div)
1513 {
1514   *(volatile uint32_t *)(REG_SPI_BASE_ADDR_ULP + 0x00) &= ~0xF;
1515   *(volatile uint32_t *)(REG_SPI_BASE_ADDR_ULP + 0x00) |= div;
1516 }
1517 
1518 /**
1519  *@fn              STATIC INLINE void RSI_ConfigXtal(uint8_t cntrl , uint8_t enable)
1520  *@brief           This API is used to control the Xtal
1521  *@param[in]       cntrl 0: Software controlled 1: Hardware controlled.
1522  *@param[in]       enable 0: Disabled if controlled by software(cntrl = 0) 1: Enabled if controlled by software(cntrl = 1)
1523  *@return     none
1524  */
RSI_ConfigXtal(uint8_t cntrl,uint8_t enable)1525 STATIC INLINE void RSI_ConfigXtal(uint8_t cntrl, uint8_t enable)
1526 {
1527   BATT_FF->MCU_FSM_CTRL_BYPASS_b.MCU_XTAL_EN_40MHZ_BYPASS      = (unsigned int)((enable & 0x1) & 0x01);
1528   BATT_FF->MCU_FSM_CTRL_BYPASS_b.MCU_XTAL_EN_40MHZ_BYPASS_CTRL = (unsigned int)((cntrl & 0x1) & 0x01);
1529 }
1530 
1531 /**
1532  *@fn              STATIC INLINE void RSI_PS_PmuUltraSleepConfig(boolean_t en)
1533  *@brief           This API is used to enable the 'NPSS_PMU_STANDBY'
1534  *@param[in]       en 1: enable the 'NPSS_PMU_STANDBY'
1535  *                 en 0: disable the 'NPSS_PMU_STANDBY'
1536  *@return     none
1537  */
RSI_PS_PmuUltraSleepConfig(boolean_t en)1538 STATIC INLINE void RSI_PS_PmuUltraSleepConfig(boolean_t en)
1539 {
1540   MCU_FSM->MCU_FSM_PMU_STATUS_REG_b.STANDBY_DC1P3_R = (unsigned int)(en & 0x01);
1541 }
1542 
1543 /**
1544  *@fn              STATIC INLINE void RSI_PS_PmuSetConfig(uint32_t  mask)
1545  *@brief           This API is used to enable/set the PMU status
1546  *@param[in]       mask : Ored values of PMU status bits
1547  *                 \n Following are the possible parameters for this parameter
1548  *                 \n PMU_STS_DCDC_ON
1549  *                 \n PMU_STS_FLASH_LDO_ON
1550  *                 \n PMU_STS_SOC_LDO_ON
1551  *@return     none
1552  */
RSI_PS_PmuSetConfig(uint32_t mask)1553 STATIC INLINE void RSI_PS_PmuSetConfig(uint32_t mask)
1554 {
1555   MCU_FSM->MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE |= mask;
1556 }
1557 
1558 /**
1559  *@fn              STATIC INLINE void RSI_PS_PmuClrConfig(uint32_t  mask)
1560  *@brief           This API is used to disable/clear the PMU status
1561  *@param[in]       mask : Ored values of PMU status bits
1562  *                 \n Following are the possible parameters for this parameter
1563  *                 \n PMU_STS_DCDC_ON
1564  *                 \n PMU_STS_FLASH_LDO_ON
1565  *                 \n PMU_STS_SOC_LDO_ON
1566  *@return     none
1567  */
RSI_PS_PmuClrConfig(uint32_t mask)1568 STATIC INLINE void RSI_PS_PmuClrConfig(uint32_t mask)
1569 {
1570   MCU_FSM->MCU_FSM_SLEEP_CTRLS_AND_WAKEUP_MODE &= ~mask;
1571 }
1572 
1573 /**
1574  *@fn         void RSI_PS_AnalogPeriPtatEnable(void)
1575  *@brief      This API is used to enable the ptat currents to analog peripherals
1576  * @return    execution status
1577  */
RSI_PS_AnalogPeriPtatEnable(void)1578 STATIC INLINE uint32_t RSI_PS_AnalogPeriPtatEnable(void)
1579 {
1580   return RSI_IPMU_ProgramConfigData(ana_perif_ptat_common_config1);
1581 }
1582 
1583 /**
1584  *@fn         void RSI_PS_AnalogPeriPtatDisable(void)
1585  *@brief      This API is used to disable the ptat currents to analog peripherals
1586  *@return     execution status
1587  */
RSI_PS_AnalogPeriPtatDisable(void)1588 STATIC INLINE uint32_t RSI_PS_AnalogPeriPtatDisable(void)
1589 {
1590   return RSI_IPMU_ProgramConfigData(ana_perif_ptat_common_config2);
1591 }
1592 
1593 /**
1594  *@fn         void RSI_PS_BodClksPtatEnable(void)
1595  *@brief      This API is used to enable the ptat currents to clocks and bod(cmp_npss)
1596  *@return     execution status
1597  */
RSI_PS_BodClksPtatEnable(void)1598 STATIC INLINE uint32_t RSI_PS_BodClksPtatEnable(void)
1599 {
1600   return RSI_IPMU_ProgramConfigData(ipmu_bod_clks_common_config1);
1601 }
1602 
1603 /**
1604  *@fn         void RSI_PS_BodClksPtatDisable(void)
1605  *@brief      This API is used to disable the ptat currents to clocks and bod(cmp_npss)
1606  *@return     execution status
1607  */
RSI_PS_BodClksPtatDisable(void)1608 STATIC INLINE uint32_t RSI_PS_BodClksPtatDisable(void)
1609 {
1610   return RSI_IPMU_ProgramConfigData(ipmu_bod_clks_common_config2);
1611 }
1612 
1613 /**
1614  *@fn         void RSI_PS_PS4SetRegisters(void)
1615  *@brief      This API is used configure the registers for clock more than 120 MHz in PS4
1616  *@return     none
1617  */
RSI_PS_PS4SetRegisters(void)1618 STATIC INLINE void RSI_PS_PS4SetRegisters(void)
1619 {
1620   // Configure the prefetch and registering when SOC clock is more than 120 MHz
1621   ICACHE2_ADDR_TRANSLATE_1_REG = BIT(21); // Icache registering when clock frequency is more than 120 MHz
1622   // When set, enables registering in M4-NWP AHB2AHB. This will have performance penalty. This has to be set above 100 MHz
1623   MISC_CFG_SRAM_REDUNDANCY_CTRL = BIT(4);
1624   MISC_CONFIG_MISC_CTRL1 |= BIT(4); // Enable Register ROM as clock frequency is 200 MHz
1625 }
1626 
1627 /**
1628  *@fn         void RSI_PS_PS4ClearRegisters(void)
1629  *@brief      This API is used to clear the MISC registers for clock less than 120 MHz for core
1630  *@return     none
1631  */
RSI_PS_PS4ClearRegisters(void)1632 STATIC INLINE void RSI_PS_PS4ClearRegisters(void)
1633 {
1634   // Clears the prefetch and registering when SOC clock is less than 120 MHz
1635   ICACHE2_ADDR_TRANSLATE_1_REG &= ~BIT(21); // Clearing Icache registering when clock frequency is less than 120 MHz
1636   // When set, enables registering in M4-NWP AHB2AHB. This will have performance penalty. This has to be set above 100 MHz
1637   MISC_CFG_SRAM_REDUNDANCY_CTRL &= ~BIT(4);
1638   MISC_CONFIG_MISC_CTRL1 &= ~BIT(4); // Disable Register ROM as clock frequency is less than 120 MHz
1639 }
1640 
1641 /**
1642  *@fn         void RSI_PS_PS2UpdateClockVariable(void)
1643  *@brief      This API is used update the global clock variable after clock setting in PS2
1644  *@return     none
1645  */
RSI_PS_PS2UpdateClockVariable(void)1646 STATIC INLINE void RSI_PS_PS2UpdateClockVariable(void)
1647 {
1648   // Updates the system clock.
1649   system_clocks.rc_mhz_clock = 20000000;
1650   // Updating the systemcoreclock variable.
1651   SystemCoreClock = 20000000;
1652 }
1653 
1654 /**
1655  *@fn         void RSI_PS_WakeupTAandProgramFlash(void)
1656  *@brief      This API is used wakeup the NWP and program the flash
1657  *@return     none
1658  */
RSI_PS_WakeupTAandProgramFlash(void)1659 STATIC INLINE void RSI_PS_WakeupTAandProgramFlash(void)
1660 {
1661   if (!(P2P_STATUS_REGISTER & BIT(3))) {
1662     //!wakeup NWP
1663     P2P_STATUS_REGISTER |= BIT(0);
1664     //!wait for NWP active
1665     while (!(P2P_STATUS_REGISTER & BIT(3)))
1666       ;
1667   }
1668   //! Request NWP to program flash
1669   //! raise an interrupt to NWP register
1670   M4SS_P2P_INTR_SET_REGISTER = BIT(4);
1671   P2P_STATUS_REGISTER        = BIT(0);
1672 
1673   while (!(P2P_STATUS_REGISTER & BIT(3)))
1674     ;
1675 }
1676 
1677 /**
1678  *@fn         void RSI_PS_SetMCUActiveStatus(void)
1679  *@brief      This API is used set the active status of mcu after wakeup
1680  *@return     none
1681  */
RSI_PS_SetMCUActiveStatus(void)1682 STATIC INLINE void RSI_PS_SetMCUActiveStatus(void)
1683 {
1684   P2P_STATUS_REGISTER = BIT(1);
1685 }
1686 
1687 /**
1688  *@fn         void RSI_PS_IsPS2State(void)
1689  *@brief      This API is used to check is current state is PS2 or not
1690  *@return     true if PS2 state false if not
1691  */
RSI_PS_IsPS2State(void)1692 STATIC INLINE boolean_t RSI_PS_IsPS2State(void)
1693 {
1694   return (M4_ULP_SLP_STATUS_REG & ULP_MODE_SWITCHED_NPSS);
1695 }
1696 
1697 /** @} */
1698 
1699 /* @} end of RSI_POWER_SAVE */
1700 
1701 void ps_clr_wkp_up_status(uint32_t wakeUpIntrClear);
1702 
1703 void ps_bg_ldo_config(uint8_t ldo_0p6_ctrl, uint8_t ldo_0p6_lp_mode);
1704 
1705 void ps_configure_trim_values(uint16_t lf_ro_trim,
1706                               uint16_t lf_rc_trim,
1707                               uint16_t hf_ro_trim,
1708                               uint16_t hf_rc_trim,
1709                               uint16_t bg_ptat_trim,
1710                               uint16_t bg_trim);
1711 
1712 void ps_wireless_shutdown(void);
1713 
1714 /*End of file not truncated*/
1715 #ifdef __cplusplus
1716 }
1717 #endif
1718 
1719 #endif /*__RSI_POWER_SAVE_H__*/
1720