How to change the watchdog timer in linux embedded

前端 未结 1 1483
慢半拍i
慢半拍i 2021-01-07 04:33

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

 echo 1 > /dev/watchdog

And the

相关标签:
1条回答
  • 2021-01-07 05:20

    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);
    }
    

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

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

    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.

    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.

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

    0 讨论(0)
提交回复
热议问题