Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Watchdog timer
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Implementation== Watchdog timers are implemented in various ways. Some electronic WDTs (e.g., Analog Devices MAX6324) use linear timing circuits that operate without a digital clock signal. Other electronic WDTs, and software WDTs, typically employ digital counters as timers and rely on a clock signal for proper operation. ===Electronic watchdogs=== Electronic WDTs are usually implemented either as a stand-alone [[integrated circuit]] (IC) or as part of a more complex IC. Some stand-alone implementations contain only a WDT, whereas others bundle a WDT with other functions (e.g. [[supply voltage supervisor]]s) in a common IC. Many microcontrollers have a watchdog "module" consisting of a digital WDT and mechanisms for controlling and monitoring the WDT. Such modules typically include related control and status registers, circuitry for qualifying restart triggers ("kicks"), and routing control logic for the timeout signal. Some microcontrollers provide an analog WDT in lieu of a digital WDT. For example, Texas Instruments' TMS470 microcontroller has an analog WDT that employs an external capacitor and resistor to program the watchdog interval.<ref name="TMS470"/> ====Digital watchdogs==== In microcontrollers and other complex digital ICs, a digital WDT is typically instantiated by synthesizing it from a description written in [[VHDL]], [[Verilog]] or some other [[hardware description language]]. For example, the following VHDL code describes a simple WDT: <syntaxhighlight lang="VHDL" class="skin-invert"> entity watchdog_timer is port ( CLK : in std_logic; -- clock INIT : in std_logic; -- initialize watchdog KICK : in std_logic; -- restart timer INTERVAL : in unsigned(31 downto 0); -- timer interval in clocks TIMEOUT : out std_logic; -- timeout indicator ); end watchdog_timer; architecture behavioral of watchdog_timer is process(CLK) variable elapsed : std_logic; -- timeout register variable counter : unsigned(31 downto 0); -- remaining clocks until timeout begin if rising_edge(CLK) then -- upon rising clock edge if INIT = '1' then -- if watchdog is being initialized counter <= INTERVAL; -- start timer elapsed <= '0'; -- reset timeout indicator elsif counter = 0 then -- else if watchdog interval has elapsed elapsed <= '1'; -- indicate timeout; timer is halted elsif KICK = '1' then -- else if watchdog is being kicked counter <= INTERVAL; -- restart timer else -- else counter <= counter - 1; -- advance timer end if; end if; TIMEOUT <= elapsed; -- send register output to TIMEOUT end process; end behavioral; </syntaxhighlight> ====Analog watchdogs==== [[File:Analog WDT.svg|thumb|Simple analog watchdog timer]] [[File:Analog WDT timing.svg|thumb|Example timing diagram for analog WDT shown above. Four timely kick pulses keep ''V<sub>C</sub>'' below ''V<sub>TH</sub>''. When kicks cease, ''V<sub>C</sub>'' rises above ''V<sub>TH</sub>'' and causes a timeout.]] Analog WDTs have a ''kick'' input and ''timeout'' output, but lack the clock input signal found in digital electronic watchdogs. Circuitry and components vary widely among analog watchdogs, but in general, analog WDTs typically base their timing functions on [[capacitor]] charging rates. For example, in the analog watchdog circuit shown to the right, electric current ''i'' gradually charges capacitor ''C'', causing voltage ''V<sub>C</sub>'' to ramp up (rise at a constant rate). In normal operation, periodic "kick" pulses are applied to the kick input. Each kick causes capacitor ''C'' to discharge, thus restarting the voltage ramp-up. However, if the kicks cease or become spaced too far apart in time, ''V<sub>C</sub>'' will rise above threshold voltage ''V<sub>TH</sub>'' and, as a result, the [[voltage comparator]] will assert the ''timeout'' signal. ===Software watchdogs=== Some software watchdog timers are implemented as standard software modules. Examples of these include "Softdog", a [[Device driver#Virtual device drivers|virtual device driver]] which emulates an electronic WDT and conforms to the [[Linux]] watchdog API,<ref name="softdog"/> and [[MathWorks]]' Software Watchdog Timer, a retriggerable one-shot timer which can be instantiated by dragging its GUI representation onto a block diagram.<ref name="mathworks"/> Other software WDTs are typically custom-designed to meet specific requirements. Every software WDT depends on a timing reference to allow it to accurately track the passage of time. Various mechanisms are commonly available for this purpose. Depending on the computer, and if used, the [[operating system]] (OS), such mechanisms may include programmable interval timers, kernel timers, the [[system clock]], and synchronization objects (e.g., [[semaphore (programming)|semaphores]]) that support timed waits. The design of a software WDT can be influenced by a number of factors, including the length of the watchdog interval, the time references available for WDT use, CPU loading, how soon the WDT must be kicked after relevant conditions have been met, whether the computer is running an OS and, if so, whether the WDT is intended to run in user or kernel mode. For example, in bare metal applications (program running without an OS), timing references are often limited to [[programmable interval timer]]s (PIT). In such cases, the WDT might be implemented with a PIT in a fashion similar to the [[flowchart]] shown below: [[File:Flowchart sw wdt pit.svg|500px|center|alt=Flowchart for a software watchdog timer based on a programmable interval timer (PIT), with example application program]] In the above example, if the application program fails to kick the watchdog (by restarting the PIT), the PIT will reach the end of the watchdog interval and generate an interrupt request (IRQ). The associated interrupt service routine (ISR) will then execute and take corrective action via programmed I/O, system calls, or other software-controlled operations.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)