Re: [avr-gcc-list] if test ignored?

2007-05-17 Thread Rick Mann


On May 17, 2007, at 20:45 , kitts wrote:


You need to make sCommandReceived a volatile variable.


Yeah, I realized that, thanks. I'm fully aware of the dangers of the  
optimizer, and was operating from the assumption that it was turned  
off. I should've known.


Thanks!

--
Rick




___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] if test ignored?

2007-05-17 Thread Parthasaradhi Nayani

Rick Mann <[EMAIL PROTECTED]> wrote: On an AVR ATmega128:

I have two source files. In Serial.c, I define a global:
char sCommandReceived;

in the corresponding Serial.h file, I have:

extern char sCommandReceived;

sCommandReceived is set to 1 when enough bytes have been copied into  
a buffer from the serial port. In main.c, which includes Serial.h, I  
have:

 while (true)
 {
  if (sCommandReceived)
  {
   parseCommand();
  }
 }

One probable cause could be 'sCommandReceived' not declared as volatile if it 
is being accessed in the interrupt

Nayani

   Choose the right car based on your needs.  Check out Yahoo! Autos new 
Car Finder 
tool.http://us.rd.yahoo.com/evt=48518/*http://autos.yahoo.com/carfinder/;_ylc=X3oDMTE3NWsyMDd2BF9TAzk3MTA3MDc2BHNlYwNtYWlsdGFncwRzbGsDY2FyLWZpbmRlcg--
 hot CTA = Yahoo! Autos new Car Finder tool___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] if test ignored?

2007-05-17 Thread kitts
On Friday 18 May 2007 9:09:32 am Rick Mann wrote:
> I have two source files. In Serial.c, I define a global:
> charsCommandReceived;
>
> in the corresponding Serial.h file, I have:
>
> extern char sCommandReceived;
>
> sCommandReceived is set to 1 when enough bytes have been copied into  
> a buffer from the serial port. In main.c, which includes Serial.h, I  
> have:
>
> while (true)
> {
> if (sCommandReceived)
> {
> parseCommand();
> }
> }
>
> If I break on the if statement, gdb tells me that sCommandReceived is  
> 1. However, a breakpoint in parseCommand(), defined earlier in the  
> file, never gets called. If I call parseCommand() directly from the  
> USART receive interrupt handler, it gets called. (parseCommand() then  
> clears sCommandReceived).
>
> What am I missing?

You need to make sCommandReceived a volatile variable.
-- 
Cheers!
kitts


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


[avr-gcc-list] if test ignored?

2007-05-17 Thread Rick Mann

On an AVR ATmega128:

I have two source files. In Serial.c, I define a global:
charsCommandReceived;

in the corresponding Serial.h file, I have:

extern char sCommandReceived;

sCommandReceived is set to 1 when enough bytes have been copied into  
a buffer from the serial port. In main.c, which includes Serial.h, I  
have:


while (true)
{
if (sCommandReceived)
{
parseCommand();
}
}

If I break on the if statement, gdb tells me that sCommandReceived is  
1. However, a breakpoint in parseCommand(), defined earlier in the  
file, never gets called. If I call parseCommand() directly from the  
USART receive interrupt handler, it gets called. (parseCommand() then  
clears sCommandReceived).


What am I missing?

TIA,
--
Rick




___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list