45 #ifndef CA821X_API_INCLUDE_CA821X_ENDIAN_H_
46 #define CA821X_API_INCLUDE_CA821X_ENDIAN_H_
59 return ((uint8_t)((x)&0xFF));
67 return ((uint8_t)(((x) >> 8) & 0xFF));
75 return ((uint8_t)((x)&0xFF));
83 return ((uint8_t)(((x) >> 8) & 0xFF));
91 return ((uint8_t)(((x) >> 16) & 0xFF));
99 return ((uint8_t)(((x) >> 24) & 0xFF));
105 STATIC
inline uint16_t
GETLE16(
const uint8_t *in)
107 return ((in[1] << 8) & 0xff00) | (in[0] & 0x00ff);
113 STATIC
inline uint32_t
GETLE32(
const uint8_t *in)
115 return (((uint32_t)in[3] << 24) + ((uint32_t)in[2] << 16) + ((uint32_t)in[1] << 8) + (uint32_t)in[0]);
121 STATIC
inline uint64_t
GETLE64(
const uint8_t *in)
123 return (((uint64_t)in[7] << 56) + ((uint64_t)in[6] << 48) + ((uint64_t)in[5] << 40) + ((uint64_t)in[4] << 32) +
124 ((uint64_t)in[3] << 24) + ((uint64_t)in[2] << 16) + ((uint64_t)in[1] << 8) + (uint64_t)in[0]);
130 STATIC
inline void PUTLE16(uint16_t in, uint8_t *out)
133 out[1] = (in >> 8) & 0xff;
139 STATIC
inline void PUTLE32(uint32_t in, uint8_t *out)
142 out[1] = (in >> 8) & 0xff;
143 out[2] = (in >> 16) & 0xff;
144 out[3] = (in >> 24) & 0xff;
150 STATIC
inline void PUTLE64(uint64_t in, uint8_t *out)
153 out[1] = (in >> 8) & 0xff;
154 out[2] = (in >> 16) & 0xff;
155 out[3] = (in >> 24) & 0xff;
156 out[4] = (in >> 32) & 0xff;
157 out[5] = (in >> 40) & 0xff;
158 out[6] = (in >> 48) & 0xff;
159 out[7] = (in >> 56) & 0xff;
165 STATIC
inline uint16_t
GETBE16(
const uint8_t *in)
167 return ((in[0] << 8) & 0xff00) | (in[1] & 0x00ff);
173 STATIC
inline void PUTBE16(uint16_t in, uint8_t *out)
176 out[0] = (in >> 8) & 0xff;
182 STATIC
inline uint32_t
GETBE32(
const uint8_t *in)
184 return (((uint32_t)in[0] << 24) + ((uint32_t)in[1] << 16) + ((uint32_t)in[2] << 8) + (uint32_t)in[3]);
190 STATIC
inline uint64_t
GETBE64(
const uint8_t *in)
192 return (((uint64_t)in[0] << 56) + ((uint64_t)in[1] << 48) + ((uint64_t)in[2] << 40) + ((uint64_t)in[3] << 32) +
193 ((uint64_t)in[4] << 24) + ((uint64_t)in[5] << 16) + ((uint64_t)in[6] << 8) + (uint64_t)in[7]);
199 STATIC
inline void PUTBE32(uint32_t in, uint8_t *out)
202 out[2] = (in >> 8) & 0xff;
203 out[1] = (in >> 16) & 0xff;
204 out[0] = (in >> 24) & 0xff;
210 STATIC
inline void PUTBE64(uint64_t in, uint8_t *out)
213 out[6] = (in >> 8) & 0xff;
214 out[5] = (in >> 16) & 0xff;
215 out[4] = (in >> 24) & 0xff;
216 out[3] = (in >> 32) & 0xff;
217 out[2] = (in >> 40) & 0xff;
218 out[1] = (in >> 48) & 0xff;
219 out[0] = (in >> 56) & 0xff;
STATIC void PUTBE16(uint16_t in, uint8_t *out)
Put a 16-bit value into a big-endian octet array.
Definition: ca821x_endian.h:173
STATIC uint64_t GETLE64(const uint8_t *in)
Extract a 64-bit value from a little-endian octet array.
Definition: ca821x_endian.h:121
STATIC uint32_t GETBE32(const uint8_t *in)
Extract a 32-bit value from a big-endian octet array.
Definition: ca821x_endian.h:182
STATIC uint64_t GETBE64(const uint8_t *in)
Extract a 64-bit value from a big-endian octet array.
Definition: ca821x_endian.h:190
STATIC uint8_t MS_BYTE(uint16_t x)
Extract the most significant octet of a 16-bit value.
Definition: ca821x_endian.h:65
STATIC uint16_t GETLE16(const uint8_t *in)
Extract a 16-bit value from a little-endian octet array.
Definition: ca821x_endian.h:105
STATIC void PUTBE64(uint64_t in, uint8_t *out)
Put a 64-bit value into a little-endian octet array.
Definition: ca821x_endian.h:210
STATIC uint32_t GETLE32(const uint8_t *in)
Extract a 32-bit value from a little-endian octet array.
Definition: ca821x_endian.h:113
STATIC uint8_t LS3_BYTE(uint32_t x)
Extract the fourth (little-endian) octet of a 32-bit value.
Definition: ca821x_endian.h:97
STATIC uint8_t LS1_BYTE(uint32_t x)
Extract the second (little-endian) octet of a 32-bit value.
Definition: ca821x_endian.h:81
STATIC uint8_t LS_BYTE(uint16_t x)
Extract the least significant octet of a 16-bit value.
Definition: ca821x_endian.h:57
STATIC void PUTLE16(uint16_t in, uint8_t *out)
Put a 16-bit value into a little-endian octet array.
Definition: ca821x_endian.h:130
STATIC uint8_t LS0_BYTE(uint16_t x)
Extract the first (little-endian) octet of a 32-bit value.
Definition: ca821x_endian.h:73
STATIC uint8_t LS2_BYTE(uint32_t x)
Extract the third (little-endian) octet of a 32-bit value.
Definition: ca821x_endian.h:89
STATIC void PUTBE32(uint32_t in, uint8_t *out)
Put a 32-bit value into a big-endian octet array.
Definition: ca821x_endian.h:199
STATIC uint16_t GETBE16(const uint8_t *in)
Extract a 16-bit value from a big-endian octet array.
Definition: ca821x_endian.h:165
STATIC void PUTLE64(uint64_t in, uint8_t *out)
Put a 64-bit value into a little-endian octet array.
Definition: ca821x_endian.h:150
STATIC void PUTLE32(uint32_t in, uint8_t *out)
Put a 32-bit value into a little-endian octet array.
Definition: ca821x_endian.h:139