mikroSDK Reference Manual
compiler_port.h
Go to the documentation of this file.
1
29#ifndef _COMPILER_PORT_H
30#define _COMPILER_PORT_H
31
32//Dependencies
33#include <stddef.h>
34#include <stdint.h>
35#include <inttypes.h>
36
37//ARM compiler V6?
38#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
39 #include <stdarg.h>
40#endif
41
42//C++ guard
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47//Types
48typedef char char_t;
49typedef signed int int_t;
50typedef unsigned int uint_t;
51
52#if !defined(R_TYPEDEFS_H) && !defined(USE_CHIBIOS_2)
53 typedef int bool_t;
54#endif
55
56//ARM compiler?
57#if defined(__CC_ARM)
58 #undef PRIu8
59 #undef PRIu16
60 #define PRIu8 "u"
61 #define PRIu16 "u"
62 #define PRIuSIZE "u"
63 #define PRIXSIZE "X"
64 #define PRIuTIME "lu"
65//Microchip XC32 compiler?
66#elif defined(__XC32)
67 #define PRIuSIZE "u"
68 #define PRIXSIZE "X"
69 #define PRIuTIME "u"
70//NXP MCUXpresso compiler?
71#elif defined(__MCUXPRESSO)
72 #undef PRIu64
73 #define PRIu64 "llu"
74 #define PRIuSIZE "u"
75 #define PRIXSIZE "X"
76 #define PRIuTIME "lu"
77//NXP CodeWarrior compiler?
78#elif defined(__CWCC__)
79 #define PRIu8 "u"
80 #define PRIu16 "u"
81 #define PRIu32 "u"
82 #define PRIx8 "x"
83 #define PRIx16 "x"
84 #define PRIx32 "x"
85 #define PRIX8 "X"
86 #define PRIX16 "X"
87 #define PRIX32 "X"
88 #define PRIuSIZE "u"
89 #define PRIXSIZE "X"
90 #define PRIuTIME "u"
91//Espressif ESP-IDF compiler?
92#elif defined(IDF_VER)
93 #undef PRIu8
94 #undef PRIu16
95 #undef PRIx8
96 #undef PRIx16
97 #undef PRIX8
98 #undef PRIX16
99 #define PRIu8 "u"
100 #define PRIu16 "u"
101 #define PRIx8 "x"
102 #define PRIx16 "x"
103 #define PRIX8 "X"
104 #define PRIX16 "X"
105 #define PRIuSIZE "u"
106 #define PRIXSIZE "X"
107 #define PRIuTIME "lu"
108//Linux GCC compiler
109#elif defined(__linux__)
110 #define PRIuSIZE "zu"
111 #define PRIXSIZE "zX"
112 #define PRIuTIME "lu"
113//Win32 compiler?
114#elif defined(_WIN32)
115 #define PRIuSIZE "Iu"
116 #define PRIXSIZE "IX"
117 #define PRIuTIME "lu"
118//GCC compiler (with newlib-nano runtime library)?
119#elif defined(__GNUC__) && defined(_NANO_FORMATTED_IO) && (_NANO_FORMATTED_IO != 0)
120 #undef PRIu8
121 #undef PRIu16
122 #undef PRIx8
123 #undef PRIx16
124 #undef PRIX8
125 #undef PRIX16
126 #define PRIu8 "u"
127 #define PRIu16 "u"
128 #define PRIx8 "x"
129 #define PRIx16 "x"
130 #define PRIX8 "X"
131 #define PRIX16 "X"
132 #define PRIuSIZE "u"
133 #define PRIXSIZE "X"
134 #define PRIuTIME "u"
135//GCC compiler (with newlib-standard runtime library)?
136#else
137 #define PRIuSIZE "u"
138 #define PRIXSIZE "X"
139 #define PRIuTIME "lu"
140#endif
141
142//ARM compiler V6?
143#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
144 int vsnprintf(char *dest, size_t size, const char *format, va_list ap);
145 char *strtok_r(char *s, const char *delim, char **last);
146//GCC compiler (for PowerPC architecture)?
147#elif defined(__GNUC__) && defined(__PPC_EABI__)
148 typedef uint32_t time_t;
149 int strcasecmp(const char *s1, const char *s2);
150 int strncasecmp(const char *s1, const char *s2, size_t n);
151 char *strtok_r(char *s, const char *delim, char **last);
152//GCC compiler?
153#elif defined(__GNUC__)
154 int strcasecmp(const char *s1, const char *s2);
155 int strncasecmp(const char *s1, const char *s2, size_t n);
156 char *strtok_r(char *s, const char *delim, char **last);
157//Tasking compiler?
158#elif defined(__TASKING__)
159 char *strtok_r(char *s, const char *delim, char **last);
160//NXP CodeWarrior compiler?
161#elif defined(__CWCC__)
162 typedef uint32_t time_t;
163 int strcasecmp(const char *s1, const char *s2);
164 int strncasecmp(const char *s1, const char *s2, size_t n);
165 char *strtok_r(char *s, const char *delim, char **last);
166//TI ARM compiler?
167#elif defined(__TI_ARM__)
168 int strcasecmp(const char *s1, const char *s2);
169 int strncasecmp(const char *s1, const char *s2, size_t n);
170 char *strtok_r(char *s, const char *delim, char **last);
171//Microchip XC32 compiler?
172#elif defined(__XC32)
173 #define sprintf _sprintf
174 int sprintf(char * str, const char * format, ...);
175 int strcasecmp(const char *s1, const char *s2);
176 int strncasecmp(const char *s1, const char *s2, size_t n);
177 char *strtok_r(char *s, const char *delim, char **last);
178#endif
179
180//ARM compiler V6?
181#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
182 #undef __packed_struct
183 #define __packed_struct struct __attribute__((packed))
184 #undef __packed_union
185 #define __packed_union union __attribute__((packed))
186//GCC compiler?
187#elif defined(__GNUC__)
188 #undef __packed_struct
189 #define __packed_struct struct __attribute__((__packed__))
190 #undef __packed_union
191 #define __packed_union union __attribute__((__packed__))
192//ARM compiler?
193#elif defined(__CC_ARM)
194 #pragma anon_unions
195 #undef __packed_struct
196 #define __packed_struct __packed struct
197 #undef __packed_union
198 #define __packed_union __packed union
199//IAR compiler?
200#elif defined(__IAR_SYSTEMS_ICC__)
201 #undef __packed_struct
202 #define __packed_struct __packed struct
203 #undef __packed_union
204 #define __packed_union __packed union
205//Tasking compiler?
206#elif defined(__TASKING__)
207 #undef __packed_struct
208 #define __packed_struct struct __packed__
209 #undef __packed_union
210 #define __packed_union union __packed__
211//NXP CodeWarrior compiler?
212#elif defined(__CWCC__)
213 #undef __packed_struct
214 #define __packed_struct struct
215 #undef __packed_union
216 #define __packed_union union
217//TI ARM compiler?
218#elif defined(__TI_ARM__)
219 #undef __packed_struct
220 #define __packed_struct struct __attribute__((__packed__))
221 #undef __packed_union
222 #define __packed_union union __attribute__((__packed__))
223//Win32 compiler?
224#elif defined(_WIN32)
225 #undef interface
226 #undef __packed_struct
227 #define __packed_struct struct
228 #undef __packed_union
229 #define __packed_union union
230#endif
231
232#ifndef __weak_func
233 //ARM compiler V6?
234 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
235 #define __weak_func __attribute__((weak))
236 //GCC compiler?
237 #elif defined(__GNUC__)
238 #define __weak_func __attribute__((weak))
239 //ARM compiler?
240 #elif defined(__CC_ARM)
241 #define __weak_func __weak
242 //IAR compiler?
243 #elif defined(__IAR_SYSTEMS_ICC__)
244 #define __weak_func __weak
245 //Tasking compiler?
246 #elif defined(__TASKING__)
247 #define __weak_func __attribute__((weak))
248 //NXP CodeWarrior compiler?
249 #elif defined(__CWCC__)
250 #define __weak_func
251 //TI ARM compiler?
252 #elif defined(__TI_ARM__)
253 #define __weak_func __attribute__((weak))
254 //Win32 compiler?
255 #elif defined(_WIN32)
256 #define __weak_func
257 #endif
258#endif
259
260//C++ guard
261#ifdef __cplusplus
262}
263#endif
264
265#endif