External Code Interface (ECI)
 All Data Structures Files Functions Variables Typedefs Groups Pages
eci_util_macro.h
Go to the documentation of this file.
1 
6 #ifndef ECI_UTIL_MACRO_H
7 #define ECI_UTIL_MACRO_H
8 
20 #define D2STR(x) #x
21 
31 #define SIZEOF_ARRAY(ar) (sizeof(ar)/sizeof(ar[0]))
32 
39 #define SIZEOF_MEMBER(memberOf, member) sizeof(((memberOf*)0)->member)
40 
47 #define SIZEOF_ARRAY_MEMBER(memberOf, member) (sizeof(((memberOf*)0)->member)/sizeof(((memberOf*)0)->member[0]))
48 
54 #define BSWAP_16(x) (((uint16_t)(x) << 8) | \
55  ((uint16_t)(x) >> 8))
56 
62 #define BSWAP_32(x) (((uint32_t)(x) << 24) | \
63  (((uint32_t)(x) << 8) & 0xff0000) | \
64  (((uint32_t)(x) >> 8) & 0xff00) | \
65  ((uint32_t)(x) >> 24))
66 
71 #define BSWAP_64(x) (((uint64_t)(x) << 56) | \
72  (((uint64_t)(x) << 40) & 0xff000000000000ULL) | \
73  (((uint64_t)(x) << 24) & 0xff0000000000ULL) | \
74  (((uint64_t)(x) << 8) & 0xff00000000ULL) | \
75  (((uint64_t)(x) >> 8) & 0xff000000ULL) | \
76  (((uint64_t)(x) >> 24) & 0xff0000ULL) | \
77  (((uint64_t)(x) >> 40) & 0xff00ULL) | \
78  ((uint64_t)(x) >> 56))
79 
80 /*
81  * Binary Constant Generator Macros
82  * By Tom Torfs - donated to the public domain
83  *
84  * All macro's evaluate to compile-time constants.
85  */
86 
94 #define HEX__(n) 0x##n##LU
95 
99 #define B8__(x) ((x&0x0000000FLU)?1:0) \
100  + ((x&0x000000F0LU)?2:0) \
101  + ((x&0x00000F00LU)?4:0) \
102  + ((x&0x0000F000LU)?8:0) \
103  + ((x&0x000F0000LU)?16:0) \
104  + ((x&0x00F00000LU)?32:0) \
105  + ((x&0x0F000000LU)?64:0) \
106  + ((x&0xF0000000LU)?128:0)
107 
109 #define B8(d) ((uint8_t)B8__(HEX__(d)))
110 
112 #define B16(dmsb, dlsb) (((uint16_t)B8(dmsb)<< \
113  + B8(dlsb))
114 
116 #define B32(dmsb, db2, db3, dlsb) (((uint32_t)B8(dmsb) << 24) \
117  + ((uint32_t)B8(db2) << 16) \
118  + ((uint32_t)B8(db3) << \
119  + B8(dlsb))
120 
122 #endif /* ECI_UTIL_MACRO_H */