有时候程序运行过程中需要单独关闭看门狗:
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/watchdog.h>
#define TIMEOUT 10
#define WDT_DEVICE_FILE "/dev/watchdog"
int main(void)
{
int g_watchdog_fd = -1;
int timeout = 0;
char arg = 1;
g_watchdog_fd = open(WDT_DEVICE_FILE, O_RDWR);
if (!g_watchdog_fd)
{
printf("Error in file open WDT device file(%s)...\n", WDT_DEVICE_FILE);
return 0;
}
ioctl(g_watchdog_fd, WDIOC_SETOPTIONS, WDIOS_ENABLECARD);
#if 1
ioctl(g_watchdog_fd, WDIOC_GETTIMEOUT, &timeout);
printf("default timeout %d sec.\n", timeout);
printf("We reset timeout as %d sec.\n", TIMEOUT);
timeout = TIMEOUT;
ioctl(g_watchdog_fd, WDIOC_SETTIMEOUT, &timeout);
ioctl(g_watchdog_fd, WDIOC_GETTIMEOUT, &timeout);
if (timeout != TIMEOUT)
{
printf("WDT timeout reset error.\n");
return 1;
}
while (1)
{
write(g_watchdog_fd, &arg, sizeof(arg));
ioctl(g_watchdog_fd, WDIOC_KEEPALIVE, 0);
sleep(2);
}
#endif
ioctl(g_watchdog_fd, WDIOC_SETOPTIONS, WDIOS_DISABLECARD);
close(g_watchdog_fd);
printf("watchdog_disable_dog!!!\n");
return 0;
}