Path: blob/master/arch/arm/mach-pxa/include/mach/bitfield.h
10820 views
/*1* FILE bitfield.h2*3* Version 1.14* Author Copyright (c) Marc A. Viredaz, 19985* DEC Western Research Laboratory, Palo Alto, CA6* Date April 1998 (April 1997)7* System Advanced RISC Machine (ARM)8* Language C or ARM Assembly9* Purpose Definition of macros to operate on bit fields.10*/11121314#ifndef __BITFIELD_H15#define __BITFIELD_H1617#ifndef __ASSEMBLY__18#define UData(Data) ((unsigned long) (Data))19#else20#define UData(Data) (Data)21#endif222324/*25* MACRO: Fld26*27* Purpose28* The macro "Fld" encodes a bit field, given its size and its shift value29* with respect to bit 0.30*31* Note32* A more intuitive way to encode bit fields would have been to use their33* mask. However, extracting size and shift value information from a bit34* field's mask is cumbersome and might break the assembler (255-character35* line-size limit).36*37* Input38* Size Size of the bit field, in number of bits.39* Shft Shift value of the bit field with respect to bit 0.40*41* Output42* Fld Encoded bit field.43*/4445#define Fld(Size, Shft) (((Size) << 16) + (Shft))464748/*49* MACROS: FSize, FShft, FMsk, FAlnMsk, F1stBit50*51* Purpose52* The macros "FSize", "FShft", "FMsk", "FAlnMsk", and "F1stBit" return53* the size, shift value, mask, aligned mask, and first bit of a54* bit field.55*56* Input57* Field Encoded bit field (using the macro "Fld").58*59* Output60* FSize Size of the bit field, in number of bits.61* FShft Shift value of the bit field with respect to bit 0.62* FMsk Mask for the bit field.63* FAlnMsk Mask for the bit field, aligned on bit 0.64* F1stBit First bit of the bit field.65*/6667#define FSize(Field) ((Field) >> 16)68#define FShft(Field) ((Field) & 0x0000FFFF)69#define FMsk(Field) (((UData (1) << FSize (Field)) - 1) << FShft (Field))70#define FAlnMsk(Field) ((UData (1) << FSize (Field)) - 1)71#define F1stBit(Field) (UData (1) << FShft (Field))727374/*75* MACRO: FInsrt76*77* Purpose78* The macro "FInsrt" inserts a value into a bit field by shifting the79* former appropriately.80*81* Input82* Value Bit-field value.83* Field Encoded bit field (using the macro "Fld").84*85* Output86* FInsrt Bit-field value positioned appropriately.87*/8889#define FInsrt(Value, Field) \90(UData (Value) << FShft (Field))919293/*94* MACRO: FExtr95*96* Purpose97* The macro "FExtr" extracts the value of a bit field by masking and98* shifting it appropriately.99*100* Input101* Data Data containing the bit-field to be extracted.102* Field Encoded bit field (using the macro "Fld").103*104* Output105* FExtr Bit-field value.106*/107108#define FExtr(Data, Field) \109((UData (Data) >> FShft (Field)) & FAlnMsk (Field))110111112#endif /* __BITFIELD_H */113114115