当前位置:网站首页>am335x 看门狗驱动&看门狗应用例程序
am335x 看门狗驱动&看门狗应用例程序
2022-07-31 11:52:00 【szembed】
<span style="font-family: Arial, Helvetica, sans-serif;">看门狗应用编程,</span>
看门狗应用编程主要是在超出定时器时间之前喂狗,如果超过时间没有喂狗系统则重启。
1. reboot指令能让系统重启,看门狗超时系统才能重启
参照看门狗驱动编写应用程序:
arch/arm/mach-omap2/omap_hwmod.c
-
static long omap_wdt_ioctl(struct file *file, unsigned int cmd,
-
unsigned
long arg)
-
{
-
struct
omap_wdt_dev *wdev;
-
int new_margin;
-
static
const
struct
watchdog_info ident = {
-
.identity =
"OMAP Watchdog",
-
.options = WDIOF_SETTIMEOUT,
-
.firmware_version =
0,
-
};
-
-
wdev = file->private_data;
-
-
switch (cmd) {
-
case WDIOC_GETSUPPORT:
-
return
copy_to_user((
struct watchdog_info __user *)arg, &ident,
-
sizeof(ident));
-
case WDIOC_GETSTATUS:
-
return
put_user(
0, (
int __user *)arg);
-
case WDIOC_GETBOOTSTATUS:
-
if (
cpu_is_omap16xx())
-
return
put_user(__raw_readw(ARM_SYSST),
-
(
int __user *)arg);
-
if (
cpu_is_omap24xx())
-
return
put_user(
omap_prcm_get_reset_sources(),
-
(
int __user *)arg);
-
case WDIOC_KEEPALIVE:
-
pm_runtime_get_sync(wdev->dev);
-
spin_lock(&wdt_lock);
-
omap_wdt_ping(wdev);
-
spin_unlock(&wdt_lock);
-
pm_runtime_put_sync(wdev->dev);
-
return
0;
-
case WDIOC_SETTIMEOUT:
-
if (get_user(new_margin, (
int __user *)arg))
-
return -EFAULT;
-
omap_wdt_adjust_timeout(new_margin);
-
-
pm_runtime_get_sync(wdev->dev);
-
spin_lock(&wdt_lock);
-
omap_wdt_disable(wdev);
-
omap_wdt_set_timeout(wdev);
-
omap_wdt_enable(wdev);
-
-
omap_wdt_ping(wdev);
-
spin_unlock(&wdt_lock);
-
pm_runtime_put_sync(wdev->dev);
-
/* Fall */
-
case WDIOC_GETTIMEOUT:
-
return put_user(timer_margin, (
int __user *)arg);
-
default:
-
return -ENOTTY;
-
}
-
}
include/linux/watchdog.h
-
#define WATCHDOG_IOCTL_BASE 'W'
-
-
struct
watchdog_info {
-
__u32 options;
/* Options the card/driver supports */
-
__u32 firmware_version;
/* Firmware version of the card */
-
__u8 identity[
32];
/* Identity of the board */
-
};
-
-
#define WDIOC_GETSUPPORT _IOR(WATCHDOG_IOCTL_BASE, 0, 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_UNKNOWN -1 /* Unknown flag error */
-
#define WDIOS_UNKNOWN -1 /* Unknown status error */
-
-
#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 */
watchdog_test.c
-
#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, 0, 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_status=
1;
-
int wdt_fd;
-
int time_out =
5;
-
-
int main(int argc, char *argv[])
-
{
-
int new_time;
-
int i;
-
int ret, count =
20;
-
struct
watchdog_info wdt_info;
-
-
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);
-
-
//set timeout
-
ioctl(wdt_fd, WDIOC_SETTIMEOUT, &time_out);
-
-
//read the timeout value
-
ioctl(wdt_fd, WDIOC_GETTIMEOUT, &time_out);
-
new_time = time_out;
-
printf(
"time_value=%d\n", new_time);
-
#if 0
-
//close the watchdog
-
i=WDIOS_DISABLECARD;
-
printf(
"%d\n",
ioctl(wdt_fd,WDIOC_SETOPTIONS,&i));
-
-
//open the watchdog
-
i=WDIOS_ENABLECARD;
-
printf(
"%d\n",
ioctl(wdt_fd,WDIOC_SETOPTIONS,&i));
-
#endif
-
while(
1)
-
{
-
count--;
-
-
//feed time
-
if(wdt_status ==
1)
-
{
-
ioctl(wdt_fd,WDIOC_KEEPALIVE,
NULL);
-
//write(wdt_fd,NULL,1); //feed time, too
-
printf(
"Feed time!\n");
-
-
}
-
-
sleep(
1);
-
-
if(count ==
0)
-
{
-
wdt_status =
0;
-
printf(
"End of feeding time!\n");
-
}
-
}
-
-
close(wdt_fd);
-
return
0;
-
}
imx6编译: ${CC} watchdog_test.c -o watchdog
am335x编译:
arm-linux-gcc watchdog_test.c -o watchdog
参考:http://www.linuxidc.com/Linux/2013-12/94074.htm
边栏推荐
- mysql根据多字段分组——group by带两个或多个参数
- file contains vulnerabilities
- pycharm汉化教程(碧蓝幻想汉化插件安装)
- MySQL 的 limit 分页查询及性能问题
- lotus-local-net 2k v1.17.0-rc4
- [Virtualization Ecological Platform] Platform Architecture Diagram & Ideas and Implementation Details
- Android studio connects to MySQL and completes simple login and registration functions
- JVS轻应用的组成与配置
- Cloudera Manager —— 端到端的企业数据中心管理工具
- JVS设置不同应用的登录时效时间
猜你喜欢
MySQL row-level locks (row locks, adjacent key locks, gap locks)
If the value of the enum map does not exist, deserialization is not performed
普林斯顿微积分读本03第二章--编程实现函数图像绘制、三角学回顾
IDEA 配置方法注释自动参数
一文带你了解redux的工作流程——actionreducerstore
ApiPost 真香真强大,是时候丢掉 Postman、Swagger 了
三六零与公安部三所发布报告:关基设施保护成为网络安全博弈关键
Obsidian设置图床
JVS函数公式使用场景介绍
Docker build Mysql master-slave replication
随机推荐
Acwing第 62 场周赛【未完结】
Obsidian设置图床
mysql 自动添加创建时间、更新时间
在 Excel 里使用 ODBC 读取 SAP BTP 平台上 CDS view 的数据
ApiPost 真香真强大,是时候丢掉 Postman、Swagger 了
R语言:文本(字符串)处理与正则表达式
瑞吉外卖项目:新增菜品与菜品分页查询
ESP8266-Arduino编程实例-MCP9808数字温度传感器驱动
How to correctly write the binary stream of the file returned by the server to the local file and save it as a file
IDEA configure method annotation automatic parameters
最近两个月谷歌 ad 掉的厉害
MySql模糊查询大全
mysql automatically adds creation time and update time
Initial JDBC programming
lotus-local-net 2k v1.17.0-rc4
【核心概念】图像分类和目标检测中的正负样本划分以及架构理解
Read through the interface to call the artifact RestTemplate
准确率(Accuracy)、精度(Precision)、召回率(Recall)和 mAP 的图解
ESP8266-Arduino编程实例-HDC1008温度湿度传感器驱动
VBA输出日志到工作簿demo