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

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

Re: [avr-gcc-list] Bug in avr-libc or?


From: Per Arnold Blåsmo
Subject: Re: [avr-gcc-list] Bug in avr-libc or?
Date: Tue, 01 Jun 2004 10:54:05 +0200
User-agent: Mozilla Thunderbird 0.6 (X11/20040502)

Thanks to all for your responses!

I should have read the docs and the FAQ in the avr-libc manual better.

I also fount this article on the usage of volatile on the net. I might be of interest to read among others.

http://www.programmersheaven.com/articles/pathak/article1.htm


Regards Per A.



Flemming Gram Christensen wrote:

Try declaring your variable "volatile".

volatile uint8_t var;

Now the compiler will know that the variable can be changed from other parallel 
executions (i.e. interrupts).

Only do it with "signal" variables as it hurts performance.

Regards

-----Original Message-----
From: Per Arnold Blåsmo [mailto:address@hidden Sent: 1. juni 2004 09:42
To: address@hidden
Subject: [avr-gcc-list] Bug in avr-libc or?

Hi,

I have been doing a program  and got into a problem with a while loop.

Basically what I wanted to do was to do a while loop that waited until a variable changed and so go out of the while loop.
The variable was altered by a interrupt routine.

What happen was that the variable in the while loop was copied into a register and the while loop did test the register instead of the variable. Thereby never detecting any change of the variable done in the interrupt routine.

I made a test program to show the result:

avrtest.c :

#include <avr/io.h>
#include <avr/signal.h>

uint8_t var;

SIGNAL(SIG_INTERRUPT0){
var = 0;
}

int main(void){

var = 1;

while(var==1){
// do nothing but wait
}

//Now do sometning
var = 2;
}




reply via email to

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