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

Graeme Russ graeme.russ at gmail.com
Wed Jun 15 14:42:55 CEST 2011


On 15/06/11 22:04, Wolfgang Denk wrote:
> Dear Aneesh V,
> 
> In message <4DF89102.9040508 at ti.com> you wrote:
>>
>> Will you accept something like this?
>>
>> a_val = (reg & a_mask) >> a_shift;
> 
> Yes, of course (that's what seems most natural to me).
> 

Me too - The code is obvious - the desired value is being masked out of a
larger composite value and then shifted right to bit 0

And to set the value then you have:

	reg &= ~a_mask;				/* Clear a_val */
	reg |= (a_val << a_shift) & a_mask;	/* Set new a_val */

AND'ing with a_mask is required to prevent accidental clobbering when a_val
is out-of-range. May give undesirable results by setting an illegal a_val,
but at least you don't clobber unrelated bit fields

Regards,

Graeme


More information about the U-Boot mailing list