[Tinyos-help] AVR GCC compiler problems

Janos Sallai sallai at isis.vanderbilt.edu
Wed Feb 27 14:49:34 PST 2008

I agree with Kevin that chances are low that it's a compiler problem. One thing I can imagine is that id and mask are stored in registers between the subsequent calls to CANReceive.setReceive, and the register values get corrputed by some asm statements that don't properly tell the compiler what registers they change (empty or wrong clobber list). You might want to check that.
Stack growing too big can also be an issue, though that usually results in overwriting static variables... Do you have big data structures allocated locally in the code you're calling? Do you have recursion in your code?
If you still suspect that it's a compiler issue, you might want to try it with a recent avr-gcc and avr-libc.
The compiler bug you were referring to is clearly not a bug. According to the C standard, operands of binary shift operator (and others) are subject to integer promotion, and the result is of the promoted integer type. The piece of code you gave gives different results on a platform that defines int as a 16-bit integer than on a platform that has a 32-bit int. On the atmega128, the result of "number1 << 14" will be a 16-bit integer.

From: tinyos-help-bounces at millennium.berkeley.edu on behalf of Kevin Klues
Sent: Wed 2/27/2008 2:27 PM
To: José Moyano
Cc: tinyos-help at millennium.berkeley.edu
Subject: Re: [Tinyos-help] AVR GCC compiler problems

> One more thing: Does C support coercion?

Yes C supports coercion, but the problem you have is that you are
really executing two statements in the assignment.  Coercion only
happens after the shift has occurred.  so first the compiler does
(number1 << 14), then it converts it to a 32 bit number to assign it
to number2.  You need the explicit cast to tell the compiler to first
convert number1 to 32 bits, then do the shift, then do the assignment.

> Do you use casting for all your 32-bit statements?

I don't know what you mean "for all my 32-bit statements".  Yes, if I
ever have a 16 bit number that I am shifting or multiplying by a
variable with a different precision then yes I use a cast.  Between
variables of the same type, no.  This is the standard way of doing
things in C.

> Another clue: The error happens only when there are few sentences betweens
> two (or more) calls to the routine. If I wait some time for the second call,
> it works fine. However, as you can see in the code, the routine doesn't need
> clock cycles to be called again.

You must have some sort of race condition somehwere that is causing
the eror somehow, otherwise I'm not sure what it might be.

Tinyos-help mailing list
Tinyos-help at millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help <https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help> 

More information about the Tinyos-help mailing list