This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Force 32 bit access to device


Hi Viswa,

I've worked with a retarded piece of hardware which only allowed 32-bit
access.  I've felt your pain.

Don't use bit fields.  Use a 32-bit word, and right-shift & mask out the
bits you don't care about.

IF you are working with hardware that you can read-and-write the bytes, AND
you need to write a byte in the middle of the 32-bit word, then read the
32-bit, mask out the hole, shift the byte, stuff the byte in the hole (in
your local variable), and put the 32-bit variable back into the hardware.

IF you are working with hardware that you can ONLY write, AND you need to
preserve the state of all four bytes, you'll really need to have a backing
store (or shadow copy of the hardware values) on your side where you do the
manipulation before sending them to the hardware.  And in the "you can ONLY
read", you'll need something similar (although trickier) for retrieving them
from the hardware, depending on what "reading a word" (or byte) means to the
hardware for that particular hardware register.

HTH,
--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]