Yahoo Groups archive

Lpc2000

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

Message

RE: [lpc2000] To bit pack or not

2005-04-01 by Tim Wade

I noticed that there were two other posts on this that were pretty much
down on the idea and they raise a lot of vaild points; if you know what
you are doing it can actually make the code a lot cleaner but there is
that issue of R/W vs RO or WO and other interesting side effects to do
with packing and order.

Having said all of that I quite like doing it and have used the an
compiler ages ago that had the registers of the chip I was using all
nicely provided as bit fields and it all worked fine. The job was a
quick in and out and I doubt it was ever ported to anything if it was
ever looked at again... But I thought at the time it made it a lot
easier to understand... (It was packing all the LUN and other weird bits
in SCSI packets).

If you are a bit worried about it then I have also seen some fairly
"intersting" definitions of bits within a register using #define macros;
it went something like:

BIT_DEFINTION(parity_bit, 4, 1);

Which made the variable parity bit the 4th bit of a register for 1 bit
and it generated a MASK and some other stuff but it was all a bit
confusing and probably more obvious long hand. I will have look to see
if I can find if if you are interested.

Cheers
Tim

-----Original Message-----
From: peterburdine [mailto:lordofdawn@...] 
Sent: Friday, 1 April 2005 9:01 AM
To: lpc2000@yahoogroups.com
Subject: [lpc2000] To bit pack or not



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





 
Yahoo! Groups Links



 



--
This email is confidential and intended solely for the use of the individual to whom it is addressed.  
Any views or opinions presented are solely those of the author and do not necessarily represent those of NAUTRONIX LTD.

If you are not the intended recipient, you have received this email in error and use, dissemination, forwarding, printing, or copying of this email is strictly prohibited.  If you have received this email in error please contact the sender.   

Although our computer systems use active virus protection software, and we take various measures to reduce the risk of viruses being transmitted in e-mail messages and attachments sent from this company, we cannot guarantee that such e-mail messages and attachments are free from viruses on receipt.  It is a condition of our using e-mail to correspond with you, that any and all liability on our part arising directly or indirectly out of any virus is excluded.  Please ensure that you run virus checking software on all e-mail messages and attachments before reading them.

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.