EE445M RTOS
Taken at the University of Texas Spring 2015
watchdog.c
Go to the documentation of this file.
1 //*****************************************************************************
2 //
3 // watchdog.c - Driver for the Watchdog Timer Module.
4 //
5 // Copyright (c) 2005-2014 Texas Instruments Incorporated. All rights reserved.
6 // Software License Agreement
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the
18 // distribution.
19 //
20 // Neither the name of Texas Instruments Incorporated nor the names of
21 // its contributors may be used to endorse or promote products derived
22 // from this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // This is part of revision 2.1.0.12573 of the Tiva Peripheral Driver Library.
37 //
38 //*****************************************************************************
39 
40 //*****************************************************************************
41 //
44 //
45 //*****************************************************************************
46 
47 #include <stdbool.h>
48 #include <stdint.h>
49 #include "inc/hw_ints.h"
50 #include "inc/hw_memmap.h"
51 #include "inc/hw_types.h"
52 #include "inc/hw_watchdog.h"
53 #include "driverlib/debug.h"
54 #include "driverlib/interrupt.h"
55 #include "driverlib/watchdog.h"
56 
57 //*****************************************************************************
58 //
67 //
68 //*****************************************************************************
69 bool
70 WatchdogRunning(uint32_t ui32Base)
71 {
72  //
73  // Check the arguments.
74  //
75  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
76 
77  //
78  // See if the watchdog timer module is enabled, and return.
79  //
80  return(HWREG(ui32Base + WDT_O_CTL) & WDT_CTL_INTEN);
81 }
82 
83 //*****************************************************************************
84 //
94 //
95 //*****************************************************************************
96 void
97 WatchdogEnable(uint32_t ui32Base)
98 {
99  //
100  // Check the arguments.
101  //
102  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
103 
104  //
105  // Enable the watchdog timer module.
106  //
107  HWREG(ui32Base + WDT_O_CTL) |= WDT_CTL_INTEN;
108 }
109 
110 //*****************************************************************************
111 //
122 //
123 //*****************************************************************************
124 void
125 WatchdogResetEnable(uint32_t ui32Base)
126 {
127  //
128  // Check the arguments.
129  //
130  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
131 
132  //
133  // Enable the watchdog reset.
134  //
135  HWREG(ui32Base + WDT_O_CTL) |= WDT_CTL_RESEN;
136 }
137 
138 //*****************************************************************************
139 //
150 //
151 //*****************************************************************************
152 void
153 WatchdogResetDisable(uint32_t ui32Base)
154 {
155  //
156  // Check the arguments.
157  //
158  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
159 
160  //
161  // Disable the watchdog reset.
162  //
163  HWREG(ui32Base + WDT_O_CTL) &= ~(WDT_CTL_RESEN);
164 }
165 
166 //*****************************************************************************
167 //
175 //
176 //*****************************************************************************
177 void
178 WatchdogLock(uint32_t ui32Base)
179 {
180  //
181  // Check the arguments.
182  //
183  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
184 
185  //
186  // Lock out watchdog register writes. Writing anything to the WDT_O_LOCK
187  // register causes the lock to go into effect.
188  //
189  HWREG(ui32Base + WDT_O_LOCK) = WDT_LOCK_LOCKED;
190 }
191 
192 //*****************************************************************************
193 //
201 //
202 //*****************************************************************************
203 void
204 WatchdogUnlock(uint32_t ui32Base)
205 {
206  //
207  // Check the arguments.
208  //
209  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
210 
211  //
212  // Unlock watchdog register writes.
213  //
214  HWREG(ui32Base + WDT_O_LOCK) = WDT_LOCK_UNLOCK;
215 }
216 
217 //*****************************************************************************
218 //
227 //
228 //*****************************************************************************
229 bool
230 WatchdogLockState(uint32_t ui32Base)
231 {
232  //
233  // Check the arguments.
234  //
235  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
236 
237  //
238  // Get the lock state.
239  //
240  return((HWREG(ui32Base + WDT_O_LOCK) == WDT_LOCK_LOCKED) ? true : false);
241 }
242 
243 //*****************************************************************************
244 //
259 //
260 //*****************************************************************************
261 void
262 WatchdogReloadSet(uint32_t ui32Base, uint32_t ui32LoadVal)
263 {
264  //
265  // Check the arguments.
266  //
267  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
268 
269  //
270  // Set the load register.
271  //
272  HWREG(ui32Base + WDT_O_LOAD) = ui32LoadVal;
273 }
274 
275 //*****************************************************************************
276 //
285 //
286 //*****************************************************************************
287 uint32_t
288 WatchdogReloadGet(uint32_t ui32Base)
289 {
290  //
291  // Check the arguments.
292  //
293  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
294 
295  //
296  // Get the load register.
297  //
298  return(HWREG(ui32Base + WDT_O_LOAD));
299 }
300 
301 //*****************************************************************************
302 //
310 //
311 //*****************************************************************************
312 uint32_t
313 WatchdogValueGet(uint32_t ui32Base)
314 {
315  //
316  // Check the arguments.
317  //
318  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
319 
320  //
321  // Get the current watchdog timer register value.
322  //
323  return(HWREG(ui32Base + WDT_O_VALUE));
324 }
325 
326 //*****************************************************************************
327 //
350 //
351 //*****************************************************************************
352 void
353 WatchdogIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
354 {
355  //
356  // Check the arguments.
357  //
358  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
359 
360  //
361  // Register the interrupt handler.
362  //
363  IntRegister(INT_WATCHDOG_TM4C123, pfnHandler);
364 
365  //
366  // Enable the watchdog timer interrupt.
367  //
369 }
370 
371 //*****************************************************************************
372 //
392 //
393 //*****************************************************************************
394 void
395 WatchdogIntUnregister(uint32_t ui32Base)
396 {
397  //
398  // Check the arguments.
399  //
400  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
401 
402  //
403  // Disable the interrupt.
404  //
406 
407  //
408  // Unregister the interrupt handler.
409  //
411 }
412 
413 //*****************************************************************************
414 //
424 //
425 //*****************************************************************************
426 void
427 WatchdogIntEnable(uint32_t ui32Base)
428 {
429  //
430  // Check the arguments.
431  //
432  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
433 
434  //
435  // Enable the watchdog interrupt.
436  //
437  HWREG(ui32Base + WDT_O_CTL) |= WDT_CTL_INTEN;
438 }
439 
440 //*****************************************************************************
441 //
454 //
455 //*****************************************************************************
456 uint32_t
457 WatchdogIntStatus(uint32_t ui32Base, bool bMasked)
458 {
459  //
460  // Check the arguments.
461  //
462  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
463 
464  //
465  // Return either the interrupt status or the raw interrupt status as
466  // requested.
467  //
468  if(bMasked)
469  {
470  return(HWREG(ui32Base + WDT_O_MIS));
471  }
472  else
473  {
474  return(HWREG(ui32Base + WDT_O_RIS));
475  }
476 }
477 
478 //*****************************************************************************
479 //
498 //
499 //*****************************************************************************
500 void
501 WatchdogIntClear(uint32_t ui32Base)
502 {
503  //
504  // Check the arguments.
505  //
506  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
507 
508  //
509  // Clear the interrupt source.
510  //
511  HWREG(ui32Base + WDT_O_ICR) = WDT_RIS_WDTRIS;
512 }
513 
514 //*****************************************************************************
515 //
536 //
537 //*****************************************************************************
538 void
539 WatchdogIntTypeSet(uint32_t ui32Base, uint32_t ui32Type)
540 {
541  //
542  // Check the arguments.
543  //
544  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
545  ASSERT((ui32Type == WATCHDOG_INT_TYPE_INT) ||
546  (ui32Type == WATCHDOG_INT_TYPE_NMI));
547 
548  //
549  // Set the interrupt type.
550  //
551  HWREG(ui32Base + WDT_O_CTL) = (HWREG(ui32Base + WDT_O_CTL) &
552  ~WDT_CTL_INTTYPE) | ui32Type;
553 }
554 
555 //*****************************************************************************
556 //
572 //
573 //*****************************************************************************
574 void
575 WatchdogStallEnable(uint32_t ui32Base)
576 {
577  //
578  // Check the arguments.
579  //
580  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
581 
582  //
583  // Enable timer stalling.
584  //
585  HWREG(ui32Base + WDT_O_TEST) |= WDT_TEST_STALL;
586 }
587 
588 //*****************************************************************************
589 //
601 //
602 //*****************************************************************************
603 void
604 WatchdogStallDisable(uint32_t ui32Base)
605 {
606  //
607  // Check the arguments.
608  //
609  ASSERT((ui32Base == WATCHDOG0_BASE) || (ui32Base == WATCHDOG1_BASE));
610 
611  //
612  // Disable timer stalling.
613  //
614  HWREG(ui32Base + WDT_O_TEST) &= ~(WDT_TEST_STALL);
615 }
616 
617 //*****************************************************************************
618 //
619 // Close the Doxygen group.
621 //
622 //*****************************************************************************
void WatchdogIntTypeSet(uint32_t ui32Base, uint32_t ui32Type)
Definition: watchdog.c:539
#define HWREG(x)
Definition: hw_types.h:48
void WatchdogResetEnable(uint32_t ui32Base)
Definition: watchdog.c:125
#define WATCHDOG1_BASE
Definition: hw_memmap.h:52
void WatchdogStallEnable(uint32_t ui32Base)
Definition: watchdog.c:575
#define WDT_O_RIS
Definition: hw_watchdog.h:52
#define WDT_LOCK_UNLOCK
Definition: hw_watchdog.h:120
#define ASSERT(expr)
Definition: debug.h:67
#define WDT_O_TEST
Definition: hw_watchdog.h:54
void WatchdogReloadSet(uint32_t ui32Base, uint32_t ui32LoadVal)
Definition: watchdog.c:262
void WatchdogIntRegister(uint32_t ui32Base, void(*pfnHandler)(void))
Definition: watchdog.c:353
#define WDT_O_ICR
Definition: hw_watchdog.h:51
void WatchdogIntUnregister(uint32_t ui32Base)
Definition: watchdog.c:395
#define WDT_O_MIS
Definition: hw_watchdog.h:53
void WatchdogIntEnable(uint32_t ui32Base)
Definition: watchdog.c:427
#define WDT_RIS_WDTRIS
Definition: hw_watchdog.h:96
#define INT_WATCHDOG_TM4C123
Definition: hw_ints.h:82
#define WDT_CTL_RESEN
Definition: hw_watchdog.h:80
void WatchdogEnable(uint32_t ui32Base)
Definition: watchdog.c:97
uint32_t WatchdogValueGet(uint32_t ui32Base)
Definition: watchdog.c:313
void WatchdogUnlock(uint32_t ui32Base)
Definition: watchdog.c:204
uint32_t WatchdogReloadGet(uint32_t ui32Base)
Definition: watchdog.c:288
#define WDT_LOCK_LOCKED
Definition: hw_watchdog.h:119
#define WDT_O_LOCK
Definition: hw_watchdog.h:55
#define WATCHDOG_INT_TYPE_INT
Definition: watchdog.h:59
void WatchdogResetDisable(uint32_t ui32Base)
Definition: watchdog.c:153
bool WatchdogRunning(uint32_t ui32Base)
Definition: watchdog.c:70
#define WDT_CTL_INTTYPE
Definition: hw_watchdog.h:79
void WatchdogIntClear(uint32_t ui32Base)
Definition: watchdog.c:501
uint32_t WatchdogIntStatus(uint32_t ui32Base, bool bMasked)
Definition: watchdog.c:457
void IntUnregister(uint32_t ui32Interrupt)
Definition: interrupt.c:381
#define WDT_CTL_INTEN
Definition: hw_watchdog.h:81
#define WDT_O_CTL
Definition: hw_watchdog.h:50
void WatchdogLock(uint32_t ui32Base)
Definition: watchdog.c:178
#define WATCHDOG_INT_TYPE_NMI
Definition: watchdog.h:60
#define WDT_TEST_STALL
Definition: hw_watchdog.h:110
bool WatchdogLockState(uint32_t ui32Base)
Definition: watchdog.c:230
#define WDT_O_VALUE
Definition: hw_watchdog.h:49
void WatchdogStallDisable(uint32_t ui32Base)
Definition: watchdog.c:604
void IntDisable(uint32_t ui32Interrupt)
Definition: interrupt.c:684
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Definition: interrupt.c:309
#define WATCHDOG0_BASE
Definition: hw_memmap.h:51
void IntEnable(uint32_t ui32Interrupt)
Definition: interrupt.c:610
#define WDT_O_LOAD
Definition: hw_watchdog.h:48