Watchdog timer for LPC1549
Diff: Watchdog.cpp
- Revision:
- 0:35b88129a223
- Child:
- 2:c72a3d9002d5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Watchdog.cpp Fri Nov 10 06:24:43 2017 +0000 @@ -0,0 +1,27 @@ +/** + * @file Watchdog.cpp + * @brief Watchdog for LPC1549 + * @author taku hachisu + * @date 2017/11/02 + */ + +#include "mbed.h" +#include "Watchdog.h" + +Watchdog::Watchdog(int ms) +{ + timeOutFlag = (LPC_WWDT->MOD >> 2) & 1; + LPC_SYSCON->SYSAHBCLKCTRL0 |= (1 << 22); + LPC_SYSCON->PDRUNCFG &= ~(1 << 20); + LPC_SYSCON->STARTERP0 |= 1; + uint32_t clk = 503000 / 4; // LPC1549's watchdog oscillator is fixed to 503 kHz + LPC_WWDT->TC = ((float)ms * (float)clk) / 1000; + LPC_WWDT->MOD = 0x03; + feed(); +} + +void Watchdog::feed() +{ + LPC_WWDT->FEED = 0xAA; + LPC_WWDT->FEED = 0x55; +} \ No newline at end of file