Yahoo Groups archive

Lpc2000

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

Message

Re: To bit pack or not

2005-04-01 by Ken Wada

For 8-bit values; your scheme will work fine. For 16 and 32-bit 
values...your scheme will not work at all! Read page 34 of the LPC2214 
users manual:
"This eliminates the need for byte lane mapping hardware that would be 
required to allow byte (8-bit) or half-word (16-
bit) accesses to occur at smaller boundaries. An implication of this 
is that word and half-word registers must be accessed all at
once. For example, it is not possible to read or write the upper byte 
of a word register separately."

This implies all registers must be accessed as a single 32-bit word. 
If you look closely at the memory map, most the registers are exactly 
organized, (LITTLE ENDIAN), as 8-bit octets using the 
least-significant-byte on 32-bit boundaries.

Ken Wada

--- In lpc2000@yahoogroups.com, "peterburdine" <lordofdawn@h...> 
wrote:
> 
> 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.