lkml.org 
[lkml]   [2008]   [Aug]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [patch] Add helper macros for little-endian bitfields
Date
 > + * NOTE: When using multibyte bitfields, you need to convert the data
> + * from Little Endian to CPU before you can access the bitfield
> + * (to make it simpler):
> + *
> + * union something {
> + * le16 value;
> + * DECL_BF_LE3(
> + * u16 bf0:3,
> + * u16 bf1:10,
> + * u16 bf2:3
> + * ) __attribute__((packed));
> + * };
> + *
> + * ...
> + *
> + * union something s;
> + *
> + * s.value = le16_to_cpu(something LE read from hw);
> + * frame_count = s.bf1;

I can't help thinking there's got to be a better way to do this... in
particular having 16 DECL_BF_LEnn() macros (and needing to count the
number of members every time you use one) is not particularly pretty.

In general the consensus with kernel code seems to be that you're better
off avoiding bitfields in structures, and just using shift/mask
operations to get at the data (with helper functions as needed).

However all of that is said without actually looking at the driver code
that uses this.

- R.


\
 
 \ /
  Last update: 2008-08-25 03:41    [from the cache]
©2003-2011 Jasper Spaans