XMLTagsEditHistoryDiscussion

In this page we show how to enable the watchdog timer of the at91rm200. It will allow you to do an automated system reset if a program fails to ping the watchdog.

Setup the kernel

Enable required options in your kernel .confg:

 CONFIG_WATCHDOG=y
 CONFIG_WATCHDOG_NOWAYOUT=y
 CONFIG_AT91RM9200_WATCHDOG=y

Boot the new kernel, and check for watchdog support when it boots.

 > dmesg |grep Watch
 AT91 Watchdog Timer enabled (5 seconds, nowayout)

Verify that the device file exists

This file has a major number 10, minor number 130.

 crw-rw---- 1 root root 10, 130 Dec 31 19:00 /dev/watchdog

If it doesn't exist, create it with mknod.

 > mknod  /dev/watchdog c 10 130

Build an example

Here we will show the example watchdog-test.c that lives in the Linux kernel documentation linux-2.6.xx/Documentation/watchdog/src.

/*
 * Watchdog Driver Test Program
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/watchdog.h>

int fd;

/*
 * This function simply sends an IOCTL to the driver, which in turn ticks
 * the PC Watchdog card to reset its internal timer so it doesn't trigger
 * a computer reset.
 */

void keep_alive(void)
{
    int dummy;

    ioctl(fd, WDIOC_KEEPALIVE, &dummy);
}

/*
 * The main program.  Run the program with "-d" to disable the card,
 * or "-e" to enable the card.
 */
int main(int argc, char *argv[])
{
    fd = open("/dev/watchdog", O_WRONLY);

    if (fd == -1) {
	fprintf(stderr, "Watchdog device not enabled.\n");
	fflush(stderr);
	exit(-1);
    }

    if (argc > 1) {
	if (!strncasecmp(argv[1], "-d", 2)) {
	    ioctl(fd, WDIOC_SETOPTIONS, WDIOS_DISABLECARD);
	    fprintf(stderr, "Watchdog card disabled.\n");
	    fflush(stderr);
	    exit(0);
	} else if (!strncasecmp(argv[1], "-e", 2)) {
	    ioctl(fd, WDIOC_SETOPTIONS, WDIOS_ENABLECARD);
	    fprintf(stderr, "Watchdog card enabled.\n");
	    fflush(stderr);
	    exit(0);
	} else {
	    fprintf(stderr, "-d to disable, -e to enable.\n");
	    fprintf(stderr, "run by itself to tick the card.\n");
	    fflush(stderr);
	    exit(0);
	}
    } else {
	fprintf(stderr, "Watchdog Ticking Away!\n");
	fflush(stderr);
    }

    while (1) {
	keep_alive();
	sleep(1);
    }
}

Now compile it:

arm-softfloat-linux-gnu-gcc  watchdog-test.c -o watchdog-test

Test the watchdog

 > ./watchdog-test -e
 Watchdog card enabled.
 > ./watchdog-test
 Watchdog Ticking Away!

Interrupt the process (with Ctrl+C) and wait five seconds. The at91rm9200 watchdog should reset the board.

References

Last update: 2007-07-30 (Rev 393)

svnwiki $Rev: 12966 $