User`s manual

UC-8410/8416/8418/8430 Programmer's Guide
5-7
When you “kill the application with -9” or “kill without option” or “Ctrl+c” the kernel will change to auto ack
the sWatchDog.
When your application enables the sWatchDog and does not ack, your application may have a logical error,
or your application has made a core dump. The kernel will not change to auto ack. This can cause a serious
problem, causing your system to reboot again and again.
5. User application example
Example 1:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <moxadevice.h>
int main(int argc, char *argv[])
{
int fd;
fd = swtd_open();
if ( fd < 0 ) {
printf(“Open sWatchDog device fail !\n”);
exit(1);
}
swtd_enable(fd, 5000); // enable it and set it 5 seconds
while ( 1 ) {
// do user application want to do
…..
….
swtd_ack(fd);
…..
….
}
swtd_close(fd);
exit(0);
}
The makefile is shown below:
all:
xscale-linux-gcc –o xxxx xxxx.c –lmoxalib
Example 2:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <moxadevice.h>
static void mydelay(unsigned long msec)
{
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;