brcmutil: add macros for setting bitfields using mask/shift operations

Added inline functions to set bitfields in an unsigned integer variable.

Reviewed-by: Hante Meuleman <meuleman@broadcom.com>
Reviewed-by: Pieter-Paul Giesberts <pieterpg@broadcom.com>
Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
This commit is contained in:
Arend van Spriel 2013-03-03 12:45:27 +01:00 committed by John W. Linville
parent bee1b84887
commit edee1668bb
1 changed files with 23 additions and 0 deletions

View File

@ -173,6 +173,29 @@ extern void brcmu_pktq_flush(struct pktq *pq, bool dir,
/* ip address */
struct ipv4_addr;
/*
* bitfield macros using masking and shift
*
* remark: the mask parameter should be a shifted mask.
*/
static inline void brcmu_maskset32(u32 *var, u32 mask, u8 shift, u32 value)
{
value = (value << shift) & mask;
*var = (*var & ~mask) | value;
}
static inline u32 brcmu_maskget32(u32 var, u32 mask, u8 shift)
{
return (var & mask) >> shift;
}
static inline void brcmu_maskset16(u16 *var, u16 mask, u8 shift, u16 value)
{
value = (value << shift) & mask;
*var = (*var & ~mask) | value;
}
static inline u16 brcmu_maskget16(u16 var, u16 mask, u8 shift)
{
return (var & mask) >> shift;
}
/* externs */
/* format/print */