# Watchdog timer handling

## Detailed Description

     #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.

Note:
  Depending on the fuse configuration of the particular device, further restrictions might apply, in particular it might be disallowed to turn off the watchdog timer.

## 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 Documentation

#define wdt_disable | (

)

Value:

    __asm__ __volatile__ (  \
        "in __tmp_reg__, __SREG__" "\n\t" \
        "out %0, %1" "\n\t" \
        "out %0, __zero_reg__" "\n\t" \
        "out __SREG__,__tmp_reg__" "\n\t" \
        : /* no outputs */ \
        : "I" (_SFR_IO_ADDR(_WD_CONTROL_REG)), \
        "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))) \
        : "r0" \
    )

Disable the watchdog timer, if possible. This attempts to turn off the Enable bit in the watchdog control register. See the datasheet for details.

#define wdt_enable | ( | timeout |  | ) | _wdt_write(timeout)

| Enable the watchdog timer, configuring it for expiry after `timeout` (which is a combination of the `WDP0` through `WDP2` bits to write into the `WDTCR` register; For those devices that have a `WDTCSR` register, it uses the combination of the `WDP0` through `WDP3` bits). See also the symbolic constants `WDTO_15MS` et al.

#define wdt_reset | (

)

__asm__ __volatile__ ("wdr")

| 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.

#define WDTO_120MS 3

| See `WDT0_15MS`

#define WDTO_15MS 0

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. Symbolic constants are formed by the prefix `WDTO_`, followed by the time.

Example that would select a watchdog timer expiry of approximately 500 ms:

       wdt_enable(WDTO_500MS);

#define WDTO_1S 6

| See `WDT0_15MS`

#define WDTO_250MS 4

| See `WDT0_15MS`

#define WDTO_2S 7

| See `WDT0_15MS`

#define WDTO_30MS 1

| See `WDT0_15MS`

#define WDTO_500MS 5

| See `WDT0_15MS`

#define WDTO_60MS 2

| `WDT0_15MS`

Automatically generated by Doxygen 1.4.1 on 13 Oct 2005.