External Code Interface (ECI)
 All Data Structures Files Functions Variables Typedefs Groups Pages
Macros
ECI Utility Macros

Macros

#define D2STR(x)   #x
 
#define SIZEOF_ARRAY(ar)   (sizeof(ar)/sizeof(ar[0]))
 
#define SIZEOF_MEMBER(memberOf, member)   sizeof(((memberOf*)0)->member)
 
#define SIZEOF_ARRAY_MEMBER(memberOf, member)   (sizeof(((memberOf*)0)->member)/sizeof(((memberOf*)0)->member[0]))
 
#define BSWAP_16(x)
 
#define BSWAP_32(x)
 
#define BSWAP_64(x)
 
#define HEX__(n)   0x##n##LU
 
#define B8__(x)
 
#define B8(d)   ((uint8_t)B8__(HEX__(d)))
 
#define B16(dmsb, dlsb)
 
#define B32(dmsb, db2, db3, dlsb)
 

Detailed Description

Various utility macros.

Macro Definition Documentation

#define B16 (   dmsb,
  dlsb 
)
Value:
(((uint16_t)B8(dmsb)<< \
+ B8(dlsb))
#define B8(d)
Definition: eci_util_macro.h:109

For up to 16-bit binary constants, MSB first.

#define B32 (   dmsb,
  db2,
  db3,
  dlsb 
)
Value:
(((uint32_t)B8(dmsb) << 24) \
+ ((uint32_t)B8(db2) << 16) \
+ ((uint32_t)B8(db3) << \
+ B8(dlsb))
#define B8(d)
Definition: eci_util_macro.h:109

For up to 32-bit binary constants, MSB first.

#define B8 (   d)    ((uint8_t)B8__(HEX__(d)))

For up to 8-bit binary constants.

#define B8__ (   x)
Value:
((x&0x0000000FLU)?1:0) \
+ ((x&0x000000F0LU)?2:0) \
+ ((x&0x00000F00LU)?4:0) \
+ ((x&0x0000F000LU)?8:0) \
+ ((x&0x000F0000LU)?16:0) \
+ ((x&0x00F00000LU)?32:0) \
+ ((x&0x0F000000LU)?64:0) \
+ ((x&0xF0000000LU)?128:0)

8-bit Conversion Function

#define BSWAP_16 (   x)
Value:
(((uint16_t)(x) << 8) | \
((uint16_t)(x) >> 8))

Swaps the low and high bytes of a 16 bit value

Parameters
x16 bit value to swap
Returns
a byte swapped x
#define BSWAP_32 (   x)
Value:
(((uint32_t)(x) << 24) | \
(((uint32_t)(x) << 8) & 0xff0000) | \
(((uint32_t)(x) >> 8) & 0xff00) | \
((uint32_t)(x) >> 24))

Swaps the 2 lowest and 2 highest bytes of a 32 bit value

Parameters
x32 bit value to swap
Returns
a byte swapped x
#define BSWAP_64 (   x)
Value:
(((uint64_t)(x) << 56) | \
(((uint64_t)(x) << 40) & 0xff000000000000ULL) | \
(((uint64_t)(x) << 24) & 0xff0000000000ULL) | \
(((uint64_t)(x) << 8) & 0xff00000000ULL) | \
(((uint64_t)(x) >> 8) & 0xff000000ULL) | \
(((uint64_t)(x) >> 24) & 0xff0000ULL) | \
(((uint64_t)(x) >> 40) & 0xff00ULL) | \
((uint64_t)(x) >> 56))

Swap the 4 lowest and 4 highest bytes of a 64 bit value

Parameters
x64 bit value to swap
Returns
a byte swapped x
#define D2STR (   x)    #x

Converts Define or Enum to string.

Parameters
xvalue to be stringified by the preprocessor
Returns
string representation of x
#define HEX__ (   n)    0x##n##LU

Turn a numeric literal into a hex constant. This avoids problems with leading zeroes. 8-bit constants have a max value of 0x11111111, which always fits in an unsigned long

Parameters
nliteral to be converted
Returns
hex representation of n
#define SIZEOF_ARRAY (   ar)    (sizeof(ar)/sizeof(ar[0]))

Returns the number of elements in the array. This uses sizeof(ar[0]) to determine the size which means the array must contain at least one element (should be null)

Parameters
ararray to calculate size of
Returns
size of the array
#define SIZEOF_ARRAY_MEMBER (   memberOf,
  member 
)    (sizeof(((memberOf*)0)->member)/sizeof(((memberOf*)0)->member[0]))

Returns the number of elements of an array for a member of a structure.

Parameters
memberOfstruct which contains the member
memberarray to calculate the size of
Returns
size of the struct array
#define SIZEOF_MEMBER (   memberOf,
  member 
)    sizeof(((memberOf*)0)->member)

Returns the number of bytes for the member of the structure.

Parameters
memberOfstruct which contains the member
membername of the member to calculate
Returns
size of the struct member