From: Maarten B. <sou...@ds...> - 2005-03-31 13:08:49
|
<?xml version="1.0" ?><html> <head> <title></title> </head> <body> <div align="left"><font face="Arial"><span style="font-size:10pt">Rod,</span></font></div> <div align="left"><br/> </div> <div align="left"><font face="Arial"><span style="font-size:10pt">This is a known bug (895992). The problem lies in the uninitialized variables. The liverange analysis doesn't correctly detect these variables to be alive at the start of the loop. Initialize them and try again please.</span></font></div> <div align="left"><br/> </div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> All,</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> I have been trying to get my main loop to run correctly.  I have been </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> having trouble with the following code:</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> void main( void )</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> {</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>     UINT16 wOldTmr;</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>     UINT16 wCurTmr;</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>     while( 1 )</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>     {</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>         while( wOldTmr == wCurTmr )</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>         {</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>             wCurTmr = ReadTimerTic();</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>         }</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>         wOldTmr = wCurTmr;</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>     /* Some more code here */</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> }</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> The function ReadTimerTic returns a 16-bit value my problem was that </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> this loop at the top of main was supposed to delay 1mS so my main loop </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> would run every 1mS.  This is not the case it seems that the optomizer </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> is allowing the loop to exit immediately without delaying 1mS.  It was </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> not until I set both variables to volatile that the loop run correctly.  </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> I have no problem with this but the definition of volatile is to tell </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> the compiler to reload a variable on each reference to the variable in </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> case of a change in value outside the main program flow.  In this case </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> the variable wCurTmr will change but that change is in sync with the </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> normal program flow.  So my question is whey do I have to have the </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> volatile declaration in any case?  This would seem to me to be a case of </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> an over aggressive optomizer.  I have never had to do this with the Keil </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> compiler so I was surprised when I did this with SDCC.</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> My code is all working now and I have very happy but I would clasify </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> this as unexpected and nothing else.</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> My version of sdcc is:</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> 2.4.0 (Mar 22 2005) (UNIX)</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> Regards,</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> Rod Boyce</span></font></div> <div align="left"><br/></div> <div align="left"><br/> </div> <div align="left"><font face="Arial"><span style="font-size:10pt">Greets,</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">Maarten</span></font></div> </body> </html> |