[U-Boot] [PATCH 1/5] Tegra2: Add bitfield access macros

Simon Glass sjg at chromium.org
Tue Jun 7 08:46:50 CEST 2011


Hi Wolfgang,

On Mon, Jun 6, 2011 at 11:28 PM, Wolfgang Denk <wd at denx.de> wrote:
> Dear Simon Glass,
>
> In message <BANLkTimCGQbih16u7772-uKHb0bUyApbe14mNQ91zhqi1SS62w at mail.gmail.com> you wrote:
>>
>> OK I understand, thank you. How about this approach: we could add a
>> new macro to io.h, something like:
>>
>> #define clrsetfield_le32(bitfield, addr, value)  ...
>>
>> Then caller can define these in a header file:
>>
>> #define FIELD_MASK 0xf0000
>> #define FIELD_SHIFT 16
>>
>> And use this macro to set the bitfield to 6, for example:
>>
>> clrsetfield_le32(FIELD, &my_device->ctrl, 6)
>>
>> (this will simply shift the value left 16 bits and apply the supplied mask)
>>
>> This captures the essence of bitfields, in that we are abstracting the
>> field under a single name. The change would just add this macro to the
>> io.h header file.
>
> Sorry, I fail to understand how you envision to use this, and how it
> would be different from  clrsetbits*() ?

For example this allows us to replace:

clrsetbits_le(&my_device->ctrl, 0xf << 16, 6 << 16)

with:

clrsetfield_le32(FIELD, &my_device->ctrl, 6)

So the two identical shifts are avoided, and the forming of the mask
is done once in the define.

Please do try to help me out with a form of bitfield definition that
you would be comfortable with. This approach here makes use of
clrsetbits*() and extends it in a simple way. If there is another
better or more acceptable approach then please do let me know.

Regards,
Simon

>
> Best regards,
>
> Wolfgang Denk
>
> --
> DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
> No one wants war.
>        -- Kirk, "Errand of Mercy", stardate 3201.7
>


More information about the U-Boot mailing list