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 _______________________________________________ AVR-libc-dev mailing list AVR-libc-dev@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-libc-dev