Skip to content

File syn_bits.h

FileList > src > syntropic > util > syn_bits.h

Go to the source code of this file

Bit manipulation macros. More...

  • #include <stdint.h>

Macros

Type Name
define SYN_BIT (n) ((uint32\_t)1U &lt;&lt; (n))
define SYN_BITMASK (width, offset) (((1U &lt;&lt; (width)) - 1U) &lt;&lt; (offset))
define SYN_BITS_GET (reg, width, offset) (((reg) &gt;&gt; (offset)) & ((1U &lt;&lt; (width)) - 1U))
define SYN_BITS_SET (reg, width, offset, value) /* multi line expression */
define SYN_BITS_TO_BYTES (bits) (((bits) + 7U) / 8U)
define SYN_BIT_CHECK (reg, bit) ((reg) & [**SYN\_BIT**](syn__bits_8h.md#define-syn_bit)(bit))
define SYN_BIT_CLEAR (reg, bit) ((reg) &= ~[**SYN\_BIT**](syn__bits_8h.md#define-syn_bit)(bit))
define SYN_BIT_SET (reg, bit) ((reg) \|= [**SYN\_BIT**](syn__bits_8h.md#define-syn_bit)(bit))
define SYN_BIT_TOGGLE (reg, bit) ((reg) ^= [**SYN\_BIT**](syn__bits_8h.md#define-syn_bit)(bit))

Detailed Description

All macros are pure preprocessor — zero overhead, no function calls.

Macro Definition Documentation

define SYN_BIT

#define SYN_BIT (
    n
) `((uint32_t)1U << (n))`

Produce a bitmask with bit n set (0-indexed).


define SYN_BITMASK

#define SYN_BITMASK (
    width,
    offset
) `(((1U << (width)) - 1U) << (offset))`

Produce a bitmask of width bits starting at bit position offset. Example: SYN_BITMASK(3, 4) → 0b0000'0000'0111'0000 → 0x70


define SYN_BITS_GET

#define SYN_BITS_GET (
    reg,
    width,
    offset
) `(((reg) >> (offset)) & ((1U << (width)) - 1U))`

Extract a bit-field of width bits starting at offset from reg.


define SYN_BITS_SET

#define SYN_BITS_SET (
    reg,
    width,
    offset,
    value
) `/* multi line expression */`

Set a bit-field: clear the field in reg, then OR in value.


define SYN_BITS_TO_BYTES

#define SYN_BITS_TO_BYTES (
    bits
) `(((bits) + 7U) / 8U)`

Number of bytes needed to store bits.


define SYN_BIT_CHECK

#define SYN_BIT_CHECK (
    reg,
    bit
) `((reg) & SYN_BIT (bit))`

Check if bit bit is set in reg. Evaluates to non-zero if set.


define SYN_BIT_CLEAR

#define SYN_BIT_CLEAR (
    reg,
    bit
) `((reg) &= ~ SYN_BIT (bit))`

Clear bit bit in register/variable reg.


define SYN_BIT_SET

#define SYN_BIT_SET (
    reg,
    bit
) `((reg) |= SYN_BIT (bit))`

Set bit bit in register/variable reg.


define SYN_BIT_TOGGLE

#define SYN_BIT_TOGGLE (
    reg,
    bit
) `((reg) ^= SYN_BIT (bit))`

Toggle bit bit in register/variable reg.



The documentation for this class was generated from the following file src/syntropic/util/syn_bits.h