avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] wdt_enable may fail to enable the watchdog on ATmega1281


From: Danjel McGougan
Subject: [avr-libc-dev] wdt_enable may fail to enable the watchdog on ATmega1281
Date: Fri, 28 Aug 2009 11:03:14 +0200

Hi,

It seems the wdt_enable macro from "avr/wdt.h" may fail to enable the
watchdog at least on ATmega1281 devices and possibly on all devices
that keep the WDTCSR register in the extended I/O space. The macro
looks like this in my version:

#define wdt_enable(value)   \
    __asm__ __volatile__ (  \
        "in __tmp_reg__,__SREG__" "\n\t"    \
        "cli" "\n\t"    \
        "wdr" "\n\t"    \
        "sts %0,%1" "\n\t"  \
        "out __SREG__,__tmp_reg__" "\n\t"   \
        "sts %0,%2" \
        : /* no outputs */  \
        : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
        "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
        "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
            _BV(WDE) | (value & 0x07)) ) \
        : "r0"  \
    )

This macro seems to depend on the fact that at least one more
instruction will be executed after global interrupts are enabled
before an actual interrupt can happen. But this fact seems only to be
true for instructions using only one instruction word (16 bits).
Instructions such as sts that use two words (32 bits) are not
guaranteed to be executed before an interrupt may fire. I have learned
this the hard way after trying to optimize interrupt latency in my
application for ATmega1281. It does not seem to be documented by
Atmel.

Could possibly other macros/functions in avr-libc be affected by this?

Best regards,
Danjel McGougan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]