summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReimu NotMoe <[email protected]>2023-04-17 21:02:12 +0800
committerReimu NotMoe <[email protected]>2023-04-17 21:02:12 +0800
commitfa8f3731c1b2e069dd07d30e86ea4a3af18c34dc (patch)
tree2618d3a8c8412b0b0c63828194ed81b8e28730ac
parentd97b6d57de0b2586624dec51b37ccd699a0314a6 (diff)
Implement TU_BSWAP{16,32} correctly for Microchip XC16
-rw-r--r--src/common/tusb_compiler.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/common/tusb_compiler.h b/src/common/tusb_compiler.h
index a1794584d..dce32e92b 100644
--- a/src/common/tusb_compiler.h
+++ b/src/common/tusb_compiler.h
@@ -155,8 +155,17 @@
#define TU_BYTE_ORDER TU_BIG_ENDIAN
#endif
- #define TU_BSWAP16(u16) (__builtin_bswap16(u16))
- #define TU_BSWAP32(u32) (__builtin_bswap32(u32))
+ // Unfortunately XC16 doesn't provide builtins for 32bit endian conversion
+ #if defined(__XC16)
+ #define TU_BSWAP16(u16) (__builtin_swap(u16))
+ #define TU_BSWAP32(u32) ((((u32) & 0xff000000) >> 24) | \
+ (((u32) & 0x00ff0000) >> 8) | \
+ (((u32) & 0x0000ff00) << 8) | \
+ (((u32) & 0x000000ff) << 24))
+ #else
+ #define TU_BSWAP16(u16) (__builtin_bswap16(u16))
+ #define TU_BSWAP32(u32) (__builtin_bswap32(u32))
+ #endif
#ifndef __ARMCC_VERSION
// List of obsolete callback function that is renamed and should not be defined.