DA-681 Linux
Software Configuration
2-18
struct timeval time;
time.tv_sec = msec / 1000;
time.tv_usec = (msec % 1000) * 1000;
select(1, NULL, NULL, NULL, &time);
}
static int swtdfd;
static int stopflag=0;
static void stop_swatchdog()
{
stopflag = 1;
}
static void do_swatchdog(void)
{
swtd_enable(swtdfd, 500);
while ( stopflag == 0 ) {
mydelay(250);
swtd_ack(swtdfd);
}
swtd_disable(swtdfd);
}
int main(int argc, char *argv[])
{
pid_t
sonpid;
signal(SIGUSR1, stop_swatchdog);
swtdfd = swtd_open();
if ( swtdfd < 0 ) {
printf(“Open sWatchDog device fail !\n”);
exit(1);
}
if ( (sonpid=fork()) == 0 )
do_swatchdog();
// do user application main function
…..
…..
…..
// end user application
kill(sonpid, SIGUSR1);
swtd_close(swtdfd);
exit(1);
}
/*
* The convenient watchdog API --- libswtd.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
// following for sWatchDog implement
#define IOCTL_SWATCHDOG_ENABLE 1
#define IOCTL_SWATCHDOG_DISABLE 2
#define IOCTL_SWATCHDOG_GET 3
#define IOCTL_SWATCHDOG_ACK 4
int swtd_open(void)
{
return open("/dev/swtd", O_RDWR);
}
int swtd_enable(int fd, unsigned long time)
{
return ioctl(fd, IOCTL_SWATCHDOG_ENABLE, &time);
}
int swtd_disable(int fd)
{