cmsis_compiler.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /**************************************************************************//**
  2. * @file cmsis_compiler.h
  3. * @brief CMSIS compiler generic header file
  4. * @version V5.3.0
  5. * @date 04. April 2023
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2009-2023 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. * TI Arm Clang Compiler (tiarmclang)
  44. */
  45. #elif defined (__ti__)
  46. #include "cmsis_tiarmclang.h"
  47. /*
  48. * GNU Compiler
  49. */
  50. #elif defined ( __GNUC__ )
  51. #include "cmsis_gcc.h"
  52. /*
  53. * IAR Compiler
  54. */
  55. #elif defined ( __ICCARM__ )
  56. #include <cmsis_iccarm.h>
  57. /*
  58. * TI Arm Compiler (armcl)
  59. */
  60. #elif defined ( __TI_ARM__ )
  61. #include <cmsis_ccs.h>
  62. #ifndef __ASM
  63. #define __ASM __asm
  64. #endif
  65. #ifndef __INLINE
  66. #define __INLINE inline
  67. #endif
  68. #ifndef __STATIC_INLINE
  69. #define __STATIC_INLINE static inline
  70. #endif
  71. #ifndef __STATIC_FORCEINLINE
  72. #define __STATIC_FORCEINLINE __STATIC_INLINE
  73. #endif
  74. #ifndef __NO_RETURN
  75. #define __NO_RETURN __attribute__((noreturn))
  76. #endif
  77. #ifndef __USED
  78. #define __USED __attribute__((used))
  79. #endif
  80. #ifndef __WEAK
  81. #define __WEAK __attribute__((weak))
  82. #endif
  83. #ifndef __PACKED
  84. #define __PACKED __attribute__((packed))
  85. #endif
  86. #ifndef __PACKED_STRUCT
  87. #define __PACKED_STRUCT struct __attribute__((packed))
  88. #endif
  89. #ifndef __PACKED_UNION
  90. #define __PACKED_UNION union __attribute__((packed))
  91. #endif
  92. #ifndef __UNALIGNED_UINT32 /* deprecated */
  93. struct __attribute__((packed)) T_UINT32 { uint32_t v; };
  94. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  95. #endif
  96. #ifndef __UNALIGNED_UINT16_WRITE
  97. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  98. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
  99. #endif
  100. #ifndef __UNALIGNED_UINT16_READ
  101. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  102. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  103. #endif
  104. #ifndef __UNALIGNED_UINT32_WRITE
  105. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  106. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  107. #endif
  108. #ifndef __UNALIGNED_UINT32_READ
  109. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  110. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  111. #endif
  112. #ifndef __ALIGNED
  113. #define __ALIGNED(x) __attribute__((aligned(x)))
  114. #endif
  115. #ifndef __RESTRICT
  116. #define __RESTRICT __restrict
  117. #endif
  118. #ifndef __COMPILER_BARRIER
  119. #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
  120. #define __COMPILER_BARRIER() (void)0
  121. #endif
  122. #ifndef __NO_INIT
  123. #define __NO_INIT __attribute__ ((section (".bss.noinit")))
  124. #endif
  125. #ifndef __ALIAS
  126. #define __ALIAS(x) __attribute__ ((alias(x)))
  127. #endif
  128. /*
  129. * TASKING Compiler
  130. */
  131. #elif defined ( __TASKING__ )
  132. /*
  133. * The CMSIS functions have been implemented as intrinsics in the compiler.
  134. * Please use "carm -?i" to get an up to date list of all intrinsics,
  135. * Including the CMSIS ones.
  136. */
  137. #ifndef __ASM
  138. #define __ASM __asm
  139. #endif
  140. #ifndef __INLINE
  141. #define __INLINE inline
  142. #endif
  143. #ifndef __STATIC_INLINE
  144. #define __STATIC_INLINE static inline
  145. #endif
  146. #ifndef __STATIC_FORCEINLINE
  147. #define __STATIC_FORCEINLINE __STATIC_INLINE
  148. #endif
  149. #ifndef __NO_RETURN
  150. #define __NO_RETURN __attribute__((noreturn))
  151. #endif
  152. #ifndef __USED
  153. #define __USED __attribute__((used))
  154. #endif
  155. #ifndef __WEAK
  156. #define __WEAK __attribute__((weak))
  157. #endif
  158. #ifndef __PACKED
  159. #define __PACKED __packed__
  160. #endif
  161. #ifndef __PACKED_STRUCT
  162. #define __PACKED_STRUCT struct __packed__
  163. #endif
  164. #ifndef __PACKED_UNION
  165. #define __PACKED_UNION union __packed__
  166. #endif
  167. #ifndef __UNALIGNED_UINT32 /* deprecated */
  168. struct __packed__ T_UINT32 { uint32_t v; };
  169. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  170. #endif
  171. #ifndef __UNALIGNED_UINT16_WRITE
  172. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  173. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  174. #endif
  175. #ifndef __UNALIGNED_UINT16_READ
  176. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  177. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  178. #endif
  179. #ifndef __UNALIGNED_UINT32_WRITE
  180. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  181. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  182. #endif
  183. #ifndef __UNALIGNED_UINT32_READ
  184. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  185. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  186. #endif
  187. #ifndef __ALIGNED
  188. #define __ALIGNED(x) __align(x)
  189. #endif
  190. #ifndef __RESTRICT
  191. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  192. #define __RESTRICT
  193. #endif
  194. #ifndef __COMPILER_BARRIER
  195. #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
  196. #define __COMPILER_BARRIER() (void)0
  197. #endif
  198. #ifndef __NO_INIT
  199. #define __NO_INIT __attribute__ ((section (".bss.noinit")))
  200. #endif
  201. #ifndef __ALIAS
  202. #define __ALIAS(x) __attribute__ ((alias(x)))
  203. #endif
  204. /*
  205. * COSMIC Compiler
  206. */
  207. #elif defined ( __CSMC__ )
  208. #include <cmsis_csm.h>
  209. #ifndef __ASM
  210. #define __ASM _asm
  211. #endif
  212. #ifndef __INLINE
  213. #define __INLINE inline
  214. #endif
  215. #ifndef __STATIC_INLINE
  216. #define __STATIC_INLINE static inline
  217. #endif
  218. #ifndef __STATIC_FORCEINLINE
  219. #define __STATIC_FORCEINLINE __STATIC_INLINE
  220. #endif
  221. #ifndef __NO_RETURN
  222. // NO RETURN is automatically detected hence no warning here
  223. #define __NO_RETURN
  224. #endif
  225. #ifndef __USED
  226. #warning No compiler specific solution for __USED. __USED is ignored.
  227. #define __USED
  228. #endif
  229. #ifndef __WEAK
  230. #define __WEAK __weak
  231. #endif
  232. #ifndef __PACKED
  233. #define __PACKED @packed
  234. #endif
  235. #ifndef __PACKED_STRUCT
  236. #define __PACKED_STRUCT @packed struct
  237. #endif
  238. #ifndef __PACKED_UNION
  239. #define __PACKED_UNION @packed union
  240. #endif
  241. #ifndef __UNALIGNED_UINT32 /* deprecated */
  242. @packed struct T_UINT32 { uint32_t v; };
  243. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  244. #endif
  245. #ifndef __UNALIGNED_UINT16_WRITE
  246. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  247. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  248. #endif
  249. #ifndef __UNALIGNED_UINT16_READ
  250. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  251. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  252. #endif
  253. #ifndef __UNALIGNED_UINT32_WRITE
  254. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  255. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  256. #endif
  257. #ifndef __UNALIGNED_UINT32_READ
  258. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  259. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  260. #endif
  261. #ifndef __ALIGNED
  262. #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
  263. #define __ALIGNED(x)
  264. #endif
  265. #ifndef __RESTRICT
  266. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  267. #define __RESTRICT
  268. #endif
  269. #ifndef __COMPILER_BARRIER
  270. #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
  271. #define __COMPILER_BARRIER() (void)0
  272. #endif
  273. #ifndef __NO_INIT
  274. #define __NO_INIT __attribute__ ((section (".bss.noinit")))
  275. #endif
  276. #ifndef __ALIAS
  277. #define __ALIAS(x) __attribute__ ((alias(x)))
  278. #endif
  279. #else
  280. #error Unknown compiler.
  281. #endif
  282. #endif /* __CMSIS_COMPILER_H */