On Tue, 2004-11-09 at 07:59, Dmitry wrote:
> No bugs at all.
> Just coding...
> read_flag must be declared volatile
> to reach if() iner code.
> ~d
> 
> 
> > while(1)                              
> >   {
> >      if(read_flag == 1)
> >      {
> >        read_flag = 0;           <-- can not reach 
> >          TXBUF0 = *Flash_ptrA;  
> >      }
> >      else if(flash_flag ==1)
> >      {
> >         flash_flag =0;
> >           
> >      }
> > }

Are you sure about that, Dmitry?
The code looks OK to me - though it is a bit odd. I assume the original
poster only posted extracts...

First time around the while loop (assuming read_flag starts off as 1)
then set it to zero and write to TXBUF0.
               ^^^^^^^^^^^^^^

Second time around the while loop (assuming flash_flag starts off as 1)
set flash flag to zero.
                 ^^^^^^^^^^^^^^^^^^^^^^

For all time after that, spin and do nothing.

I suppose I can see that if the loop gets unrolled, the both "set X to
zero" statements underlined above might get optimised out. 

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

The only explanation I can see for having to declare 'read_flag'
volatile is if something else (like an IRQ handler) might set read_flag
to 1. If that's the case, then of course the 'while' loop won't see the
change if it's not declared volatile.

But the original poster didn't say that, did he? And why does the
rewrite without the 'else' work? Did the compiler unroll the loop in the
first case, but not in the rewritten version?

Steve.



Reply via email to