39 #define ECU_SWAP16_COMPILETIME(x_) \
40 ((uint16_t)((((x_) & 0xFF00) >> 8) | \
41 (((x_) & 0x00FF) << 8)))
50 #define ECU_SWAP32_COMPILETIME(x_) \
51 ((uint32_t)((((x_) & 0xFF000000UL) >> 24) | \
52 (((x_) & 0x00FF0000UL) >> 8) | \
53 (((x_) & 0x0000FF00UL) << 8) | \
54 (((x_) & 0x000000FFUL) << 24)))
63 #define ECU_SWAP64_COMPILETIME(x_) \
64 ((uint64_t)((((x_) & 0xFF00000000000000ULL) >> 56) | \
65 (((x_) & 0x00FF000000000000ULL) >> 40) | \
66 (((x_) & 0x0000FF0000000000ULL) >> 24) | \
67 (((x_) & 0x000000FF00000000ULL) >> 8) | \
68 (((x_) & 0x00000000FF000000ULL) << 8) | \
69 (((x_) & 0x0000000000FF0000ULL) << 24) | \
70 (((x_) & 0x000000000000FF00ULL) << 40) | \
71 (((x_) & 0x00000000000000FFULL) << 56)))
98 return (((val & 0xFF00) >> 8) | ((val & 0x00FF) << 8));
112 return (((val & (uint_fast32_t)0xFF000000) >> 24) |
113 ((val & (uint_fast32_t)0x00FF0000) >> 8) |
114 ((val & (uint_fast32_t)0x0000FF00) << 8) |
115 ((val & (uint_fast32_t)0x000000FF) << 24));
129 return (((val & (uint_fast64_t)0xFF00000000000000) >> 56) |
130 ((val & (uint_fast64_t)0x00FF000000000000) >> 40) |
131 ((val & (uint_fast64_t)0x0000FF0000000000) >> 24) |
132 ((val & (uint_fast64_t)0x000000FF00000000) >> 8) |
133 ((val & (uint_fast64_t)0x00000000FF000000) << 8) |
134 ((val & (uint_fast64_t)0x0000000000FF0000) << 24) |
135 ((val & (uint_fast64_t)0x000000000000FF00) << 40) |
136 ((val & (uint_fast64_t)0x00000000000000FF) << 56));
148 #if defined(ECU_DOXYGEN)
158 #define ECU_BE16_TO_CPU_COMPILETIME(x_)
159 #define ECU_BE32_TO_CPU_COMPILETIME(x_)
160 #define ECU_BE64_TO_CPU_COMPILETIME(x_)
167 #define ECU_BE32_TO_CPU_RUNTIME(x_)
168 #define ECU_BE64_TO_CPU_RUNTIME(x_)
169 #define ECU_BE16_TO_CPU_RUNTIME(x_)
181 #define ECU_LE16_TO_CPU_COMPILETIME(x_)
182 #define ECU_LE32_TO_CPU_COMPILETIME(x_)
183 #define ECU_LE64_TO_CPU_COMPILETIME(x_)
190 #define ECU_LE16_TO_CPU_RUNTIME(x_)
191 #define ECU_LE32_TO_CPU_RUNTIME(x_)
192 #define ECU_LE64_TO_CPU_RUNTIME(x_)
204 #define ECU_CPU_TO_BE16_COMPILETIME(x_)
205 #define ECU_CPU_TO_BE32_COMPILETIME(x_)
206 #define ECU_CPU_TO_BE64_COMPILETIME(x_)
213 #define ECU_CPU_TO_BE16_RUNTIME(x_)
214 #define ECU_CPU_TO_BE32_RUNTIME(x_)
215 #define ECU_CPU_TO_BE64_RUNTIME(x_)
227 #define ECU_CPU_TO_LE16_COMPILETIME(x_)
228 #define ECU_CPU_TO_LE32_COMPILETIME(x_)
229 #define ECU_CPU_TO_LE64_COMPILETIME(x_)
236 #define ECU_CPU_TO_LE16_RUNTIME(x_)
237 #define ECU_CPU_TO_LE32_RUNTIME(x_)
238 #define ECU_CPU_TO_LE64_RUNTIME(x_)
241 #if defined(ECU_LITTLE_ENDIAN)
242 #define ECU_BE16_TO_CPU_COMPILETIME(x_) ECU_SWAP16_COMPILETIME(x_)
243 #define ECU_BE32_TO_CPU_COMPILETIME(x_) ECU_SWAP32_COMPILETIME(x_)
244 #define ECU_BE64_TO_CPU_COMPILETIME(x_) ECU_SWAP64_COMPILETIME(x_)
245 #define ECU_BE16_TO_CPU_RUNTIME(x_) ecu_swap16_runtime(x_)
246 #define ECU_BE32_TO_CPU_RUNTIME(x_) ecu_swap32_runtime(x_)
247 #define ECU_BE64_TO_CPU_RUNTIME(x_) ecu_swap64_runtime(x_)
249 #define ECU_LE16_TO_CPU_COMPILETIME(x_) (x_)
250 #define ECU_LE32_TO_CPU_COMPILETIME(x_) (x_)
251 #define ECU_LE64_TO_CPU_COMPILETIME(x_) (x_)
252 #define ECU_LE16_TO_CPU_RUNTIME(x_) (x_)
253 #define ECU_LE32_TO_CPU_RUNTIME(x_) (x_)
254 #define ECU_LE64_TO_CPU_RUNTIME(x_) (x_)
256 #define ECU_CPU_TO_BE16_COMPILETIME(x_) ECU_SWAP16_COMPILETIME(x_)
257 #define ECU_CPU_TO_BE32_COMPILETIME(x_) ECU_SWAP32_COMPILETIME(x_)
258 #define ECU_CPU_TO_BE64_COMPILETIME(x_) ECU_SWAP64_COMPILETIME(x_)
259 #define ECU_CPU_TO_BE16_RUNTIME(x_) ecu_swap16_runtime(x_)
260 #define ECU_CPU_TO_BE32_RUNTIME(x_) ecu_swap32_runtime(x_)
261 #define ECU_CPU_TO_BE64_RUNTIME(x_) ecu_swap64_runtime(x_)
263 #define ECU_CPU_TO_LE16_COMPILETIME(x_) (x_)
264 #define ECU_CPU_TO_LE32_COMPILETIME(x_) (x_)
265 #define ECU_CPU_TO_LE64_COMPILETIME(x_) (x_)
266 #define ECU_CPU_TO_LE16_RUNTIME(x_) (x_)
267 #define ECU_CPU_TO_LE32_RUNTIME(x_) (x_)
268 #define ECU_CPU_TO_LE64_RUNTIME(x_) (x_)
269 #elif defined(ECU_BIG_ENDIAN)
270 #define ECU_BE16_TO_CPU_COMPILETIME(x_) (x_)
271 #define ECU_BE32_TO_CPU_COMPILETIME(x_) (x_)
272 #define ECU_BE64_TO_CPU_COMPILETIME(x_) (x_)
273 #define ECU_BE16_TO_CPU_RUNTIME(x_) (x_)
274 #define ECU_BE32_TO_CPU_RUNTIME(x_) (x_)
275 #define ECU_BE64_TO_CPU_RUNTIME(x_) (x_)
277 #define ECU_LE16_TO_CPU_COMPILETIME(x_) ECU_SWAP16_COMPILETIME(x_)
278 #define ECU_LE32_TO_CPU_COMPILETIME(x_) ECU_SWAP32_COMPILETIME(x_)
279 #define ECU_LE64_TO_CPU_COMPILETIME(x_) ECU_SWAP64_COMPILETIME(x_)
280 #define ECU_LE16_TO_CPU_RUNTIME(x_) ecu_swap16_runtime(x_)
281 #define ECU_LE32_TO_CPU_RUNTIME(x_) ecu_swap32_runtime(x_)
282 #define ECU_LE64_TO_CPU_RUNTIME(x_) ecu_swap64_runtime(x_)
284 #define ECU_CPU_TO_BE16_COMPILETIME(x_) (x_)
285 #define ECU_CPU_TO_BE32_COMPILETIME(x_) (x_)
286 #define ECU_CPU_TO_BE64_COMPILETIME(x_) (x_)
287 #define ECU_CPU_TO_BE16_RUNTIME(x_) (x_)
288 #define ECU_CPU_TO_BE32_RUNTIME(x_) (x_)
289 #define ECU_CPU_TO_BE64_RUNTIME(x_) (x_)
291 #define ECU_CPU_TO_LE16_COMPILETIME(x_) ECU_SWAP16_COMPILETIME(x_)
292 #define ECU_CPU_TO_LE32_COMPILETIME(x_) ECU_SWAP32_COMPILETIME(x_)
293 #define ECU_CPU_TO_LE64_COMPILETIME(x_) ECU_SWAP64_COMPILETIME(x_)
294 #define ECU_CPU_TO_LE16_RUNTIME(x_) ecu_swap16_runtime(x_)
295 #define ECU_CPU_TO_LE32_RUNTIME(x_) ecu_swap32_runtime(x_)
296 #define ECU_CPU_TO_LE64_RUNTIME(x_) ecu_swap64_runtime(x_)
299 #error "CMake build system unable to detect target endianness from CMAKE_C_BYTE_ORDER variable. "
300 "Manually define ECU_LITTLE_ENDIAN or ECU_BIG_ENDIAN to use this module."
static uint64_t ecu_swap64_runtime(uint_fast64_t val)
Returns byte-swapped value (switches endianness) of 64-bit input at runtime. Can handle signed inputs...
Definition: endian.h:124
static uint16_t ecu_swap16_runtime(uint_fast16_t val)
Returns byte-swapped value (switches endianness) of 16-bit input at runtime. Can handle signed inputs...
Definition: endian.h:92
static uint32_t ecu_swap32_runtime(uint_fast32_t val)
Returns byte-swapped value (switches endianness) of 32-bit input at runtime. Can handle signed inputs...
Definition: endian.h:107