On 10/27/2013 1:31 AM, Russel Winder wrote:
The core problem with peek and poke for writing device drivers is that hardware controllers do not just use byte structured memory for things, they use bit structures.So for data I/O, device->buffer = value value = device->buffer can be replaced easily with: poke(device->buffer, value) value = peek(device->buffer) but this doesn't work when you are using bitfields, you end up having to do all the ugly bit mask manipulation explicitly. Thus, what the equivalent of: device->csw.enable = 1 status = device->csw.ready is, is left to the imagination.
Bitfield code generation for C compilers has generally been rather crappy. If you wanted performant code, you always had to do the masking yourself.
I've written device drivers, and have designed, built, and programmed single board computers. I've never found dealing with the oddities of memory mapped I/O and bit flags to be of any difficulty.
Do you really find & and | operations to be ugly? I don't find them any uglier than + and *. Maybe that's because of my hardware background.
