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

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

问题描述

我要使用Linux的看门狗驱动程序(的/ dev /看门狗)。它的伟大工程,我写一个像这样的字符:

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?

推荐答案

请阅读<一href=\"https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/watchdog/watchdog-api.txt\"相对=nofollow> 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

然而,通常使用的用户空间监视计划。这应该采取的所有深奥的功能服务。您可以很好用户空间程序到最低优先级,然后系统会产生用户空间变得复位的挂了的。 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.

每个看门狗驱动程序有<一个href=\"https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/watchdog/watchdog-parameters.txt\"相对=nofollow>独立的模块参数,最有一个机制来设置超时;请使用内核命令行或模块参数设置机制。然而,基础结构的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.

样的用户空间code包含在<一个href=\"https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/watchdog/src\"相对=nofollow> Linux文档目录。

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

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

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