1 /**
2  * @file    wdt.h
3  * @brief   Watchdog timer (WDT) function prototypes and data types.
4  */
5 
6 /* ****************************************************************************
7  * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the "Software"),
11  * to deal in the Software without restriction, including without limitation
12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  * and/or sell copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included
17  * in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
23  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  *
27  * Except as contained in this notice, the name of Maxim Integrated
28  * Products, Inc. shall not be used except as stated in the Maxim Integrated
29  * Products, Inc. Branding Policy.
30  *
31  * The mere transfer of this software does not imply any licenses
32  * of trade secrets, proprietary technology, copyrights, patents,
33  * trademarks, maskwork rights, or any other form of intellectual
34  * property whatsoever. Maxim Integrated Products, Inc. retains all
35  * ownership rights.
36  *
37  * $Date: 2020-04-20 15:06:58 -0500 (Mon, 20 Apr 2020) $
38  * $Revision: 53142 $
39  *
40  *************************************************************************** */
41 
42 /* Define to prevent redundant inclusion */
43 #ifndef _WDT_H_
44 #define _WDT_H_
45 
46 /* **** Includes **** */
47 #include <stdint.h>
48 #include "mxc_config.h"
49 #include "mxc_sys.h"
50 #include "wdt_regs.h"
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 /**
57  * @defgroup wdt Watchdog Timer (WDT)
58  * @ingroup periphlibs
59  * @{
60  */
61 
62 /* **** Definitions **** */
63 
64 /** @brief Watchdog period enumeration.
65     Used to configure the period of the watchdog interrupt */
66 typedef enum {
67     WDT_PERIOD_2_31 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW31, /**< Period 2^31 */
68     WDT_PERIOD_2_30 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW30, /**< Period 2^30 */
69     WDT_PERIOD_2_29 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW29, /**< Period 2^29 */
70     WDT_PERIOD_2_28 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW28, /**< Period 2^28 */
71     WDT_PERIOD_2_27 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW27, /**< Period 2^27 */
72     WDT_PERIOD_2_26 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW26, /**< Period 2^26 */
73     WDT_PERIOD_2_25 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW25, /**< Period 2^25 */
74     WDT_PERIOD_2_24 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW24, /**< Period 2^24 */
75     WDT_PERIOD_2_23 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW23, /**< Period 2^23 */
76     WDT_PERIOD_2_22 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW22, /**< Period 2^22 */
77     WDT_PERIOD_2_21 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW21, /**< Period 2^21 */
78     WDT_PERIOD_2_20 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW20, /**< Period 2^20 */
79     WDT_PERIOD_2_19 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW19, /**< Period 2^19 */
80     WDT_PERIOD_2_18 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW18, /**< Period 2^18 */
81     WDT_PERIOD_2_17 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW17, /**< Period 2^17 */
82     WDT_PERIOD_2_16 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW16, /**< Period 2^16 */
83 } wdt_period_t;
84 
85 /* **** Function Prototypes **** */
86 
87 /**
88  * @brief Initialize the Watchdog Timer
89  * @param      wdt      Pointer to the watchdog registers
90  * @param      sys_cfg  The system configuration object
91  */
92 int WDT_Init(mxc_wdt_regs_t* wdt, sys_cfg_wdt_t sys_cfg);
93 /**
94  * @brief       Set the period of the watchdog interrupt.
95  * @param       wdt     Pointer to watchdog registers.
96  * @param       period  Enumeration of the desired watchdog period.
97  */
98 void WDT_SetIntPeriod(mxc_wdt_regs_t* wdt, wdt_period_t period);
99 
100 /**
101  * @brief       Set the period of the watchdog reset.
102  * @param       wdt     Pointer to watchdog registers.
103  * @param       period  Enumeration of the desired watchdog period.
104  */
105 void WDT_SetResetPeriod(mxc_wdt_regs_t* wdt, wdt_period_t period);
106 
107 /**
108  * @brief       Enable the watchdog timer.
109  * @param       wdt     Pointer to watchdog registers.
110  * @param       enable  1 to enable the timer, 0 to disable.
111  */
112 void WDT_Enable(mxc_wdt_regs_t* wdt, int enable);
113 
114 /**
115  * @brief       Enable the watchdog interrupt.
116  * @param       wdt     Pointer to watchdog registers.
117  * @param       enable  1 to enable the interrupt, 0 to disable.
118  */
119 void WDT_EnableInt(mxc_wdt_regs_t* wdt, int enable);
120 
121 /**
122  * @brief       Enable the watchdog reset.
123  * @param       wdt     Pointer to watchdog registers.
124  * @param       enable  1 to enable the reset, 0 to disable.
125  */
126 void WDT_EnableReset(mxc_wdt_regs_t* wdt, int enable);
127 
128 /**
129  * @brief       Reset the watchdog timer.
130  * @param       wdt     Pointer to watchdog registers.
131  */
132 void WDT_ResetTimer(mxc_wdt_regs_t* wdt);
133 
134 /**
135  * @brief       Get the status of the reset flag.
136  * @param       wdt     Pointer to watchdog registers.
137  * @returns     1 if the previous reset was caused by the watchdog, 0 otherwise.
138  */
139 int WDT_GetResetFlag(mxc_wdt_regs_t* wdt);
140 
141 /**
142  * @brief       Clears the reset flag.
143  * @param       wdt     Pointer to watchdog registers.
144  */
145 void WDT_ClearResetFlag(mxc_wdt_regs_t* wdt);
146 
147 /**
148  * @brief     Get the status of the interrupt flag.
149  * @param       wdt     Pointer to watchdog registers.
150  * @returns   1 if the interrupt is pending, 0 otherwise.
151  */
152 int WDT_GetIntFlag(mxc_wdt_regs_t* wdt);
153 
154 /**
155  * @brief       Clears the interrupt flag.
156  * @param       wdt     Pointer to watchdog registers.
157  */
158 void WDT_ClearIntFlag(mxc_wdt_regs_t* wdt);
159 
160 /**@} end of group wdt */
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 #endif /* _WDT_H_ */
167