Skip to content

Commit fa8f373

Browse files
committed
Implement TU_BSWAP{16,32} correctly for Microchip XC16
1 parent d97b6d5 commit fa8f373

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/common/tusb_compiler.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,17 @@
155155
#define TU_BYTE_ORDER TU_BIG_ENDIAN
156156
#endif
157157

158-
#define TU_BSWAP16(u16) (__builtin_bswap16(u16))
159-
#define TU_BSWAP32(u32) (__builtin_bswap32(u32))
158+
// Unfortunately XC16 doesn't provide builtins for 32bit endian conversion
159+
#if defined(__XC16)
160+
#define TU_BSWAP16(u16) (__builtin_swap(u16))
161+
#define TU_BSWAP32(u32) ((((u32) & 0xff000000) >> 24) | \
162+
(((u32) & 0x00ff0000) >> 8) | \
163+
(((u32) & 0x0000ff00) << 8) | \
164+
(((u32) & 0x000000ff) << 24))
165+
#else
166+
#define TU_BSWAP16(u16) (__builtin_bswap16(u16))
167+
#define TU_BSWAP32(u32) (__builtin_bswap32(u32))
168+
#endif
160169

161170
#ifndef __ARMCC_VERSION
162171
// List of obsolete callback function that is renamed and should not be defined.

0 commit comments

Comments
 (0)