Moxa V2403-C2-W-T [55/90] Examples

Moxa V2403-C2-W-T [55/90] Examples
V2403 Series Linux Software Programmer’s Guide
4-8
Examples
The example watchdog-test.c acks the watchdog.
/*
* Watchdog Driver Test Program
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/watchdog.h>
int fd;
/*
* This function simply sends an IOCTL to the driver, which in turn ticks
* the PC Watchdog card to reset its internal timer so it doesn't trigger
* a computer reset.
*/
static void keep_alive(void)
{
int dummy;
ioctl(fd, WDIOC_KEEPALIVE, &dummy);
}
/*
* The main program. Run the program with "-d" to disable the card,
* or "-e" to enable the card.
*/
static void term(int sig)
{
close(fd);
fprintf(stderr, "Stopping watchdog ticks...\n");
exit(0);
}
int main(int argc, char *argv[])
{
int flags;
unsigned int ping_rate = 1;
fd = open("/dev/watchdog", O_WRONLY);
if (fd == -1) {
fprintf(stderr, "Watchdog device not enabled.\n");
fflush(stderr);

Содержание

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

Скачать