cmsis_compiler.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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)
  124. { return 32u; }
  125. uint32_t count = 0;
  126. uint32_t mask = 0x80000000;
  127. while ((data & mask) == 0)
  128. {
  129. count += 1u;
  130. mask = mask >> 1u;
  131. }
  132. return (count);
  133. }
  134. #endif
  135. /*
  136. * TI ARM Compiler
  137. */
  138. #elif defined ( __TI_ARM__ )
  139. #include <cmsis_ccs.h>
  140. #ifndef __ASM
  141. #define __ASM __asm
  142. #endif
  143. #ifndef __INLINE
  144. #define __INLINE inline
  145. #endif
  146. #ifndef __STATIC_INLINE
  147. #define __STATIC_INLINE 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 __attribute__((packed))
  160. #endif
  161. #ifndef __PACKED_STRUCT
  162. #define __PACKED_STRUCT struct __attribute__((packed))
  163. #endif
  164. #ifndef __PACKED_UNION
  165. #define __PACKED_UNION union __attribute__((packed))
  166. #endif
  167. #ifndef __UNALIGNED_UINT32 /* deprecated */
  168. struct __attribute__((packed))T_UINT32
  169. { 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) __attribute__((aligned(x)))
  190. #endif
  191. #ifndef __RESTRICT
  192. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  193. #define __RESTRICT
  194. #endif
  195. /*
  196. * TASKING Compiler
  197. */
  198. #elif defined ( __TASKING__ )
  199. /*
  200. * The CMSIS functions have been implemented as intrinsics in the compiler.
  201. * Please use "carm -?i" to get an up to date list of all intrinsics,
  202. * Including the CMSIS ones.
  203. */
  204. #ifndef __ASM
  205. #define __ASM __asm
  206. #endif
  207. #ifndef __INLINE
  208. #define __INLINE inline
  209. #endif
  210. #ifndef __STATIC_INLINE
  211. #define __STATIC_INLINE static inline
  212. #endif
  213. #ifndef __NO_RETURN
  214. #define __NO_RETURN __attribute__((noreturn))
  215. #endif
  216. #ifndef __USED
  217. #define __USED __attribute__((used))
  218. #endif
  219. #ifndef __WEAK
  220. #define __WEAK __attribute__((weak))
  221. #endif
  222. #ifndef __PACKED
  223. #define __PACKED __packed__
  224. #endif
  225. #ifndef __PACKED_STRUCT
  226. #define __PACKED_STRUCT struct __packed__
  227. #endif
  228. #ifndef __PACKED_UNION
  229. #define __PACKED_UNION union __packed__
  230. #endif
  231. #ifndef __UNALIGNED_UINT32 /* deprecated */
  232. struct __packed__ T_UINT32 { uint32_t v; };
  233. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  234. #endif
  235. #ifndef __UNALIGNED_UINT16_WRITE
  236. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  237. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  238. #endif
  239. #ifndef __UNALIGNED_UINT16_READ
  240. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  241. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  242. #endif
  243. #ifndef __UNALIGNED_UINT32_WRITE
  244. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  245. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  246. #endif
  247. #ifndef __UNALIGNED_UINT32_READ
  248. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  249. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  250. #endif
  251. #ifndef __ALIGNED
  252. #define __ALIGNED(x) __align(x)
  253. #endif
  254. #ifndef __RESTRICT
  255. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  256. #define __RESTRICT
  257. #endif
  258. /*
  259. * COSMIC Compiler
  260. */
  261. #elif defined ( __CSMC__ )
  262. #include <cmsis_csm.h>
  263. #ifndef __ASM
  264. #define __ASM _asm
  265. #endif
  266. #ifndef __INLINE
  267. #define __INLINE inline
  268. #endif
  269. #ifndef __STATIC_INLINE
  270. #define __STATIC_INLINE static inline
  271. #endif
  272. #ifndef __NO_RETURN
  273. /* NO RETURN is automatically detected hence no warning here*/
  274. #define __NO_RETURN
  275. #endif
  276. #ifndef __USED
  277. #warning No compiler specific solution for __USED. __USED is ignored.
  278. #define __USED
  279. #endif
  280. #ifndef __WEAK
  281. #define __WEAK __weak
  282. #endif
  283. #ifndef __PACKED
  284. #define __PACKED @packed
  285. #endif
  286. #ifndef __PACKED_STRUCT
  287. #define __PACKED_STRUCT @packed struct
  288. #endif
  289. #ifndef __PACKED_UNION
  290. #define __PACKED_UNION @packed union
  291. #endif
  292. #ifndef __UNALIGNED_UINT32 /* deprecated */
  293. @packed struct T_UINT32 { uint32_t v; };
  294. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  295. #endif
  296. #ifndef __UNALIGNED_UINT16_WRITE
  297. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  298. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  299. #endif
  300. #ifndef __UNALIGNED_UINT16_READ
  301. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  302. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  303. #endif
  304. #ifndef __UNALIGNED_UINT32_WRITE
  305. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  306. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  307. #endif
  308. #ifndef __UNALIGNED_UINT32_READ
  309. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  310. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  311. #endif
  312. #ifndef __ALIGNED
  313. #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
  314. #define __ALIGNED(x)
  315. #endif
  316. #ifndef __RESTRICT
  317. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  318. #define __RESTRICT
  319. #endif
  320. #else
  321. #error Unknown compiler.
  322. #endif
  323. #endif /* __CMSIS_COMPILER_H */