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

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

RE: [avr-gcc-list] gcc bug


From: Rune Christensen
Subject: RE: [avr-gcc-list] gcc bug
Date: Thu, 24 Jun 2004 09:41:42 +0200

Hello

Please try the following

struct smotor { uint16_t count; };
volatile struct smotor motor;

This should generate the correct code. 
Volatile indicates that the variable is changed by the interrupt function.
It's not possible for gcc to guess that the variable is changed by another
function when you don't call the function directly. That is the case with
interrupt functions.

Cheers
Rune


> -----Original Message-----
> From: address@hidden 
> [mailto:address@hidden On Behalf Of Troy
> Sent: Wednesday, June 23, 2004 8:38 PM
> To: address@hidden
> Subject: [avr-gcc-list] gcc bug
> 
> 
> Hi,
> 
> I am writing on behalf of a friend who has a problem
> with output from win-avr-gcc (I am writing on his behalf 
> because of language issues).
> 
> The program has a global variable called "motor"
> which is a struct containing a uint16_t variable
> called "count."
> 
> struct smotor { uint16_t count; } motor;
> 
> main() {
>       // code to set up a timer which sets up a 
>       // signal handler for SIG_OVERFLOW0.
>       ... 
>       func();
>       // never returns from func().
> }
> 
> func() {
>       motor.count = 10;
>       while(motor.count > 0) {
>               ;
>       }
> }
> 
> signal(SIG_OVERFLOW0) {
>       if (motor.count) {
>               motor.count--;
>       }
> }
> 
> 
> The assembly code produced by gcc uses register R24 for "motor.count."
> signal() stores R24 properly in data space, altering its 
> value to 0, as it should.
> func() has the problem. It doesn't read R24 from data space 
> before each comparison, but instead treats it as a local 
> variable. This causes the 
> busy loop in func() to never exit.
> 
> Optimizer options used were the default values for the 
> Makefile which came with the latest win-avr-gcc (downloaded 
> one month ago).
> 
> If the code is altered to include further steps inside func()'s 
> while loop, the generated assembly code is different and 
> works properly. This is, however, not desirable.
> 
> It seems like an error that the R24 variable's value is not 
> read from data space before each comparison, since it is a 
> global variable.
> 
> 
> 
> 
> Thank you.
> 
> 
> 
> Troy (on behalf of Timo)
> 
>  
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden 
> http://www.avr1.org/mailman/listinfo/avr-gcc-list
> 
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.710 / Virus Database: 466 - Release Date: 23-06-2004
>  
> 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.710 / Virus Database: 466 - Release Date: 23-06-2004
 



reply via email to

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