#include <linux/watchdog.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <syslog.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int OpenTheWatchdog(int time)//开启看门狗
{
int timeout = time;
int fd_watchdog = open("/dev/watchdog", O_WRONLY);
ioctl(fd_watchdog, WDIOC_SETTIMEOUT, &timeout);
if(fd_watchdog == -1)
{
int err = errno;
LOG4CPLUS_ERROR(my_logger,"FAILED to open /dev/watchdog, errno: "<<err<<strerror(err));
}
else
{
LOG4CPLUS_INFO(my_logger," Watchdog open the success!");
}
return fd_watchdog;
}
void *FeedWatchdog(void *arg)//喂狗
{
int fd_watchdog = OpenTheWatchdog(20);//看门狗
if(fd_watchdog == -1)
return (void*)(-1);
int i=0;
while(1)
{
if(i<5)
{
if(fd_watchdog >= 0)
{
static unsigned char food = 0;
ssize_t eaten = write(fd_watchdog, &food, 1);
if(eaten != 1)
{
LOG4CPLUS_ERROR(my_logger, "FAILED feeding watchdog");
}
}
sleep(8);
}
}
}