2

I want to change the timeout value of RPi (I use RPi3) internal watchdog.

I wrote the simple application like so:

#include <sys/ioctl.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/watchdog.h>
#include <iostream>
#include <stdio.h>

int main(int argc, const char* argv[])
{
  int timeout = 25;
  int fd;
  fd = open("/dev/watchdog", O_WRONLY);
  if (-1 == fd)
  {
    std::cout << "Failed to opeln file " << argv[1] << ". Errno: " << std::endl;
    perror("ERROR MSG: ");
    return 4;
  }

  int retIoctl = ioctl(fd, WDIOC_SETTIMEOUT, &timeout);

  std::cout << "Ioctl returned: " << retIoctl << " and errno: " << std::endl;
  perror("ERROR MSG: ");

  close(fd);

  return 0;
}

Unfortunately it does not work on RPi and I get the message:

Ioctl returned: -1 and errno: 
ERROR MSG: : Bad file descriptor

I have tested this with /dev/watchdog and /dev/watchdog0, but I think that there is no difference between them.

I use bcm2835_wdt kernel module to enable watchdog.

Question:
What is the correct way to change the watchdog timeout value?

Is RPi watchdog configuration handled somehow differently that a typical linux watchdog?

EDIT:
Updated the code.

I'm running my application as root and I do it in initramfs where I don't have systemd.

I have also found a blog entry that claims that bcm2835 watchdog can only have timeout value equal to 15 seconds.

I have tested it and it is partially true: I was unable to set timeout bigger than 15 sec.

Does anybody can explain why is that and point to some bcm2835 documentation?

4
  • 1
    You didnt check the return code of open(). It presumably failed. Did you run as root? If using systemd see the wdctl command.
    – meuh
    Commented Aug 12, 2017 at 16:54
  • 1
    It did fail on open when I tried it as non-root user, but later I have tried as root and open worked (I have changed a code a bit) and I got the message that ioctl returned -1 and perror gave the output: Invalid argument, but which argument? Somehow it works on my PC but not on RPi...
    – lewiatan
    Commented Aug 14, 2017 at 7:40
  • 2
    You are right. The bcm watchdog is limited to 15 seconds. The latest kernel driver shows the register mask PM_WDOG_TIME_SET is 20 bits, and WDOG_TICKS_TO_SECS involves shifting by 16 bits which leaves only 4 bits to hold the time in seconds.
    – meuh
    Commented Aug 14, 2017 at 11:55
  • 1
    Ok. This sucks, but thank you anyway for info and link to the driver.
    – lewiatan
    Commented Aug 14, 2017 at 12:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.