<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE></TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3059" name=GENERATOR></HEAD>
<BODY>
<DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans">The 
environment is an ATmega64 with a 32 KHz watch crystal running a real time clock 
on AVR timer0.<?xml:namespace prefix = o ns = 
"urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans">The 
problem is with an occasional watch dog reset that happens every few days or 
longer is resetting the AVR processor and wiping out the current real time clock 
values. The long term fix it to find what is causing the watchdog resets, but 
saving the real time clock through a watchdog reset is still a desirable program 
enhancement.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt">What I 
would like to do is use<SPAN class=Teletype><SPAN 
style="mso-bidi-font-family: Arial; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial"> 
the MCUSR register reset flags to detect the watchdog (WDRF) flag only and treat 
this as a warm start (i.e. a warm start as in the SRAM real time clock variables 
still have valid data in them).</SPAN></SPAN></SPAN><SPAN 
style="mso-bidi-font-family: Lucidasans"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="mso-bidi-font-family: Lucidasans; mso-ascii-font-family: 'Thorndale AMT'; mso-hansi-font-family: 'Thorndale AMT'"><SPAN 
style="mso-spacerun: yes">&nbsp;</SPAN></SPAN></SPAN><SPAN class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans; mso-hansi-font-family: 'Thorndale AMT'; mso-bidi-font-size: 12.0pt">In 
order to do this, I need to read the MCUSR register and copy the real time clock 
variables before these real time clock variables are initialized, before main() 
is run. I think using a custom startup file is the correct place to access the 
MCUSR and the real time clock variables. The problem is I cannot see a straight 
forward way of creating a protected memory storage area just for the copies of 
the real time clock variables and the MCUSR flag.</SPAN></SPAN><SPAN 
style="mso-bidi-font-family: Lucidasans"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt">Of 
course, if it is not a warm start then the normal real time clock initialization 
would still apply.</SPAN></SPAN><SPAN 
style="mso-bidi-font-family: Lucidasans"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt">The idea 
is roughly:</SPAN></SPAN><SPAN 
style="mso-bidi-font-family: Lucidasans"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt">STARTUP-</SPAN></SPAN><SPAN 
style="mso-bidi-font-family: Lucidasans"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="mso-bidi-font-family: Lucidasans; mso-ascii-font-family: 'Thorndale AMT'; mso-hansi-font-family: 'Thorndale AMT'"><SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN></SPAN></SPAN><SPAN class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans; mso-hansi-font-family: 'Thorndale AMT'; mso-bidi-font-size: 12.0pt">read 
MCUSR</SPAN></SPAN><SPAN 
style="mso-bidi-font-family: Lucidasans"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="mso-bidi-font-family: Lucidasans; mso-ascii-font-family: 'Thorndale AMT'; mso-hansi-font-family: 'Thorndale AMT'"><SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN></SPAN></SPAN><SPAN class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans; mso-hansi-font-family: 'Thorndale AMT'; mso-bidi-font-size: 12.0pt">save 
MCUSR to a protected temporary location</SPAN></SPAN><SPAN 
style="mso-bidi-font-family: Lucidasans"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="mso-bidi-font-family: Lucidasans; mso-ascii-font-family: 'Thorndale AMT'; mso-hansi-font-family: 'Thorndale AMT'"><SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN></SPAN></SPAN><SPAN class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans; mso-hansi-font-family: 'Thorndale AMT'; mso-bidi-font-size: 12.0pt">clear 
MCUSR (as per data sheet instructions)</SPAN></SPAN><SPAN 
style="mso-bidi-font-family: Lucidasans"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="mso-bidi-font-family: Lucidasans; mso-ascii-font-family: 'Thorndale AMT'; mso-hansi-font-family: 'Thorndale AMT'"><SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN></SPAN></SPAN><SPAN class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans; mso-hansi-font-family: 'Thorndale AMT'; mso-bidi-font-size: 12.0pt">if 
MCUSR == WDRF</SPAN></SPAN><SPAN 
style="mso-bidi-font-family: Lucidasans"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="mso-bidi-font-family: Lucidasans; mso-ascii-font-family: 'Thorndale AMT'; mso-hansi-font-family: 'Thorndale AMT'"><SPAN 
style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN 
class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans; mso-hansi-font-family: 'Thorndale AMT'; mso-bidi-font-size: 12.0pt">read 
the real time clock values</SPAN></SPAN><SPAN 
style="mso-bidi-font-family: Lucidasans"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="mso-bidi-font-family: Lucidasans; mso-ascii-font-family: 'Thorndale AMT'; mso-hansi-font-family: 'Thorndale AMT'"><SPAN 
style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN 
class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans; mso-hansi-font-family: 'Thorndale AMT'; mso-bidi-font-size: 12.0pt"><SPAN 
style="mso-spacerun: yes">&nbsp;</SPAN>save the real time clock values in a 
protected temporary location</SPAN></SPAN><SPAN 
style="mso-bidi-font-family: Lucidasans"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt">memory 
will be initialized before main() is run, except for the protected 
memory-</SPAN></SPAN><SPAN 
style="mso-bidi-font-family: Lucidasans"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans">main()-<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans"><SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN>read the MCUSR flag from the 
</SPAN><SPAN class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">protected temporary 
location</SPAN></SPAN><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="mso-bidi-font-family: Lucidasans; mso-ascii-font-family: 'Thorndale AMT'; mso-hansi-font-family: 'Thorndale AMT'"><SPAN 
style="mso-spacerun: yes">&nbsp; </SPAN></SPAN></SPAN><SPAN class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans; mso-hansi-font-family: 'Thorndale AMT'; mso-bidi-font-size: 12.0pt">if 
MCUSR == WDRF</SPAN></SPAN><SPAN 
style="mso-bidi-font-family: Lucidasans"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="mso-bidi-font-family: Lucidasans; mso-ascii-font-family: 'Thorndale AMT'; mso-hansi-font-family: 'Thorndale AMT'"><SPAN 
style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN 
class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans; mso-hansi-font-family: 'Thorndale AMT'; mso-bidi-font-size: 12.0pt"><SPAN 
style="mso-spacerun: yes">&nbsp;</SPAN>read the real time clock values from the 
protected temporary location</SPAN></SPAN><SPAN 
style="mso-bidi-font-family: Lucidasans"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="mso-bidi-font-family: Lucidasans; mso-ascii-font-family: 'Thorndale AMT'; mso-hansi-font-family: 'Thorndale AMT'"><SPAN 
style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN 
class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans; mso-hansi-font-family: 'Thorndale AMT'; mso-bidi-font-size: 12.0pt"><SPAN 
style="mso-spacerun: yes">&nbsp;</SPAN>restore the real time clock values (i.e. 
overwrite the ICC initialized values)</SPAN></SPAN><SPAN 
style="mso-bidi-font-family: Lucidasans"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-family: Lucidasans">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt">I'm open 
to any other suggestions on how to do this.</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt"></SPAN></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt"></SPAN></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN class=Teletype><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt">Scott</SPAN></SPAN></P></DIV></BODY></HTML>