Moxa DA-662A-16-LX [55/63] 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

Moxa DA-662A-I-8-LX [55/63] 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
DA-662A Series Software Programmer's Guide
5-8
int swtd_ack(int fd)
Description
Acknowledge sWatchDog. When the user application enables WatchDog. It needs to call this function
periodically using the user predefined time in the application program.
Input
int fd - the file handle from swtd_open() return value.
Output
If OK, zero will be returned. Nonzero values indicate an error. Get the error code from errno().
int swtd_close(int fd)
Description
Close the file handle.
Input
int fd - the file handle from swtd_open() return value.
Output
If OK, zero will be returned. Nonzero values indicate an error. Get the error code from errno().
4. Special Note
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:

Содержание

Похожие устройства

Скачать