Difference between revisions of "Watchdog timers on AM335x boards"

From IGEP - ISEE Wiki

Jump to: navigation, search
(Created page with '== Watchdog timers on AM335x boards == {{Message/Work in progress}} === Overview of this article === This article is meant to be a starting point for people to learn setup the…')
 
Line 52: Line 52:
  
 
The watchdog can be configured by editing the underlying device parameters of special files. It can easily be implemented inside our simple test with ''ioctl()''.
 
The watchdog can be configured by editing the underlying device parameters of special files. It can easily be implemented inside our simple test with ''ioctl()''.
 +
 +
====Timeout====
  
 
For example, we can change the timeout value by adding the following lines to our main function, before the ''while'' loop:
 
For example, we can change the timeout value by adding the following lines to our main function, before the ''while'' loop:
Line 64: Line 66:
  
 
Note too that the timeout can be set to 60 seconds depending on the device's granularity.
 
Note too that the timeout can be set to 60 seconds depending on the device's granularity.
 +
 +
We can also request the timeout value by using the following commands:
 +
 +
ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
 +
printf("The timeout value is %d seconds\n", timeout);
 +
 +
====Pretimeout====
 +
 +
If your watchdog supports pretimeout, you can set the time lapse between the pretimeout and the timeout:
 +
 +
pretimeout = 10;
 +
ioctl(fd, WDIOC_SETPRETIMEOUT, &pretimeout);
 +
 +
It can be useful for recording useful information and/or saving the data that the program was handling before rebooting the machine.
 +
 +
We can also request the timeout value by using the following commands:
 +
 +
ioctl(fd, WDIOC_GETPRETIMEOUT, &pretimeout);
 +
printf("The pretimeout value is %d seconds\n", pretimeout);
 +
 +
====Time left====
 +
 +
Some watchdog drivers can report the remaining time before the system will reboot. With these lines we can ask the driver for the number of seconds remaining before timeout:
 +
 +
ioctl(fd, WDIOC_GETTIMELEFT, &timeleft);
 +
printf("The time left is %d seconds\n", timeleft);
 +
 +
  
 
<center>''Work in progress, for more information on WD parameters please read [http://www.kernel.org/doc/Documentation/watchdog/watchdog-api.txt Linux Watchdog driver API.]''</center>
 
<center>''Work in progress, for more information on WD parameters please read [http://www.kernel.org/doc/Documentation/watchdog/watchdog-api.txt Linux Watchdog driver API.]''</center>
  
 
[[Category:Software]]
 
[[Category:Software]]

Revision as of 10:32, 29 June 2015

Watchdog timers on AM335x boards

Igep community logo.png This is a work in progress article. Help other developers like you in the IGEP Community by improving it!

Overview of this article

This article is meant to be a starting point for people to learn setup the watchdog timer on IGEP0033 AQUILA COM MODULE boards.

Feedback and Contributing

Creating articles in the wiki is a collaborative process, at any point, if you see a mistake you can contribute to this article.

Please, use the discussion tab for user comments. This is useful to separate page content and the discussion thereof and also, if you don't want to give normal users the right to edit the page but still want user contributed notes.

Editing permissions are restricted to registered users. Register in the main IGEP site and you will have single sign-on.

Consult the User's Guide for information on using the wiki software.

There is a set of Wiki contribution guidelines.


Aquila watchdog overview

There are 2 watchdog timers in the Aquila, inside the /dev/ directory:

  • watchdog
  • watchdog0

This watchdogs are special files which, when opened, count time while there's no writing on them. Whenever a process writes data on that files, they reset the timer. But if timer reaches the timeout value between writings, then watchdog forces the microcontroller to reboot, as it detects it as that process is freezing.


Watchdog timers under Linux kernel

The following documentation from kernel.org can give you more information about the watchdogs:

Compile the watchdog-simple.c source code with your board's compiler. This is the application we will use demonstrate the basical watchdog functionality.

With this tiny piece of software, we can enable, and tick the watchdog card. First, we will run it to see the typical behaviour:

$ watchdog-simple

As the program ticks the card (writes on it every 10 seconds), the watchdog observes normal activity and doesn't reset the board.

Now we will modify the code in order to avoid the ticking, and only enabling the watchdog to count. For that purpose, we will comment or erase all the code inside the while loop, obtaining an infinite loop that makes nothing (which simulates the system freezing).

$ watchdog-simple

After the timer reaches the timeout value, the board resets on itself.

Adding configuration parameters and flags

The watchdog can be configured by editing the underlying device parameters of special files. It can easily be implemented inside our simple test with ioctl().

Timeout

For example, we can change the timeout value by adding the following lines to our main function, before the while loop:

int timeout = 45;
ioctl(fd, WDIOC_SETTIMEOUT, &timeout);
printf("The timeout was set to %d seconds\n", timeout);

Please, note that you may include some header files in order to compile the program succesfully:

#include <sys/ioctl.h>
#include <linux/watchdog.h>

Note too that the timeout can be set to 60 seconds depending on the device's granularity.

We can also request the timeout value by using the following commands:

ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
printf("The timeout value is %d seconds\n", timeout);

Pretimeout

If your watchdog supports pretimeout, you can set the time lapse between the pretimeout and the timeout:

pretimeout = 10;
ioctl(fd, WDIOC_SETPRETIMEOUT, &pretimeout);

It can be useful for recording useful information and/or saving the data that the program was handling before rebooting the machine.

We can also request the timeout value by using the following commands:

ioctl(fd, WDIOC_GETPRETIMEOUT, &pretimeout);
printf("The pretimeout value is %d seconds\n", pretimeout);

Time left

Some watchdog drivers can report the remaining time before the system will reboot. With these lines we can ask the driver for the number of seconds remaining before timeout:

ioctl(fd, WDIOC_GETTIMELEFT, &timeleft);
printf("The time left is %d seconds\n", timeleft);


Work in progress, for more information on WD parameters please read Linux Watchdog driver API.