EFM32 Gecko Software Documentation  efm32g-doc-5.1.2
em_wdog.h
Go to the documentation of this file.
1 /***************************************************************************/
34 #ifndef EM_WDOG_H
35 #define EM_WDOG_H
36 
37 #include "em_device.h"
38 #if defined(WDOG_COUNT) && (WDOG_COUNT > 0)
39 
40 #include <stdbool.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /***************************************************************************/
51 /***************************************************************************/
56 /*******************************************************************************
57  ******************************** ENUMS ************************************
58  ******************************************************************************/
59 
61 typedef enum
62 {
67 
69 typedef enum
70 {
71  wdogPeriod_9 = 0x0,
72  wdogPeriod_17 = 0x1,
73  wdogPeriod_33 = 0x2,
74  wdogPeriod_65 = 0x3,
78  wdogPeriod_1k = 0x7,
79  wdogPeriod_2k = 0x8,
80  wdogPeriod_4k = 0x9,
81  wdogPeriod_8k = 0xA,
88 
89 
90 #if defined( _WDOG_CTRL_WARNSEL_MASK )
91 
92 typedef enum
93 {
94  wdogWarnDisable = 0,
95  wdogWarnTime25pct = 1,
96  wdogWarnTime50pct = 2,
97  wdogWarnTime75pct = 3,
98 } WDOG_WarnSel_TypeDef;
99 #endif
100 
101 #if defined( _WDOG_CTRL_WINSEL_MASK )
102 
103 typedef enum
104 {
105  wdogIllegalWindowDisable = 0,
106  wdogIllegalWindowTime12_5pct = 1,
107  wdogIllegalWindowTime25_0pct = 2,
108  wdogIllegalWindowTime37_5pct = 3,
109  wdogIllegalWindowTime50_0pct = 4,
110  wdogIllegalWindowTime62_5pct = 5,
111  wdogIllegalWindowTime75_0pct = 6,
112  wdogIllegalWindowTime87_5pct = 7,
113 } WDOG_WinSel_TypeDef;
114 #endif
115 
116 /*******************************************************************************
117  ******************************* STRUCTS ***********************************
118  ******************************************************************************/
119 
121 typedef struct
122 {
124  bool enable;
125 
127  bool debugRun;
128 
130  bool em2Run;
131 
133  bool em3Run;
134 
136  bool em4Block;
137 
140 
142  bool lock;
143 
146 
149 
150 #if defined( _WDOG_CTRL_WARNSEL_MASK )
151 
152  WDOG_WarnSel_TypeDef warnSel;
153 #endif
154 
155 #if defined( _WDOG_CTRL_WINSEL_MASK )
156 
157  WDOG_WinSel_TypeDef winSel;
158 #endif
159 
160 #if defined( _WDOG_CTRL_WDOGRSTDIS_MASK )
161 
162  bool resetDisable;
163 #endif
164 
166 
168 #if defined( _WDOG_CTRL_WARNSEL_MASK ) \
169  && defined( _WDOG_CTRL_WDOGRSTDIS_MASK ) \
170  && defined( _WDOG_CTRL_WINSEL_MASK )
171 #define WDOG_INIT_DEFAULT \
172 { \
173  true, /* Start watchdog when init done */ \
174  false, /* WDOG not counting during debug halt */ \
175  false, /* WDOG not counting when in EM2 */ \
176  false, /* WDOG not counting when in EM3 */ \
177  false, /* EM4 can be entered */ \
178  false, /* Do not block disabling LFRCO/LFXO in CMU */ \
179  false, /* Do not lock WDOG configuration (if locked,
180  reset needed to unlock) */ \
181  wdogClkSelULFRCO, /* Select 1kHZ WDOG oscillator */ \
182  wdogPeriod_256k, /* Set longest possible timeout period */ \
183  wdogWarnDisable, /* Disable warning interrupt */ \
184  wdogIllegalWindowDisable, /* Disable illegal window interrupt */ \
185  false /* Do not disable reset */ \
186 }
187 #else
188 #define WDOG_INIT_DEFAULT \
189 { \
190  true, /* Start watchdog when init done */ \
191  false, /* WDOG not counting during debug halt */ \
192  false, /* WDOG not counting when in EM2 */ \
193  false, /* WDOG not counting when in EM3 */ \
194  false, /* EM4 can be entered */ \
195  false, /* Do not block disabling LFRCO/LFXO in CMU */ \
196  false, /* Do not lock WDOG configuration (if locked,
197  reset needed to unlock) */ \
198  wdogClkSelULFRCO, /* Select 1kHZ WDOG oscillator */ \
199  wdogPeriod_256k /* Set longest possible timeout period */ \
200 }
201 #endif
202 
203 
204 /*******************************************************************************
205  ***************************** PROTOTYPES **********************************
206  ******************************************************************************/
207 
208 void WDOGn_Enable(WDOG_TypeDef *wdog, bool enable);
209 void WDOGn_Feed(WDOG_TypeDef *wdog);
210 void WDOGn_Init(WDOG_TypeDef *wdog, const WDOG_Init_TypeDef *init);
211 void WDOGn_Lock(WDOG_TypeDef *wdog);
212 
213 
214 #if defined( _WDOG_IF_MASK )
215 /***************************************************************************/
226 __STATIC_INLINE void WDOGn_IntClear(WDOG_TypeDef *wdog, uint32_t flags)
227 {
228  wdog->IFC = flags;
229 }
230 
231 /***************************************************************************/
242 __STATIC_INLINE void WDOGn_IntDisable(WDOG_TypeDef *wdog, uint32_t flags)
243 {
244  wdog->IEN &= ~flags;
245 }
246 
247 /***************************************************************************/
263 __STATIC_INLINE void WDOGn_IntEnable(WDOG_TypeDef *wdog, uint32_t flags)
264 {
265  wdog->IEN |= flags;
266 }
267 
268 /***************************************************************************/
282 __STATIC_INLINE uint32_t WDOGn_IntGet(WDOG_TypeDef *wdog)
283 {
284  return wdog->IF;
285 }
286 
287 /***************************************************************************/
301 __STATIC_INLINE uint32_t WDOGn_IntGetEnabled(WDOG_TypeDef *wdog)
302 {
303  uint32_t tmp;
304 
305  tmp = wdog->IEN;
306 
307  /* Bitwise AND of pending and enabled interrupt flags. */
308  return wdog->IF & tmp;
309 }
310 
311 /***************************************************************************/
322 __STATIC_INLINE void WDOGn_IntSet(WDOG_TypeDef *wdog, uint32_t flags)
323 {
324  wdog->IFS = flags;
325 }
326 #endif
327 
328 
330 #if !defined(DEFAULT_WDOG)
331 #if defined(WDOG)
332 #define DEFAULT_WDOG WDOG
333 #elif defined(WDOG0)
334 #define DEFAULT_WDOG WDOG0
335 #endif
336 #endif
337 
338 /***************************************************************************/
350 __STATIC_INLINE void WDOG_Enable(bool enable)
351 {
352  WDOGn_Enable(DEFAULT_WDOG, enable);
353 }
354 
355 
356 /***************************************************************************/
364 __STATIC_INLINE void WDOG_Feed(void)
365 {
367 }
368 
369 
370 /***************************************************************************/
383 __STATIC_INLINE void WDOG_Init(const WDOG_Init_TypeDef *init)
384 {
385  WDOGn_Init(DEFAULT_WDOG, init);
386 }
387 
388 
389 /***************************************************************************/
397 __STATIC_INLINE void WDOG_Lock(void)
398 {
400 }
401 
402 
406 #ifdef __cplusplus
407 }
408 #endif
409 
410 #endif /* defined(WDOG_COUNT) && (WDOG_COUNT > 0) */
411 #endif /* EM_WDOG_H */
WDOG_ClkSel_TypeDef clkSel
Definition: em_wdog.h:145
__STATIC_INLINE void WDOG_Init(const WDOG_Init_TypeDef *init)
Initialize watchdog (assuming the watchdog configuration has not been locked).
Definition: em_wdog.h:383
#define _WDOG_CTRL_CLKSEL_LFRCO
Definition: efm32g_wdog.h:100
void WDOGn_Lock(WDOG_TypeDef *wdog)
Lock the watchdog configuration.
Definition: em_wdog.c:243
__STATIC_INLINE void WDOG_Enable(bool enable)
Enable/disable the watchdog timer.
Definition: em_wdog.h:350
__STATIC_INLINE void WDOG_Lock(void)
Lock the watchdog configuration.
Definition: em_wdog.h:397
#define DEFAULT_WDOG
Definition: em_wdog.h:332
#define _WDOG_CTRL_CLKSEL_LFXO
Definition: efm32g_wdog.h:101
WDOG_PeriodSel_TypeDef perSel
Definition: em_wdog.h:148
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
void WDOGn_Init(WDOG_TypeDef *wdog, const WDOG_Init_TypeDef *init)
Initialize watchdog (assuming the watchdog configuration has not been locked).
Definition: em_wdog.c:158
__STATIC_INLINE void WDOG_Feed(void)
Feed the watchdog.
Definition: em_wdog.h:364
void WDOGn_Enable(WDOG_TypeDef *wdog, bool enable)
Enable/disable the watchdog timer.
Definition: em_wdog.c:75
#define _WDOG_CTRL_CLKSEL_ULFRCO
Definition: efm32g_wdog.h:99
WDOG_ClkSel_TypeDef
Definition: em_wdog.h:61
WDOG_PeriodSel_TypeDef
Definition: em_wdog.h:69
void WDOGn_Feed(WDOG_TypeDef *wdog)
Feed the watchdog.
Definition: em_wdog.c:115