CC26xx Driver Library
watchdog.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: wdt.h
3 * Revised: 2015-07-16 12:53:29 +0200 (Thu, 16 Jul 2015)
4 * Revision: 44153
5 *
6 * Description: Defines and prototypes for the Watchdog Timer.
7 *
8 * Copyright (c) 2015, Texas Instruments Incorporated
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1) Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2) Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38 
39 //*****************************************************************************
40 //
45 //
46 //*****************************************************************************
47 
48 #ifndef __WDT_H__
49 #define __WDT_H__
50 
51 //*****************************************************************************
52 //
53 // If building with a C++ compiler, make all of the definitions in this header
54 // have a C binding.
55 //
56 //*****************************************************************************
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61 
62 #include <stdbool.h>
63 #include <stdint.h>
64 #include <inc/hw_types.h>
65 #include <inc/hw_ints.h>
66 #include <inc/hw_memmap.h>
67 #include <inc/hw_wdt.h>
68 #include <driverlib/debug.h>
69 #include <driverlib/interrupt.h>
70 
71 //*****************************************************************************
72 //
73 // The following are defines for the bit fields in the WDT_O_LOCK register.
74 //
75 //*****************************************************************************
76 #define WATCHDOG_LOCK_UNLOCKED 0x00000000 // Unlocked
77 #define WATCHDOG_LOCK_LOCKED 0x00000001 // Locked
78 #define WATCHDOG_LOCK_UNLOCK 0x1ACCE551 // Unlocks the Watchdog Timer
79 
80 //*****************************************************************************
81 //
82 // The following are defines for the bit fields in the WDT_ISR, WDT_RIS, and
83 // WDT_MIS registers.
84 //
85 //*****************************************************************************
86 #define WATCHDOG_INT_TIMEOUT 0x00000001 // Watchdog timer expired
87 
88 //*****************************************************************************
89 //
90 // The type of interrupt that can be generated by the watchdog.
91 //
92 //*****************************************************************************
93 #define WATCHDOG_INT_TYPE_INT 0x00000000
94 #define WATCHDOG_INT_TYPE_NMI 0x00000004
95 
96 //*****************************************************************************
97 //
98 // API Functions and prototypes
99 //
100 //*****************************************************************************
101 
102 //*****************************************************************************
103 //
111 //
112 //*****************************************************************************
113 __STATIC_INLINE bool
115 {
116  //
117  // See if the watchdog timer module is enabled, and return.
118  //
119  return((HWREG(WDT_BASE + WDT_O_CTL) & WDT_CTL_INTEN) ? true : false);
120 }
121 
122 //*****************************************************************************
123 //
133 //
134 //*****************************************************************************
135 __STATIC_INLINE void
137 {
138  // Enable the watchdog timer module.
139  HWREGBITW(WDT_BASE + WDT_O_CTL, WDT_CTL_INTEN_BITN) = 1;
140 }
141 
142 //*****************************************************************************
143 //
154 //
155 //*****************************************************************************
156 __STATIC_INLINE void
158 {
159  // Enable the watchdog reset.
160  HWREGBITW(WDT_BASE + WDT_O_CTL, WDT_CTL_RESEN_BITN) = 1;
161 }
162 
163 //*****************************************************************************
164 //
175 //
176 //*****************************************************************************
177 __STATIC_INLINE void
179 {
180  // Disable the watchdog reset.
181  HWREGBITW(WDT_BASE + WDT_O_CTL, WDT_CTL_RESEN_BITN) = 0;
182 }
183 
184 //*****************************************************************************
185 //
192 //
193 //*****************************************************************************
194 __STATIC_INLINE void
196 {
197  //
198  // Lock out watchdog register writes. Writing anything to the WDT_O_LOCK
199  // register causes the lock to go into effect.
200  //
202 }
203 
204 //*****************************************************************************
205 //
212 //
213 //*****************************************************************************
214 __STATIC_INLINE void
216 {
217  //
218  // Unlock watchdog register writes.
219  //
221 }
222 
223 //*****************************************************************************
224 //
232 //
233 //*****************************************************************************
234 __STATIC_INLINE bool
236 {
237  //
238  // Get the lock state.
239  //
240  return((HWREG(WDT_BASE + WDT_O_LOCK) == WATCHDOG_LOCK_LOCKED) ?
241  true : false);
242 }
243 
244 //*****************************************************************************
245 //
261 //
262 //*****************************************************************************
263 __STATIC_INLINE void
264 WatchdogReloadSet(uint32_t ui32LoadVal)
265 {
266  //
267  // Set the load register.
268  //
269  HWREG(WDT_BASE + WDT_O_LOAD) = ui32LoadVal;
270 }
271 
272 //*****************************************************************************
273 //
282 //
283 //*****************************************************************************
284 __STATIC_INLINE uint32_t
286 {
287  //
288  // Get the load register.
289  //
290  return(HWREG(WDT_BASE + WDT_O_LOAD));
291 }
292 
293 //*****************************************************************************
294 //
300 //
301 //*****************************************************************************
302 __STATIC_INLINE uint32_t
304 {
305  //
306  // Get the current watchdog timer register value.
307  //
308  return(HWREG(WDT_BASE + WDT_O_VALUE));
309 }
310 
311 //*****************************************************************************
312 //
332 //
333 //*****************************************************************************
334 __STATIC_INLINE void
335 WatchdogIntRegister(void (*pfnHandler)(void))
336 {
337  //
338  // Register the interrupt handler.
339  //
340  IntRegister(INT_WATCHDOG, pfnHandler);
341 
342  //
343  // Enable the watchdog timer interrupt.
344  //
345  IntEnable(INT_WATCHDOG);
346 }
347 
348 //*****************************************************************************
349 //
365 //
366 //*****************************************************************************
367 __STATIC_INLINE void
369 {
370  //
371  // Disable the interrupt.
372  //
373  IntDisable(INT_WATCHDOG);
374 
375  //
376  // Unregister the interrupt handler.
377  //
378  IntUnregister(INT_WATCHDOG);
379 }
380 
381 //*****************************************************************************
382 //
390 //
391 //*****************************************************************************
392 __STATIC_INLINE void
394 {
395  // Enable the Watchdog interrupt.
396  WatchdogEnable();
397 }
398 
399 //*****************************************************************************
400 //
410 //
411 //*****************************************************************************
412 __STATIC_INLINE uint32_t
414 {
415  //
416  // Return either the interrupt status or the raw interrupt status as
417  // requested.
418  //
419  return(HWREG(WDT_BASE + WDT_O_RIS));
420 }
421 
422 //*****************************************************************************
423 //
439 //
440 //*****************************************************************************
441 __STATIC_INLINE void
443 {
444  //
445  // Clear the interrupt source.
446  //
448 }
449 
450 //*****************************************************************************
451 //
466 //
467 //*****************************************************************************
468 __STATIC_INLINE void
469 WatchdogIntTypeSet(uint32_t ui32Type)
470 {
471  // Check the arguments.
472  ASSERT((ui32Type == WATCHDOG_INT_TYPE_INT) ||
473  (ui32Type == WATCHDOG_INT_TYPE_NMI));
474 
475  // Set the interrupt type.
476  HWREGBITW(WDT_BASE + WDT_O_CTL, WDT_CTL_INTTYPE_BITN) = (ui32Type == WATCHDOG_INT_TYPE_INT)? 0 : 1;
477 }
478 
479 //*****************************************************************************
480 //
491 //
492 //*****************************************************************************
493 __STATIC_INLINE void
495 {
496  // Enable timer stalling.
497  HWREGBITW(WDT_BASE + WDT_O_TEST, WDT_TEST_STALL_BITN) = 1;
498 }
499 
500 //*****************************************************************************
501 //
509 //
510 //*****************************************************************************
511 __STATIC_INLINE void
513 {
514  // Disable timer stalling.
515  HWREGBITW(WDT_BASE + WDT_O_TEST, WDT_TEST_STALL_BITN) = 0;
516 }
517 
518 //*****************************************************************************
519 //
520 // Mark the end of the C bindings section for C++ compilers.
521 //
522 //*****************************************************************************
523 #ifdef __cplusplus
524 }
525 #endif
526 
527 #endif // __WDT_H__
528 
529 //*****************************************************************************
530 //
534 //
535 //*****************************************************************************
#define WATCHDOG_INT_TIMEOUT
Definition: watchdog.h:86
static void WatchdogIntRegister(void(*pfnHandler)(void))
Registers an interrupt handler for the watchdog timer interrupt.
Definition: watchdog.h:335
#define WATCHDOG_INT_TYPE_NMI
Definition: watchdog.h:94
static void WatchdogUnlock(void)
Disables the watchdog timer lock mechanism.
Definition: watchdog.h:215
static bool WatchdogRunning(void)
Determines if the watchdog timer is enabled.
Definition: watchdog.h:114
static void WatchdogIntUnregister(void)
Unregisters an interrupt handler for the watchdog timer interrupt.
Definition: watchdog.h:368
static void WatchdogLock(void)
Enables the watchdog timer lock mechanism.
Definition: watchdog.h:195
static void WatchdogStallDisable(void)
Disables stalling of the watchdog timer during debug events.
Definition: watchdog.h:512
static uint32_t WatchdogIntStatus(void)
Gets the current watchdog timer interrupt status.
Definition: watchdog.h:413
static void WatchdogIntEnable(void)
Enables the watchdog timer.
Definition: watchdog.h:393
static uint32_t WatchdogReloadGet(void)
Gets the watchdog timer reload value.
Definition: watchdog.h:285
static void WatchdogEnable(void)
Enables the watchdog timer.
Definition: watchdog.h:136
static void WatchdogStallEnable(void)
Enables stalling of the watchdog timer during debug events.
Definition: watchdog.h:494
#define ASSERT(expr)
Definition: debug.h:74
static void WatchdogResetEnable(void)
Enables the watchdog timer reset.
Definition: watchdog.h:157
#define WATCHDOG_INT_TYPE_INT
Definition: watchdog.h:93
static void WatchdogResetDisable(void)
Disables the watchdog timer reset.
Definition: watchdog.h:178
#define WATCHDOG_LOCK_UNLOCK
Definition: watchdog.h:78
static bool WatchdogLockState(void)
Gets the state of the watchdog timer lock mechanism.
Definition: watchdog.h:235
void IntUnregister(uint32_t ui32Interrupt)
Unregisters the function to be called when an interrupt occurs.
Definition: interrupt.c:203
static uint32_t WatchdogValueGet(void)
Gets the current watchdog timer value.
Definition: watchdog.h:303
static void WatchdogIntTypeSet(uint32_t ui32Type)
Sets the type of interrupt generated by the watchdog.
Definition: watchdog.h:469
static void WatchdogReloadSet(uint32_t ui32LoadVal)
Sets the watchdog timer reload value.
Definition: watchdog.h:264
static void WatchdogIntClear(void)
Clears the watchdog timer interrupt.
Definition: watchdog.h:442
#define WATCHDOG_LOCK_LOCKED
Definition: watchdog.h:77
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:381
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Registers a function to be called when an interrupt occurs.
Definition: interrupt.c:155
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:321