https://os.mbed.com/cookbook/WatchDog-Timer This link has demonstrated a way to implement Watchdog Timer on Mbed. This library is the library version of that code.
WatchdogTimer.cpp@1:7d0312e56c87, 2018-02-09 (annotated)
- Committer:
- mreda
- Date:
- Fri Feb 09 11:29:05 2018 +0000
- Revision:
- 1:7d0312e56c87
- Parent:
- 0:dece639e483e
- Child:
- 2:1b576cfa3f49
Edit Comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mreda | 0:dece639e483e | 1 | #include "mbed.h" |
mreda | 0:dece639e483e | 2 | #include "WatchdogTimer.h" |
mreda | 1:7d0312e56c87 | 3 | |
mreda | 1:7d0312e56c87 | 4 | |
mreda | 0:dece639e483e | 5 | // "kick" or "feed" the dog - reset the watchdog timer |
mreda | 0:dece639e483e | 6 | // by writing this required bit pattern |
mreda | 0:dece639e483e | 7 | void WatchdogTimer::kick() { |
mreda | 0:dece639e483e | 8 | LPC_WDT->WDFEED = 0xAA; |
mreda | 0:dece639e483e | 9 | LPC_WDT->WDFEED = 0x55; |
mreda | 0:dece639e483e | 10 | } |
mreda | 0:dece639e483e | 11 | // Load timeout value in watchdog timer and enable |
mreda | 0:dece639e483e | 12 | void WatchdogTimer::kick(float s) { |
mreda | 0:dece639e483e | 13 | LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK |
mreda | 0:dece639e483e | 14 | uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4 |
mreda | 0:dece639e483e | 15 | LPC_WDT->WDTC = s * (float)clk; |
mreda | 0:dece639e483e | 16 | LPC_WDT->WDMOD = 0x3; // Enabled and Reset |
mreda | 0:dece639e483e | 17 | kick(); |
mreda | 0:dece639e483e | 18 | } |
mreda | 0:dece639e483e | 19 |