Kinetis Bit Manipulation Engine (BME)¶
Macros for using decorated memory accesses with the Bit Manipulation Engine available in Kinetis Cortex-M0+ devices.
-
void *
bme_bf_addr
(volatile void * ptr, uintptr_t bit, uintptr_t width)¶ Bit field address macro.
Parameters
ptr: Pointer to target register bit: Location of the LSB of the bitfield within the register width: Width of the the bitfield, in bits Return values
- bitfield address as an uintptr_t
-
uint32_t *
bme_bitfield32
(volatile uint32_t * ptr, uint8_t bit, uint8_t width)¶ Access a bitfield (32 bit load/store)
This macro can be used both for store
(*bme_bitfield32(xxx) = y)
and load(y = *bme_bitfield32(ptr, bit))
Parameters
ptr: Pointer to target register bit: Location of the LSB of the bitfield within the register width: Width of the the bitfield, in bits Return values
- bitfield extracted as a (modifiable) lvalue
-
uint16_t *
bme_bitfield16
(volatile uint16_t * ptr, uint8_t bit, uint8_t width)¶ Access a bitfield (16 bit load/store)
This macro can be used both for store
(*bme_bitfield16(xxx) = y)
and load(y = *bme_bitfield16(ptr, bit))
Parameters
ptr: Pointer to target register bit: Location of the LSB of the bitfield within the register width: Width of the the bitfield, in bits Return values
- bitfield extracted as a (modifiable) lvalue
-
uint8_t *
bme_bitfield8
(volatile uint8_t * ptr, uint8_t bit, uint8_t width)¶ Access a bitfield (8 bit load/store)
This macro can be used both for store
(*bme_bitfield8(xxx) = y)
and load(y = *bme_bitfield8(ptr, bit))
Parameters
ptr: Pointer to target register bit: Location of the LSB of the bitfield within the register width: Width of the the bitfield, in bits Return values
- bitfield extracted as a (modifiable) lvalue
-
void
bit_set32
(volatile uint32_t * ptr, uint8_t bit)¶ Set a single bit in the 32 bit word pointed to by
ptr
.The effect is the same as for the following snippet:
1
*ptr |= (1 << bit);
There is a read-modify-write cycle occurring within the core, but this cycle is atomic and can not be disrupted by IRQs
Parameters
ptr: pointer to target word bit: bit number within the word
-
void
bit_set16
(volatile uint16_t * ptr, uint8_t bit)¶ Set a single bit in the 16 bit word pointed to by
ptr
.The effect is the same as for the following snippet:
1
*ptr |= (1 << bit);
There is a read-modify-write cycle occurring within the core, but this cycle is atomic and can not be disrupted by IRQs
Parameters
ptr: pointer to target word bit: bit number within the word
-
void
bit_set8
(volatile uint8_t * ptr, uint8_t bit)¶ Set a single bit in the 8 bit byte pointed to by
ptr
.The effect is the same as for the following snippet:
1
*ptr |= (1 << bit);
There is a read-modify-write cycle occurring within the core, but this cycle is atomic and can not be disrupted by IRQs
Parameters
ptr: pointer to target byte bit: bit number within the byte
-
void
bit_clear32
(volatile uint32_t * ptr, uint8_t bit)¶ Clear a single bit in the 32 bit word pointed to by
ptr
.The effect is the same as for the following snippet:
1
*ptr &= ~(1 << bit);
There is a read-modify-write cycle occurring within the core, but this cycle is atomic and can not be disrupted by IRQs
Parameters
ptr: pointer to target word bit: bit number within the word
-
void
bit_clear16
(volatile uint16_t * ptr, uint8_t bit)¶ Clear a single bit in the 16 bit word pointed to by
ptr
.The effect is the same as for the following snippet:
1
*ptr &= ~(1 << bit);
There is a read-modify-write cycle occurring within the core, but this cycle is atomic and can not be disrupted by IRQs
Parameters
ptr: pointer to target word bit: bit number within the word
-
void
bit_clear8
(volatile uint8_t * ptr, uint8_t bit)¶ Clear a single bit in the 8 bit byte pointed to by
ptr
.The effect is the same as for the following snippet:
1
*ptr &= ~(1 << bit);
There is a read-modify-write cycle occurring within the core, but this cycle is atomic and can not be disrupted by IRQs
Parameters
ptr: pointer to target byte bit: bit number within the byte
-
BME_AND_MASK
¶ AND decoration bitmask.
1
(1 << 26)
-
BME_OR_MASK
¶ OR decoration bitmask.
1
(1 << 27)
-
BME_XOR_MASK
¶ XOR decoration bitmask.
1
(3 << 26)
-
BME_LAC1_MASK
( BIT)¶ Load-and-clear 1 bit.
1
((1 << 27) | ((BIT) << 21))
-
BME_LAS1_MASK
( BIT)¶ Load-and-set 1 bit.
1
((3 << 26) | ((BIT) << 21))
-
BME_BF_MASK
( bit, width)¶ Bit field extraction bitmask.
1
((1 << 28) | ((bit) << 23) | (((width) - 1 ) << 19))
Parameters
bit: LSB of the bitfield within the word/halfword/byte width: Number of bits to extract