CC13xx Driver Library
watchdog.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: wdt.h
3 * Revised: 2015-09-21 15:19:36 +0200 (Mon, 21 Sep 2015)
4 * Revision: 44629
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 //
135 //
136 //*****************************************************************************
137 __STATIC_INLINE void
139 {
140  // Enable the watchdog timer module.
141  HWREGBITW(WDT_BASE + WDT_O_CTL, WDT_CTL_INTEN_BITN) = 1;
142 }
143 
144 //*****************************************************************************
145 //
156 //
157 //*****************************************************************************
158 __STATIC_INLINE void
160 {
161  // Enable the watchdog reset.
162  HWREGBITW(WDT_BASE + WDT_O_CTL, WDT_CTL_RESEN_BITN) = 1;
163 }
164 
165 //*****************************************************************************
166 //
177 //
178 //*****************************************************************************
179 __STATIC_INLINE void
181 {
182  // Disable the watchdog reset.
183  HWREGBITW(WDT_BASE + WDT_O_CTL, WDT_CTL_RESEN_BITN) = 0;
184 }
185 
186 //*****************************************************************************
187 //
194 //
195 //*****************************************************************************
196 __STATIC_INLINE void
198 {
199  //
200  // Lock out watchdog register writes. Writing anything to the WDT_O_LOCK
201  // register causes the lock to go into effect.
202  //
204 }
205 
206 //*****************************************************************************
207 //
214 //
215 //*****************************************************************************
216 __STATIC_INLINE void
218 {
219  //
220  // Unlock watchdog register writes.
221  //
223 }
224 
225 //*****************************************************************************
226 //
234 //
235 //*****************************************************************************
236 __STATIC_INLINE bool
238 {
239  //
240  // Get the lock state.
241  //
242  return((HWREG(WDT_BASE + WDT_O_LOCK) == WATCHDOG_LOCK_LOCKED) ?
243  true : false);
244 }
245 
246 //*****************************************************************************
247 //
263 //
264 //*****************************************************************************
265 __STATIC_INLINE void
266 WatchdogReloadSet(uint32_t ui32LoadVal)
267 {
268  //
269  // Set the load register.
270  //
271  HWREG(WDT_BASE + WDT_O_LOAD) = ui32LoadVal;
272 }
273 
274 //*****************************************************************************
275 //
284 //
285 //*****************************************************************************
286 __STATIC_INLINE uint32_t
288 {
289  //
290  // Get the load register.
291  //
292  return(HWREG(WDT_BASE + WDT_O_LOAD));
293 }
294 
295 //*****************************************************************************
296 //
302 //
303 //*****************************************************************************
304 __STATIC_INLINE uint32_t
306 {
307  //
308  // Get the current watchdog timer register value.
309  //
310  return(HWREG(WDT_BASE + WDT_O_VALUE));
311 }
312 
313 //*****************************************************************************
314 //
334 //
335 //*****************************************************************************
336 __STATIC_INLINE void
337 WatchdogIntRegister(void (*pfnHandler)(void))
338 {
339  //
340  // Register the interrupt handler.
341  //
342  IntRegister(INT_WATCHDOG, pfnHandler);
343 
344  //
345  // Enable the watchdog timer interrupt.
346  //
347  IntEnable(INT_WATCHDOG);
348 }
349 
350 //*****************************************************************************
351 //
367 //
368 //*****************************************************************************
369 __STATIC_INLINE void
371 {
372  //
373  // Disable the interrupt.
374  //
375  IntDisable(INT_WATCHDOG);
376 
377  //
378  // Unregister the interrupt handler.
379  //
380  IntUnregister(INT_WATCHDOG);
381 }
382 
383 //*****************************************************************************
384 //
392 //
393 //*****************************************************************************
394 __STATIC_INLINE void
396 {
397  // Enable the Watchdog interrupt.
398  WatchdogEnable();
399 }
400 
401 //*****************************************************************************
402 //
412 //
413 //*****************************************************************************
414 __STATIC_INLINE uint32_t
416 {
417  //
418  // Return either the interrupt status or the raw interrupt status as
419  // requested.
420  //
421  return(HWREG(WDT_BASE + WDT_O_RIS));
422 }
423 
424 //*****************************************************************************
425 //
447 //
448 //*****************************************************************************
449 __STATIC_INLINE void
451 {
452  //
453  // Clear the interrupt source.
454  //
456 }
457 
458 //*****************************************************************************
459 //
474 //
475 //*****************************************************************************
476 __STATIC_INLINE void
477 WatchdogIntTypeSet(uint32_t ui32Type)
478 {
479  // Check the arguments.
480  ASSERT((ui32Type == WATCHDOG_INT_TYPE_INT) ||
481  (ui32Type == WATCHDOG_INT_TYPE_NMI));
482 
483  // Set the interrupt type.
484  HWREGBITW(WDT_BASE + WDT_O_CTL, WDT_CTL_INTTYPE_BITN) = (ui32Type == WATCHDOG_INT_TYPE_INT)? 0 : 1;
485 }
486 
487 //*****************************************************************************
488 //
499 //
500 //*****************************************************************************
501 __STATIC_INLINE void
503 {
504  // Enable timer stalling.
505  HWREGBITW(WDT_BASE + WDT_O_TEST, WDT_TEST_STALL_BITN) = 1;
506 }
507 
508 //*****************************************************************************
509 //
517 //
518 //*****************************************************************************
519 __STATIC_INLINE void
521 {
522  // Disable timer stalling.
523  HWREGBITW(WDT_BASE + WDT_O_TEST, WDT_TEST_STALL_BITN) = 0;
524 }
525 
526 //*****************************************************************************
527 //
528 // Mark the end of the C bindings section for C++ compilers.
529 //
530 //*****************************************************************************
531 #ifdef __cplusplus
532 }
533 #endif
534 
535 #endif // __WDT_H__
536 
537 //*****************************************************************************
538 //
542 //
543 //*****************************************************************************
#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:337
#define WATCHDOG_INT_TYPE_NMI
Definition: watchdog.h:94
static void WatchdogUnlock(void)
Disables the watchdog timer lock mechanism.
Definition: watchdog.h:217
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:370
static void WatchdogLock(void)
Enables the watchdog timer lock mechanism.
Definition: watchdog.h:197
static void WatchdogStallDisable(void)
Disables stalling of the watchdog timer during debug events.
Definition: watchdog.h:520
static uint32_t WatchdogIntStatus(void)
Gets the current watchdog timer interrupt status.
Definition: watchdog.h:415
static void WatchdogIntEnable(void)
Enables the watchdog timer.
Definition: watchdog.h:395
static uint32_t WatchdogReloadGet(void)
Gets the watchdog timer reload value.
Definition: watchdog.h:287
static void WatchdogEnable(void)
Enables the watchdog timer.
Definition: watchdog.h:138
static void WatchdogStallEnable(void)
Enables stalling of the watchdog timer during debug events.
Definition: watchdog.h:502
#define ASSERT(expr)
Definition: debug.h:74
static void WatchdogResetEnable(void)
Enables the watchdog timer reset.
Definition: watchdog.h:159
#define WATCHDOG_INT_TYPE_INT
Definition: watchdog.h:93
static void WatchdogResetDisable(void)
Disables the watchdog timer reset.
Definition: watchdog.h:180
#define WATCHDOG_LOCK_UNLOCK
Definition: watchdog.h:78
static bool WatchdogLockState(void)
Gets the state of the watchdog timer lock mechanism.
Definition: watchdog.h:237
void IntUnregister(uint32_t ui32Interrupt)
Unregisters the function to be called when an interrupt occurs.
Definition: interrupt.c:200
static uint32_t WatchdogValueGet(void)
Gets the current watchdog timer value.
Definition: watchdog.h:305
static void WatchdogIntTypeSet(uint32_t ui32Type)
Sets the type of interrupt generated by the watchdog.
Definition: watchdog.h:477
static void WatchdogReloadSet(uint32_t ui32LoadVal)
Sets the watchdog timer reload value.
Definition: watchdog.h:266
static void WatchdogIntClear(void)
Clears the watchdog timer interrupt.
Definition: watchdog.h:450
#define WATCHDOG_LOCK_LOCKED
Definition: watchdog.h:77
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:378
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Registers a function to be called when an interrupt occurs.
Definition: interrupt.c:152
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:318