How to Change the Watchdog Timer in Linux Embedded

WatchDog Timer In Linux

If you want to use timer interrupts, use signals, and especially SIGALRM.
You can use the function alarm() to ask for a timeout. if you want usec granularity you can use ualarm().
Once the timeout has reached it will call a Callback function you defined before.

Here's an example code:

#include <signal.h>

void watchdog(int sig)
{
printf("Pet the dog\r\n");
/* reset the timer so we get called again in 5 seconds */
alarm(5);
}

/* start the timer - we want to wake up in 5 seconds */
int main()
{
/* set up our signal handler to catch SIGALRM */
signal(SIGALRM, watchdog);
alarm(5);
while (true)
;
}

You have few other options for implementing a watchdog:

  1. Write / Use a kernel driver, which actually works as a watchdog, applying a hard reset to the device if the dog is not pet (or kicked)
  2. Use an watchdog, an interesting implementation of a software watchdog daemon.

How to debug a watchdog timeout

Add an uninitialized global variable that is set to different values throughout the code. Specifically, set it before and after major function calls.

Put a breakpoint at the beginning of main.

When the processor resets the global variable will still have the last value it was set to. Keep adding these "bread crumbs" to narrow down to the problem function.



Related Topics



Leave a reply



Submit