In message <[EMAIL PROTECTED]>, Poul-Henning Kamp
 writes:
>phk         2003/02/27 13:13:08 PST
>
>  Modified files:
>    sys/i386/i386        elan-mmcr.c 
>  Log:
>  Add support for the Elan CPU hardware watchdog used in "active" mode.

Now we can get the watchdog to kill the machine if it goes unresponsive.

(And no, I don't have an MFC plan, I don't have any Soekris' runing
-stable)

This is a small program which shows how to use the api.  See also
the comments in <sys/watchdog.h> (also new file).

------------------------------------------------------------------------
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/watchdog.h>

int
main(int argc, char **argv)
{
        int fd;
        int i, j;
        unsigned u;

        fd = open("/dev/elan-mmcr", O_RDWR);
        if (fd < 0)
                err(1, "/dev/elan-mmcr");

        /*
         * Set a two second timeout, but reset it after one second.
         * Do this five times to see that it works as advertised.
         */
        for (j = 0; j < 5; j++) {
                u = WD_ACTIVE | WD_TO_2SEC;
                i = ioctl(fd, WDIOCPATPAT, &u);
                printf("2SEC %d %d\n", i, errno);
                sleep (1);
        }
        /*
         * Turn the watchdog off.
         * Wait twice the previous timeout, we should survive.
         */
        u = 0;
        i = ioctl(fd, WDIOCPATPAT, &u);
        printf("OFF %d %d\n", i, errno);
        sleep (5);
        /*
         * Set a two second timeout, and let it, and us, expire.
         */
        u = WD_ACTIVE | WD_TO_2SEC;
        i = ioctl(fd, WDIOCPATPAT, &u);
        printf("2SEC %d %d\n", i, errno);
        sleep (5);

        /*
         * We shouldn't get here alive.
         */
        printf("Where's the kaboom ?\n");
        exit (0);
}
------------------------------------------------------------------------



-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
[EMAIL PROTECTED]         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to