CC26xx Driver Library |

- Main Page
- Related Pages
- CC26xx APIs
- Register Descriptions
- Online Resources

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
watchdog.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: wdt.h
3 * Revised: 2015-01-14 12:12:44 +0100 (on, 14 jan 2015)
4 * Revision: 42373
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 //
43 //
44 //*****************************************************************************
45
46 #ifndef __WDT_H__
47 #define __WDT_H__
48
49 //*****************************************************************************
50 //
51 // If building with a C++ compiler, make all of the definitions in this header
52 // have a C binding.
53 //
54 //*****************************************************************************
55 #ifdef __cplusplus
56 extern "C"
57 {
58 #endif
59
60 #include <stdbool.h>
61 #include <stdint.h>
62 #include <inc/hw_types.h>
63 #include <inc/hw_ints.h>
64 #include <inc/hw_memmap.h>
65 #include <inc/hw_wdt.h>
66 #include <driverlib/debug.h>
67 #include <driverlib/interrupt.h>
68
69 //*****************************************************************************
70 //
71 // The following are defines for the bit fields in the WDT_O_LOCK register.
72 //
73 //*****************************************************************************
74 #define WATCHDOG_LOCK_UNLOCKED 0x00000000 // Unlocked
75 #define WATCHDOG_LOCK_LOCKED 0x00000001 // Locked
76 #define WATCHDOG_LOCK_UNLOCK 0x1ACCE551 // Unlocks the Watchdog Timer
77
78 //*****************************************************************************
79 //
80 // The following are defines for the bit fields in the WDT_ISR, WDT_RIS, and
81 // WDT_MIS registers.
82 //
83 //*****************************************************************************
84 #define WATCHDOG_INT_TIMEOUT 0x00000001 // Watchdog timer expired
85
86 //*****************************************************************************
87 //
88 // The type of interrupt that can be generated by the watchdog.
89 //
90 //*****************************************************************************
91 #define WATCHDOG_INT_TYPE_INT 0x00000000
92 #define WATCHDOG_INT_TYPE_NMI 0x00000004
93
94 //*****************************************************************************
95 //
96 // API Functions and prototypes
97 //
98 //*****************************************************************************
99
100 //*****************************************************************************
101 //
109 //
110 //*****************************************************************************
111 __STATIC_INLINE bool
112 WatchdogRunning(void)
113 {
114 //
115 // See if the watchdog timer module is enabled, and return.
116 //
117 return((HWREG(WDT_BASE + WDT_O_CTL) & WDT_CTL_INTEN) ? true : false);
118 }
119
120 //*****************************************************************************
121 //
131 //
132 //*****************************************************************************
133 __STATIC_INLINE void
134 WatchdogEnable(void)
135 {
136 //
137 // Enable the watchdog timer module.
138 //
139 HWREG(WDT_BASE + WDT_O_CTL) |= WDT_CTL_INTEN;
140 }
141
142 //*****************************************************************************
143 //
154 //
155 //*****************************************************************************
156 __STATIC_INLINE void
157 WatchdogResetEnable(void)
158 {
159 //
160 // Enable the watchdog reset.
161 //
162 HWREG(WDT_BASE + WDT_O_CTL) |= WDT_CTL_RESEN;
163 }
164
165 //*****************************************************************************
166 //
177 //
178 //*****************************************************************************
179 __STATIC_INLINE void
180 WatchdogResetDisable(void)
181 {
182 //
183 // Disable the watchdog reset.
184 //
185 HWREG(WDT_BASE + WDT_O_CTL) &= ~(WDT_CTL_RESEN);
186 }
187
188 //*****************************************************************************
189 //
196 //
197 //*****************************************************************************
198 __STATIC_INLINE void
199 WatchdogLock(void)
200 {
201 //
202 // Lock out watchdog register writes. Writing anything to the WDT_O_LOCK
203 // register causes the lock to go into effect.
204 //
205 HWREG(WDT_BASE + WDT_O_LOCK) = WATCHDOG_LOCK_LOCKED;
206 }
207
208 //*****************************************************************************
209 //
216 //
217 //*****************************************************************************
218 __STATIC_INLINE void
219 WatchdogUnlock(void)
220 {
221 //
222 // Unlock watchdog register writes.
223 //
224 HWREG(WDT_BASE + WDT_O_LOCK) = WATCHDOG_LOCK_UNLOCK;
225 }
226
227 //*****************************************************************************
228 //
236 //
237 //*****************************************************************************
238 __STATIC_INLINE bool
239 WatchdogLockState(void)
240 {
241 //
242 // Get the lock state.
243 //
244 return((HWREG(WDT_BASE + WDT_O_LOCK) == WATCHDOG_LOCK_LOCKED) ?
245 true : false);
246 }
247
248 //*****************************************************************************
249 //
265 //
266 //*****************************************************************************
267 __STATIC_INLINE void
268 WatchdogReloadSet(uint32_t ui32LoadVal)
269 {
270 //
271 // Set the load register.
272 //
273 HWREG(WDT_BASE + WDT_O_LOAD) = ui32LoadVal;
274 }
275
276 //*****************************************************************************
277 //
286 //
287 //*****************************************************************************
288 __STATIC_INLINE uint32_t
289 WatchdogReloadGet(void)
290 {
291 //
292 // Get the load register.
293 //
294 return(HWREG(WDT_BASE + WDT_O_LOAD));
295 }
296
297 //*****************************************************************************
298 //
304 //
305 //*****************************************************************************
306 __STATIC_INLINE uint32_t
307 WatchdogValueGet(void)
308 {
309 //
310 // Get the current watchdog timer register value.
311 //
312 return(HWREG(WDT_BASE + WDT_O_VALUE));
313 }
314
315 //*****************************************************************************
316 //
336 //
337 //*****************************************************************************
338 __STATIC_INLINE void
339 WatchdogIntRegister(void (*pfnHandler)(void))
340 {
341 //
342 // Register the interrupt handler.
343 //
344 IntRegister(INT_WATCHDOG, pfnHandler);
345
346 //
347 // Enable the watchdog timer interrupt.
348 //
349 IntEnable(INT_WATCHDOG);
350 }
351
352 //*****************************************************************************
353 //
369 //
370 //*****************************************************************************
371 __STATIC_INLINE void
372 WatchdogIntUnregister(void)
373 {
374 //
375 // Disable the interrupt.
376 //
377 IntDisable(INT_WATCHDOG);
378
379 //
380 // Unregister the interrupt handler.
381 //
382 IntUnregister(INT_WATCHDOG);
383 }
384
385 //*****************************************************************************
386 //
396 //
397 //*****************************************************************************
398 __STATIC_INLINE void
399 WatchdogIntEnable(void)
400 {
401 //
402 // Enable the Watchdog interrupt.
403 //
404 HWREG(WDT_BASE + WDT_O_CTL) |= WDT_CTL_INTEN;
405 }
406
407 //*****************************************************************************
408 //
416 //
417 //*****************************************************************************
418 __STATIC_INLINE uint32_t
419 WatchdogIntStatus(void)
420 {
421 //
422 // Return either the interrupt status or the raw interrupt status as
423 // requested.
424 //
425 return(HWREG(WDT_BASE + WDT_O_RIS));
426 }
427
428 //*****************************************************************************
429 //
445 //
446 //*****************************************************************************
447 __STATIC_INLINE void
448 WatchdogIntClear(void)
449 {
450 //
451 // Clear the interrupt source.
452 //
453 HWREG(WDT_BASE + WDT_O_ICR) = WATCHDOG_INT_TIMEOUT;
454 }
455
456 //*****************************************************************************
457 //
472 //
473 //*****************************************************************************
474 __STATIC_INLINE void
475 WatchdogIntTypeSet(uint32_t ui32Type)
476 {
477 uint32_t ui32Reg;
478
479 //
480 // Check the arguments.
481 //
482 ASSERT((ui32Type == WATCHDOG_INT_TYPE_INT) ||
483 (ui32Type == WATCHDOG_INT_TYPE_NMI));
484
485 //
486 // Set the interrupt type.
487 //
488 ui32Reg = HWREG(WDT_BASE + WDT_O_CTL);
489 ui32Reg &= ~WDT_CTL_INTTYPE;
490 HWREG(WDT_BASE + WDT_O_CTL) = ui32Reg | ui32Type;
491 }
492
493 //*****************************************************************************
494 //
505 //
506 //*****************************************************************************
507 __STATIC_INLINE void
508 WatchdogStallEnable(void)
509 {
510 //
511 // Enable timer stalling.
512 //
513 HWREG(WDT_BASE + WDT_O_TEST) |= WDT_TEST_STALL;
514 }
515
516 //*****************************************************************************
517 //
525 //
526 //*****************************************************************************
527 __STATIC_INLINE void
528 WatchdogStallDisable(void)
529 {
530 //
531 // Disable timer stalling.
532 //
533 HWREG(WDT_BASE + WDT_O_TEST) &= ~WDT_TEST_STALL;
534 }
535
536 //*****************************************************************************
537 //
538 // Mark the end of the C bindings section for C++ compilers.
539 //
540 //*****************************************************************************
541 #ifdef __cplusplus
542 }
543 #endif
544
545 #endif // __WDT_H__
546
547 //*****************************************************************************
548 //
551 //
552 //*****************************************************************************
WatchdogUnlock
__STATIC_INLINE void WatchdogUnlock(void)
Disables the watchdog timer lock mechanism.
Definition: watchdog.h:219
WATCHDOG_INT_TIMEOUT
#define WATCHDOG_INT_TIMEOUT
Definition: watchdog.h:84
WATCHDOG_INT_TYPE_NMI
#define WATCHDOG_INT_TYPE_NMI
Definition: watchdog.h:92
debug.h
ASSERT
#define ASSERT(expr)
Definition: debug.h:65
WatchdogValueGet
__STATIC_INLINE uint32_t WatchdogValueGet(void)
Gets the current watchdog timer value.
Definition: watchdog.h:307
WatchdogIntEnable
__STATIC_INLINE void WatchdogIntEnable(void)
Enables the watchdog timer interrupt.
Definition: watchdog.h:399
WatchdogResetDisable
__STATIC_INLINE void WatchdogResetDisable(void)
Disables the watchdog timer reset.
Definition: watchdog.h:180
WatchdogIntClear
__STATIC_INLINE void WatchdogIntClear(void)
Clears the watchdog timer interrupt.
Definition: watchdog.h:448
WatchdogIntTypeSet
__STATIC_INLINE void WatchdogIntTypeSet(uint32_t ui32Type)
Sets the type of interrupt generated by the watchdog.
Definition: watchdog.h:475
WatchdogLock
__STATIC_INLINE void WatchdogLock(void)
Enables the watchdog timer lock mechanism.
Definition: watchdog.h:199
WatchdogStallEnable
__STATIC_INLINE void WatchdogStallEnable(void)
Enables stalling of the watchdog timer during debug events.
Definition: watchdog.h:508
WatchdogRunning
__STATIC_INLINE bool WatchdogRunning(void)
Determines if the watchdog timer is enabled.
Definition: watchdog.h:112
interrupt.h
WATCHDOG_INT_TYPE_INT
#define WATCHDOG_INT_TYPE_INT
Definition: watchdog.h:91
WatchdogLockState
__STATIC_INLINE bool WatchdogLockState(void)
Gets the state of the watchdog timer lock mechanism.
Definition: watchdog.h:239
WATCHDOG_LOCK_UNLOCK
#define WATCHDOG_LOCK_UNLOCK
Definition: watchdog.h:76
WatchdogIntRegister
__STATIC_INLINE void WatchdogIntRegister(void(*pfnHandler)(void))
Registers an interrupt handler for the watchdog timer interrupt.
Definition: watchdog.h:339
WatchdogReloadGet
__STATIC_INLINE uint32_t WatchdogReloadGet(void)
Gets the watchdog timer reload value.
Definition: watchdog.h:289
IntUnregister
void IntUnregister(uint32_t ui32Interrupt)
Unregisters the function to be called when an interrupt occurs.
Definition: interrupt.c:205
WatchdogResetEnable
__STATIC_INLINE void WatchdogResetEnable(void)
Enables the watchdog timer reset.
Definition: watchdog.h:157
WatchdogEnable
__STATIC_INLINE void WatchdogEnable(void)
Enables the watchdog timer.
Definition: watchdog.h:134
WatchdogReloadSet
__STATIC_INLINE void WatchdogReloadSet(uint32_t ui32LoadVal)
Sets the watchdog timer reload value.
Definition: watchdog.h:268
WatchdogIntUnregister
__STATIC_INLINE void WatchdogIntUnregister(void)
Unregisters an interrupt handler for the watchdog timer interrupt.
Definition: watchdog.h:372
WatchdogIntStatus
__STATIC_INLINE uint32_t WatchdogIntStatus(void)
Gets the current watchdog timer interrupt status.
Definition: watchdog.h:419
WATCHDOG_LOCK_LOCKED
#define WATCHDOG_LOCK_LOCKED
Definition: watchdog.h:75
IntDisable
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:383
IntRegister
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Registers a function to be called when an interrupt occurs.
Definition: interrupt.c:157
IntEnable
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:323
WatchdogStallDisable
__STATIC_INLINE void WatchdogStallDisable(void)
Disables stalling of the watchdog timer during debug events.
Definition: watchdog.h:528