cmsis_compiler.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. #include "cmsis_armclang.h"
  29. /*
  30. * TI Arm Clang Compiler (tiarmclang)
  31. */
  32. #elif defined (__ti__)
  33. #include "cmsis_tiarmclang.h"
  34. /*
  35. * LLVM/Clang Compiler
  36. */
  37. #elif defined ( __clang__ )
  38. #include "cmsis_clang.h"
  39. /*
  40. * GNU Compiler
  41. */
  42. #elif defined ( __GNUC__ )
  43. #include "cmsis_gcc.h"
  44. /*
  45. * IAR Compiler
  46. */
  47. #elif defined ( __ICCARM__ )
  48. #if __ARM_ARCH_PROFILE == 'A'
  49. #include "a-profile/cmsis_iccarm_a.h"
  50. #elif __ARM_ARCH_PROFILE == 'R'
  51. #include "r-profile/cmsis_iccarm_r.h"
  52. #elif __ARM_ARCH_PROFILE == 'M'
  53. #include "m-profile/cmsis_iccarm_m.h"
  54. #else
  55. #error "Unknown Arm architecture profile"
  56. #endif
  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_UINT16_WRITE
  93. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  94. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
  95. #endif
  96. #ifndef __UNALIGNED_UINT16_READ
  97. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  98. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  99. #endif
  100. #ifndef __UNALIGNED_UINT32_WRITE
  101. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  102. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  103. #endif
  104. #ifndef __UNALIGNED_UINT32_READ
  105. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  106. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  107. #endif
  108. #ifndef __ALIGNED
  109. #define __ALIGNED(x) __attribute__((aligned(x)))
  110. #endif
  111. #ifndef __RESTRICT
  112. #define __RESTRICT __restrict
  113. #endif
  114. #ifndef __COMPILER_BARRIER
  115. #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
  116. #define __COMPILER_BARRIER() (void)0
  117. #endif
  118. #ifndef __NO_INIT
  119. #define __NO_INIT __attribute__ ((section (".noinit")))
  120. #endif
  121. #ifndef __ALIAS
  122. #define __ALIAS(x) __attribute__ ((alias(x)))
  123. #endif
  124. /*
  125. * TASKING Compiler
  126. */
  127. #elif defined ( __TASKING__ )
  128. /*
  129. * The CMSIS functions have been implemented as intrinsics in the compiler.
  130. * Please use "carm -?i" to get an up to date list of all intrinsics,
  131. * Including the CMSIS ones.
  132. */
  133. #ifndef __ASM
  134. #define __ASM __asm
  135. #endif
  136. #ifndef __INLINE
  137. #define __INLINE inline
  138. #endif
  139. #ifndef __STATIC_INLINE
  140. #define __STATIC_INLINE static inline
  141. #endif
  142. #ifndef __STATIC_FORCEINLINE
  143. #define __STATIC_FORCEINLINE __STATIC_INLINE
  144. #endif
  145. #ifndef __NO_RETURN
  146. #define __NO_RETURN __attribute__((noreturn))
  147. #endif
  148. #ifndef __USED
  149. #define __USED __attribute__((used))
  150. #endif
  151. #ifndef __WEAK
  152. #define __WEAK __attribute__((weak))
  153. #endif
  154. #ifndef __PACKED
  155. #define __PACKED __packed__
  156. #endif
  157. #ifndef __PACKED_STRUCT
  158. #define __PACKED_STRUCT struct __packed__
  159. #endif
  160. #ifndef __PACKED_UNION
  161. #define __PACKED_UNION union __packed__
  162. #endif
  163. #ifndef __UNALIGNED_UINT16_WRITE
  164. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  165. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  166. #endif
  167. #ifndef __UNALIGNED_UINT16_READ
  168. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  169. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  170. #endif
  171. #ifndef __UNALIGNED_UINT32_WRITE
  172. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  173. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  174. #endif
  175. #ifndef __UNALIGNED_UINT32_READ
  176. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  177. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  178. #endif
  179. #ifndef __ALIGNED
  180. #define __ALIGNED(x) __align(x)
  181. #endif
  182. #ifndef __RESTRICT
  183. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  184. #define __RESTRICT
  185. #endif
  186. #ifndef __COMPILER_BARRIER
  187. #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
  188. #define __COMPILER_BARRIER() (void)0
  189. #endif
  190. #ifndef __NO_INIT
  191. #define __NO_INIT __attribute__ ((section (".noinit")))
  192. #endif
  193. #ifndef __ALIAS
  194. #define __ALIAS(x) __attribute__ ((alias(x)))
  195. #endif
  196. /*
  197. * COSMIC Compiler
  198. */
  199. #elif defined ( __CSMC__ )
  200. #include <cmsis_csm.h>
  201. #ifndef __ASM
  202. #define __ASM _asm
  203. #endif
  204. #ifndef __INLINE
  205. #define __INLINE inline
  206. #endif
  207. #ifndef __STATIC_INLINE
  208. #define __STATIC_INLINE static inline
  209. #endif
  210. #ifndef __STATIC_FORCEINLINE
  211. #define __STATIC_FORCEINLINE __STATIC_INLINE
  212. #endif
  213. #ifndef __NO_RETURN
  214. // NO RETURN is automatically detected hence no warning here
  215. #define __NO_RETURN
  216. #endif
  217. #ifndef __USED
  218. #warning No compiler specific solution for __USED. __USED is ignored.
  219. #define __USED
  220. #endif
  221. #ifndef __WEAK
  222. #define __WEAK __weak
  223. #endif
  224. #ifndef __PACKED
  225. #define __PACKED @packed
  226. #endif
  227. #ifndef __PACKED_STRUCT
  228. #define __PACKED_STRUCT @packed struct
  229. #endif
  230. #ifndef __PACKED_UNION
  231. #define __PACKED_UNION @packed union
  232. #endif
  233. #ifndef __UNALIGNED_UINT16_WRITE
  234. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  235. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  236. #endif
  237. #ifndef __UNALIGNED_UINT16_READ
  238. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  239. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  240. #endif
  241. #ifndef __UNALIGNED_UINT32_WRITE
  242. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  243. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  244. #endif
  245. #ifndef __UNALIGNED_UINT32_READ
  246. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  247. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  248. #endif
  249. #ifndef __ALIGNED
  250. #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
  251. #define __ALIGNED(x)
  252. #endif
  253. #ifndef __RESTRICT
  254. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  255. #define __RESTRICT
  256. #endif
  257. #ifndef __COMPILER_BARRIER
  258. #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
  259. #define __COMPILER_BARRIER() (void)0
  260. #endif
  261. #ifndef __NO_INIT
  262. #define __NO_INIT __attribute__ ((section (".noinit")))
  263. #endif
  264. #ifndef __ALIAS
  265. #define __ALIAS(x) __attribute__ ((alias(x)))
  266. #endif
  267. #else
  268. #error Unknown compiler.
  269. #endif
  270. #endif /* __CMSIS_COMPILER_H */