Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

To bit pack or not

2005-04-01 by peterburdine

While not lpc2000 specific, I wanted to see if anyone else here was
using bit packing to access registers or if they were writing macros
or just doing to shifts and masking (w/o macros).

I spoke with the software guys here where I work (I'm and EE) and 2
out of 3 of them didn't think that using bit packing was a good idea
for any application, but the 1 thought that using it to access fields
with a register was a great idea.  I know that portability is a
concern of theirs, but since this is a device driver for 1 chip and
the code already has extensions which force it to be compiled with a
specific compiler (Keil's in the case) that I don't see that as a
valid argument.  What do you think?

For those who don't know bit packing it allows you to do this (for
example the ADDR Register):

struct	ADDR_REG {
	unsigned	pad0:6;  // not used
	unsigned	V_V3A:10;
	unsigned	pad1:8; // not used
	unsigned	CHN:3;
	unsigned	pad2:3; // not used
	unsigned	OVERRUN:1;
	unsigned	DONE:1;
};

#define ADDR           (*((volatile struct ADDR_REG *) 0xE0034004))

while(!ADDR.DONE); // spin
adcVal = ADDR.V_V3A; // read value

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.