[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: AW: [avr-gcc-list] Gcc bug??
From: |
Dave Hansen |
Subject: |
RE: AW: [avr-gcc-list] Gcc bug?? |
Date: |
Thu, 04 Mar 2004 09:55:22 -0500 |
<x-flowed>
From: "Dave Hylands" <address@hidden>
[...]
While we're talking about volatile, here's an example where volatile
might not help you (I've helped several people with this who had
misconceptions about what volatile does). Let's say I have a peripheral
which has a two register interface, the first register being an index
into an internal register and the second register gets the value.
struct hw
{
uint8_t reg;
uint8_t val;
};
struct hw *p;
void SetReg( uint8_t inReg, uint8_t inVal )
{
p->reg = inReg;
p->val = inVal;
}
It's possible for the compiler to reorder these to set val first and
then set reg. Declaring p as volatile will NOT change this behaviour.
But declaring what p points to _should_ work, right? e.g.
struct hw * volatile p;
makes p volatile, but
struct hw volatile * p;
makes what p points to volatile.
In any case, I believe you can modify your data structure as follows to make
it work without a barrier function:
struct hw
{
uint8_t volatile reg;
uint8_t volatile val;
};
Regards,
-=Dave
_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar get it now!
http://clk.atdmt.com/AVE/go/onm00200415ave/direct/01/
_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list
</x-flowed>
RE: AW: [avr-gcc-list] Gcc bug??,
Dave Hansen <=
RE: AW: [avr-gcc-list] Gcc bug??, Dave Hylands, 2004/03/04