Difference between revisions of "Example watchdog"

From wiki.emacinc.com
Jump to: navigation, search
m (Summary: Added note.)
(Added OE5 instructions)
(16 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{todo|Buggy(01.03.14-11:32->JG+);(01.03.14-11:42->MD-)|Jgreene|project=oe 4,oe 5,jg,md,Buggy}}
+
{{todo|Complete (01.03.14-11:32->JG+);(01.03.14-11:42->MD-);(02.04.14-19:30->MD);(02.06.14-17:32->BS+);(02.06.14-19:15->MD+);(04.07.14-10:15->BS+);(04.10.14-11:50->BS+);(11.10.15-15:30->MG+)|Brian Serrano|project=oe 4,oe 5,bs,md,SEOKWREV,Complete}}
 +
 
 +
{{#seo:
 +
|title=Example watchdog
 +
|titlemode=append
 +
|keywords=Example watchdog,watchdog timer,watchdog test,Linux watchdog
 +
|description=This is a guide to the <code>watchdog</code> C example project included in the EMAC OE SDK.
 +
}}
 
This is a guide to the <code>watchdog</code> C example project included in the EMAC OE SDK.
 
This is a guide to the <code>watchdog</code> C example project included in the EMAC OE SDK.
  
 
A '''watchdog timer''' (WDT) is a hardware circuit that can reset the computer system in case of a software fault. This is an example test for the Linux watchdog API.  
 
A '''watchdog timer''' (WDT) is a hardware circuit that can reset the computer system in case of a software fault. This is an example test for the Linux watchdog API.  
 +
 +
For more information about the protocol see the following page: http://en.wikipedia.org/wiki/Watchdog_timer
  
 
The <code>watchdog</code> project builds one executable: <code>watchdog-test</code>.
 
The <code>watchdog</code> project builds one executable: <code>watchdog-test</code>.
Line 10: Line 19:
 
For information on opening the project from within Eclipse, please see [[Importing the EMAC OE SDK Projects with Eclipse]].  Then, follow [[Using the EMAC OE SDK Projects with Eclipse]] for information on how to build, upload and execute the example.
 
For information on opening the project from within Eclipse, please see [[Importing the EMAC OE SDK Projects with Eclipse]].  Then, follow [[Using the EMAC OE SDK Projects with Eclipse]] for information on how to build, upload and execute the example.
  
Alternatively, the <code>Makefile</code> can be used with the <code>make</code> command from the commandline to build and upload the example.  For more information on this method, please see [[Using EMAC OE SDK Example Projects]].
+
Alternatively, the <code>Makefile</code> can be used with the <code>make</code> command from the commandline to build and upload the example.  For information on this method, please see [[Using EMAC OE SDK Example Projects]].
 +
 
 +
====EMAC SDK 5.X====
 +
 
 +
