1 /***************************************************************************//**
2  * @file
3  * @brief Watchdog (WDOG) peripheral API
4  * @author Energy Micro AS
5  * @version 3.0.0
6  *******************************************************************************
7  * @section License
8  * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
9  *******************************************************************************
10  *
11  * Permission is granted to anyone to use this software for any purpose,
12  * including commercial applications, and to alter it and redistribute it
13  * freely, subject to the following restrictions:
14  *
15  * 1. The origin of this software must not be misrepresented; you must not
16  *    claim that you wrote the original software.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  *    misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  *
21  * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
22  * obligation to support this Software. Energy Micro AS is providing the
23  * Software "AS IS", with no express or implied warranties of any kind,
24  * including, but not limited to, any implied warranties of merchantability
25  * or fitness for any particular purpose or warranties against infringement
26  * of any proprietary rights of a third party.
27  *
28  * Energy Micro AS will not be liable for any consequential, incidental, or
29  * special damages, or any other relief, or for any claim by any third party,
30  * arising from your use of this Software.
31  *
32  ******************************************************************************/
33 #ifndef __EM_WDOG_H
34 #define __EM_WDOG_H
35 
36 #include <stdbool.h>
37 #include "em_part.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /***************************************************************************//**
44  * @addtogroup EM_Library
45  * @{
46  ******************************************************************************/
47 
48 /***************************************************************************//**
49  * @addtogroup WDOG
50  * @{
51  ******************************************************************************/
52 
53 /*******************************************************************************
54  ********************************   ENUMS   ************************************
55  ******************************************************************************/
56 
57 /** Watchdog clock selection. */
58 typedef enum
59 {
60   wdogClkSelULFRCO = _WDOG_CTRL_CLKSEL_ULFRCO,   /**< Ultra low frequency (1 kHz) clock */
61   wdogClkSelLFRCO  = _WDOG_CTRL_CLKSEL_LFRCO,    /**< Low frequency RC oscillator */
62   wdogClkSelLFXO   = _WDOG_CTRL_CLKSEL_LFXO      /**< Low frequency crystal oscillator */
63 } WDOG_ClkSel_TypeDef;
64 
65 /** Watchdog period selection. */
66 typedef enum
67 {
68   wdogPeriod_9    = 0x0, /**< 9 clock periods */
69   wdogPeriod_17   = 0x1, /**< 17 clock periods */
70   wdogPeriod_33   = 0x2, /**< 33 clock periods */
71   wdogPeriod_65   = 0x3, /**< 65 clock periods */
72   wdogPeriod_129  = 0x4, /**< 129 clock periods */
73   wdogPeriod_257  = 0x5, /**< 257 clock periods */
74   wdogPeriod_513  = 0x6, /**< 513 clock periods */
75   wdogPeriod_1k   = 0x7, /**< 1025 clock periods */
76   wdogPeriod_2k   = 0x8, /**< 2049 clock periods */
77   wdogPeriod_4k   = 0x9, /**< 4097 clock periods */
78   wdogPeriod_8k   = 0xA, /**< 8193 clock periods */
79   wdogPeriod_16k  = 0xB, /**< 16385 clock periods */
80   wdogPeriod_32k  = 0xC, /**< 32769 clock periods */
81   wdogPeriod_64k  = 0xD, /**< 65537 clock periods */
82   wdogPeriod_128k = 0xE, /**< 131073 clock periods */
83   wdogPeriod_256k = 0xF  /**< 262145 clock periods */
84 } WDOG_PeriodSel_TypeDef;
85 
86 /*******************************************************************************
87  *******************************   STRUCTS   ***********************************
88  ******************************************************************************/
89 
90 /** Watchdog initialization structure. */
91 typedef struct
92 {
93   /** Enable watchdog when init completed. */
94   bool                   enable;
95 
96   /** Counter shall keep running during debug halt. */
97   bool                   debugRun;
98 
99   /** Counter shall keep running when in EM2. */
100   bool                   em2Run;
101 
102   /** Counter shall keep running when in EM3. */
103   bool                   em3Run;
104 
105   /** Block EMU from entering EM4. */
106   bool                   em4Block;
107 
108   /** Block SW from disabling LFRCO/LFXO oscillators. */
109   bool                   swoscBlock;
110 
111   /** Block SW from modifying the configuration (a reset is needed to reconfigure). */
112   bool                   lock;
113 
114   /** Clock source to use for watchdog. */
115   WDOG_ClkSel_TypeDef    clkSel;
116 
117   /** Watchdog timeout period. */
118   WDOG_PeriodSel_TypeDef perSel;
119 } WDOG_Init_TypeDef;
120 
121 /** Suggested default config for WDOG init structure. */
122 #define WDOG_INIT_DEFAULT                                                                        \
123   { true,               /* Start watchdog when init done */                                      \
124     false,              /* WDOG not counting during debug halt */                                \
125     false,              /* WDOG not counting when in EM2 */                                      \
126     false,              /* WDOG not counting when in EM3 */                                      \
127     false,              /* EM4 can be entered */                                                 \
128     false,              /* Do not block disabling LFRCO/LFXO in CMU */                           \
129     false,              /* Do not lock WDOG configuration (if locked, reset needed to unlock) */ \
130     wdogClkSelULFRCO,   /* Select 1kHZ WDOG oscillator */                                        \
131     wdogPeriod_256k     /* Set longest possible timeout period */                                \
132   }
133 
134 
135 /*******************************************************************************
136  *****************************   PROTOTYPES   **********************************
137  ******************************************************************************/
138 
139 void WDOG_Enable(bool enable);
140 void WDOG_Feed(void);
141 void WDOG_Init(const WDOG_Init_TypeDef *init);
142 void WDOG_Lock(void);
143 
144 /** @} (end addtogroup WDOG) */
145 /** @} (end addtogroup EM_Library) */
146 
147 #ifdef __cplusplus
148 }
149 #endif
150 
151 #endif /* __EM_WDOG_H */
152