cmsis_compiler.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /**************************************************************************//**
  2. * @file cmsis_compiler.h
  3. * @brief CMSIS compiler generic header file
  4. * @version V5.1.0
  5. * @date 09. October 2018
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2009-2018 Arm Limited. All rights reserved.
  9. *
  10. * SPDX-License-Identifier: Apache-2.0
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the License); you may
  13. * not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  20. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. #ifndef __CMSIS_COMPILER_H
  25. #define __CMSIS_COMPILER_H
  26. #include <stdint.h>
  27. /*
  28. * Arm Compiler 4/5
  29. */
  30. #if defined ( __CC_ARM )
  31. #include "cmsis_armcc.h"
  32. /*
  33. * Arm Compiler 6.6 LTM (armclang)
  34. */
  35. #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) && (__ARMCC_VERSION < 6100100)
  36. #include "cmsis_armclang_ltm.h"
  37. /*
  38. * Arm Compiler above 6.10.1 (armclang)
  39. */
  40. #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
  41. #include "cmsis_armclang.h"
  42. /*
  43. * GNU Compiler
  44. */
  45. #elif defined ( __GNUC__ )
  46. #include "cmsis_gcc.h"
  47. /*
  48. * IAR Compiler
  49. */
  50. #elif defined ( __ICCARM__ )
  51. #include <cmsis_iccarm.h>
  52. /*
  53. * TI Arm Compiler
  54. */
  55. #elif defined ( __TI_ARM__ )
  56. #include <cmsis_ccs.h>
  57. #ifndef __ASM
  58. #define __ASM __asm
  59. #endif
  60. #ifndef __INLINE
  61. #define __INLINE inline
  62. #endif
  63. #ifndef __STATIC_INLINE
  64. #define __STATIC_INLINE static inline
  65. #endif
  66. #ifndef __STATIC_FORCEINLINE
  67. #define __STATIC_FORCEINLINE __STATIC_INLINE
  68. #endif
  69. #ifndef __NO_RETURN
  70. #define __NO_RETURN __attribute__((noreturn))
  71. #endif
  72. #ifndef __USED
  73. #define __USED __attribute__((used))
  74. #endif
  75. #ifndef __WEAK
  76. #define __WEAK __attribute__((weak))
  77. #endif
  78. #ifndef __PACKED
  79. #define __PACKED __attribute__((packed))
  80. #endif
  81. #ifndef __PACKED_STRUCT
  82. #define __PACKED_STRUCT struct __attribute__((packed))
  83. #endif
  84. #ifndef __PACKED_UNION
  85. #define __PACKED_UNION union __attribute__((packed))
  86. #endif
  87. #ifndef __UNALIGNED_UINT32 /* deprecated */
  88. struct __attribute__((packed)) T_UINT32
  89. {
  90. uint32_t v;
  91. };
  92. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  93. #endif
  94. #ifndef __UNALIGNED_UINT16_WRITE
  95. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  96. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
  97. #endif
  98. #ifndef __UNALIGNED_UINT16_READ
  99. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  100. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  101. #endif
  102. #ifndef __UNALIGNED_UINT32_WRITE
  103. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  104. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  105. #endif
  106. #ifndef __UNALIGNED_UINT32_READ
  107. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  108. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  109. #endif
  110. #ifndef __ALIGNED
  111. #define __ALIGNED(x) __attribute__((aligned(x)))
  112. #endif
  113. #ifndef __RESTRICT
  114. #define __RESTRICT __restrict
  115. #endif
  116. /*
  117. * TASKING Compiler
  118. */
  119. #elif defined ( __TASKING__ )
  120. /*
  121. * The CMSIS functions have been implemented as intrinsics in the compiler.
  122. * Please use "carm -?i" to get an up to date list of all intrinsics,
  123. * Including the CMSIS ones.
  124. */
  125. #ifndef __ASM
  126. #define __ASM __asm
  127. #endif
  128. #ifndef __INLINE
  129. #define __INLINE inline
  130. #endif
  131. #ifndef __STATIC_INLINE
  132. #define __STATIC_INLINE static inline
  133. #endif
  134. #ifndef __STATIC_FORCEINLINE
  135. #define __STATIC_FORCEINLINE __STATIC_INLINE
  136. #endif
  137. #ifndef __NO_RETURN
  138. #define __NO_RETURN __attribute__((noreturn))
  139. #endif
  140. #ifndef __USED
  141. #define __USED __attribute__((used))
  142. #endif
  143. #ifndef __WEAK
  144. #define __WEAK __attribute__((weak))
  145. #endif
  146. #ifndef __PACKED
  147. #define __PACKED __packed__
  148. #endif
  149. #ifndef __PACKED_STRUCT
  150. #define __PACKED_STRUCT struct __packed__
  151. #endif
  152. #ifndef __PACKED_UNION
  153. #define __PACKED_UNION union __packed__
  154. #endif
  155. #ifndef __UNALIGNED_UINT32 /* deprecated */
  156. struct __packed__ T_UINT32
  157. {
  158. uint32_t v;
  159. };
  160. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  161. #endif
  162. #ifndef __UNALIGNED_UINT16_WRITE
  163. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  164. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  165. #endif
  166. #ifndef __UNALIGNED_UINT16_READ
  167. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  168. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  169. #endif
  170. #ifndef __UNALIGNED_UINT32_WRITE
  171. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  172. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  173. #endif
  174. #ifndef __UNALIGNED_UINT32_READ
  175. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  176. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  177. #endif
  178. #ifndef __ALIGNED
  179. #define __ALIGNED(x) __align(x)
  180. #endif
  181. #ifndef __RESTRICT
  182. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  183. #define __RESTRICT
  184. #endif
  185. /*
  186. * COSMIC Compiler
  187. */
  188. #elif defined ( __CSMC__ )
  189. #include <cmsis_csm.h>
  190. #ifndef __ASM
  191. #define __ASM _asm
  192. #endif
  193. #ifndef __INLINE
  194. #define __INLINE inline
  195. #endif
  196. #ifndef __STATIC_INLINE
  197. #define __STATIC_INLINE static inline
  198. #endif
  199. #ifndef __STATIC_FORCEINLINE
  200. #define __STATIC_FORCEINLINE __STATIC_INLINE
  201. #endif
  202. #ifndef __NO_RETURN
  203. // NO RETURN is automatically detected hence no warning here
  204. #define __NO_RETURN
  205. #endif
  206. #ifndef __USED
  207. #warning No compiler specific solution for __USED. __USED is ignored.
  208. #define __USED
  209. #endif
  210. #ifndef __WEAK
  211. #define __WEAK __weak
  212. #endif
  213. #ifndef __PACKED
  214. #define __PACKED @packed
  215. #endif
  216. #ifndef __PACKED_STRUCT
  217. #define __PACKED_STRUCT @packed struct
  218. #endif
  219. #ifndef __PACKED_UNION
  220. #define __PACKED_UNION @packed union
  221. #endif
  222. #ifndef __UNALIGNED_UINT32 /* deprecated */
  223. @packed struct T_UINT32
  224. {
  225. uint32_t v;
  226. };
  227. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  228. #endif
  229. #ifndef __UNALIGNED_UINT16_WRITE
  230. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  231. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  232. #endif
  233. #ifndef __UNALIGNED_UINT16_READ
  234. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  235. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  236. #endif
  237. #ifndef __UNALIGNED_UINT32_WRITE
  238. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  239. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  240. #endif
  241. #ifndef __UNALIGNED_UINT32_READ
  242. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  243. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  244. #endif
  245. #ifndef __ALIGNED
  246. #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
  247. #define __ALIGNED(x)
  248. #endif
  249. #ifndef __RESTRICT
  250. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  251. #define __RESTRICT
  252. #endif
  253. #else
  254. #error Unknown compiler.
  255. #endif
  256. #endif /* __CMSIS_COMPILER_H */