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

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

Re: [avr-gcc-list] Affecting variables


From: Christoph Plattner
Subject: Re: [avr-gcc-list] Affecting variables
Date: Tue, 08 May 2001 09:15:18 +0200

Uuuuh !

If you need a "volatile" in this situation, then we speek about
and compiler bug !! There is no specification, that a variable 
"shared" via parallel execution threads (the interrupt can be
seen as parallel (asynchron) thread to the routine in `main').

We know the method under unix ... :

signal handler says
        runflag = 0;

And main loop:

        while (runflag)
        {
                ...
        }

And this case, nobody uses `volatile' !!

Is Mr. Paulo Abreu sure, that the interrupt routine is really called ?
A good idea is to use a LED on an output pin to debug this.

With friendly regards
        Christoph Plattner



Larry Barello wrote:
> 
> You need to declare bTest as a "volatile".  The compiler has cached the
> value of the variable in a register and referred to the register inside the
> loop.  Declaring it volatile will tell the compiler that the variable might
> change between loops and to re-load it each time.  Any shared static or
> global variable that can be modified outside of the code flow (e.g.
> multitasking or interrupts) needs to be declared volatile so the compiler
> knows not to cache the value in a register.
> 
> Try using the -S compiler switch and generate the assembly code and look at
> it.  You can learn a lot that way.
> 
> Question: could someone illuminate the difference between:
> 
> volatile char bTest;
> char volatile bTest;
> 
> or are they the same?
> 
> Cheers!
> 
> ----- Original Message -----
> From: "Paulo Abreu" <address@hidden>
> To: <address@hidden>
> Sent: Monday, May 07, 2001 4:53 PM
> Subject: [avr-gcc-list] Affecting variables
> 
> > I am doing something like this (unfortunately I forgot my .c file)
> >
> > char bTest;
> >
> > void init(void)
> > {
> >   bTest=0;
> > }
> >
> > /* receive uart handler */
> > SIGNAL(...)
> > {
> >   bTest=1;
> > }
> >
> > int main(void)
> > {
> >
> >   init();
> >
> >   while(1)
> >   {
> >     if(bTest == 1)
> >     {
> >       /* do something*/
> >     }
> >   }
> > }
> >
> >
> > what is happening is that bTest is not being affected, that is, bTest!=1,
> > why?
> >
> > I am using the last version of avr-gcc for windows.
> >
> > Thanks in advance for your attention,
> >
> > Paulo Abreu
> >
> >
> >
> > _______________________________________________
> > avr-gcc-list mailing list
> > address@hidden
> > http://avr.jpk.co.nz/mailman/listinfo/avr-gcc-list
> >
> 
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://avr.jpk.co.nz/mailman/listinfo/avr-gcc-list


------------------------------------------------------------------
private:  address@hidden
company:  address@hidden



reply via email to

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