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

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

[avr-libc-dev] wdt.h enhancement?


From: larry barello
Subject: [avr-libc-dev] wdt.h enhancement?
Date: Wed, 24 Jun 2009 02:56:30 -0700

The file wdt.h doesn't support fancy stuff like WDIE (interrupt enable bit)
I hacked it as follows for the STS case.  Note I set it up so the macro
fails if there is no WDIE bit defined.  There is only one line added to the
wdt_enable() macro...

Usage (in my code...)

        wdt_enable((WDTO_4S | WDT_IE));

Note, the need for double parenthesis.  Should "value", below, be encased in
parenthesis so I don't need it in the calling code?
Note, shouldn't this be extended to allowing the user to "specify" if reset
behavior is enabled or not?  I didn't make that change because it would
break prior use..  Maybe set up a flag to "disable" the WDE flag so the
default behavior is compatible?

------- wdt.h-----------

#ifdef WDIE
#  define WDT_IE 0x10
#  define _WDT_IE_MASK _BV(WDIE)
#else
#  define _WDT_IE_MASK 0
#endif

#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" "\n\t" \
    : /* 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) | \
        (value & 0x10 ? _WDT_IE_MASK:0x00) | \ <<<I ADDED THIS LINE>>>
                _BV(WDE) | (value & 0x07)) ) \
    : "r0"  \
)







reply via email to

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