linux 嵌入式看门狗使用

linux 嵌入式看门狗使用,第1张

概述linux看门狗使用很简单,在应用层使用,只需要ioctl设置一下溢出时间,既可以使用看门狗,定时喂狗即可   前提是kernel支持看门狗 Device Drivers ─>   [*] Watchdog Timer Support  --->       配置好好后,即可make 应用层的使用,直接上代码 #include <stdio.h>#include <sys/types.h>

linux看门狗使用很简单,在应用层使用,只需要ioctl设置一下溢出时间,既可以使用看门狗,定时喂狗即可

 

前提是kernel支持看门狗

Device Drivers ─>

  [*] Watchdog Timer Support  --->

 

 

 

配置好好后,即可make

应用层的使用,直接上代码

#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <errno.h>#include <pthread.h>#include <sys/ioctl.h>#include <stdlib.h>#include <unistd.h>#include <fcntl.h>#include <sys/time.h>#include <unistd.h>#include <time.h>#include <getopt.h>#include <sys/signal.h>//watchdog #define WATCHDOG_IOCTL_BASE     ‘W‘struct watchdog_info {    unsigned int options;          /* Options the card/driver supports */    unsigned int firmware_version; /* Firmware version of the card */    char IDentity[32];     /* IDentity of the board */};#define WdioC_GETSUPPORT        _IOR(WATCHDOG_IOCTL_BASE,struct watchdog_info)#define WdioC_GETSTATUS         _IOR(WATCHDOG_IOCTL_BASE,1,int)#define WdioC_GETBOOTSTATUS     _IOR(WATCHDOG_IOCTL_BASE,2,int)#define WdioC_GETTEMP           _IOR(WATCHDOG_IOCTL_BASE,3,int)#define WdioC_SetoPTIONS        _IOR(WATCHDOG_IOCTL_BASE,4,int)#define WdioC_KEEPAliVE         _IOR(WATCHDOG_IOCTL_BASE,5,int)#define WdioC_SETTIMEOUT        _IOWR(WATCHDOG_IOCTL_BASE,6,int)#define WdioC_GETTIMEOUT        _IOR(WATCHDOG_IOCTL_BASE,7,int)#define WdioC_SETPRETIMEOUT     _IOWR(WATCHDOG_IOCTL_BASE,8,int)#define WdioC_GETPRETIMEOUT     _IOR(WATCHDOG_IOCTL_BASE,9,int)#define WdioC_GETTIMEleft       _IOR(WATCHDOG_IOCTL_BASE,10,int)#define WdioF_OVERHEAT          0x0001  /* reset due to cpu overheat */#define WdioF_FANFAulT          0x0002  /* Fan Failed */#define WdioF_EXTERN1           0x0004  /* External relay 1 */#define WdioF_EXTERN2           0x0008  /* External relay 2 */#define WdioF_POWERUNDER        0x0010  /* Power bad/power fault */#define WdioF_CARDreset         0x0020  /* Card prevIoUsly reset the cpu */#define WdioF_POWEROVER         0x0040  /* Power over voltage */#define WdioF_SETTIMEOUT        0x0080  /* Set timeout (in seconds) */#define WdioF_MAGIcclOSE        0x0100  /* Supports magic close char */#define WdioF_PRETIMEOUT        0x0200  /* Pretimeout (in seconds),get/set */#define WdioF_KEEPAliVEPing     0x8000  /* Keep alive Ping reply */#define WdioS_disABLECARD       0x0001  /* Turn off the watchdog timer */#define WdioS_ENABLECARD        0x0002  /* Turn on the watchdog timer */#define WdioS_TEMPPANIC         0x0004  /* Kernel panic on temperature trip */int wdt_fd;int time_out = 5;voID stop_signal(){    int i = 0,ret = 0 ;    i = WdioS_disABLECARD ;    ioctl(wdt_fd,WdioC_SetoPTIONS,&i) ;    printf("===watchdow will be closed===\n") ;    close(wdt_fd) ;    exit(0) ;}int main(int argc,char *argv[]){    int new_time;        int i;    int ret,count = 10;    struct watchdog_info wdt_info;    signal(SIGINT,stop_signal) ;    wdt_fd = open("/dev/watchdog",O_RDWR);    if(wdt_fd == -1)        perror("Open Watchdog ERROR!\n");    //get watchdog infomation struct    ioctl(wdt_fd,WdioC_GETSUPPORT,&wdt_info);    //printf("options=%d,ID=%s\n",wdt_info.options,wdt_info.IDentity);    ioctl(wdt_fd,WdioC_SETTIMEOUT,&time_out);        while(1)    {        ioctl(wdt_fd,WdioC_KEEPAliVE,NulL);        sleep(atoi(argv[1]));    }        close(wdt_fd);    return 0;}
总结

以上是内存溢出为你收集整理的linux 嵌入式看门狗使用全部内容,希望文章能够帮你解决linux 嵌入式看门狗使用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/1024030.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-23
下一篇2022-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存