Watchdog timer for LPC1549
Watchdog.cpp@3:bbe4a2eff805, 2017-11-10 (annotated)
- Committer:
- takuhachisu
- Date:
- Fri Nov 10 07:23:02 2017 +0000
- Revision:
- 3:bbe4a2eff805
- Parent:
- 2:c72a3d9002d5
Modified.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takuhachisu | 3:bbe4a2eff805 | 1 | #if defined(TARGET_LPC1549) |
takuhachisu | 3:bbe4a2eff805 | 2 | |
takuhachisu | 0:35b88129a223 | 3 | #include "mbed.h" |
takuhachisu | 0:35b88129a223 | 4 | #include "Watchdog.h" |
takuhachisu | 0:35b88129a223 | 5 | |
takuhachisu | 0:35b88129a223 | 6 | Watchdog::Watchdog(int ms) |
takuhachisu | 0:35b88129a223 | 7 | { |
takuhachisu | 0:35b88129a223 | 8 | timeOutFlag = (LPC_WWDT->MOD >> 2) & 1; |
takuhachisu | 0:35b88129a223 | 9 | LPC_SYSCON->SYSAHBCLKCTRL0 |= (1 << 22); |
takuhachisu | 0:35b88129a223 | 10 | LPC_SYSCON->PDRUNCFG &= ~(1 << 20); |
takuhachisu | 0:35b88129a223 | 11 | LPC_SYSCON->STARTERP0 |= 1; |
takuhachisu | 0:35b88129a223 | 12 | uint32_t clk = 503000 / 4; // LPC1549's watchdog oscillator is fixed to 503 kHz |
takuhachisu | 0:35b88129a223 | 13 | LPC_WWDT->TC = ((float)ms * (float)clk) / 1000; |
takuhachisu | 0:35b88129a223 | 14 | LPC_WWDT->MOD = 0x03; |
takuhachisu | 0:35b88129a223 | 15 | feed(); |
takuhachisu | 0:35b88129a223 | 16 | } |
takuhachisu | 0:35b88129a223 | 17 | |
takuhachisu | 0:35b88129a223 | 18 | void Watchdog::feed() |
takuhachisu | 0:35b88129a223 | 19 | { |
takuhachisu | 0:35b88129a223 | 20 | LPC_WWDT->FEED = 0xAA; |
takuhachisu | 0:35b88129a223 | 21 | LPC_WWDT->FEED = 0x55; |
takuhachisu | 3:bbe4a2eff805 | 22 | } |
takuhachisu | 3:bbe4a2eff805 | 23 | |
takuhachisu | 3:bbe4a2eff805 | 24 | #endif |