Commit edee1668 authored by Arend van Spriel's avatar Arend van Spriel Committed by John W. Linville

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

Added inline functions to set bitfields in an unsigned integer variable.
Reviewed-by: default avatarHante Meuleman <meuleman@broadcom.com>
Reviewed-by: default avatarPieter-Paul Giesberts <pieterpg@broadcom.com>
Signed-off-by: default avatarArend van Spriel <arend@broadcom.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent bee1b848
...@@ -173,6 +173,29 @@ extern void brcmu_pktq_flush(struct pktq *pq, bool dir, ...@@ -173,6 +173,29 @@ extern void brcmu_pktq_flush(struct pktq *pq, bool dir,
/* ip address */ /* ip address */
struct ipv4_addr; 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 */ /* externs */
/* format/print */ /* format/print */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment