1 /* 2 * Copyright (c) 2006-2023, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2023-02-25 GuEe-GUI the first version 9 */ 10 11 #ifndef __BYTEORDER__ 12 #define __BYTEORDER__ 13 14 #ifdef __CHECKER__ 15 #define __bitwise __attribute__((bitwise)) 16 #else 17 #define __bitwise 18 #endif 19 20 typedef rt_uint16_t __bitwise rt_le16_t; 21 typedef rt_uint32_t __bitwise rt_le32_t; 22 typedef rt_uint64_t __bitwise rt_le64_t; 23 typedef rt_uint16_t __bitwise rt_be16_t; 24 typedef rt_uint32_t __bitwise rt_be32_t; 25 typedef rt_uint64_t __bitwise rt_be64_t; 26 27 /* gcc defines __BIG_ENDIAN__ on big endian targets */ 28 #if defined(__BIG_ENDIAN__) || defined(ARCH_CPU_BIG_ENDIAN) 29 #define rt_cpu_to_be16(x) (x) 30 #define rt_cpu_to_be32(x) (x) 31 #define rt_cpu_to_be64(x) (x) 32 #define rt_be16_to_cpu(x) (x) 33 #define rt_be32_to_cpu(x) (x) 34 #define rt_be64_to_cpu(x) (x) 35 #define rt_le16_to_cpu(x) __builtin_bswap16(x) 36 #define rt_le32_to_cpu(x) __builtin_bswap32(x) 37 #define rt_le64_to_cpu(x) __builtin_bswap64(x) 38 #define rt_cpu_to_le16(x) __builtin_bswap16(x) 39 #define rt_cpu_to_le32(x) __builtin_bswap32(x) 40 #define rt_cpu_to_le64(x) __builtin_bswap64(x) 41 #else 42 #define rt_cpu_to_be16(x) __builtin_bswap16(x) 43 #define rt_cpu_to_be32(x) __builtin_bswap32(x) 44 #define rt_cpu_to_be64(x) __builtin_bswap64(x) 45 #define rt_be16_to_cpu(x) __builtin_bswap16(x) 46 #define rt_be32_to_cpu(x) __builtin_bswap32(x) 47 #define rt_be64_to_cpu(x) __builtin_bswap64(x) 48 #define rt_le16_to_cpu(x) (x) 49 #define rt_le32_to_cpu(x) (x) 50 #define rt_le64_to_cpu(x) (x) 51 #define rt_cpu_to_le16(x) (x) 52 #define rt_cpu_to_le32(x) (x) 53 #define rt_cpu_to_le64(x) (x) 54 #endif /* __BIG_ENDIAN__ || ARCH_CPU_BIG_ENDIAN */ 55 56 #undef __bitwise 57 58 #endif /* __BYTEORDER__ */ 59