|
|
View previous topic :: View next topic |
Author |
Message |
faessler
Joined: 28 Nov 2003 Posts: 3
|
Variable watchdog resistent (reset resistent) |
Posted: Mon Aug 09, 2004 2:43 am |
|
|
Hello,
it is possible to use a variable after reset or watchdog ?
example:
int testvar;
...
if (restart_cause() == WDT_TIMEOUT)
{
testvar++;
if (testvar == 5)
printf ("Ohh we have now 5 restarts ... ");
}
...
It is possible ?
regards
Oliver |
|
|
Guest
|
|
Posted: Mon Aug 09, 2004 5:08 am |
|
|
Register file is fully static so you can use it.
Don't forget to clear your variable on power-on reset (take a look on Restart_cause() function). |
|
|
Ttelmah Guest
|
Re: Variable watchdog resistent (reset resistent) |
Posted: Mon Aug 09, 2004 5:26 am |
|
|
faessler wrote: | Hello,
it is possible to use a variable after reset or watchdog ?
example:
int testvar;
...
if (restart_cause() == WDT_TIMEOUT)
{
testvar++;
if (testvar == 5)
printf ("Ohh we have now 5 restarts ... ");
}
...
It is possible ?
regards
Oliver |
Yes.
However you have to be careful of the 'self clear' behaviour of the compiler. If (for instance), you have 'zero_ram' set, all memory will be lost on the restart. Similarly, a variable declared as 'static', will also be cleared. Variables declared inside a routine, may well be cleared/overwritten by earlier code.
Hence the only safe variable declaration for this type of operation, is a default global (where the variable is declared outside any function), with no 'zero_ram' declaration.
Also remember to read the 'restart_cause', right near the start of the program. This ensures the flag is correctly cleared, in case something happens early in the code.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|