compiler_port.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /**
  2. * @file compiler_port.h
  3. * @brief Compiler specific definitions
  4. *
  5. * @section License
  6. *
  7. * SPDX-License-Identifier: GPL-2.0-or-later
  8. *
  9. * Copyright (C) 2010-2023 Oryx Embedded SARL. All rights reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software Foundation,
  23. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  24. *
  25. * @author Oryx Embedded SARL (www.oryx-embedded.com)
  26. * @version 2.2.4
  27. **/
  28. #ifndef _COMPILER_PORT_H
  29. #define _COMPILER_PORT_H
  30. //Dependencies
  31. #include <stddef.h>
  32. #include <stdint.h>
  33. #include <inttypes.h>
  34. //ARM compiler V6?
  35. #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
  36. #include <stdarg.h>
  37. #endif
  38. //C++ guard
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. //Types
  43. typedef char char_t;
  44. typedef signed int int_t;
  45. typedef unsigned int uint_t;
  46. #if !defined(R_TYPEDEFS_H) && !defined(USE_CHIBIOS_2)
  47. typedef int bool_t;
  48. #endif
  49. //ARM compiler?
  50. #if defined(__CC_ARM)
  51. #undef PRIu8
  52. #undef PRIu16
  53. #define PRIu8 "u"
  54. #define PRIu16 "u"
  55. #define PRIuSIZE "u"
  56. #define PRIXSIZE "X"
  57. #define PRIuTIME "lu"
  58. //Microchip XC32 compiler?
  59. #elif defined(__XC32)
  60. #define PRIuSIZE "u"
  61. #define PRIXSIZE "X"
  62. #define PRIuTIME "u"
  63. //NXP MCUXpresso compiler?
  64. #elif defined(__MCUXPRESSO)
  65. #undef PRIu64
  66. #define PRIu64 "llu"
  67. #define PRIuSIZE "u"
  68. #define PRIXSIZE "X"
  69. #define PRIuTIME "lu"
  70. //NXP CodeWarrior compiler?
  71. #elif defined(__CWCC__)
  72. #define PRIu8 "u"
  73. #define PRIu16 "u"
  74. #define PRIu32 "u"
  75. #define PRIx8 "x"
  76. #define PRIx16 "x"
  77. #define PRIx32 "x"
  78. #define PRIX8 "X"
  79. #define PRIX16 "X"
  80. #define PRIX32 "X"
  81. #define PRIuSIZE "u"
  82. #define PRIXSIZE "X"
  83. #define PRIuTIME "u"
  84. //Espressif ESP-IDF compiler?
  85. #elif defined(IDF_VER)
  86. #undef PRIu8
  87. #undef PRIu16
  88. #undef PRIu32
  89. #undef PRIx8
  90. #undef PRIx16
  91. #undef PRIx32
  92. #undef PRIX8
  93. #undef PRIX16
  94. #undef PRIX32
  95. #define PRIu8 "u"
  96. #define PRIu16 "u"
  97. #define PRIu32 "u"
  98. #define PRIx8 "x"
  99. #define PRIx16 "x"
  100. #define PRIx32 "x"
  101. #define PRIX8 "X"
  102. #define PRIX16 "X"
  103. #define PRIX32 "X"
  104. #define PRIuSIZE "u"
  105. #define PRIXSIZE "X"
  106. #define PRIuTIME "lu"
  107. //Linux GCC compiler
  108. #elif defined(__linux__)
  109. #define PRIuSIZE "zu"
  110. #define PRIXSIZE "zX"
  111. #define PRIuTIME "lu"
  112. //Win32 compiler?
  113. #elif defined(_WIN32)
  114. #define PRIuSIZE "Iu"
  115. #define PRIXSIZE "IX"
  116. #define PRIuTIME "lu"
  117. #else
  118. #define PRIuSIZE "u"
  119. #define PRIXSIZE "X"
  120. #define PRIuTIME "lu"
  121. #endif
  122. //ARM compiler V6?
  123. #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
  124. int vsnprintf(char *dest, size_t size, const char *format, va_list ap);
  125. char *strtok_r(char *s, const char *delim, char **last);
  126. //GCC compiler?
  127. #elif defined(__GNUC__)
  128. int strcasecmp(const char *s1, const char *s2);
  129. int strncasecmp(const char *s1, const char *s2, size_t n);
  130. char *strtok_r(char *s, const char *delim, char **last);
  131. //NXP CodeWarrior compiler?
  132. #elif defined(__CWCC__)
  133. typedef uint32_t time_t;
  134. int strcasecmp(const char *s1, const char *s2);
  135. int strncasecmp(const char *s1, const char *s2, size_t n);
  136. char *strtok_r(char *s, const char *delim, char **last);
  137. //TI ARM compiler?
  138. #elif defined(__TI_ARM__)
  139. int strcasecmp(const char *s1, const char *s2);
  140. int strncasecmp(const char *s1, const char *s2, size_t n);
  141. char *strtok_r(char *s, const char *delim, char **last);
  142. //Microchip XC32 compiler?
  143. #elif defined(__XC32)
  144. #define sprintf _sprintf
  145. int sprintf(char * str, const char * format, ...);
  146. int strcasecmp(const char *s1, const char *s2);
  147. int strncasecmp(const char *s1, const char *s2, size_t n);
  148. char *strtok_r(char *s, const char *delim, char **last);
  149. #endif
  150. //ARM compiler V6?
  151. #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
  152. #undef __start_packed
  153. #define __start_packed
  154. #undef __end_packed
  155. #define __end_packed __attribute__((packed))
  156. //GCC compiler?
  157. #elif defined(__GNUC__)
  158. #undef __start_packed
  159. #define __start_packed
  160. #undef __end_packed
  161. #define __end_packed __attribute__((__packed__))
  162. //ARM compiler?
  163. #elif defined(__CC_ARM)
  164. #pragma anon_unions
  165. #undef __start_packed
  166. #define __start_packed __packed
  167. #undef __end_packed
  168. #define __end_packed
  169. //IAR compiler?
  170. #elif defined(__IAR_SYSTEMS_ICC__)
  171. #undef __start_packed
  172. #define __start_packed __packed
  173. #undef __end_packed
  174. #define __end_packed
  175. //NXP CodeWarrior compiler?
  176. #elif defined(__CWCC__)
  177. #undef __start_packed
  178. #define __start_packed
  179. #undef __end_packed
  180. #define __end_packed
  181. //TI ARM compiler?
  182. #elif defined(__TI_ARM__)
  183. #undef __start_packed
  184. #define __start_packed
  185. #undef __end_packed
  186. #define __end_packed __attribute__((__packed__))
  187. //Win32 compiler?
  188. #elif defined(_WIN32)
  189. #undef interface
  190. #undef __start_packed
  191. #define __start_packed
  192. #undef __end_packed
  193. #define __end_packed
  194. #endif
  195. #ifndef __weak_func
  196. //ARM compiler V6?
  197. #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
  198. #define __weak_func __attribute__((weak))
  199. //GCC compiler?
  200. #elif defined(__GNUC__)
  201. #define __weak_func __attribute__((weak))
  202. //ARM compiler?
  203. #elif defined(__CC_ARM)
  204. #define __weak_func __weak
  205. //IAR compiler?
  206. #elif defined(__IAR_SYSTEMS_ICC__)
  207. #define __weak_func __weak
  208. //NXP CodeWarrior compiler?
  209. #elif defined(__CWCC__)
  210. #define __weak_func
  211. //TI ARM compiler?
  212. #elif defined(__TI_ARM__)
  213. #define __weak_func __attribute__((weak))
  214. //Win32 compiler?
  215. #elif defined(_WIN32)
  216. #define __weak_func
  217. #endif
  218. #endif
  219. //C++ guard
  220. #ifdef __cplusplus
  221. }
  222. #endif
  223. #endif