Skip to end of metadata
Go to start of metadata

Creates a contiguous, multi-bit bit field.




          DEF_BIT_FIELD(bit_field, bit_shift);
          DEF_BIT_FIELD_08(bit_field, bit_shift);
          DEF_BIT_FIELD_16(bit_field, bit_shift);
          DEF_BIT_FIELD_32(bit_field, bit_shift);
          DEF_BIT_FIELD_64(bit_field, bit_shift);



Number of contiguous bits to set in the bit field.


Number of bit positions to left-shift the bit field.

Returned Value

Contiguous bit field of bit_field number of bits left-shifted by bit_shift number of bits.

Required Configuration


Notes / Warnings

bit_field and bit_shift should be non-negative integers.

bit_field/bit_shift values that overflow the target CPU and/or compiler environment (e.g. negative or greater-than-CPU-data-size values) may generate compiler warnings and/or errors.

To avoid overflowing any target CPU and/or compiler’s integer data type, unsigned bit constant 1 is either cast to specified integer data type size or suffixed with long integer modifier, ‘L’. This may still be insufficient for CPUs and/or compilers that support long long integer data types, in which case ‘LL’ integer modifier should be suffixed. However, since almost all 16- and 32-bit CPUs and compilers support long integer data types but many may not support long long integer data types, only long integer data types and modifiers are supported.

Example Usage

          CPU_INT08U  upper_nibble;
          CPU_INT32U  mask_32;
          upper_nibble = DEF_BIT_FIELD(4u, 4u);
          mask_32 = DEF_BIT_FIELD_16(7u, 13u);   /* 16-bit shift macro overflows; sets mask_32 = 0x0000E000 */
          mask_32 = DEF_BIT_FIELD_16(7u, 23u);   /* 16-bit shift macro overflows; sets mask_32 = 0          */
          mask_32 = DEF_BIT_FIELD_32(7u, 23u);   /* 32-bit shift macro correctly  sets mask_32 = 0x3F800000 */
  • No labels