cmsis_compiler.h 10 KB

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