1 /*******************************************************************************
2 * @file rsi_wwdt.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 #ifndef __RSI_WDT_H__
34 #define __RSI_WDT_H__
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 #include "rsi_ccp_common.h"
40 #include "base_types.h"
41 #include "rsi_power_save.h"
42
43 #ifndef UNUSED_PARAMETER
44 #define UNUSED_PARAMETER(x) (void)(x)
45 #endif // UNUSED_PARAMETER
46
47 #define WDT_SYSTEM_RESET_TIMER 0x3
48 #define WDT_INTERRUPT_TIMER 0x1
49 #define WDT_IRQHandler IRQ020_Handler /*!<WDT IRQ Handler*/
50 #define NVIC_WDT NPSS_TO_MCU_WDT_INTR_IRQn /*!<WDT NVIC IRQ Numb */
51
52 /**
53 * @fn void RSI_WWDT_ConfigWindowTimer(MCU_WDT_Type *pstcWDT , uint16_t u16IntrTimerVal)
54 * @brief This API is used to configure the window timer of the watch dog timer
55 * @param[in] pstcWDT : pointer to the WDT register instance
56 * @param[in] u16WindowTimerVal : window timer value
57 * @return None
58 */
RSI_WWDT_ConfigWindowTimer(MCU_WDT_Type * pstcWDT,uint8_t u8WindowTimerVal)59 STATIC INLINE void RSI_WWDT_ConfigWindowTimer(MCU_WDT_Type *pstcWDT, uint8_t u8WindowTimerVal)
60 {
61 pstcWDT->MCU_WWD_WINDOW_TIMER_b.WINDOW_TIMER = (unsigned int)(u8WindowTimerVal & 0x0F);
62 }
63
64 /**
65 * @fn void RSI_WWDT_ConfigIntrTimer(MCU_WDT_Type *pstcWDT , uint16_t u16IntrTimerVal)
66 * @brief This API is used to configure the interrupt timer of the watch dog timer
67 * @param[in] pstcWDT : pointer to the WDT register instance
68 * @param[in] u16IntrTimerVal : interrupt timer value
69 * @return None
70 */
RSI_WWDT_ConfigIntrTimer(MCU_WDT_Type * pstcWDT,uint16_t u16IntrTimerVal)71 STATIC INLINE void RSI_WWDT_ConfigIntrTimer(MCU_WDT_Type *pstcWDT, uint16_t u16IntrTimerVal)
72 {
73 pstcWDT->MCU_WWD_INTERRUPT_TIMER_b.WWD_INTERRUPT_TIMER = (unsigned int)(u16IntrTimerVal & 0x1F);
74 }
75
76 /**
77 * @fn void RSI_WWDT_ConfigSysRstTimer(MCU_WDT_Type *pstcWDT , uint16_t u16SysRstVal)
78 * @brief This API is used to configure the system reset timer of the watch dog timer
79 * @param[in] pstcWDT : pointer to the WDT register instance
80 * @param[in] u16SysRstVal : reset value
81 * @return NONE
82 */
RSI_WWDT_ConfigSysRstTimer(MCU_WDT_Type * pstcWDT,uint16_t u16SysRstVal)83 STATIC INLINE void RSI_WWDT_ConfigSysRstTimer(MCU_WDT_Type *pstcWDT, uint16_t u16SysRstVal)
84 {
85 pstcWDT->MCU_WWD_SYSTEM_RESET_TIMER_b.WWD_SYSTEM_RESET_TIMER = (unsigned int)(u16SysRstVal & 0x1F);
86 }
87
88 /**
89 * @fn void RSI_WWDT_Disable(MCU_WDT_Type *pstcWDT)
90 * @brief This API is used to Disable the Watch dog timer
91 * @param[in] pstcWDT :pointer to the WDT register instance
92 * @return None
93 */
RSI_WWDT_Disable(MCU_WDT_Type * pstcWDT)94 STATIC INLINE void RSI_WWDT_Disable(MCU_WDT_Type *pstcWDT)
95 {
96 /*0xF0 to Disable the watch dog */
97 pstcWDT->MCU_WWD_MODE_AND_RSTART_b.WWD_MODE_EN_STATUS = 0xF0;
98 }
99
100 /**
101 * @fn void RSI_WWDT_ReStart(MCU_WDT_Type *pstcWDT)
102 * @brief This API is used to restart the Watch dog timer
103 * @param[in] pstcWDT :pointer to the WDT register instance
104 * @return None
105 */
RSI_WWDT_ReStart(MCU_WDT_Type * pstcWDT)106 STATIC INLINE void RSI_WWDT_ReStart(MCU_WDT_Type *pstcWDT)
107 {
108 pstcWDT->MCU_WWD_MODE_AND_RSTART_b.WWD_MODE_RSTART = 1U;
109 }
110
111 /**
112 * @fn void RSI_WWDT_IntrUnMask(void)
113 * @brief This API is used to unmask the Watch dog timer
114 * @return None
115 */
RSI_WWDT_IntrUnMask(void)116 STATIC INLINE void RSI_WWDT_IntrUnMask(void)
117 {
118 NPSS_INTR_MASK_CLR_REG = NPSS_TO_MCU_WDT_INTR;
119 }
120
121 /**
122 * @fn void RSI_WWDT_IntrMask(void)
123 * @brief This API is used to mask the Watch dog timer
124 * @return None
125 */
RSI_WWDT_IntrMask(void)126 STATIC INLINE void RSI_WWDT_IntrMask(void)
127 {
128 NPSS_INTR_MASK_SET_REG = NPSS_TO_MCU_WDT_INTR;
129 }
130
131 /**
132 * @fn void RSI_WWDT_SysRstOnProcLockEnable(MCU_WDT_Type *pstcWDT)
133 * @brief This API is used to enable Watch dog timer to reset system on processor stuck
134 * @return None
135 */
RSI_WWDT_SysRstOnProcLockEnable(MCU_WDT_Type * pstcWDT)136 STATIC INLINE void RSI_WWDT_SysRstOnProcLockEnable(MCU_WDT_Type *pstcWDT)
137 {
138 pstcWDT->MCU_WWD_ARM_STUCK_EN_b.PROCESSOR_STUCK_RESET_EN = ENABLE;
139 }
140
141 /**
142 * @fn void RSI_WWDT_SysRstOnProcLockDisable(MCU_WDT_Type *pstcWDT)
143 * @brief This API is used to disable Watch dog timer to reset system on processor stuck
144 * @return None
145 */
RSI_WWDT_SysRstOnProcLockDisable(MCU_WDT_Type * pstcWDT)146 STATIC INLINE void RSI_WWDT_SysRstOnProcLockDisable(MCU_WDT_Type *pstcWDT)
147 {
148 pstcWDT->MCU_WWD_ARM_STUCK_EN_b.PROCESSOR_STUCK_RESET_EN = DISABLE;
149 }
150
151 /**
152 * @fn void RSI_WWDT_GetProcLockSignal(const MCU_WDT_Type *pstcWDT)
153 * @brief This API is used to read signal for processor stuck reset enable
154 * @return None
155 */
RSI_WWDT_GetProcLockRstEnableSignal(const MCU_WDT_Type * pstcWDT)156 STATIC INLINE uint8_t RSI_WWDT_GetProcLockRstEnableSignal(const MCU_WDT_Type *pstcWDT)
157 {
158 if (pstcWDT->MCU_WWD_ARM_STUCK_EN_b.PROCESSOR_STUCK_RESET_EN_) {
159 return 1;
160 } else {
161 return 0;
162 }
163 }
164
165 /**
166 * @fn uint16_t RSI_WWDT_GetIntrTime(const MCU_WDT_Type *pstcWDT)
167 * @brief This API is used to read the interrupt time of the watch dog timer
168 * @param[in] pstcWDT : pointer to the WDT register instance
169 * @return uint8_t : interrupt timer value
170 */
RSI_WWDT_GetIntrTime(const MCU_WDT_Type * pstcWDT)171 STATIC INLINE uint8_t RSI_WWDT_GetIntrTime(const MCU_WDT_Type *pstcWDT)
172 {
173 uint8_t interrupt_time;
174 interrupt_time = pstcWDT->MCU_WWD_INTERRUPT_TIMER_b.WWD_INTERRUPT_TIMER;
175 return interrupt_time;
176 }
177
178 /**
179 * @fn uint16_t RSI_WWDT_GetSysRstTime(const MCU_WDT_Type *pstcWDT)
180 * @brief This API is used to read the system reset time of the watch dog timer
181 * @param[in] pstcWDT : pointer to the WDT register instance
182 * @return uint8_t : system reset timer value
183 */
RSI_WWDT_GetSysRstTime(const MCU_WDT_Type * pstcWDT)184 STATIC INLINE uint8_t RSI_WWDT_GetSysRstTime(const MCU_WDT_Type *pstcWDT)
185 {
186 uint8_t system_reset_time;
187 system_reset_time = pstcWDT->MCU_WWD_SYSTEM_RESET_TIMER_b.WWD_SYSTEM_RESET_TIMER;
188 return system_reset_time;
189 }
190
191 /**
192 * @fn uint8_t RSI_WWDT_GetWindowTime(const MCU_WDT_Type *pstcWDT)
193 * @brief This API is used to read the system reset time of the watch dog timer
194 * @param[in] pstcWDT : pointer to the WDT register instance
195 * @return uint8_t : system reset timer value
196 */
RSI_WWDT_GetWindowTime(const MCU_WDT_Type * pstcWDT)197 STATIC INLINE uint8_t RSI_WWDT_GetWindowTime(const MCU_WDT_Type *pstcWDT)
198 {
199 uint8_t window_time;
200 window_time = pstcWDT->MCU_WWD_WINDOW_TIMER_b.WINDOW_TIMER;
201 return window_time;
202 }
203 // Function prototypes
204 void RSI_WWDT_IntrClear(void);
205
206 uint8_t RSI_WWDT_GetIntrStatus(void);
207
208 void RSI_WWDT_DeInit(MCU_WDT_Type *pstcWDT);
209
210 void RSI_WWDT_Start(MCU_WDT_Type *pstcWDT);
211
212 void RSI_WWDT_Init(MCU_WDT_Type *pstcWDT);
213 void IRQ020_Handler(void);
214
215 #ifdef __cplusplus
216 }
217 #endif
218
219 /*End of file not truncated*/
220 #endif /*__RSI_WDT_H__*/
221