AVR Libc Home Page | AVR Libc Development Pages | |||
Main Page | FAQ | Library Reference | Additional Documentation | Example Projects |
#include <avr/wdt.h>
This header file declares the interface to some inline macros handling the watchdog timer present in many AVR devices. In order to prevent the watchdog timer configuration from being accidentally altered by a crashing application, a special timed sequence is required in order to change it. The macros within this header file handle the required sequence automatically before changing any value. Interrupts will be disabled during the manipulation.
#include <stdint.h> #include <avr/wdt.h> uint8_t mcusr_mirror; void get_mcusr(void) \ __attribute__((naked)) \ __attribute__((section(".init3"))); void get_mcusr(void) { mcusr_mirror = MCUSR; MCUSR = 0; wdt_disable(); }
Saving the value of MCUSR in mcusr_mirror
is only needed if the application later wants to examine the reset source, but clearing in particular the watchdog reset flag before disabling the watchdog is required, according to the datasheet.
Defines | |
#define | wdt_reset() __asm__ __volatile__ ("wdr") |
#define | wdt_disable() |
#define | wdt_enable(timeout) _wdt_write(timeout) |
#define | WDTO_15MS 0 |
#define | WDTO_30MS 1 |
#define | WDTO_60MS 2 |
#define | WDTO_120MS 3 |
#define | WDTO_250MS 4 |
#define | WDTO_500MS 5 |
#define | WDTO_1S 6 |
#define | WDTO_2S 7 |
#define | WDTO_4S 8 |
#define | WDTO_8S 9 |
|
Value: Disable the watchdog timer, if possible. This attempts to turn off the Enable bit in the watchdog control register. See the datasheet for details. |
|
Enable the watchdog timer, configuring it for expiry after
See also the symbolic constants |
|
Reset the watchdog timer. When the watchdog timer is enabled, a call to this instruction is required before the timer expires, otherwise a watchdog-initiated device reset will occur. |
|
See |
|
Symbolic constants for the watchdog timeout. Since the watchdog timer is based on a free-running RC oscillator, the times are approximate only and apply to a supply voltage of 5 V. At lower supply voltages, the times will increase. For older devices, the times will be as large as three times when operating at Vcc = 3 V, while the newer devices (e. g. ATmega128, ATmega8) only experience a negligible change.
Possible timeout values are: 15 ms, 30 ms, 60 ms, 120 ms, 250 ms, 500 ms, 1 s, 2 s. (Some devices also allow for 4 s and 8 s.) Symbolic constants are formed by the prefix Example that would select a watchdog timer expiry of approximately 500 ms: |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
|
|
See |