嵌入式watchdog

#include <stdio.h>  
#include <unistd.h>  
#include <sys/types.h>  
#include <sys/stat.h>  
#include <fcntl.h>  
#include <syslog.h>  
#include <errno.h>  
  
void main(void)  
{  
    int   fd_watchdog=-1;
    while (1)
    {
    
    // fd_watchdog = open("/dev/watchdog", O_WRONLY);
    
    if(fd_watchdog == -1)  
    {  

        int err = errno;  
        printf("failed to open /dev/watchdog, errno: %d, %s\n", err, strerror(err));  
        fd_watchdog = open("/dev/watchdog", O_WRONLY);
        // return;  
    }  
    else  
    {  
        printf("open watchdog success!\n");  
    }  
  
    // 每个一段时间向/dev/watchdog 设备写入数据(“定期喂狗”)  
    if(fd_watchdog >= 0)  
    {  
        static unsigned char food = 0;  
        ssize_t eaten = write(fd_watchdog, &food, 1);  
        if(eaten != 1)  
        {  
            printf("failed feeding watchdog\n");  
        }  
        else  
        {  
            printf("success feeded watchdog\n");  
        }  
    }  
  }
    //close(fd_watchdog);  
}

  

posted @ 2020-10-10 17:24  ahuo  阅读(172)  评论(0编辑  收藏  举报