UDOO watchdog

From eLinux.org
Jump to: navigation, search

A watchdog timer (WDT; sometimes called a computer operating properly or COP timer, or simply a watchdog) is an electronic timer that is used to detect and recover from computer malfunctions. During normal operation, the computer regularly restarts the watchdog timer to prevent it from elapsing, or "timing out". If, due to a hardware fault or program error, the computer fails to restart the watchdog, the timer will elapse and generate a timeout signal. The timeout signal is used to initiate corrective action or actions. The corrective actions typically include placing the computer system in a safe state and restoring normal system operation. You can use Watchdog to provide hardware stability control to your projects.

To enable Watchdog function you need to export two gpios. You should run these commands as root user.

sudo su

Enter root password.

Export the two gpios.

echo 132 > /sys/class/gpio/export && echo 83 > /sys/class/gpio/export
gpio132 ---> WDT_EN ---> Enable/disable Watchdog (LOW => ENABLE)
gpio83  ---> WDT_TR ---> Trigger signal

Set the WDT_EN signal as output with high value. This signal enable Watchdog when it's LOW.

echo out > /sys/class/gpio/gpio132/direction && echo 1 > /sys/class/gpio/gpio132/value


Now you should create and launch some task that generate a trigger sequence command. This c program generate an impulse sequence at 5Hz (each pulse il 0.2 seconds long).

Open a terminal, create and open a file named, for example, wdoggy.c

nano wdoggy.c

Copy this content inside the file:

#include<stdlib.h>
#include<stdio.h>
int main(void){
   
   printf("UDOO Watchdog trigger example running ...");
   system( "echo out > /sys/class/gpio/gpio83/direction" );
   
   for(;;) {
       system( "echo 0 > /sys/class/gpio/gpio83/value" );
       usleep(100000);
       system( "echo 1 > /sys/class/gpio/gpio83/value" );
       usleep(100000);
   } 
}

Save the file, and compile it

gcc wdoggy.c -o wdoggy

Then run it

./wdoggy

If you try to stop the process, after one second the board reboot automatically.

So if you need a Watchdog function in your application you need to enable the Watchdog and provide a service that ping the WDT_TR more then one a second.