User`s manual

UC-7400-LX Plus User’s Manual Programmer’s Guide
5-8
exit(0);
}
The makefile is shown below:
all:
arm-elf-gcc –Wl, -elf2flt –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;
static void stop_watchdog()
{
stopflag = 1;
}
static void do_watchdog(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_watchdog);
swtdfd = swtd_open();
if ( swtdfd < 0 ) {
printf(“Open watchdog device fail !\n”);
exit(1);
}
if ( (sonpid=fork()) == 0 )
do_watchdog();
// do user application main function
…..
…..
…..
// end user application
kill(sonpid, SIGUSR1);
swtd_close(swtdfd);