]> git.sur5r.net Git - freertos/blob - Demo/CORTEX_LM3S811_GCC/hw_include/watchdog.c
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / CORTEX_LM3S811_GCC / hw_include / watchdog.c
1 //*****************************************************************************\r
2 //\r
3 // watchdog.c - Driver for the Watchdog Timer Module.\r
4 //\r
5 // Copyright (c) 2005,2006 Luminary Micro, Inc.  All rights reserved.\r
6 //\r
7 // Software License Agreement\r
8 //\r
9 // Luminary Micro, Inc. (LMI) is supplying this software for use solely and\r
10 // exclusively on LMI's Stellaris Family of microcontroller products.\r
11 //\r
12 // The software is owned by LMI and/or its suppliers, and is protected under\r
13 // applicable copyright laws.  All rights are reserved.  Any use in violation\r
14 // of the foregoing restrictions may subject the user to criminal sanctions\r
15 // under applicable laws, as well as to civil liability for the breach of the\r
16 // terms and conditions of this license.\r
17 //\r
18 // THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
19 // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
20 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
21 // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\r
22 // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.\r
23 //\r
24 // This is part of revision 991 of the Stellaris Driver Library.\r
25 //\r
26 //*****************************************************************************\r
27 \r
28 //*****************************************************************************\r
29 //\r
30 //! \addtogroup watchdog_api\r
31 //! @{\r
32 //\r
33 //*****************************************************************************\r
34 \r
35 #include "../hw_ints.h"\r
36 #include "../hw_memmap.h"\r
37 #include "../hw_types.h"\r
38 #include "../hw_watchdog.h"\r
39 #include "debug.h"\r
40 #include "interrupt.h"\r
41 #include "watchdog.h"\r
42 \r
43 //*****************************************************************************\r
44 //\r
45 //! Determines if the watchdog timer is enabled.\r
46 //!\r
47 //! \param ulBase is the base address of the watchdog timer module.\r
48 //!\r
49 //! This will check to see if the watchdog timer is enabled.\r
50 //!\r
51 //! \return Returns \b true if the watchdog timer is enabled, and \b false\r
52 //! if it is not.\r
53 //\r
54 //*****************************************************************************\r
55 #if defined(GROUP_running) || defined(BUILD_ALL) || defined(DOXYGEN)\r
56 tBoolean\r
57 WatchdogRunning(unsigned long ulBase)\r
58 {\r
59     //\r
60     // Check the arguments.\r
61     //\r
62     ASSERT(ulBase == WATCHDOG_BASE);\r
63 \r
64     //\r
65     // See if the watchdog timer module is enabled, and return.\r
66     //\r
67     return(HWREG(ulBase + WDT_O_CTL) & WDT_CTL_INTEN);\r
68 }\r
69 #endif\r
70 \r
71 //*****************************************************************************\r
72 //\r
73 //! Enables the watchdog timer.\r
74 //!\r
75 //! \param ulBase is the base address of the watchdog timer module.\r
76 //!\r
77 //! This will enable the watchdog timer counter and interrupt.\r
78 //!\r
79 //! \note This function will have no effect if the watchdog timer has\r
80 //! been locked.\r
81 //!\r
82 //! \sa WatchdogLock(), WatchdogUnlock()\r
83 //!\r
84 //! \return None.\r
85 //\r
86 //*****************************************************************************\r
87 #if defined(GROUP_enable) || defined(BUILD_ALL) || defined(DOXYGEN)\r
88 void\r
89 WatchdogEnable(unsigned long ulBase)\r
90 {\r
91     //\r
92     // Check the arguments.\r
93     //\r
94     ASSERT(ulBase == WATCHDOG_BASE);\r
95 \r
96     //\r
97     // Enable the watchdog timer module.\r
98     //\r
99     HWREG(ulBase + WDT_O_CTL) |= WDT_CTL_INTEN;\r
100 }\r
101 #endif\r
102 \r
103 //*****************************************************************************\r
104 //\r
105 //! Enables the watchdog timer reset.\r
106 //!\r
107 //! \param ulBase is the base address of the watchdog timer module.\r
108 //!\r
109 //! Enables the capability of the watchdog timer to issue a reset to the\r
110 //! processor upon a second timeout condition.\r
111 //!\r
112 //! \note This function will have no effect if the watchdog timer has\r
113 //! been locked.\r
114 //!\r
115 //! \sa WatchdogLock(), WatchdogUnlock()\r
116 //!\r
117 //! \return None.\r
118 //\r
119 //*****************************************************************************\r
120 #if defined(GROUP_resetenable) || defined(BUILD_ALL) || defined(DOXYGEN)\r
121 void\r
122 WatchdogResetEnable(unsigned long ulBase)\r
123 {\r
124     //\r
125     // Check the arguments.\r
126     //\r
127     ASSERT(ulBase == WATCHDOG_BASE);\r
128 \r
129     //\r
130     // Enable the watchdog reset.\r
131     //\r
132     HWREG(ulBase + WDT_O_CTL) |= WDT_CTL_RESEN;\r
133 }\r
134 #endif\r
135 \r
136 //*****************************************************************************\r
137 //\r
138 //! Disables the watchdog timer reset.\r
139 //!\r
140 //! \param ulBase is the base address of the watchdog timer module.\r
141 //!\r
142 //! Disables the capability of the watchdog timer to issue a reset to the\r
143 //! processor upon a second timeout condition.\r
144 //!\r
145 //! \note This function will have no effect if the watchdog timer has\r
146 //! been locked.\r
147 //!\r
148 //! \sa WatchdogLock(), WatchdogUnlock()\r
149 //!\r
150 //! \return None.\r
151 //\r
152 //*****************************************************************************\r
153 #if defined(GROUP_resetdisable) || defined(BUILD_ALL) || defined(DOXYGEN)\r
154 void\r
155 WatchdogResetDisable(unsigned long ulBase)\r
156 {\r
157     //\r
158     // Check the arguments.\r
159     //\r
160     ASSERT(ulBase == WATCHDOG_BASE);\r
161 \r
162     //\r
163     // Disable the watchdog reset.\r
164     //\r
165     HWREG(ulBase + WDT_O_CTL) &= ~(WDT_CTL_RESEN);\r
166 }\r
167 #endif\r
168 \r
169 //*****************************************************************************\r
170 //\r
171 //! Enables the watchdog timer lock mechanism.\r
172 //!\r
173 //! \param ulBase is the base address of the watchdog timer module.\r
174 //!\r
175 //! Locks out write access to the watchdog timer configuration registers.\r
176 //!\r
177 //! \return None.\r
178 //\r
179 //*****************************************************************************\r
180 #if defined(GROUP_lock) || defined(BUILD_ALL) || defined(DOXYGEN)\r
181 void\r
182 WatchdogLock(unsigned long ulBase)\r
183 {\r
184     //\r
185     // Check the arguments.\r
186     //\r
187     ASSERT(ulBase == WATCHDOG_BASE);\r
188 \r
189     //\r
190     // Lock out watchdog register writes.  Writing anything to the WDT_O_LOCK\r
191     // register causes the lock to go into effect.\r
192     //\r
193     HWREG(ulBase + WDT_O_LOCK) = WDT_LOCK_LOCKED;\r
194 }\r
195 #endif\r
196 \r
197 //*****************************************************************************\r
198 //\r
199 //! Disables the watchdog timer lock mechanism.\r
200 //!\r
201 //! \param ulBase is the base address of the watchdog timer module.\r
202 //!\r
203 //! Enables write access to the watchdog timer configuration registers.\r
204 //!\r
205 //! \return None.\r
206 //\r
207 //*****************************************************************************\r
208 #if defined(GROUP_unlock) || defined(BUILD_ALL) || defined(DOXYGEN)\r
209 void\r
210 WatchdogUnlock(unsigned long ulBase)\r
211 {\r
212     //\r
213     // Check the arguments.\r
214     //\r
215     ASSERT(ulBase == WATCHDOG_BASE);\r
216 \r
217     //\r
218     // Unlock watchdog register writes.\r
219     //\r
220     HWREG(ulBase + WDT_O_LOCK) = WDT_LOCK_UNLOCK;\r
221 }\r
222 #endif\r
223 \r
224 //*****************************************************************************\r
225 //\r
226 //! Gets the state of the watchdog timer lock mechanism.\r
227 //!\r
228 //! \param ulBase is the base address of the watchdog timer module.\r
229 //!\r
230 //! Returns the lock state of the watchdog timer registers.\r
231 //!\r
232 //! \return Returns \b true if the watchdog timer registers are locked, and\r
233 //! \b false if they are not locked.\r
234 //\r
235 //*****************************************************************************\r
236 #if defined(GROUP_lockstate) || defined(BUILD_ALL) || defined(DOXYGEN)\r
237 tBoolean\r
238 WatchdogLockState(unsigned long ulBase)\r
239 {\r
240     //\r
241     // Check the arguments.\r
242     //\r
243     ASSERT(ulBase == WATCHDOG_BASE);\r
244 \r
245     //\r
246     // Get the lock state.\r
247     //\r
248     return((HWREG(ulBase + WDT_O_LOCK) == WDT_LOCK_LOCKED) ? true : false);\r
249 }\r
250 #endif\r
251 \r
252 //*****************************************************************************\r
253 //\r
254 //! Sets the watchdog timer reload value.\r
255 //!\r
256 //! \param ulBase is the base address of the watchdog timer module.\r
257 //! \param ulLoadVal is the load value for the watchdog timer.\r
258 //!\r
259 //! This function sets the value to load into the watchdog timer when the count\r
260 //! reaches zero for the first time; if the watchdog timer is running when this\r
261 //! function is called, then the value will be immediately loaded into the\r
262 //! watchdog timer counter. If the parameter \e ulLoadVal is 0, then an\r
263 //! interrupt is immediately generated.\r
264 //!\r
265 //! \note This function will have no effect if the watchdog timer has\r
266 //! been locked.\r
267 //!\r
268 //! \sa WatchdogLock(), WatchdogUnlock(), WatchdogReloadGet()\r
269 //!\r
270 //! \return None.\r
271 //\r
272 //*****************************************************************************\r
273 #if defined(GROUP_reloadset) || defined(BUILD_ALL) || defined(DOXYGEN)\r
274 void\r
275 WatchdogReloadSet(unsigned long ulBase, unsigned long ulLoadVal)\r
276 {\r
277     //\r
278     // Check the arguments.\r
279     //\r
280     ASSERT(ulBase == WATCHDOG_BASE);\r
281 \r
282     //\r
283     // Set the load register.\r
284     //\r
285     HWREG(ulBase + WDT_O_LOAD) = ulLoadVal;\r
286 }\r
287 #endif\r
288 \r
289 //*****************************************************************************\r
290 //\r
291 //! Gets the watchdog timer reload value.\r
292 //!\r
293 //! \param ulBase is the base address of the watchdog timer module.\r
294 //!\r
295 //! This function gets the value that is loaded into the watchdog timer when\r
296 //! the count reaches zero for the first time.\r
297 //!\r
298 //! \sa WatchdogReloadSet()\r
299 //!\r
300 //! \return None.\r
301 //\r
302 //*****************************************************************************\r
303 #if defined(GROUP_reloadget) || defined(BUILD_ALL) || defined(DOXYGEN)\r
304 unsigned long\r
305 WatchdogReloadGet(unsigned long ulBase)\r
306 {\r
307     //\r
308     // Check the arguments.\r
309     //\r
310     ASSERT(ulBase == WATCHDOG_BASE);\r
311 \r
312     //\r
313     // Get the load register.\r
314     //\r
315     return(HWREG(ulBase + WDT_O_LOAD));\r
316 }\r
317 #endif\r
318 \r
319 //*****************************************************************************\r
320 //\r
321 //! Gets the current watchdog timer value.\r
322 //!\r
323 //! \param ulBase is the base address of the watchdog timer module.\r
324 //!\r
325 //! This function reads the current value of the watchdog timer.\r
326 //!\r
327 //! \return Returns the current value of the watchdog timer.\r
328 //\r
329 //*****************************************************************************\r
330 #if defined(GROUP_valueget) || defined(BUILD_ALL) || defined(DOXYGEN)\r
331 unsigned long\r
332 WatchdogValueGet(unsigned long ulBase)\r
333 {\r
334     //\r
335     // Check the arguments.\r
336     //\r
337     ASSERT(ulBase == WATCHDOG_BASE);\r
338 \r
339     //\r
340     // Get the current watchdog timer register value.\r
341     //\r
342     return(HWREG(ulBase + WDT_O_VALUE));\r
343 }\r
344 #endif\r
345 \r
346 //*****************************************************************************\r
347 //\r
348 //! Registers an interrupt handler for watchdog timer interrupt.\r
349 //!\r
350 //! \param ulBase is the base address of the watchdog timer module.\r
351 //! \param pfnHandler is a pointer to the function to be called when the\r
352 //! watchdog timer interrupt occurs.\r
353 //!\r
354 //! This function does the actual registering of the interrupt handler.  This\r
355 //! will enable the global interrupt in the interrupt controller; the watchdog\r
356 //! timer interrupt must be enabled via WatchdogEnable(). It is the interrupt\r
357 //! handler's responsibility to clear the interrupt source via\r
358 //! WatchdogIntClear().\r
359 //!\r
360 //! \sa IntRegister() for important information about registering interrupt\r
361 //! handlers.\r
362 //!\r
363 //! \return None.\r
364 //\r
365 //*****************************************************************************\r
366 #if defined(GROUP_intregister) || defined(BUILD_ALL) || defined(DOXYGEN)\r
367 void\r
368 WatchdogIntRegister(unsigned long ulBase, void (*pfnHandler)(void))\r
369 {\r
370     //\r
371     // Check the arguments.\r
372     //\r
373     ASSERT(ulBase == WATCHDOG_BASE);\r
374 \r
375     //\r
376     // Register the interrupt handler.\r
377     //\r
378     IntRegister(INT_WATCHDOG, pfnHandler);\r
379 \r
380     //\r
381     // Enable the watchdog timer interrupt.\r
382     //\r
383     IntEnable(INT_WATCHDOG);\r
384 }\r
385 #endif\r
386 \r
387 //*****************************************************************************\r
388 //\r
389 //! Unregisters an interrupt handler for the watchdog timer interrupt.\r
390 //!\r
391 //! \param ulBase is the base address of the watchdog timer module.\r
392 //!\r
393 //! This function does the actual unregistering of the interrupt handler.  This\r
394 //! function will clear the handler to be called when a watchdog timer\r
395 //! interrupt occurs.  This will also mask off the interrupt in the interrupt\r
396 //! controller so that the interrupt handler no longer is called.\r
397 //!\r
398 //! \sa IntRegister() for important information about registering interrupt\r
399 //! handlers.\r
400 //!\r
401 //! \return None.\r
402 //\r
403 //*****************************************************************************\r
404 #if defined(GROUP_intunregister) || defined(BUILD_ALL) || defined(DOXYGEN)\r
405 void\r
406 WatchdogIntUnregister(unsigned long ulBase)\r
407 {\r
408     //\r
409     // Check the arguments.\r
410     //\r
411     ASSERT(ulBase == WATCHDOG_BASE);\r
412 \r
413     //\r
414     // Disable the interrupt.\r
415     //\r
416     IntDisable(INT_WATCHDOG);\r
417 \r
418     //\r
419     // Unregister the interrupt handler.\r
420     //\r
421     IntUnregister(INT_WATCHDOG);\r
422 }\r
423 #endif\r
424 \r
425 //*****************************************************************************\r
426 //\r
427 //! Enables the watchdog timer interrupt.\r
428 //!\r
429 //! \param ulBase is the base address of the watchdog timer module.\r
430 //!\r
431 //! Enables the watchdog timer interrupt.\r
432 //!\r
433 //! \note This function will have no effect if the watchdog timer has\r
434 //! been locked.\r
435 //!\r
436 //! \sa WatchdogLock(), WatchdogUnlock(), WatchdogEnable()\r
437 //!\r
438 //! \return None.\r
439 //\r
440 //*****************************************************************************\r
441 #if defined(GROUP_intenable) || defined(BUILD_ALL) || defined(DOXYGEN)\r
442 void\r
443 WatchdogIntEnable(unsigned long ulBase)\r
444 {\r
445     //\r
446     // Check the arguments.\r
447     //\r
448     ASSERT(ulBase == WATCHDOG_BASE);\r
449 \r
450     //\r
451     // Enable the watchdog interrupt.\r
452     //\r
453     HWREG(ulBase + WDT_O_CTL) |= WDT_CTL_INTEN;\r
454 }\r
455 #endif\r
456 \r
457 //*****************************************************************************\r
458 //\r
459 //! Gets the current watchdog timer interrupt status.\r
460 //!\r
461 //! \param ulBase is the base address of the watchdog timer module.\r
462 //! \param bMasked is \b false if the raw interrupt status is required and\r
463 //! \b true if the masked interrupt status is required.\r
464 //!\r
465 //! This returns the interrupt status for the watchdog timer module.  Either\r
466 //! the raw interrupt status or the status of interrupt that is allowed to\r
467 //! reflect to the processor can be returned.\r
468 //!\r
469 //! \return The current interrupt status, where a 1 indicates that the watchdog\r
470 //! interrupt is active, and a 0 indicates that it is not active.\r
471 //\r
472 //*****************************************************************************\r
473 #if defined(GROUP_intstatus) || defined(BUILD_ALL) || defined(DOXYGEN)\r
474 unsigned long\r
475 WatchdogIntStatus(unsigned long ulBase, tBoolean bMasked)\r
476 {\r
477     //\r
478     // Check the arguments.\r
479     //\r
480     ASSERT(ulBase == WATCHDOG_BASE);\r
481 \r
482     //\r
483     // Return either the interrupt status or the raw interrupt status as\r
484     // requested.\r
485     //\r
486     if(bMasked)\r
487     {\r
488         return(HWREG(ulBase + WDT_O_MIS));\r
489     }\r
490     else\r
491     {\r
492         return(HWREG(ulBase + WDT_O_RIS));\r
493     }\r
494 }\r
495 #endif\r
496 \r
497 //*****************************************************************************\r
498 //\r
499 //! Clears the watchdog timer interrupt.\r
500 //!\r
501 //! \param ulBase is the base address of the watchdog timer module.\r
502 //!\r
503 //! The watchdog timer interrupt source is cleared, so that it no longer\r
504 //! asserts.\r
505 //!\r
506 //! \return None.\r
507 //\r
508 //*****************************************************************************\r
509 #if defined(GROUP_intclear) || defined(BUILD_ALL) || defined(DOXYGEN)\r
510 void\r
511 WatchdogIntClear(unsigned long ulBase)\r
512 {\r
513     //\r
514     // Check the arguments.\r
515     //\r
516     ASSERT(ulBase == WATCHDOG_BASE);\r
517 \r
518     //\r
519     // Clear the interrupt source.\r
520     //\r
521     HWREG(ulBase + WDT_O_ICR) = WDT_INT_TIMEOUT;\r
522 }\r
523 #endif\r
524 \r
525 //*****************************************************************************\r
526 //\r
527 //! Enables stalling of the watchdog timer during debug events.\r
528 //!\r
529 //! \param ulBase is the base address of the watchdog timer module.\r
530 //!\r
531 //! This function allows the watchdog timer to stop counting when the processor\r
532 //! is stopped by the debugger.  By doing so, the watchdog is prevented from\r
533 //! expiring (typically almost immediately from a human time perspective) and\r
534 //! resetting the system (if reset is enabled).  The watchdog will instead\r
535 //! expired after the appropriate number of processor cycles have been executed\r
536 //! while debugging (or at the appropriate time after the processor has been\r
537 //! restarted).\r
538 //!\r
539 //! \return None.\r
540 //\r
541 //*****************************************************************************\r
542 #if defined(GROUP_stallenable) || defined(BUILD_ALL) || defined(DOXYGEN)\r
543 void\r
544 WatchdogStallEnable(unsigned long ulBase)\r
545 {\r
546     //\r
547     // Check the arguments.\r
548     //\r
549     ASSERT(ulBase == WATCHDOG_BASE);\r
550 \r
551     //\r
552     // Enable timer stalling.\r
553     //\r
554     HWREG(ulBase + WDT_O_TEST) |= WDT_TEST_STALL;\r
555 }\r
556 #endif\r
557 \r
558 //*****************************************************************************\r
559 //\r
560 //! Disables stalling of the watchdog timer during debug events.\r
561 //!\r
562 //! \param ulBase is the base address of the watchdog timer module.\r
563 //!\r
564 //! This function disables the debug mode stall of the watchdog timer.  By\r
565 //! doing so, the watchdog timer continues to count regardless of the processor\r
566 //! debug state.\r
567 //!\r
568 //! \return None.\r
569 //\r
570 //*****************************************************************************\r
571 #if defined(GROUP_stalldisable) || defined(BUILD_ALL) || defined(DOXYGEN)\r
572 void\r
573 WatchdogStallDisable(unsigned long ulBase)\r
574 {\r
575     //\r
576     // Check the arguments.\r
577     //\r
578     ASSERT(ulBase == WATCHDOG_BASE);\r
579 \r
580     //\r
581     // Disable timer stalling.\r
582     //\r
583     HWREG(ulBase + WDT_O_TEST) &= ~(WDT_TEST_STALL);\r
584 }\r
585 #endif\r
586 \r
587 //*****************************************************************************\r
588 //\r
589 // Close the Doxygen group.\r
590 //! @}\r
591 //\r
592 //*****************************************************************************\r