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

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

Re: [avr-gcc-list] Question about gcc preprocessing and port/pin assignm


From: Graham Davies
Subject: Re: [avr-gcc-list] Question about gcc preprocessing and port/pin assignments
Date: Wed, 8 Dec 2004 14:42:40 -0500

I agree with Dave that there's more to volatile than
someone-else-might-change-it.  A variable must be declared volatile if
access to it can have side-effects.  This is generally true of registers
that control hardware.  Dave provided good examples.

I reported a defect to ZiLOG in their ZDS II for Z8 Encore! related to this.
I wrote something like this:
SOME_REG = (SOME_REG & 0xFE) | 0x02;
where SOME_REG is declared volatile and the intent is to flip the state of
two enable signals to external hardware devices.  The machine code produced
enables the second device and then disables the first in two successive
instructions.  My argument is that since SOME_REG is volatile the compiler
is supposed to do exactly as I say and so it must evaluate the right hand
side of the assignment and write once to SOME_REG, even if this is not as
fast as writing twice to SOME_REG.  So far I have been unable to convince
ZiLOG that what they're doing is wrong.  This and similar episodes explains
my switch to AVR.

By the way, I realize that flipping the enables at the same time may be
borderline in some cases but I have checked the timing and it's OK in this
case.  Having them both enabled for a few hundred nanoseconds may not be so
bad either, but what if an interrupt comes along between the two
instruction?

Graham.



reply via email to

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