2 * Watchdog Driver Test Program
12 #include <sys/ioctl.h>
13 #include <linux/types.h>
14 #include <linux/watchdog.h>
20 * This function simply sends an IOCTL to the driver, which in turn ticks
21 * the PC Watchdog card to reset its internal timer so it doesn't trigger
24 static void keep_alive(void)
29 ioctl(fd, WDIOC_KEEPALIVE, &dummy);
33 * The main program. Run the program with "-d" to disable the card,
34 * or "-e" to enable the card.
37 static void term(int sig)
39 int ret = write(fd, &v, 1);
43 printf("\nStopping watchdog ticks failed (%d)...\n", errno);
45 printf("\nStopping watchdog ticks...\n");
49 int main(int argc, char *argv[])
52 unsigned int ping_rate = 1;
57 fd = open("/dev/watchdog", O_WRONLY);
60 printf("Watchdog device not enabled.\n");
65 if (!strncasecmp(argv[1], "-d", 2)) {
66 flags = WDIOS_DISABLECARD;
67 ioctl(fd, WDIOC_SETOPTIONS, &flags);
68 printf("Watchdog card disabled.\n");
70 } else if (!strncasecmp(argv[1], "-e", 2)) {
71 flags = WDIOS_ENABLECARD;
72 ioctl(fd, WDIOC_SETOPTIONS, &flags);
73 printf("Watchdog card enabled.\n");
75 } else if (!strncasecmp(argv[1], "-t", 2) && argv[2]) {
76 flags = atoi(argv[2]);
77 ioctl(fd, WDIOC_SETTIMEOUT, &flags);
78 printf("Watchdog timeout set to %u seconds.\n", flags);
80 } else if (!strncasecmp(argv[1], "-p", 2) && argv[2]) {
81 ping_rate = strtoul(argv[2], NULL, 0);
82 printf("Watchdog ping rate set to %u seconds.\n", ping_rate);
84 printf("-d to disable, -e to enable, -t <n> to set " \
85 "the timeout,\n-p <n> to set the ping rate, and \n");
86 printf("run by itself to tick the card.\n");
91 printf("Watchdog Ticking Away!\n");
100 ret = write(fd, &v, 1);
102 printf("Stopping watchdog ticks failed (%d)...\n", errno);