ron minnich wrote:
On Wed, Jun 4, 2008 at 10:32 AM, Stefan Reinauer stepan@coresystems.de wrote:
#define MCHBAR8(x) *((volatile u8 *)(DEFAULT_MCHBAR + x)) #define MCHBAR16(x) *((volatile u16 *)(DEFAULT_MCHBAR + x)) #define MCHBAR32(x) *((volatile u32 *)(DEFAULT_MCHBAR + x))
so you can write
MCHBAR8(DCC) |= (1<<1);
for maximum readablility
yes but as I mentioned .... one of the very earliest uses of struct, from the guy who designed C, was to avoid this kind of construct. Register structures accessed via mmio? set up a struct.
The one disadvantage of structs for this kind of thing is that you have no way to cleanly describe offsets except through padding bytes. So you end up recalculating offsets of registers and numbers of bytes of reserved1 - reserved100 arrays within your struct, one for every hole. And when you add a register, you do the work again, and it's error prone, a single byte off, and all your registers are wrong.
I'm not against using structs, in fact maybe we should just do it, but they're not the optimal solution either. The guy who invented struct was not a firmware developer.