cmsis_compiler.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /**************************************************************************//**
  2. * @file cmsis_compiler.h
  3. * @brief CMSIS compiler generic header file
  4. * @version V5.0.2
  5. * @date 13. February 2017
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2009-2017 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 (armclang)
  34. */
  35. #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
  36. #include "cmsis_armclang.h"
  37. /*
  38. * GNU Compiler
  39. */
  40. #elif defined ( __GNUC__ )
  41. #include "cmsis_gcc.h"
  42. /*
  43. * IAR Compiler
  44. */
  45. #elif defined ( __ICCARM__ )
  46. #ifndef __ASM
  47. #define __ASM __asm
  48. #endif
  49. #ifndef __INLINE
  50. #define __INLINE inline
  51. #endif
  52. #ifndef __STATIC_INLINE
  53. #define __STATIC_INLINE static inline
  54. #endif
  55. #include <cmsis_iar.h>
  56. /* CMSIS compiler control architecture macros */
  57. #if (__CORE__ == __ARM6M__) || (__CORE__ == __ARM6SM__)
  58. #ifndef __ARM_ARCH_6M__
  59. #define __ARM_ARCH_6M__ 1
  60. #endif
  61. #elif (__CORE__ == __ARM7M__)
  62. #ifndef __ARM_ARCH_7M__
  63. #define __ARM_ARCH_7M__ 1
  64. #endif
  65. #elif (__CORE__ == __ARM7EM__)
  66. #ifndef __ARM_ARCH_7EM__
  67. #define __ARM_ARCH_7EM__ 1
  68. #endif
  69. #endif
  70. #ifndef __NO_RETURN
  71. #define __NO_RETURN __noreturn
  72. #endif
  73. #ifndef __USED
  74. #define __USED __root
  75. #endif
  76. #ifndef __WEAK
  77. #define __WEAK __weak
  78. #endif
  79. #ifndef __PACKED
  80. #define __PACKED __packed
  81. #endif
  82. #ifndef __PACKED_STRUCT
  83. #define __PACKED_STRUCT __packed struct
  84. #endif
  85. #ifndef __PACKED_UNION
  86. #define __PACKED_UNION __packed union
  87. #endif
  88. #ifndef __UNALIGNED_UINT32 /* deprecated */
  89. __packed struct T_UINT32 { uint32_t v; };
  90. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  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. #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
  110. #define __ALIGNED(x)
  111. #endif
  112. #ifndef __RESTRICT
  113. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  114. #define __RESTRICT
  115. #endif
  116. // Workaround for missing __CLZ intrinsic in
  117. // various versions of the IAR compilers.
  118. // __IAR_FEATURE_CLZ__ should be defined by
  119. // the compiler that supports __CLZ internally.
  120. #if (defined (__ARM_ARCH_6M__)) && (__ARM_ARCH_6M__ == 1) && (!defined (__IAR_FEATURE_CLZ__))
  121. __STATIC_INLINE uint32_t __CLZ(uint32_t data)
  122. {
  123. if (data == 0u) { return 32u; }
  124. uint32_t count = 0;
  125. uint32_t mask = 0x80000000;
  126. while ((data & mask) == 0)
  127. {
  128. count += 1u;
  129. mask = mask >> 1u;
  130. }
  131. return (count);
  132. }
  133. #endif
  134. /*
  135. * TI ARM Compiler
  136. */
  137. #elif defined ( __TI_ARM__ )
  138. #include <cmsis_ccs.h>
  139. #ifndef __ASM
  140. #define __ASM __asm
  141. #endif
  142. #ifndef __INLINE
  143. #define __INLINE inline
  144. #endif
  145. #ifndef __STATIC_INLINE
  146. #define __STATIC_INLINE static inline
  147. #endif
  148. #ifndef __NO_RETURN
  149. #define __NO_RETURN __attribute__((noreturn))
  150. #endif
  151. #ifndef __USED
  152. #define __USED __attribute__((used))
  153. #endif
  154. #ifndef __WEAK
  155. #define __WEAK __attribute__((weak))
  156. #endif
  157. #ifndef __PACKED
  158. #define __PACKED __attribute__((packed))
  159. #endif
  160. #ifndef __PACKED_STRUCT
  161. #define __PACKED_STRUCT struct __attribute__((packed))
  162. #endif
  163. #ifndef __PACKED_UNION
  164. #define __PACKED_UNION union __attribute__((packed))
  165. #endif
  166. #ifndef __UNALIGNED_UINT32 /* deprecated */
  167. struct __attribute__((packed)) T_UINT32 { uint32_t v; };
  168. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  169. #endif
  170. #ifndef __UNALIGNED_UINT16_WRITE
  171. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  172. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
  173. #endif
  174. #ifndef __UNALIGNED_UINT16_READ
  175. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  176. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  177. #endif
  178. #ifndef __UNALIGNED_UINT32_WRITE
  179. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  180. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  181. #endif
  182. #ifndef __UNALIGNED_UINT32_READ
  183. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  184. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  185. #endif
  186. #ifndef __ALIGNED
  187. #define __ALIGNED(x) __attribute__((aligned(x)))
  188. #endif
  189. #ifndef __RESTRICT
  190. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  191. #define __RESTRICT
  192. #endif
  193. /*
  194. * TASKING Compiler
  195. */
  196. #elif defined ( __TASKING__ )
  197. /*
  198. * The CMSIS functions have been implemented as intrinsics in the compiler.
  199. * Please use "carm -?i" to get an up to date list of all intrinsics,
  200. * Including the CMSIS ones.
  201. */
  202. #ifndef __ASM
  203. #define __ASM __asm
  204. #endif
  205. #ifndef __INLINE
  206. #define __INLINE inline
  207. #endif
  208. #ifndef __STATIC_INLINE
  209. #define __STATIC_INLINE static inline
  210. #endif
  211. #ifndef __NO_RETURN
  212. #define __NO_RETURN __attribute__((noreturn))
  213. #endif
  214. #ifndef __USED
  215. #define __USED __attribute__((used))
  216. #endif
  217. #ifndef __WEAK
  218. #define __WEAK __attribute__((weak))
  219. #endif
  220. #ifndef __PACKED
  221. #define __PACKED __packed__
  222. #endif
  223. #ifndef __PACKED_STRUCT
  224. #define __PACKED_STRUCT struct __packed__
  225. #endif
  226. #ifndef __PACKED_UNION
  227. #define __PACKED_UNION union __packed__
  228. #endif
  229. #ifndef __UNALIGNED_UINT32 /* deprecated */
  230. struct __packed__ T_UINT32 { uint32_t v; };
  231. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  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. #define __ALIGNED(x) __align(x)
  251. #endif
  252. #ifndef __RESTRICT
  253. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  254. #define __RESTRICT
  255. #endif
  256. /*
  257. * COSMIC Compiler
  258. */
  259. #elif defined ( __CSMC__ )
  260. #include <cmsis_csm.h>
  261. #ifndef __ASM
  262. #define __ASM _asm
  263. #endif
  264. #ifndef __INLINE
  265. #define __INLINE inline
  266. #endif
  267. #ifndef __STATIC_INLINE
  268. #define __STATIC_INLINE static inline
  269. #endif
  270. #ifndef __NO_RETURN
  271. // NO RETURN is automatically detected hence no warning here
  272. #define __NO_RETURN
  273. #endif
  274. #ifndef __USED
  275. #warning No compiler specific solution for __USED. __USED is ignored.
  276. #define __USED
  277. #endif
  278. #ifndef __WEAK
  279. #define __WEAK __weak
  280. #endif
  281. #ifndef __PACKED
  282. #define __PACKED @packed
  283. #endif
  284. #ifndef __PACKED_STRUCT
  285. #define __PACKED_STRUCT @packed struct
  286. #endif
  287. #ifndef __PACKED_UNION
  288. #define __PACKED_UNION @packed union
  289. #endif
  290. #ifndef __UNALIGNED_UINT32 /* deprecated */
  291. @packed struct T_UINT32 { uint32_t v; };
  292. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  293. #endif
  294. #ifndef __UNALIGNED_UINT16_WRITE
  295. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  296. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  297. #endif
  298. #ifndef __UNALIGNED_UINT16_READ
  299. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  300. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  301. #endif
  302. #ifndef __UNALIGNED_UINT32_WRITE
  303. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  304. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  305. #endif
  306. #ifndef __UNALIGNED_UINT32_READ
  307. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  308. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  309. #endif
  310. #ifndef __ALIGNED
  311. #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
  312. #define __ALIGNED(x)
  313. #endif
  314. #ifndef __RESTRICT
  315. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  316. #define __RESTRICT
  317. #endif
  318. #else
  319. #error Unknown compiler.
  320. #endif
  321. #endif /* __CMSIS_COMPILER_H */