You appear to be reading the correct register (and I assume WDTOF is set to 2). Carrying on from Simon's example, I have:
#include "mbed.h"
// Simon's Watchdog example
class Watchdog {
public:
void kick(float s) {
LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK
uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4
LPC_WDT->WDTC = s * (float)clk;
LPC_WDT->WDMOD = 0x3; // Enabled and Reset
kick();
}
void kick() {
LPC_WDT->WDFEED = 0xAA;
LPC_WDT->WDFEED = 0x55;
}
};
Watchdog wdt;
// Watchdog service routine
void bad_dog(void)
{
wdt.kick();
printf("Dog kicked\n");
}
int main() {
Ticker service;
DigitalOut heartbeat(LED1);
unsigned long wd_flag;
int count = 0;
printf("Reset!\n");
wd_flag = (LPC_WDT->WDMOD >> 2) & 1;
printf("Watchdog caused reset: %s\n", (wd_flag > 0) ? "True" : "False");
wd_flag = (LPC_WDT->WDMOD >> 2) & 1;
printf("Check watchdog cleared before clear: %s\n", (wd_flag == 0) ? "True" : "False");
LPC_WDT->WDMOD &= ~(1 << 2);
wd_flag = (LPC_WDT->WDMOD >> 2) & 1;
printf("Check watchdog cleared after clear: %s\n", (wd_flag == 0) ? "True" : "False");
wdt.kick(5.0); // 5 second timeout on watchdog - to make it visible
service.attach(&bad_dog, 2);
while(1)
{
heartbeat = !heartbeat;
wait(0.5);
count++;
if(count > 20)
service.detach(); // Stop servicing watchdog, to force "bite"
}
}
On the serial console, after a button push, this give me:
Reset!
Watchdog caused reset: False
Check watchdog cleared before clear: True
Check watchdog cleared after clear: True
Dog kicked
Dog kicked
Dog kicked
Dog kicked
Dog kicked
Reset!
Watchdog caused reset: True
Check watchdog cleared before clear: False
Check watchdog cleared after clear: True
Dog kicked
...
Hi, I'm wonder if it's possible to control watchdog on mbed ?
Regards
macc