avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] Watchdog wakeup from sleep mode?


From: Artur Lipowski
Subject: Re: [avr-gcc-list] Watchdog wakeup from sleep mode?
Date: Mon, 25 Aug 2003 14:22:21 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5b) Gecko/20030820 Mozilla Thunderbird/0.2a

Josh Pieper wrote:
...
Is there an easy way to work around this?  I'm working with an
ATmega8535 and ATTiny26 at the moment, but I think the problem is
applicable to most AVR devices.
It's easy, just put into source something like this:
void check_reset_cond() __attribute__ ((naked)) \
            __attribute__ ((section (".init3")));

void check_reset_cond()
{
        uint8_t mcusr = MCUSR;
        MCUSR = 0;
        if (mcusr & _BV(WDRF))
        {
                // avoid avr-libc initialization because
                // it is a watchdog reset
                main();
        }
        else if (mcusr & _BV(PORF))
        {
                // Power-on reset - do normal startup
        }
        else
        {
                // other reset source - power down device
        }
}

It works with devices which have WDRF status bit, but it can be extended for other just by using some global variable as a reset source flag (I usually use 2 bytes with "checkboard" pattern eg. 0xA55A, and _only_ if flag word has such value it means watchdog reset).

Regards,
--
Artur Lipowski



reply via email to

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