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

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

RE: [avr-gcc-list] preserve state during watchdog reset


From: Gavin Jackson
Subject: RE: [avr-gcc-list] preserve state during watchdog reset
Date: Wed, 04 Feb 2004 10:18:59 +1300

-----Original Message-----
From: Simon Han [mailto:address@hidden 
Sent: Wednesday, 4 February 2004 10:07 a.m.
To: Gavin Jackson
Cc: address@hidden (address@hidden)
Subject: Re: [avr-gcc-list] preserve state during watchdog reset



On Tuesday, February 3, 2004, at 12:43 PM, Gavin Jackson wrote:

> -----Original Message-----
> From: Simon Han [mailto:address@hidden
> Sent: Wednesday, 4 February 2004 9:30 a.m.
> To: address@hidden
> Subject: [avr-gcc-list] preserve state during watchdog reset
>
>
> Hi all,
>       Does anyone figure out a way to preserve state during watchdog
reset?
>       I am using watchdog to monitor for some of my functions.  Before and
>
> after function calls, I do a watchdog reset.  Now the problem is how I 
> can figure out which function caused the watchdog timeout.  I was 
> thinking to store this information in EEPROM, but the delay of doing 
> this is way too high.  Will it be possible to assume certain registers 
> are not reset?
>
> Any suggestions?
> Simon
>
> ----------------------------------------------------------------------
> -
>
> Hi Simon
>
> Store whatever it is you want to remember in the SRAM.
>
> Just remember to either place it in the .noinit section as below:
>
> static int KeepTrack __attribute__ ((section (".noinit")));
>
> so that it's not set to 0x00 at startup or you can declare a 'normal' 
> static variable and check it's value before the startup code runs that 
> clears all static variables to 0x00.
>
> To .noinit option is the easiest to do.
>
> Regards
> Gavin

Hi Gavin,
Thank you for the help!
One more question.  How can I tell between a cold start and a watchdog 
reset?
Placing KeepTrack in .noinit will make KeepTrack arbitrary value when I 
use it in main().
AVR datasheet suggests using MCUCSR to tell between them.
Now my question is that will avr-libc change this register during 
initialization?

Thank you again,
Simon

----------------------------------------------------------------------

AFAIK, the startup code doesn't do anything to the MCUSR register
and you are free to check it in main() and take any action needed.

By the way, only place static in front of the variable if you want
to keep its scope local to the module you declare it in. Otherwise
just declare a non-static variable, keep the section .noinit just
to ensure that it's value is not changed by the startup code.

Regards

Gavin


reply via email to

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