For information on opening the project from within QtCreator, please see [[Getting_Started_With_Qt_Creator#Adding_Source_Files | QtCreator: Adding Source Files]].  Then, follow [[Getting Started With Qt Creator]] for information on how to build, upload and execute the example.
 +
 
 +
Alternatively, the <code>CMakefile.txt</code> can be used with the <code>cmake</code> command from the commandline to build and upload the example.  For information on this method, please see [[Getting_Started_with_the_EMAC_OE_SDK#Target_Machine_Compiling | Getting Started with the EMAC OE SDK]].
  
 
==Usage and Behavior==
 
==Usage and Behavior==
  
 
A '''watchdog timer''' is a hardware circuit that can reset the computer system in case of a software fault.  The <code>watchdog-test</code> application can enable, disable, activate, configure and interrupt the '''watchdog timer'''.  
 
A '''watchdog timer''' is a hardware circuit that can reset the computer system in case of a software fault.  The <code>watchdog-test</code> application can enable, disable, activate, configure and interrupt the '''watchdog timer'''.  
{{imbox|type=content|textstyle=font-weight:bold;|text= Activating watchdog invokes system reset (after timeout)}}
+
{{note| Activating watchdog invokes system reset (after timeout)}}
  
 
===Hardware Requirements===
 
===Hardware Requirements===
Line 23: Line 38:
 
===<code>watchdog</code> Usage===
 
===<code>watchdog</code> Usage===
  
./watchdog-test [-det]
+
{{cli | ./watchdog-test [-det] | hostname=emac-oe}}
  
 
;-d:Disable watchdog.
 
;-d:Disable watchdog.
Line 33: Line 48:
 
This will activate <code>watchdog</code> and initiate a periodic interrupt to keep it from timing out.
 
This will activate <code>watchdog</code> and initiate a periodic interrupt to keep it from timing out.
  
<syntaxhighlight lang="text">
+
{{clo}}
root@som9g20:/tmp# ./watchdog-test  
+
{{clio | pwd=/tmp | hostname=emac-oe | ./watchdog-test }}
 
Watchdog Ticking Away!
 
Watchdog Ticking Away!
</syntaxhighlight>
+
{{clos}}
 
+
Every second <code>watchdog-test</code> is sending an IOCTL to the watchdog driver, which in turn ticks <code>watchdog</code> to reset its internal timer so it doesn't timeout and trigger a system reset.
'''NOTE: The watchdog timer is counting down.  We reset its countdown to keep the count from reaching zero, at which point it would reset the board.  The actual count is the number of seconds specified times a scalar, which may be 1,000 or more.  This is because timing circuits of very short durations are very small and cheap to make, whereas one which doesn't time out until a full second has elapsed requires a rather large and pricey capacitor.  You don't need to explain that to the reader, though. Additionally, the second sentence is vague.'''
 
  
We have activated the <code>watchdog</code> and it is now counting down to computer reset - or rather it would be if we didn't keep resetting its timer. That's the LED on the SoM blinking at about 1 Hz. Every second <code>watchdog-test</code> is sending an IOCTL to the watchdog driver, which in turn ticks <code>watchdog</code> to reset its internal timer so it doesn't timeout and trigger a system reset.
+
Now we will stop interrupting <code>watchdog</code> and let it trigger a computer reset by pressing ''Ctrl+C''.
 
 
Now we will stop interrupting <code>watchdog</code> and let it trigger a computer reset. Hit CTRL-C.
 
 
 
...and the system resets.
 
  
 
===Usage Example. Disabling <code>watchdog</code>===
 
===Usage Example. Disabling <code>watchdog</code>===
  
<syntaxhighlight lang="text">
+
{{clo}}
root@som9g20:/tmp# ./watchdog-test -d
+
{{clio | pwd=/tmp | hostname=emac-oe | ./watchdog-test -d }}
 
Watchdog card disabled.
 
Watchdog card disabled.
</syntaxhighlight>
+
{{clos}}
  
'''NOTE: the ellipses starting off a sentence fragment is unacceptable. This needs to be worded nicely instead (for every fragment starting with an ellipses throughout this document).'''
+
After running the <code>./watchdog-test -d</code> command, the program exits normally.
 
 
...and the program exits normally.
 
  
 
===Usage Example. Enabling <code>watchdog</code>===
 
===Usage Example. Enabling <code>watchdog</code>===
Line 61: Line 69:
 
This will enable and activate <code>watchdog</code> but it won't perform a periodic timeout interrupt (see the first usage example, above). So when you run it the program activates <code>watchdog</code> and then <code>watchdog</code> resets the system.
 
This will enable and activate <code>watchdog</code> but it won't perform a periodic timeout interrupt (see the first usage example, above). So when you run it the program activates <code>watchdog</code> and then <code>watchdog</code> resets the system.
  
<syntaxhighlight lang="text">
+
{{clo}}
root@som9g20:/tmp# ./watchdog-test -e
+
{{clio | pwd=/tmp | hostname=emac-oe | ./watchdog-test -e }}
 
Watchdog card enabled.
 
Watchdog card enabled.
</syntaxhighlight>
+
{{clos}}
  
...and the system resets.
+
After running the <code>./watchdog-test -e</code> command, the system resets.
  
 
===Usage Example. Setting <code>watchdog</code> timeout===
 
===Usage Example. Setting <code>watchdog</code> timeout===
Line 72: Line 80:
 
This will activate <code>watchdog</code> and set it to timeout in 5 seconds.
 
This will activate <code>watchdog</code> and set it to timeout in 5 seconds.
  
<syntaxhighlight lang="text">
+
{{clo}}
root@som9g20:/tmp# ./watchdog-test -t
+
{{clio | pwd=/tmp | hostname=emac-oe | ./watchdog-test -t }}
 
Watchdog timeout set to 5 seconds!
 
Watchdog timeout set to 5 seconds!
</syntaxhighlight>
 
  
...the program exits normally, then 5 seconds elapse, and then the system resets.
+
{{clos}}
 +
 
 +
After running the <code>./watchdog-test -t</code> command, the program exits normally. Once it exits, 5 seconds will elapse, and then the system resets.
  
 
==Summary==
 
==Summary==
  
The <code>watchdog</code> C example project demonstrates how to use the '''watchdog timer'''. We provide examples of how to enable, disable, activate, configure and interrupt the <code>watchdog</code> hardware circuit.
+
The <code>watchdog</code> C example project demonstrates how to use the '''watchdog timer'''. The '''watchdog timer''' is there to help ensure that your system will return to a functional state should your program get stuck while executing.
  
'''NOTE: At least give the reader an idea of ''why'' they may want to use this, and how to incorporate it into their system.'''
+
EMAC provides examples of how to enable, disable, activate, configure and interrupt the <code>watchdog</code> hardware circuit. To use <code>watchdog</code> peripheral in Linux you will need a <code>watchdog</code> driver, and a <code>watchdog</code> device file. A device file is a special kind of virtual file which marks the device node in your root filesystem. Normally it's called <code>/dev/watchdog</code> .

Revision as of 11:25, 25 September 2020

TODO: {{#todo:Complete (01.03.14-11:32->JG+);(01.03.14-11:42->MD-);(02.04.14-19:30->MD);(02.06.14-17:32->BS+);(02.06.14-19:15->MD+);(04.07.14-10:15->BS+);(04.10.14-11:50->BS+);(11.10.15-15:30->MG+)|Brian Serrano|oe 4,oe 5,bs,md,SEOKWREV,Complete}}

This is a guide to the watchdog C example project included in the EMAC OE SDK.

A watchdog timer (WDT) is a hardware circuit that can reset the computer system in case of a software fault. This is an example test for the Linux watchdog API.

For more information about the protocol see the following page: http://en.wikipedia.org/wiki/Watchdog_timer

The watchdog project builds one executable: watchdog-test.

Opening, Building and Uploading the Project Files

For information on opening the project from within Eclipse, please see Importing the EMAC OE SDK Projects with Eclipse. Then, follow Using the EMAC OE SDK Projects with Eclipse for information on how to build, upload and execute the example.

Alternatively, the Makefile can be used with the make command from the commandline to build and upload the example. For information on this method, please see Using EMAC OE SDK Example Projects.

EMAC SDK 5.X

For information on opening the project from within QtCreator, please see QtCreator: Adding Source Files. Then, follow Getting Started With Qt Creator for information on how to build, upload and execute the example.

Alternatively, the CMakefile.txt can be used with the cmake command from the commandline to build and upload the example. For information on this method, please see Getting Started with the EMAC OE SDK.

Usage and Behavior

A watchdog timer is a hardware circuit that can reset the computer system in case of a software fault. The watchdog-test application can enable, disable, activate, configure and interrupt the watchdog timer.



NOTE
Activating watchdog invokes system reset (after timeout)


Hardware Requirements

watchdog will run on any system for which it can be compiled and implements the standard Linux watchdog API.

watchdog Usage

root@emac-oe:~# ./watchdog-test [-det]
-d
Disable watchdog.
-e
Enable watchdog.
-t
Set the watchdog timeout (to a value specified in code. Default is five seconds).

Usage Example. Activating watchdog with a periodic interrupt

This will activate watchdog and initiate a periodic interrupt to keep it from timing out.

root@emac-oe:/tmp# ./watchdog-test

Watchdog Ticking Away!

Every second watchdog-test is sending an IOCTL to the watchdog driver, which in turn ticks watchdog to reset its internal timer so it doesn't timeout and trigger a system reset.

Now we will stop interrupting watchdog and let it trigger a computer reset by pressing Ctrl+C.

Usage Example. Disabling watchdog

root@emac-oe:/tmp# ./watchdog-test -d

Watchdog card disabled.

After running the ./watchdog-test -d command, the program exits normally.

Usage Example. Enabling watchdog

This will enable and activate watchdog but it won't perform a periodic timeout interrupt (see the first usage example, above). So when you run it the program activates watchdog and then watchdog resets the system.

root@emac-oe:/tmp# ./watchdog-test -e

Watchdog card enabled.

After running the ./watchdog-test -e command, the system resets.

Usage Example. Setting watchdog timeout

This will activate watchdog and set it to timeout in 5 seconds.

root@emac-oe:/tmp# ./watchdog-test -t

Watchdog timeout set to 5 seconds!

After running the ./watchdog-test -t command, the program exits normally. Once it exits, 5 seconds will elapse, and then the system resets.

Summary

The watchdog C example project demonstrates how to use the watchdog timer. The watchdog timer is there to help ensure that your system will return to a functional state should your program get stuck while executing.

EMAC provides examples of how to enable, disable, activate, configure and interrupt the watchdog hardware circuit. To use watchdog peripheral in Linux you will need a watchdog driver, and a watchdog device file. A device file is a special kind of virtual file which marks the device node in your root filesystem. Normally it's called /dev/watchdog .