Bit, mask and register field macros.
More...
|
| #define | PBL_BIT(n) (1U << (n)) |
| | Unsigned 32-bit value with a single bit set.
|
| |
| #define | PBL_BIT64(n) (1ULL << (n)) |
| | Unsigned 64-bit value with a single bit set.
|
| |
| #define | PBL_BIT_MASK(n) (PBL_BIT(n) - 1U) |
| | Unsigned 32-bit mask with the n least significant bits set.
|
| |
| #define | PBL_BIT64_MASK(n) (PBL_BIT64(n) - 1ULL) |
| | Unsigned 64-bit mask with the n least significant bits set.
|
| |
| #define | PBL_GENMASK(h, l) (((2U << ((h) - (l))) - 1U) << (l)) |
| | Unsigned 32-bit mask with bits l to h set, both included.
|
| |
| #define | PBL_GENMASK64(h, l) (((2ULL << ((h) - (l))) - 1ULL) << (l)) |
| | Unsigned 64-bit mask with bits l to h set, both included.
|
| |
| #define | PBL_LSB_GET(value) ((value) & -(value)) |
| | Isolate the least significant set bit of a value.
|
| |
| #define | PBL_FIELD_GET(mask, value) (((value) & (mask)) / PBL_LSB_GET(mask)) |
| | Extract a field from a register value.
|
| |
| #define | PBL_FIELD_PREP(mask, value) (((value) * PBL_LSB_GET(mask)) & (mask)) |
| | Prepare a field value for a register.
|
| |
| #define | PBL_WRITE_BIT(var, bit, set) |
| | Set or clear a bit in a variable.
|
| |
Bit, mask and register field macros.
A field is described by a contiguous mask, usually built with PBL_GENMASK(). PBL_FIELD_PREP() shifts a value into the field and PBL_FIELD_GET() extracts it, so the field position never has to be spelled out. With a constant mask both fold to a plain shift and mask.
#define CTRL1_ODR_MASK PBL_GENMASK(7, 4)
#define CTRL1_ODR_50HZ 0x4U
#define CTRL1_LP_EN PBL_BIT(0)
#define PBL_FIELD_GET(mask, value)
Extract a field from a register value.
Definition bits.h:85
#define PBL_FIELD_PREP(mask, value)
Prepare a field value for a register.
Definition bits.h:94
◆ PBL_BIT
| #define PBL_BIT |
( |
|
n | ) |
(1U << (n)) |
Unsigned 32-bit value with a single bit set.
- Parameters
-
◆ PBL_BIT64
| #define PBL_BIT64 |
( |
|
n | ) |
(1ULL << (n)) |
Unsigned 64-bit value with a single bit set.
- Parameters
-
◆ PBL_BIT64_MASK
| #define PBL_BIT64_MASK |
( |
|
n | ) |
(PBL_BIT64(n) - 1ULL) |
Unsigned 64-bit mask with the n least significant bits set.
- Parameters
-
| n | Number of bits, 0 to 63. |
◆ PBL_BIT_MASK
| #define PBL_BIT_MASK |
( |
|
n | ) |
(PBL_BIT(n) - 1U) |
Unsigned 32-bit mask with the n least significant bits set.
- Parameters
-
| n | Number of bits, 0 to 31. |
◆ PBL_FIELD_GET
| #define PBL_FIELD_GET |
( |
|
mask, |
|
|
|
value |
|
) |
| (((value) & (mask)) / PBL_LSB_GET(mask)) |
Extract a field from a register value.
- Parameters
-
| mask | Contiguous, non-zero field mask, evaluated twice. |
| value | Register value. |
- Returns
- Field value, shifted down to bit 0.
◆ PBL_FIELD_PREP
| #define PBL_FIELD_PREP |
( |
|
mask, |
|
|
|
value |
|
) |
| (((value) * PBL_LSB_GET(mask)) & (mask)) |
Prepare a field value for a register.
- Parameters
-
| mask | Contiguous, non-zero field mask, evaluated twice. |
| value | Field value; bits that do not fit the field are dropped. |
- Returns
value shifted into the field position and masked.
◆ PBL_GENMASK
| #define PBL_GENMASK |
( |
|
h, |
|
|
|
l |
|
) |
| (((2U << ((h) - (l))) - 1U) << (l)) |
Unsigned 32-bit mask with bits l to h set, both included.
- Parameters
-
| h | Most significant bit of the mask, 0 to 31. |
| l | Least significant bit of the mask, at most h. |
◆ PBL_GENMASK64
| #define PBL_GENMASK64 |
( |
|
h, |
|
|
|
l |
|
) |
| (((2ULL << ((h) - (l))) - 1ULL) << (l)) |
Unsigned 64-bit mask with bits l to h set, both included.
- Parameters
-
| h | Most significant bit of the mask, 0 to 63. |
| l | Least significant bit of the mask, at most h. |
◆ PBL_LSB_GET
| #define PBL_LSB_GET |
( |
|
value | ) |
((value) & -(value)) |
Isolate the least significant set bit of a value.
- Parameters
-
| value | Unsigned value, evaluated twice. |
- Returns
value with every bit cleared but its lowest set one, or 0 if value is 0.
◆ PBL_WRITE_BIT
| #define PBL_WRITE_BIT |
( |
|
var, |
|
|
|
bit, |
|
|
|
set |
|
) |
| |
Value: ((var) = \
(set) ? ((var) | ((__typeof__(var))1 << (bit))) : ((var) & ~((__typeof__(var))1 << (bit))))
Set or clear a bit in a variable.
The mask is built in the type of var, so other bits are preserved whatever its width.
- Parameters
-
| var | Unsigned integer variable to update, evaluated more than once. |
| bit | Bit position, less than the width of var. |
| set | Set the bit if true, clear it otherwise. |