Watchdog Timer Sample Code - Advantech RSB-4411 User Manual

3.5" sbc with nxp i.mx6 processor arm cortex a9 architecture
Table of Contents

Advertisement

3.7.2

Watchdog Timer Sample Code

WatchDog Timer (WDT) sample code is as below:
   #include <stdio.h>
   #include <stdlib.h>
   #include <fcntl.h>
   #include <linux/watchdog.h>
   #include <sys/ioctl.h>
   #include <unistd.h>
   void help_info(void);
   int main(int argc, const char *argv[])
   {
   
int fd, timeout, sleep_sec, test;
   
int count=1;
   
if (argc < 2) {
   
   
   
}
   t
imeout = atoi(argv[1]);
   
sleep_sec = atoi(argv[2]);
   
if (sleep_sec <= 0) {
   
   
   
   
}
   
test = atoi(argv[3]);
   
printf("Starting wdt_driver (timeout: %d, sleep: %d, test: %s)\n",
   
   
fd = open("/dev/watchdog", O_WRONLY);
   
if (fd == ‐1) {
   
   
   
}
   
printf("Trying to set timeout value=%d seconds\n", timeout);
   
ioctl(fd, WDIOC_SETTIMEOUT, &timeout);
   
printf("The actual timeout was set to %d seconds\n", timeout);
   
ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
   
printf("Now reading back ‐‐ The timeout is %d seconds\n", timeout);
   
while (1) {
   
   
   
   
   
help_info();
return 1;
sleep_sec = 1;
printf("correct 0 or negative sleep time to %d seconds\n",
       sleep_sec);
timeout, sleep_sec, (test == 0) ? "ioctl" : "write");
perror("watchdog");
exit(1);
printf("WDT Time out counter:%d\n",count);
if ((test !=0) && (test ==count)) {
printf("Ping Watchdog (reset wdt)\n");
ioctl(fd, WDIOC_KEEPALIVE, 0);
test=0;
57
RSB-4411 User Manual

Advertisement

Table of Contents
loading

Table of Contents