Watchdog timer for LPC1549

Committer:
takuhachisu
Date:
Fri Nov 10 06:53:18 2017 +0000
Revision:
2:c72a3d9002d5
Parent:
0:35b88129a223
Child:
3:bbe4a2eff805
Modified.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takuhachisu 0:35b88129a223 1 #include "mbed.h"
takuhachisu 0:35b88129a223 2 #include "Watchdog.h"
takuhachisu 0:35b88129a223 3
takuhachisu 0:35b88129a223 4 Watchdog::Watchdog(int ms)
takuhachisu 0:35b88129a223 5 {
takuhachisu 0:35b88129a223 6 timeOutFlag = (LPC_WWDT->MOD >> 2) & 1;
takuhachisu 0:35b88129a223 7 LPC_SYSCON->SYSAHBCLKCTRL0 |= (1 << 22);
takuhachisu 0:35b88129a223 8 LPC_SYSCON->PDRUNCFG &= ~(1 << 20);
takuhachisu 0:35b88129a223 9 LPC_SYSCON->STARTERP0 |= 1;
takuhachisu 0:35b88129a223 10 uint32_t clk = 503000 / 4; // LPC1549's watchdog oscillator is fixed to 503 kHz
takuhachisu 0:35b88129a223 11 LPC_WWDT->TC = ((float)ms * (float)clk) / 1000;
takuhachisu 0:35b88129a223 12 LPC_WWDT->MOD = 0x03;
takuhachisu 0:35b88129a223 13 feed();
takuhachisu 0:35b88129a223 14 }
takuhachisu 0:35b88129a223 15
takuhachisu 0:35b88129a223 16 void Watchdog::feed()
takuhachisu 0:35b88129a223 17 {
takuhachisu 0:35b88129a223 18 LPC_WWDT->FEED = 0xAA;
takuhachisu 0:35b88129a223 19 LPC_WWDT->FEED = 0x55;
takuhachisu 0:35b88129a223 20 }