Linux之看门狗
来源:互联网 发布:明略数据校园招聘 编辑:程序博客网 时间:2024/04/28 17:40
Linux之看门狗
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <fcntl.h>#include <sys/ioctl.h>#include <errno.h>#include <sys/time.h>#include <unistd.h>#include <time.h>#include <getopt.h>#include <sys/signal.h>#include <termios.h>struct watchdog_info{ unsigned int options; //options the card/driver supprots 19 unsigned int firmware_version; //firmcard version of the card unsigned char identity[32]; //identity of the board 21 };#define WATCHDOG_IOCTL_BASE 'W'#define WDIOC_GETSUPPORT _IOR(WATCHDOG_IOCTL_BASE, 0, struct watchdog_info)#define WDIOC_SETTIMEOUT _IOWR(WATCHDOG_IOCTL_BASE, 6, int)#define WDIOC_GETTIMEOUT _IOR(WATCHDOG_IOCTL_BASE, 7, int) 27 #define WDIOS_DISABLECARD 0x0001 /* Turn off the watchdog timer */#define WDIOS_ENABLECARD 0x0002 /* Turn on the watchdog timer */#define WDIOC_SETOPTIONS _IOR(WATCHDOG_IOCTL_BASE, 4, int)#define WDIOC_KEEPALIVE _IOR(WATCHDOG_IOCTL_BASE, 5, int)int Getch (void) //无回显的从屏幕输入字符,来达到喂狗的目的{ int ch; struct termios oldt, newt; //终端设备结构体 tcgetattr(STDIN_FILENO, &oldt); //获得终端属性 newt = oldt; newt.c_lflag &= ~(ECHO|ICANON); //设置无回显属性 tcsetattr(STDIN_FILENO, TCSANOW, &newt); //设置新的终端属性 ch = getchar(); //从键盘输入一个数据 tcsetattr(STDIN_FILENO, TCSANOW, &oldt); //恢复终端设备初始设置 return ch;} //suspend some secondsint zsleep(int millisecond){ unsigned long usec; usec=1000*millisecond; usleep(usec); //睡眠usec秒}int Init(){ int fd; //open device file fd = open("/dev/watchdog",O_RDWR); //打开看门狗设备 if(fd < 0) { printf("device open fail\n"); return -1; } return fd;}int main(int argc,char **argv){ int fd,ch; int i,j; char c; struct watchdog_info wi; fd=Init(); //打开终端看门狗设备 //读板卡信息,但不常用 ioctl(fd,WDIOC_GETSUPPORT,&wi); printf("%d,%s\n",wi.options,wi.identity); //读看门狗溢出时间,默认是5s //重新设置时间为10s i=5; printf("%d\n",ioctl(fd,WDIOC_SETTIMEOUT,&i)); //读新的设置时间 printf("%d\n",ioctl(fd,WDIOC_GETTIMEOUT,&i)); printf("%d\n",i); //看门狗开始和停止工作,打开和关闭设备具有同样的功能 //关闭 i=WDIOS_DISABLECARD; printf("%d\n",ioctl(fd,WDIOC_SETOPTIONS,&i)); //打开 i=WDIOS_ENABLECARD; printf("%d\n",ioctl(fd,WDIOC_SETOPTIONS,&i)); while(1) { zsleep(100); if((c=Getch())!=27){ //输入如果不是ESC,就喂狗,否则不喂狗,到时间后系统重启 ioctl(fd,WDIOC_KEEPALIVE,NULL); //write(fd,NULL,1); //同样是喂狗 } } close(fd); //关闭设备 return 0;}
0 0
- linux之看门狗
- Linux之看门狗
- linux驱动之看门狗
- linux驱动之S3C2440看门狗驱动
- linux之软看门狗的实现
- LINUX 看门狗
- LINUX 看门狗
- Linux 看门狗
- Linux驱动修炼之道-看门狗框架源码分析
- linux嵌入式系统开发之看门狗----应用篇。
- Linux驱动修炼之道-看门狗框架源码分析
- linux看门狗 ioctl
- linux驱动 看门狗
- linux看门狗程序
- linux看门狗程序
- Linux 软件看门狗 watchdog
- LINUX系统看门狗
- Linux看门狗脚本 1.4
- IOS7 隐藏状态栏 (电池栏 )
- 6.Swift教程翻译系列——Swift集合类型
- LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏——引用大神终极解决方案
- 数据结构+算法系列四:I 堆排序
- 2014第一帖
- Linux之看门狗
- JSP我的认识,你呢?
- adb错误的解决方法
- Android不同手机屏幕分辨率自适应
- Android开发中部分设计原则及解决方案
- POJ 1995 Raising Modulo Numbers (数论-整数快速幂)
- 接口的定义和抽象的关系
- FileDialog的使用
- 设计模式之策略模式(Strategy)摘录