Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
freertos/endian.h
Go to the documentation of this file.
1
34#ifndef _endian_h_
35#define _endian_h_
36
37#include <stdint.h>
38
43static inline uint16_t __bswap_16(uint16_t x)
44{
45 return (((x & 0xff00) >> 8) | ((x & 0x00ff) << 8));
46}
47
52static inline uint32_t __bswap_32(uint32_t x)
53{
54 return (((x & 0xff000000) >> 24) | ((x & 0x00ff0000) >> 8) |
55 ((x & 0x0000ff00) << 8) | ((x & 0x000000ff) << 24));
56}
57
62static inline uint64_t __bswap_64(uint64_t x)
63{
64 return (((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));
72}
73
74#ifdef CONFIG_ENDIAN_BIG
75 #define htobe16(x) (x)
76 #define htole16(x) __bswap_16 (x)
77 #define be16toh(x) (x)
78 #define le16toh(x) __bswap_16 (x)
79
80 #define htobe32(x) (x)
81 #define htole32(x) __bswap_32 (x)
82 #define be32toh(x) (x)
83 #define le32toh(x) __bswap_32 (x)
84
85 #define htobe64(x) (x)
86 #define htole64(x) __bswap_64 (x)
87 #define be64toh(x) (x)
88 #define le64toh(x) __bswap_64 (x)
89#else
91 #define htobe16(x) __bswap_16 (x)
93 #define htole16(x) (x)
95 #define be16toh(x) __bswap_16 (x)
97 #define le16toh(x) (x)
98
100 #define htobe32(x) __bswap_32 (x)
102 #define htole32(x) (x)
104 #define be32toh(x) __bswap_32 (x)
106 #define le32toh(x) (x)
107
109 #define htobe64(x) __bswap_64 (x)
111 #define htole64(x) (x)
113 #define be64toh(x) __bswap_64 (x)
115 #define le64toh(x) (x)
116#endif
117
118#endif /* _endian_h_ */
119
static uint64_t __bswap_64(uint64_t x)
Byte swap a 64 bit value.
static uint16_t __bswap_16(uint16_t x)
Byte swap a 16 bit value.
static uint32_t __bswap_32(uint32_t x)
Byte swap a 32 bit value.