[U-Boot] [PATCH v3 02/10] armv7: add miscellaneous utility macros

Wolfgang Denk
2011-06-14T13:53:35Z

Dear Aneesh V,

In message <4DF7488A.6000909@ti.com> you wrote:
>
> Yes. I have seen those macros. But more often than not the bit field is
> more than 1 bit wide and the value to be set is not necessarily all 0's
> or all 1's. That's why I have to use clrsetbits_*()

I see. In such a case (and only then) clrsetbits_*() is indeed the
right choice.

> The problem I have to deal with is different. get_bit_field() was
> intended to extract bit fields from an integer. So, the target usage
> will be something like this(where a, b, and c are bit fields in
> register my_reg)
>
> u32 my_reg, a_val, b_val, c_val;
>
> u32 my_reg = readl(my_reg_addr);
>
> a_val = get_bit_field(my_reg, a_mask);
> b_val = get_bit_field(my_reg, b_mask);
> c_val = get_bit_field(my_reg, c_mask);
>
> Do you see an alternative method for doing this using the standard
> macros?

Please see the example given here:

http://article.gmane.org/gmane.comp.boot-loaders.u-boot/101146

Looking closer, the "FIELD_VAL" macro alone will probably not suffice,
as you need both shift directions, like that:

#define FIELD_SHIFT 16
#define FIELD_MASK 0xF

#define FIELD_BITS(x) (x << 16)
#define FIELD_MASK FIELD_BITS(0xF)
#define FIELD_VAL(x) ((x & FIELD_MASK) >> 16)

The code would then look something like this:

my_reg = readl(my_reg_addr);

a_val = A_VAL(my_reg);
b_val = B_VAL(my_reg);
c_val = C_VAL(my_reg);

...or similar.

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
"I dislike companies that have a we-are-the-high-priests-of-hardware-
so-you'll-like-what-we-give-you attitude. I like commodity markets in
which iron-and-silicon hawkers know that they exist to provide fast
toys for software types like me to play with..." - Eric S. Raymond