如何在嵌入式Linux中更改看门狗定时器 [英] How to change the watchdog timer in linux embedded

查看:49
本文介绍了如何在嵌入式Linux中更改看门狗定时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用 linux 看门狗驱动程序 (/dev/watchdog).效果很好,我写了一个这样的角色:

I have to use the linux watchdog driver (/dev/watchdog). It works great, I write an character like this:

 echo 1 > /dev/watchdog

看门狗启动,大约1分钟后,系统重新启动.

And the watchdog start and after an about 1 minute, the system reboot.

问题是,如何更改超时时间?我必须在驱动程序中更改时间间隔?

The question is, how can I change the timeout? I have to change the time interval in the driver?

推荐答案

请阅读Linux 文档.从用户空间更改超时的标准方法是使用ioctl().

Please read the Linux documentation. The standard method of changing the timeout from user space is to use an ioctl().

int timeout = 45;                        /* a time in seconds */
int fd;
fd = open("/dev/watchdog");
ioctl(fd, WDIOC_SETTIMEOUT, &timeout);   /* Send time request to the driver. */

每个看门狗设备可能有硬件支持的上限(也可能下限),因此您不能将超时设置得任意高.所以设置了超时时间后,再读回超时时间就好了.

Each watchdog device may have an upper (and possibly lower) limit on that the hardware supports, so you can not set the timeout arbitrarily high. So after setting a timeout, it is good to read back the timeout.

ioctl(fd, WDIOC_GETTIMEOUT, &timeout);   /* Update timeout with driver value. */

现在,重读超时可以用作踢频.

Now, the re-read timeout can be used as a kick frequency.

assert(timeout > 2);
while (1) {
  ioctl(fd, WDIOC_KEEPALIVE, 0);
  sleep(timeout-2);
}

您可以在脚本/shell 命令中编写自己的踢球例程,

You can write your own kicking routine in a script/shell command,

    while [ 1 ] ; do sleep 1; echo V > /dev/watchdog; done

然而,通常使用用户空间看门狗程序.这应该处理所有深奥的功能.您可以nice将用户空间程序设置为最低优先级,然后如果用户空间挂断,系统将重置.BusyBox 包括一个看门狗小程序.

However, the userspace watchdog program is usually used. This should take care of all the esoteric features. You can nice the user space program to a minimum priority and then the system will reset if user space becomes hung up. BusyBox includes a watchdog applet.

每个看门狗驱动都有单独的模块参数,大多数都包含设置超时的机制;使用内核命令行或模块参数设置机制.但是,如果您对看门狗硬件没有特定的了解,基础结构 ioctl 超时将更具可移植性.ioctl 可能更面向未来,因为您的硬件可能会发生变化.

Each watchdog driver has separate module parameters and most include a mechanism to set the timeout; use either the kernel command line or module parameter setting mechanism. However, the infra-structure ioctl timeout is more portable if you do not have specific knowledge of your watchdog hardware. The ioctl is probably more future proof, in that your hardware may change.

示例用户空间代码包含在 Linux 示例目录.

Sample user space code is included in the Linux samples directory.

这篇关于如何在嵌入式Linux中更改看门狗定时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