11#ifndef ZEPHYR_INCLUDE_SYS_BYTEORDER_H_
12#define ZEPHYR_INCLUDE_SYS_BYTEORDER_H_
20#define __bswap_16(x) ((uint16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
21#define __bswap_24(x) ((uint32_t) ((((x) >> 16) & 0xff) | \
23 (((x) & 0xff) << 16)))
24#define __bswap_32(x) ((uint32_t) ((((x) >> 24) & 0xff) | \
25 (((x) >> 8) & 0xff00) | \
26 (((x) & 0xff00) << 8) | \
27 (((x) & 0xff) << 24)))
28#define __bswap_48(x) ((uint64_t) ((((x) >> 40) & 0xff) | \
29 (((x) >> 24) & 0xff00) | \
30 (((x) >> 8) & 0xff0000) | \
31 (((x) & 0xff0000) << 8) | \
32 (((x) & 0xff00) << 24) | \
33 (((x) & 0xff) << 40)))
34#define __bswap_64(x) ((uint64_t) ((((x) >> 56) & 0xff) | \
35 (((x) >> 40) & 0xff00) | \
36 (((x) >> 24) & 0xff0000) | \
37 (((x) >> 8) & 0xff000000) | \
38 (((x) & 0xff000000) << 8) | \
39 (((x) & 0xff0000) << 24) | \
40 (((x) & 0xff00) << 40) | \
41 (((x) & 0xff) << 56)))
214#ifdef CONFIG_LITTLE_ENDIAN
215#define sys_le16_to_cpu(val) (val)
216#define sys_cpu_to_le16(val) (val)
217#define sys_le24_to_cpu(val) (val)
218#define sys_cpu_to_le24(val) (val)
219#define sys_le32_to_cpu(val) (val)
220#define sys_cpu_to_le32(val) (val)
221#define sys_le48_to_cpu(val) (val)
222#define sys_cpu_to_le48(val) (val)
223#define sys_le64_to_cpu(val) (val)
224#define sys_cpu_to_le64(val) (val)
225#define sys_be16_to_cpu(val) __bswap_16(val)
226#define sys_cpu_to_be16(val) __bswap_16(val)
227#define sys_be24_to_cpu(val) __bswap_24(val)
228#define sys_cpu_to_be24(val) __bswap_24(val)
229#define sys_be32_to_cpu(val) __bswap_32(val)
230#define sys_cpu_to_be32(val) __bswap_32(val)
231#define sys_be48_to_cpu(val) __bswap_48(val)
232#define sys_cpu_to_be48(val) __bswap_48(val)
233#define sys_be64_to_cpu(val) __bswap_64(val)
234#define sys_cpu_to_be64(val) __bswap_64(val)
236#define sys_uint16_to_array(val) { \
238 (((val) >> 8) & 0xff)}
240#define sys_uint32_to_array(val) { \
242 (((val) >> 8) & 0xff), \
243 (((val) >> 16) & 0xff), \
244 (((val) >> 24) & 0xff)}
246#define sys_uint64_to_array(val) { \
248 (((val) >> 8) & 0xff), \
249 (((val) >> 16) & 0xff), \
250 (((val) >> 24) & 0xff), \
251 (((val) >> 32) & 0xff), \
252 (((val) >> 40) & 0xff), \
253 (((val) >> 48) & 0xff), \
254 (((val) >> 56) & 0xff)}
257#define sys_le16_to_cpu(val) __bswap_16(val)
258#define sys_cpu_to_le16(val) __bswap_16(val)
259#define sys_le24_to_cpu(val) __bswap_24(val)
260#define sys_cpu_to_le24(val) __bswap_24(val)
261#define sys_le32_to_cpu(val) __bswap_32(val)
262#define sys_cpu_to_le32(val) __bswap_32(val)
263#define sys_le48_to_cpu(val) __bswap_48(val)
264#define sys_cpu_to_le48(val) __bswap_48(val)
265#define sys_le64_to_cpu(val) __bswap_64(val)
266#define sys_cpu_to_le64(val) __bswap_64(val)
267#define sys_be16_to_cpu(val) (val)
268#define sys_cpu_to_be16(val) (val)
269#define sys_be24_to_cpu(val) (val)
270#define sys_cpu_to_be24(val) (val)
271#define sys_be32_to_cpu(val) (val)
272#define sys_cpu_to_be32(val) (val)
273#define sys_be48_to_cpu(val) (val)
274#define sys_cpu_to_be48(val) (val)
275#define sys_be64_to_cpu(val) (val)
276#define sys_cpu_to_be64(val) (val)
278#define sys_uint16_to_array(val) { \
279 (((val) >> 8) & 0xff), \
282#define sys_uint32_to_array(val) { \
283 (((val) >> 24) & 0xff), \
284 (((val) >> 16) & 0xff), \
285 (((val) >> 8) & 0xff), \
288#define sys_uint64_to_array(val) { \
289 (((val) >> 56) & 0xff), \
290 (((val) >> 48) & 0xff), \
291 (((val) >> 40) & 0xff), \
292 (((val) >> 32) & 0xff), \
293 (((val) >> 24) & 0xff), \
294 (((val) >> 16) & 0xff), \
295 (((val) >> 8) & 0xff), \
462 return ((
uint16_t)src[0] << 8) | src[1];
537 return ((
uint16_t)src[1] << 8) | src[0];
618 __ASSERT(((psrc < pdst && (psrc + length) <= pdst) ||
619 (psrc > pdst && (pdst + length) <= psrc)),
620 "Source and destination buffers must not overlap");
624 for (; length > 0; length--) {
643 for (i = 0; i < (length/2); i++) {
647 ((
uint8_t *)buf)[length - 1 - i] = tmp;
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT64_TYPE__ uint64_t
Definition: stdint.h:91
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
static void sys_memcpy_swap(void *dst, const void *src, size_t length)
Swap one buffer content into another.
Definition: byteorder.h:613
static void sys_put_le24(uint32_t val, uint8_t dst[3])
Put a 24-bit integer as little-endian to arbitrary location.
Definition: byteorder.h:399
static void sys_put_be32(uint32_t val, uint8_t dst[4])
Put a 32-bit integer as big-endian to arbitrary location.
Definition: byteorder.h:339
static void sys_put_be64(uint64_t val, uint8_t dst[8])
Put a 64-bit integer as big-endian to arbitrary location.
Definition: byteorder.h:369
static uint32_t sys_get_be32(const uint8_t src[4])
Get a 32-bit integer stored in big-endian format.
Definition: byteorder.h:490
static uint16_t sys_get_le16(const uint8_t src[2])
Get a 16-bit integer stored in little-endian format.
Definition: byteorder.h:535
static uint64_t sys_get_le48(const uint8_t src[6])
Get a 48-bit integer stored in little-endian format.
Definition: byteorder.h:580
static uint64_t sys_get_le64(const uint8_t src[8])
Get a 64-bit integer stored in little-endian format.
Definition: byteorder.h:595
static void sys_put_be16(uint16_t val, uint8_t dst[2])
Put a 16-bit integer as big-endian to arbitrary location.
Definition: byteorder.h:309
static void sys_put_be24(uint32_t val, uint8_t dst[3])
Put a 24-bit integer as big-endian to arbitrary location.
Definition: byteorder.h:324
static void sys_put_le64(uint64_t val, uint8_t dst[8])
Put a 64-bit integer as little-endian to arbitrary location.
Definition: byteorder.h:444
static uint16_t sys_get_be16(const uint8_t src[2])
Get a 16-bit integer stored in big-endian format.
Definition: byteorder.h:460
static void sys_put_le48(uint64_t val, uint8_t dst[6])
Put a 48-bit integer as little-endian to arbitrary location.
Definition: byteorder.h:429
static uint32_t sys_get_le32(const uint8_t src[4])
Get a 32-bit integer stored in little-endian format.
Definition: byteorder.h:565
static uint32_t sys_get_le24(const uint8_t src[3])
Get a 24-bit integer stored in little-endian format.
Definition: byteorder.h:550
static void sys_put_be48(uint64_t val, uint8_t dst[6])
Put a 48-bit integer as big-endian to arbitrary location.
Definition: byteorder.h:354
static uint32_t sys_get_be24(const uint8_t src[3])
Get a 24-bit integer stored in big-endian format.
Definition: byteorder.h:475
static uint64_t sys_get_be48(const uint8_t src[6])
Get a 48-bit integer stored in big-endian format.
Definition: byteorder.h:505
static uint64_t sys_get_be64(const uint8_t src[8])
Get a 64-bit integer stored in big-endian format.
Definition: byteorder.h:520
static void sys_mem_swap(void *buf, size_t length)
Swap buffer content.
Definition: byteorder.h:639
static void sys_put_le16(uint16_t val, uint8_t dst[2])
Put a 16-bit integer as little-endian to arbitrary location.
Definition: byteorder.h:384
static void sys_put_le32(uint32_t val, uint8_t dst[4])
Put a 32-bit integer as little-endian to arbitrary location.
Definition: byteorder.h:414