|
|
 |
Distribution Guide
Device drivers
Watchdog
|
|
Watchdog
The Watchdog is a simple hardware circuit which can reset the computer system in the event of a software fault.
In normal operation, a userspace daemon notifies the kernel watchdog driver at regular intervals that the userspace is still alive, via the /dev/watchdog special device file.
Configuring the kernel
By default, distribution 2.0 does not include the Watchdog support. To enable this, enter the configuration options:
-
Device Drivers ---> Character devices ---> Watchdog Cards ---> Watchdog Timer Support
-
Device Drivers ---> Character devices ---> Watchdog Cards ---> STM Watchdog
The Watchdog is supported on the following platforms:
- STi5528 Espresso (silicon cuts 1.3 and 2.0 with ST40 core),
- STb7100 (mb411 with ST40 core),
- ST220 evaluation board (mb392 - STm8000 with ST40 core),
- STi5301 board (with ST231 core).
Note: During the kernel configuration in the "Watchdog Cards" page, the user can also select Disable watchdog shutdown on close.
If this is selected and the user application closes the watchdog device file (even if it sends a V character; see Using the Watchdog device), the Watchdog stays on and, after <timeout> seconds, it resets the board.
Using the Watchdog device
A user application can use the Watchdog by referring to a special device, /dev/watchdog. This is a character device file with permission, device name, major and minor numbers, for example:
crw-rw-rw- /dev/watchdog 10 130 |
|
|
By default, the Watchdog is turned on when the device file is opened. When the device is closed, the Watchdog is not disabled unless a specific `magic character' V is sent to the /dev/watchdog file just before it is closed.
Watchdog driver ioctl calls
-
WDIOC_KEEPALIVE This notifies the watchdog that the user application is still alive. The argument to the ioctl is ignored.
-
WDIOC_SETTIMEOUT This sets the timeout. The default is 15 seconds.
-
WDIOC_GETTIMEOUT This reads the timeout value.
Example C code software
#include <stdio.h> #include <unistd.h> #include <fcntl.h> int fd=0; void sighandler (int signo) { if (!fd) { /* Be careful. * If the kernel was compiled with the "Disable watchdog shutdown on close" * support, then the next write & close operations will not disable the watchdog */ write(fd,"V",1); close(fd); } exit(0); } int main(int argc, const char *argv[]) { struct sigaction new, old; new.sa_handler = sighandler; sigemptyset (&new.sa_mask); new.sa_flags = 0; if (sigaction (SIGINT, &new, &old) < 0) { printf ("Error setting SIGINT handler!\n"); exit(0); } fd=open("/dev/watchdog",O_WRONLY); if(fd==-1) { perror("watchdog"); exit(1); } ioctl(fd,WDIOC_SETTIMEOUT,20); /* 20 seconds */ while(1) { ioctl(fd, WDIOC_KEEPALIVE, 0); sleep(18); } } |
|
|
|