Skip to content

Commit 9771c76

Browse files
authored
Merge pull request hathach#2033 from ReimuNotMoe/master
Fix compatibility with the latest Microchip XC16 compiler
2 parents c3a60ed + c067414 commit 9771c76

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/common/tusb_compiler.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,14 @@
138138
#define TU_ATTR_BIT_FIELD_ORDER_BEGIN
139139
#define TU_ATTR_BIT_FIELD_ORDER_END
140140

141-
#if __has_attribute(__fallthrough__)
142-
#define TU_ATTR_FALLTHROUGH __attribute__((fallthrough))
143-
#else
141+
#if __GNUC__ < 5
144142
#define TU_ATTR_FALLTHROUGH do {} while (0) /* fallthrough */
143+
#else
144+
#if __has_attribute(__fallthrough__)
145+
#define TU_ATTR_FALLTHROUGH __attribute__((fallthrough))
146+
#else
147+
#define TU_ATTR_FALLTHROUGH do {} while (0) /* fallthrough */
148+
#endif
145149
#endif
146150

147151
// Endian conversion use well-known host to network (big endian) naming
@@ -151,8 +155,17 @@
151155
#define TU_BYTE_ORDER TU_BIG_ENDIAN
152156
#endif
153157

154-
#define TU_BSWAP16(u16) (__builtin_bswap16(u16))
155-
#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
156169

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

0 commit comments

Comments
 (0)