Watchdog timer for LPC1549

Committer:
takuhachisu
Date:
Fri Nov 10 06:24:43 2017 +0000
Revision:
0:35b88129a223
Child:
2:c72a3d9002d5
Watchdog timer for LPC1549

Who changed what in which revision?

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