cmsis_compiler.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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
  94. { uint32_t v; };
  95. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  96. #endif
  97. #ifndef __UNALIGNED_UINT16_WRITE
  98. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  99. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
  100. #endif
  101. #ifndef __UNALIGNED_UINT16_READ
  102. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  103. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  104. #endif
  105. #ifndef __UNALIGNED_UINT32_WRITE
  106. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  107. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  108. #endif
  109. #ifndef __UNALIGNED_UINT32_READ
  110. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  111. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  112. #endif
  113. #ifndef __ALIGNED
  114. #define __ALIGNED(x) __attribute__((aligned(x)))
  115. #endif
  116. #ifndef __RESTRICT
  117. #define __RESTRICT __restrict
  118. #endif
  119. #ifndef __COMPILER_BARRIER
  120. #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
  121. #define __COMPILER_BARRIER() (void)0
  122. #endif
  123. #ifndef __NO_INIT
  124. #define __NO_INIT __attribute__ ((section (".bss.noinit")))
  125. #endif
  126. #ifndef __ALIAS
  127. #define __ALIAS(x) __attribute__ ((alias(x)))
  128. #endif
  129. /*
  130. * TASKING Compiler
  131. */
  132. #elif defined ( __TASKING__ )
  133. /*
  134. * The CMSIS functions have been implemented as intrinsics in the compiler.
  135. * Please use "carm -?i" to get an up to date list of all intrinsics,
  136. * Including the CMSIS ones.
  137. */
  138. #ifndef __ASM
  139. #define __ASM __asm
  140. #endif
  141. #ifndef __INLINE
  142. #define __INLINE inline
  143. #endif
  144. #ifndef __STATIC_INLINE
  145. #define __STATIC_INLINE static inline
  146. #endif
  147. #ifndef __STATIC_FORCEINLINE
  148. #define __STATIC_FORCEINLINE __STATIC_INLINE
  149. #endif
  150. #ifndef __NO_RETURN
  151. #define __NO_RETURN __attribute__((noreturn))
  152. #endif
  153. #ifndef __USED
  154. #define __USED __attribute__((used))
  155. #endif
  156. #ifndef __WEAK
  157. #define __WEAK __attribute__((weak))
  158. #endif
  159. #ifndef __PACKED
  160. #define __PACKED __packed__
  161. #endif
  162. #ifndef __PACKED_STRUCT
  163. #define __PACKED_STRUCT struct __packed__
  164. #endif
  165. #ifndef __PACKED_UNION
  166. #define __PACKED_UNION union __packed__
  167. #endif
  168. #ifndef __UNALIGNED_UINT32 /* deprecated */
  169. struct __packed__ T_UINT32 { uint32_t v; };
  170. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  171. #endif
  172. #ifndef __UNALIGNED_UINT16_WRITE
  173. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  174. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  175. #endif
  176. #ifndef __UNALIGNED_UINT16_READ
  177. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  178. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  179. #endif
  180. #ifndef __UNALIGNED_UINT32_WRITE
  181. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  182. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  183. #endif
  184. #ifndef __UNALIGNED_UINT32_READ
  185. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  186. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  187. #endif
  188. #ifndef __ALIGNED
  189. #define __ALIGNED(x) __align(x)
  190. #endif
  191. #ifndef __RESTRICT
  192. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  193. #define __RESTRICT
  194. #endif
  195. #ifndef __COMPILER_BARRIER
  196. #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
  197. #define __COMPILER_BARRIER() (void)0
  198. #endif
  199. #ifndef __NO_INIT
  200. #define __NO_INIT __attribute__ ((section (".bss.noinit")))
  201. #endif
  202. #ifndef __ALIAS
  203. #define __ALIAS(x) __attribute__ ((alias(x)))
  204. #endif
  205. /*
  206. * COSMIC Compiler
  207. */
  208. #elif defined ( __CSMC__ )
  209. #include <cmsis_csm.h>
  210. #ifndef __ASM
  211. #define __ASM _asm
  212. #endif
  213. #ifndef __INLINE
  214. #define __INLINE inline
  215. #endif
  216. #ifndef __STATIC_INLINE
  217. #define __STATIC_INLINE static inline
  218. #endif
  219. #ifndef __STATIC_FORCEINLINE
  220. #define __STATIC_FORCEINLINE __STATIC_INLINE
  221. #endif
  222. #ifndef __NO_RETURN
  223. /* NO RETURN is automatically detected hence no warning here*/
  224. #define __NO_RETURN
  225. #endif
  226. #ifndef __USED
  227. #warning No compiler specific solution for __USED. __USED is ignored.
  228. #define __USED
  229. #endif
  230. #ifndef __WEAK
  231. #define __WEAK __weak
  232. #endif
  233. #ifndef __PACKED
  234. #define __PACKED @packed
  235. #endif
  236. #ifndef __PACKED_STRUCT
  237. #define __PACKED_STRUCT @packed struct
  238. #endif
  239. #ifndef __PACKED_UNION
  240. #define __PACKED_UNION @packed union
  241. #endif
  242. #ifndef __UNALIGNED_UINT32 /* deprecated */
  243. @packed struct T_UINT32 { uint32_t v; };
  244. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  245. #endif
  246. #ifndef __UNALIGNED_UINT16_WRITE
  247. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  248. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  249. #endif
  250. #ifndef __UNALIGNED_UINT16_READ
  251. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  252. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  253. #endif
  254. #ifndef __UNALIGNED_UINT32_WRITE
  255. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  256. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  257. #endif
  258. #ifndef __UNALIGNED_UINT32_READ
  259. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  260. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  261. #endif
  262. #ifndef __ALIGNED
  263. #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
  264. #define __ALIGNED(x)
  265. #endif
  266. #ifndef __RESTRICT
  267. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  268. #define __RESTRICT
  269. #endif
  270. #ifndef __COMPILER_BARRIER
  271. #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
  272. #define __COMPILER_BARRIER() (void)0
  273. #endif
  274. #ifndef __NO_INIT
  275. #define __NO_INIT __attribute__ ((section (".bss.noinit")))
  276. #endif
  277. #ifndef __ALIAS
  278. #define __ALIAS(x) __attribute__ ((alias(x)))
  279. #endif
  280. #else
  281. #error Unknown compiler.
  282. #endif
  283. #endif /* __CMSIS_COMPILER_H */