当前位置:网站首页>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
边栏推荐
- How MySQL's allowMultiQueries flag relates to JDBC and jOOQ
- lotus-local-net 2k v1.17.0-rc4
- LeetCode 1161.最大层内元素和:层序遍历
- [Virtualization ecological platform] Raspberry Pi installation virtualization platform operation process
- DCM 中间件家族迎来新成员
- MySQL 的几种碎片整理方案总结(解决delete大量数据后空间不释放的问题)
- deeplab implements its own remote sensing geological segmentation dataset
- MySQL 的 limit 分页查询及性能问题
- 生命不息,刷题不止,简单题学习知识点
- 3.网页信息解析方法:Xpath与BeautifulSoup
猜你喜欢

分布式事务——分布式事务简介、分布式事务框架 Seata(AT模式、Tcc模式、Tcc Vs AT)、分布式事务—MQ

“带薪划水”偷刷阿里老哥的面经宝典,三次挑战字节,终成正果

Read through the interface to call the artifact RestTemplate

音视频基础

Redis学习笔记-3.慢查询和其他高级数据结构

学自动化测试哪个培训机构好 试听课程后就选了这个地方学习

Chrome开发自定义右键菜单实现快速跳转到指定页面

LeetCode - 025. 链表中的两数相加

If the value of the enum map does not exist, deserialization is not performed

PyQt5快速开发与实战 9.5 PyQtGraph在PyQt中的应用 && 9.6 Plotly在PyQt中的应用
随机推荐
Distributed id solution
如何正确地把服务器端返回的文件二进制流写入到本地保存成文件
Selenium自动化测试之Selenium IDE
在 Excel 里使用 ODBC 读取 SAP BTP 平台上 CDS view 的数据
MySQL index usage and optimization
【虚拟化生态平台】树莓派安装虚拟化平台操作流程
给你一个大厂面试的机会,你能面试上吗?进来看看!
Life is endless, there are more questions, simple questions to learn knowledge points
Candence学习篇(11) allegro中设置规则,布局,走线,铺铜
Different lower_case_table_names settings for server ('1') and data dictionary ('0') solution
生命不息,刷题不止,简单题学习知识点
St. Regis Takeaway Project: New dishes and dishes paged query
Redis学习笔记-3.慢查询和其他高级数据结构
Docker installs canal and mysql for simple testing and achieves cache consistency between redis and mysql
使用 Excel 读取 SAP ABAP CDS View 通过 ODBC 暴露出来的数据
一文吃透接口调用神器RestTemplate
VBA实现双击单元格自动输出对号再次双击取消对号
分布式事务Seata详细使用教程
一文带你了解redux的工作流程——actionreducerstore
Different lower_case_table_names settings for server (‘1‘) and data dictionary (‘0‘) 解决方案
