Simple library to manage the WatchDog timer, tested on LPC1768
WatchDogTimer.cpp@0:3744cb611b63, 2015-01-03 (annotated)
- Committer:
- wyunreal
- Date:
- Sat Jan 03 13:26:51 2015 +0000
- Revision:
- 0:3744cb611b63
Simple library to manage the WatchDog timer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wyunreal | 0:3744cb611b63 | 1 | /** |
wyunreal | 0:3744cb611b63 | 2 | * Apache License |
wyunreal | 0:3744cb611b63 | 3 | * Version 2.0, January 2004 |
wyunreal | 0:3744cb611b63 | 4 | * http://www.apache.org/licenses/ |
wyunreal | 0:3744cb611b63 | 5 | */ |
wyunreal | 0:3744cb611b63 | 6 | |
wyunreal | 0:3744cb611b63 | 7 | #include "WatchDogTimer.h" |
wyunreal | 0:3744cb611b63 | 8 | |
wyunreal | 0:3744cb611b63 | 9 | int WatchDogTimer::systemResetReason() { |
wyunreal | 0:3744cb611b63 | 10 | return ((LPC_WDT->WDMOD >> 2) & 1) ? SYSTEM_RESET_WATCH_DOG : SYSTEM_RESET_NORMAL; |
wyunreal | 0:3744cb611b63 | 11 | } |
wyunreal | 0:3744cb611b63 | 12 | |
wyunreal | 0:3744cb611b63 | 13 | WatchDogTimer::WatchDogTimer(float seconds) { |
wyunreal | 0:3744cb611b63 | 14 | LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK |
wyunreal | 0:3744cb611b63 | 15 | uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4 |
wyunreal | 0:3744cb611b63 | 16 | LPC_WDT->WDTC = seconds * (float)clk; // Load WD Timer Constant with value determined by float s |
wyunreal | 0:3744cb611b63 | 17 | LPC_WDT->WDMOD = 0x3; // Enabled and Reset |
wyunreal | 0:3744cb611b63 | 18 | feed(); |
wyunreal | 0:3744cb611b63 | 19 | } |
wyunreal | 0:3744cb611b63 | 20 | |
wyunreal | 0:3744cb611b63 | 21 | void WatchDogTimer::feed() { |
wyunreal | 0:3744cb611b63 | 22 | LPC_WDT->WDFEED = 0xAA; |
wyunreal | 0:3744cb611b63 | 23 | LPC_WDT->WDFEED = 0x55; |
wyunreal | 0:3744cb611b63 | 24 | } |