《开发板 — 实现看门狗》
1.内核配置
------->Device Drivers
-------->Watchdog Timer Support
-------->WatchDog Timer Driver Core[*]
-------->Software watchdog[*]
编译烧录内核,然后在板卡上面可以看到/dev/watchdog
2.看门狗编程
喂狗、喂狗时间设置、喂狗时间读取的接口如下:
ioctl(fd, WDIOC_KEEPALIVE, 0); ioctl(fd, WDIOC_SETTIMEOUT, &timeout); ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
3.例程
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/watchdog.h>
void main(int argc, char *argv[])
{
int fd,timeout;
timeout = 15;
fd = open("/dev/watchdog", O_WRONLY);
if(fd == -1)
{
printf("open watchdog error \r\n");
return 0;
}
ioctl(fd,WDIOC_SETTIMEOUT, &timeout);
while(1)
{
ioctl(fd, WDIOC_KEEPALIVE);
sleep(10);
}
}
在内核中有看门狗的说明以及例程,也可以查看:
4.github网址
https://github.com/ssahai/linux/blob/master/Documentation/watchdog/watchdog-api.txt