Well, I'm certainly glad I starting asking about this instead of just
doing it. It seems that all around it can be a very bad idea at least
when using them to read and sometimes write to registers.
Thanks for all the advice.
--- 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 valueMessage
Re: To bit pack or not
2005-04-01 by peterburdine
Attachments
- No local attachments were found for this message.