Re: A basic question question about volatile use
- From: gordonb.q7d1t@xxxxxxxxxxx (Gordon Burditt)
- Date: Thu, 31 Jul 2008 14:27:34 -0500
What if it is not an I/O but a normal memory location with intendedI have a memory-mapped peripheral with a mapping like, say,
struct T {uint8_t read, write, status, forkicks;};
If I slap a volatile on an object of type struct T, does it guarantee
that all accesses to the members are byte-wide, or is the compiler free
to read or read-modify-write in any data width it chooses?
I don't believe that anything in the standard guarantees the right
thing for memory-mapped I/O (the vague promises aren't good enough),
byte-size members? (BTW, why the difference?)
Ordinary RAM does not care about the number of accesses or the width
of accesses. What you write can be read back. Ordinary RAM doesn't
usually NEED volatile unless there is some asynchronous code (signal
handler, interrupt routine, etc.) that can change the contents
without the compiler knowing about it.
With memory-mapped I/O, reading or writing a register may trigger
an action (clearing a "data ready" flag, fetching the next set of
data, launching a missile, etc. What you read (the "status" register)
may have nothing to do with what you write (the "command" register)
except they share the same address (so turning a byte write into a
word fetch, replace a byte, write a word may be a disaster, even
though it's not an issue with ordinary RAM). Accessing the register
with the wrong I/O width may cause malfunctions or access something
entirely different. The contents of a memory-mapped I/O device
register may change on its own (e.g. data ready or status flags,
or a clock).
.
- References:
- A basic question question about volatile use
- From: Ark Khasin
- Re: A basic question question about volatile use
- From: Gordon Burditt
- Re: A basic question question about volatile use
- From: Ark Khasin
- A basic question question about volatile use
- Prev by Date: Re: stream io in c
- Next by Date: Re: diagnostic message
- Previous by thread: Re: A basic question question about volatile use
- Next by thread: Re: A basic question question about volatile use
- Index(es):
Relevant Pages
|