Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
nuttx/endian.h
Go to the documentation of this file.
1
34#include <stdint.h>
35
40static inline uint16_t __bswap_16(uint16_t x)
41{
42 return (((x & 0xff00) >> 8) | ((x & 0x00ff) << 8));
43}
44
49static inline uint32_t __bswap_32(uint32_t x)
50{
51 return (((x & 0xff000000) >> 24) | ((x & 0x00ff0000) >> 8) |
52 ((x & 0x0000ff00) << 8) | ((x & 0x000000ff) << 24));
53}
54
59static inline uint64_t __bswap_64(uint64_t x)
60{
61 return (((x & 0xff00000000000000ULL) >> 56) |
62 ((x & 0x00ff000000000000ULL) >> 40) |
63 ((x & 0x0000ff0000000000ULL) >> 24) |
64 ((x & 0x000000ff00000000ULL) >> 8) |
65 ((x & 0x00000000ff000000ULL) << 8) |
66 ((x & 0x0000000000ff0000ULL) << 24) |
67 ((x & 0x000000000000ff00ULL) << 40) |
68 ((x & 0x00000000000000ffULL) << 56));
69}
70
71#ifdef CONFIG_ENDIAN_BIG
72 #define htobe16(x) (x)
73 #define htole16(x) __bswap_16 (x)
74 #define be16toh(x) (x)
75 #define le16toh(x) __bswap_16 (x)
76
77 #define htobe32(x) (x)
78 #define htole32(x) __bswap_32 (x)
79 #define be32toh(x) (x)
80 #define le32toh(x) __bswap_32 (x)
81
82 #define htobe64(x) (x)
83 #define htole64(x) __bswap_64 (x)
84 #define be64toh(x) (x)
85 #define le64toh(x) __bswap_64 (x)
86#else
88 #define htobe16(x) __bswap_16 (x)
90 #define htole16(x) (x)
92 #define be16toh(x) __bswap_16 (x)
94 #define le16toh(x) (x)
95
97 #define htobe32(x) __bswap_32 (x)
99 #define htole32(x) (x)
101 #define be32toh(x) __bswap_32 (x)
103 #define le32toh(x) (x)
104
106 #define htobe64(x) __bswap_64 (x)
108 #define htole64(x) (x)
110 #define be64toh(x) __bswap_64 (x)
112 #define le64toh(x) (x)
113#endif
114
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.