2 * Watchdog Driver Test Program
11 #include <sys/ioctl.h>
12 #include <linux/types.h>
13 #include <linux/watchdog.h>
18 * This function simply sends an IOCTL to the driver, which in turn ticks
19 * the PC Watchdog card to reset its internal timer so it doesn't trigger
22 static void keep_alive(void)
26 ioctl(fd, WDIOC_KEEPALIVE, &dummy);
30 * The main program. Run the program with "-d" to disable the card,
31 * or "-e" to enable the card.
34 static void term(int sig)
37 fprintf(stderr, "Stopping watchdog ticks...\n");
41 int main(int argc, char *argv[])
44 unsigned int ping_rate = 1;
46 fd = open("/dev/watchdog", O_WRONLY);
49 fprintf(stderr, "Watchdog device not enabled.\n");
55 if (!strncasecmp(argv[1], "-d", 2)) {
56 flags = WDIOS_DISABLECARD;
57 ioctl(fd, WDIOC_SETOPTIONS, &flags);
58 fprintf(stderr, "Watchdog card disabled.\n");
61 } else if (!strncasecmp(argv[1], "-e", 2)) {
62 flags = WDIOS_ENABLECARD;
63 ioctl(fd, WDIOC_SETOPTIONS, &flags);
64 fprintf(stderr, "Watchdog card enabled.\n");
67 } else if (!strncasecmp(argv[1], "-t", 2) && argv[2]) {
68 flags = atoi(argv[2]);
69 ioctl(fd, WDIOC_SETTIMEOUT, &flags);
70 fprintf(stderr, "Watchdog timeout set to %u seconds.\n", flags);
73 } else if (!strncasecmp(argv[1], "-p", 2) && argv[2]) {
74 ping_rate = strtoul(argv[2], NULL, 0);
75 fprintf(stderr, "Watchdog ping rate set to %u seconds.\n", ping_rate);
78 fprintf(stderr, "-d to disable, -e to enable, -t <n> to set " \
79 "the timeout,\n-p <n> to set the ping rate, and \n");
80 fprintf(stderr, "run by itself to tick the card.\n");
86 fprintf(stderr, "Watchdog Ticking Away!\n");