blob: bf17e65037b84884d02f0ca75e7bf052f339e5e0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
/******************************************************************************
*
* @brief Provide common watchdog module routines.
*
* @history:
* Jun. 25, 2013 modified the watch dog unlock sequence and disable sequence
******************************************************************************/
#include "common.h"
#include "wdog.h"
/******************************************************************************
* Global variables
******************************************************************************/
/******************************************************************************
* Constants and macros
******************************************************************************/
/******************************************************************************
* Local types
******************************************************************************/
/******************************************************************************
* Local function prototypes
******************************************************************************/
/******************************************************************************
* Local variables
******************************************************************************/
/******************************************************************************
* Local functions
******************************************************************************/
/******************************************************************************
* Global functions
******************************************************************************/
/******************************************************************************
* define watchdog API list
*
*//*! @addtogroup wdog_api_list
* @{
*******************************************************************************/
/*****************************************************************************//*!
*
* @brief Watchdog ETMer disable routine.
*
* @param none
*
* @return none
*
* @ Pass/ Fail criteria: none
* @see WDOG_Enable
*****************************************************************************/
void WDOG_Disable(void)
{
uint8_t u8Cs1 = WDOG->CS1;
uint8_t u8Cs2 = WDOG->CS2;
uint16_t u16TOVAL = WDOG->TOVAL;
uint16_t u16WIN = WDOG->WIN;
u8Cs1 &= ~WDOG_CS1_EN_MASK;
/* First unlock the watchdog so that we can write to registers */
WDOG_Unlock();
WDOG->CS2 = u8Cs2;
WDOG->TOVAL = u16TOVAL;
WDOG->WIN = u16WIN;
WDOG->CS1 = u8Cs1;
}
/*****************************************************************************//*!
*
* @brief Watchdog ETMer disable routine with update enabled.
*
* Disable watchdog but the watchdog can be enabled and updated later.
*
* @param none
*
* @return none
*
* @ Pass/ Fail criteria: none
* @see WDOG_Enable
*****************************************************************************/
void WDOG_DisableWDOGEnableUpdate(void)
{
uint8_t u8Cs1 = WDOG->CS1;
uint8_t u8Cs2 = WDOG->CS2;
uint16_t u16TOVAL = WDOG->TOVAL;
uint16_t u16WIN = WDOG->WIN;
u8Cs1 &= ~WDOG_CS1_EN_MASK;
u8Cs1 |= WDOG_CS1_UPDATE_MASK;
/* First unlock the watchdog so that we can write to registers */
//WDOG_Unlock();
WDOG->CS2 = u8Cs2;
WDOG->TOVAL = u16TOVAL;
WDOG->WIN = u16WIN;
WDOG->CS1 = u8Cs1;
}
/*****************************************************************************//*!
*
* @brief Watchdog ETMer enable routine.
*
* @param none
*
* @return none
*
* @ Pass/ Fail criteria: none
* @see WDOG_Disable
*****************************************************************************/
void WDOG_Enable(void)
{
uint8_t u8Cs1 = WDOG->CS1;
u8Cs1 |= WDOG_CS1_EN_MASK;
/* First unlock the watchdog so that we can write to registers */
WDOG_Unlock();
WDOG->CS1 = u8Cs1;
}
/*****************************************************************************//*!
*
* @brief initialize watchdog.
*
* @param[in] pConfig poiner to watchdog configuration strcture.
*
* @return none
*
* @ Pass/ Fail criteria: none
*
* @warning make sure that WDOG is not initialized after reset or WDOG update is enabled
* after reset by calling WDOG_EnableUpdate / WDOG_DisableWDOGEnableUpdate.
*
* @see WDOG_EnableUpdate, WDOG_DisableWDOGEnableUpdate
*
*****************************************************************************/
void WDOG_Init(WDOG_ConfigPtr pConfig)
{
uint8_t u8Cs1;
uint8_t u8Cs2;
uint16_t u16Toval;
uint16_t u16Win;
u8Cs1 = 0x80; /* default CS1 register value */
u8Cs2 = 0;
u16Toval = pConfig->u16ETMeOut;
u16Win = pConfig->u16WinETMe;
if(pConfig->sBits.bDisable)
{
u8Cs1 &= ~WDOG_CS1_EN_MASK;
}
if(pConfig->sBits.bIntEnable)
{
u8Cs1 |= WDOG_CS1_INT_MASK;
}
if(pConfig->sBits.bStopEnable)
{
u8Cs1 |= WDOG_CS1_STOP_MASK;
}
if(pConfig->sBits.bDbgEnable)
{
u8Cs1 |= WDOG_CS1_DBG_MASK;
}
if(pConfig->sBits.bWaitEnable)
{
u8Cs1 |= WDOG_CS1_WAIT_MASK;
}
if(pConfig->sBits.bUpdateEnable)
{
u8Cs1 |= WDOG_CS1_UPDATE_MASK;
}
if(pConfig->sBits.bWinEnable)
{
u8Cs2 |= WDOG_CS2_WIN_MASK;
}
if(pConfig->sBits.bPrescaler)
{
u8Cs2 |= WDOG_CS2_PRES_MASK;
}
u8Cs2 |= (pConfig->sBits.bClkSrc & 0x03);
/* write regisers */
WDOG_Unlock(); /* unlock watchdog first */
WDOG->CS2 = u8Cs2;
WDOG->TOVAL8B.TOVALL = u16Toval;
WDOG->TOVAL8B.TOVALH = u16Toval >> 8;
WDOG->WIN8B.WINL = u16Win;
WDOG->WIN8B.WINH = u16Win >> 8;
WDOG->CS1 = u8Cs1;
}
/*****************************************************************************//*!
*
* @brief initialize watchdog to the default state.
*
* @param none
*
* @return none
*
* @ Pass/ Fail criteria: none
* @warning make sure that WDOG update is enabled after reset by calling WDOG_EnableUpdate.
* or by calling WDOG_DisableWDOGEnableUpdate.
*
* @see WDOG_DisableWDOGEnableUpdate, WDOG_EnableUpdate
*
*****************************************************************************/
void WDOG_DeInit(void)
{
WDOG_Unlock();
WDOG->CS2 = WDOG_CS2_DEFAULT_VALUE;
WDOG->TOVAL = WDOG_TOVAL_DEFAULT_VALUE;
WDOG->WIN = WDOG_WIN_DEFAULT_VALUE;
WDOG->CS1 = WDOG_CS1_DEFAULT_VALUE;
}
/*****************************************************************************//*!
*
* @brief feed/refresh watchdog.
*
* @param none
*
* @return none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void WDOG_Feed(void)
{
DisableInterrupts;
WDOG->CNT = 0x02A6;
WDOG->CNT = 0x80B4;
EnableInterrupts;
}
/*****************************************************************************//*!
*
* @brief enable update of WDOG.
*
* @param none
*
* @return none
*
* @ Pass/ Fail criteria: none
* @warning this must be the last step of writing control bits sequence.
*****************************************************************************/
void WDOG_EnableUpdate(void)
{
uint8_t u8Cs1 = WDOG->CS1;
uint8_t u8Cs2 = WDOG->CS2;
uint16_t u16TOVAL = WDOG->TOVAL;
uint16_t u16WIN = WDOG->WIN;
u8Cs1 |= WDOG_CS1_UPDATE_MASK;
/* First unlock the watchdog so that we can write to registers */
WDOG_Unlock();
WDOG->CS2 = u8Cs2;
WDOG->TOVAL = u16TOVAL;
WDOG->WIN = u16WIN;
WDOG->CS1 = u8Cs1;
}
/*****************************************************************************//*!
*
* @brief disable update of WDOG.
*
* @param none
*
* @return none
*
* @ Pass/ Fail criteria: none
* @warning this must be the last step of writing control bits sequence.
*****************************************************************************/
void WDOG_DisableUpdate(void)
{
uint8_t u8Cs1 = WDOG->CS1;
uint8_t u8Cs2 = WDOG->CS2;
uint16_t u16TOVAL = WDOG->TOVAL;
uint16_t u16WIN = WDOG->WIN;
u8Cs1 &= ~WDOG_CS1_UPDATE_MASK;
/* First unlock the watchdog so that we can write to registers */
WDOG_Unlock();
WDOG->CS2 = u8Cs2;
WDOG->TOVAL = u16TOVAL;
WDOG->WIN = u16WIN;
WDOG->CS1 = u8Cs1;
}
/********************************************************************/
/*! @} End of wdog_api_list */
|