Hardware Watchdog

From OpenTom

(Redirected from Watchdog)
Jump to: navigation, search

Excerpt from the 2.4.x sourcecode how to use the watchdog:


Create the proper device 'mknod /dev/watchdog c 246 0'
Set watchdog timeout with ioctl on /dev/watchdog (IOW_WD_SET_TIME, in  seconds)
Kick the watchdog within the set time using IOW_WD_KICK (NULL argument)


Source is in the kernel 2.4 trunk ..../drivers/Barcelona/Watchdog/


Note that in the 2.6.x kernel there is no port of the Barcelona Watchdog driver, since it already provides a generic s3c2410 watchdog driver. Of course the userspace is not compatible, since the TTGO driver authors apparently didn't know the generic watchdog api.

Sample Code

#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
 
int main(int argc, char* argv[])
{
    int fd;

    if((fd = open("/dev/watchdog", O_RDWR | O_NOCTTY)) < 0) {
        fprintf(stderr, "could not open watchdog: %s", strerror(errno));
        return 1;
    }

    // If you're running this program via ttn,
    // daemonizing will be automatic,
    // so this call to daemonize() won't be necessary.
    if(daemonize() < 0) {
        fprintf(stderr, "could not daemonize: %s", strerror(errno));
        return 1;
    }

    while(1) {
        write(fd, "\0", 1);
        sleep(15);               // Perhaps 13 would be safer...
    }
}

Execute via ttn

Let's say, you name this little utility dogfeed and put it in /mnt/sdcard/bin, then your ttn should look like this:

/mnt/sdcard/bin/dogfeed &

ttn &

and you'll never be bothered with this watchdog stuff again.

Now, here's the nice part.

When there's too much interference from the navigation application /bin/ttn and you need to stop it so that your own program works properly, you don't necessarily have to kill and then restart it anymore, instead you can suspend it and then make it continue.

Start your program via a shell script, e.g. MyProg.sh, which should look like this:

#! /bin/sh

# Suspend ttn
killall -q -SIGSTOP ttn

cd /mnt/sdcard/<MyProg-folder>
./<MyProg>

# We're done, let ttn continue.
killall -q -SIGCONT ttn

In this fashion you're immediately back to the nav app, rather than having to wait 10 seconds or so for it to restart. (Which would be the case if, in your script, you used: killall ttn, <MyProg>, /bin/ttn &)

Personal tools