MCCI Trusted Bootloader
Simple trusted bootloader and tools for small embedded systems
mcci_bootloader_bits.h File Reference

Go to the source code of this file.

Macros

#define _mcci_bootloader_bits_h_   /* prevent multiple includes */
 
#define MCCI_BOOTLOADER_FIELD_LSB(fmask)    ((fmask) & (~(fmask) + 1u))
 
#define MCCI_BOOTLOADER_FIELD_SET_VALUE(fmask, val)    (MCCI_BOOTLOADER_FIELD_LSB(fmask) * (val))
 
#define MCCI_BOOTLOADER_FIELD_SHIFT(x)   MCCI_BOOTLOADER_LOG2_POW2((x) & (~(x)+1))
 get shift count from field mask.
 
#define MCCI_BOOTLOADER_LOG2_POW2(x)
 compute log2 of an power of 2.
 
#define MCCI_BOOTLOADER_VALUE_GET_FIELD(val, fmask)    (((val) & (fmask)) >> MCCI_BOOTLOADER_FIELD_SHIFT(fmask))
 
#define MCCI_BOOTLOADER_VALUE_MAKE_FIELD(val, fmask)    (MCCI_BOOTLOADER_FIELD_LSB(fmask) * (val))
 

Macro Definition Documentation

◆ _mcci_bootloader_bits_h_

#define _mcci_bootloader_bits_h_   /* prevent multiple includes */

Definition at line 23 of file mcci_bootloader_bits.h.

◆ MCCI_BOOTLOADER_FIELD_LSB

#define MCCI_BOOTLOADER_FIELD_LSB (   fmask)     ((fmask) & (~(fmask) + 1u))

get LSB from field mask

Definition at line 64 of file mcci_bootloader_bits.h.

◆ MCCI_BOOTLOADER_FIELD_SET_VALUE

#define MCCI_BOOTLOADER_FIELD_SET_VALUE (   fmask,
  val 
)     (MCCI_BOOTLOADER_FIELD_LSB(fmask) * (val))

generate field value (properly positioned)

Definition at line 72 of file mcci_bootloader_bits.h.

◆ MCCI_BOOTLOADER_FIELD_SHIFT

#define MCCI_BOOTLOADER_FIELD_SHIFT (   x)    MCCI_BOOTLOADER_LOG2_POW2((x) & (~(x)+1))

get shift count from field mask.

Parameters
[in]xfield mask; bitmask should be of form 0*11*0*

We might have some 64-bit fields, so... this goes through through bit 63. We use ~(x)+1 to form the unsigned twos- complement of x without trying to negate an unsigned or doing a type-cast. Avoids warnings on some compilers. This is exactly what Knuth calls "rho" (the ruler function).

See also
Knuth V4 7.1.3.

Definition at line 61 of file mcci_bootloader_bits.h.

◆ MCCI_BOOTLOADER_LOG2_POW2

#define MCCI_BOOTLOADER_LOG2_POW2 (   x)
Value:
((x) == 0 ? -1 : \
(((x) & 0x5555555555555555u) == 0 ? 1 : 0) + \
(((x) & 0x3333333333333333u) == 0 ? 2 : 0) + \
(((x) & 0x0f0f0f0f0f0f0f0fu) == 0 ? 4 : 0) + \
(((x) & 0x00FF00FF00FF00FFu) == 0 ? 8 : 0) + \
(((x) & 0x0000FFFF0000FFFFu) == 0 ? 16 : 0) + \
(((x) & 0x00000000FFFFFFFFu) == 0 ? 32 : 0))

compute log2 of an power of 2.

This can be used at compile time or run time.

See also
Knuth V4 7.1.3 (49).

Definition at line 38 of file mcci_bootloader_bits.h.

◆ MCCI_BOOTLOADER_VALUE_GET_FIELD

#define MCCI_BOOTLOADER_VALUE_GET_FIELD (   val,
  fmask 
)     (((val) & (fmask)) >> MCCI_BOOTLOADER_FIELD_SHIFT(fmask))

extract and normalize value of field

Definition at line 76 of file mcci_bootloader_bits.h.

◆ MCCI_BOOTLOADER_VALUE_MAKE_FIELD

#define MCCI_BOOTLOADER_VALUE_MAKE_FIELD (   val,
  fmask 
)     (MCCI_BOOTLOADER_FIELD_LSB(fmask) * (val))

generate field value (properly positioned)

Definition at line 68 of file mcci_bootloader_bits.h.