cmsis_compiler.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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
  90. {
  91. uint32_t v;
  92. };
  93. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  94. #endif
  95. #ifndef __UNALIGNED_UINT16_WRITE
  96. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  97. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  98. #endif
  99. #ifndef __UNALIGNED_UINT16_READ
  100. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  101. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  102. #endif
  103. #ifndef __UNALIGNED_UINT32_WRITE
  104. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  105. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  106. #endif
  107. #ifndef __UNALIGNED_UINT32_READ
  108. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  109. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  110. #endif
  111. #ifndef __ALIGNED
  112. //#warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
  113. #define __ALIGNED(x)
  114. #endif
  115. #ifndef __RESTRICT
  116. //#warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  117. #define __RESTRICT
  118. #endif
  119. // Workaround for missing __CLZ intrinsic in
  120. // various versions of the IAR compilers.
  121. // __IAR_FEATURE_CLZ__ should be defined by
  122. // the compiler that supports __CLZ internally.
  123. #if (defined (__ARM_ARCH_6M__)) && (__ARM_ARCH_6M__ == 1) && (!defined (__IAR_FEATURE_CLZ__))
  124. __STATIC_INLINE uint32_t __CLZ(uint32_t data)
  125. {
  126. if (data == 0u)
  127. {
  128. return 32u;
  129. }
  130. uint32_t count = 0;
  131. uint32_t mask = 0x80000000;
  132. while ((data & mask) == 0)
  133. {
  134. count += 1u;
  135. mask = mask >> 1u;
  136. }
  137. return (count);
  138. }
  139. #endif
  140. /*
  141. * TI ARM Compiler
  142. */
  143. #elif defined ( __TI_ARM__ )
  144. #include <cmsis_ccs.h>
  145. #ifndef __ASM
  146. #define __ASM __asm
  147. #endif
  148. #ifndef __INLINE
  149. #define __INLINE inline
  150. #endif
  151. #ifndef __STATIC_INLINE
  152. #define __STATIC_INLINE static inline
  153. #endif
  154. #ifndef __NO_RETURN
  155. #define __NO_RETURN __attribute__((noreturn))
  156. #endif
  157. #ifndef __USED
  158. #define __USED __attribute__((used))
  159. #endif
  160. #ifndef __WEAK
  161. #define __WEAK __attribute__((weak))
  162. #endif
  163. #ifndef __PACKED
  164. #define __PACKED __attribute__((packed))
  165. #endif
  166. #ifndef __PACKED_STRUCT
  167. #define __PACKED_STRUCT struct __attribute__((packed))
  168. #endif
  169. #ifndef __PACKED_UNION
  170. #define __PACKED_UNION union __attribute__((packed))
  171. #endif
  172. #ifndef __UNALIGNED_UINT32 /* deprecated */
  173. struct __attribute__((packed)) T_UINT32
  174. {
  175. uint32_t v;
  176. };
  177. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  178. #endif
  179. #ifndef __UNALIGNED_UINT16_WRITE
  180. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  181. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
  182. #endif
  183. #ifndef __UNALIGNED_UINT16_READ
  184. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  185. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  186. #endif
  187. #ifndef __UNALIGNED_UINT32_WRITE
  188. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  189. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  190. #endif
  191. #ifndef __UNALIGNED_UINT32_READ
  192. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  193. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  194. #endif
  195. #ifndef __ALIGNED
  196. #define __ALIGNED(x) __attribute__((aligned(x)))
  197. #endif
  198. #ifndef __RESTRICT
  199. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  200. #define __RESTRICT
  201. #endif
  202. /*
  203. * TASKING Compiler
  204. */
  205. #elif defined ( __TASKING__ )
  206. /*
  207. * The CMSIS functions have been implemented as intrinsics in the compiler.
  208. * Please use "carm -?i" to get an up to date list of all intrinsics,
  209. * Including the CMSIS ones.
  210. */
  211. #ifndef __ASM
  212. #define __ASM __asm
  213. #endif
  214. #ifndef __INLINE
  215. #define __INLINE inline
  216. #endif
  217. #ifndef __STATIC_INLINE
  218. #define __STATIC_INLINE static inline
  219. #endif
  220. #ifndef __NO_RETURN
  221. #define __NO_RETURN __attribute__((noreturn))
  222. #endif
  223. #ifndef __USED
  224. #define __USED __attribute__((used))
  225. #endif
  226. #ifndef __WEAK
  227. #define __WEAK __attribute__((weak))
  228. #endif
  229. #ifndef __PACKED
  230. #define __PACKED __packed__
  231. #endif
  232. #ifndef __PACKED_STRUCT
  233. #define __PACKED_STRUCT struct __packed__
  234. #endif
  235. #ifndef __PACKED_UNION
  236. #define __PACKED_UNION union __packed__
  237. #endif
  238. #ifndef __UNALIGNED_UINT32 /* deprecated */
  239. struct __packed__ T_UINT32
  240. {
  241. uint32_t v;
  242. };
  243. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  244. #endif
  245. #ifndef __UNALIGNED_UINT16_WRITE
  246. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  247. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  248. #endif
  249. #ifndef __UNALIGNED_UINT16_READ
  250. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  251. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  252. #endif
  253. #ifndef __UNALIGNED_UINT32_WRITE
  254. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  255. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  256. #endif
  257. #ifndef __UNALIGNED_UINT32_READ
  258. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  259. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  260. #endif
  261. #ifndef __ALIGNED
  262. #define __ALIGNED(x) __align(x)
  263. #endif
  264. #ifndef __RESTRICT
  265. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  266. #define __RESTRICT
  267. #endif
  268. /*
  269. * COSMIC Compiler
  270. */
  271. #elif defined ( __CSMC__ )
  272. #include <cmsis_csm.h>
  273. #ifndef __ASM
  274. #define __ASM _asm
  275. #endif
  276. #ifndef __INLINE
  277. #define __INLINE inline
  278. #endif
  279. #ifndef __STATIC_INLINE
  280. #define __STATIC_INLINE static inline
  281. #endif
  282. #ifndef __NO_RETURN
  283. // NO RETURN is automatically detected hence no warning here
  284. #define __NO_RETURN
  285. #endif
  286. #ifndef __USED
  287. #warning No compiler specific solution for __USED. __USED is ignored.
  288. #define __USED
  289. #endif
  290. #ifndef __WEAK
  291. #define __WEAK __weak
  292. #endif
  293. #ifndef __PACKED
  294. #define __PACKED @packed
  295. #endif
  296. #ifndef __PACKED_STRUCT
  297. #define __PACKED_STRUCT @packed struct
  298. #endif
  299. #ifndef __PACKED_UNION
  300. #define __PACKED_UNION @packed union
  301. #endif
  302. #ifndef __UNALIGNED_UINT32 /* deprecated */
  303. @packed struct T_UINT32
  304. {
  305. uint32_t v;
  306. };
  307. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  308. #endif
  309. #ifndef __UNALIGNED_UINT16_WRITE
  310. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  311. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  312. #endif
  313. #ifndef __UNALIGNED_UINT16_READ
  314. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  315. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  316. #endif
  317. #ifndef __UNALIGNED_UINT32_WRITE
  318. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  319. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  320. #endif
  321. #ifndef __UNALIGNED_UINT32_READ
  322. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  323. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  324. #endif
  325. #ifndef __ALIGNED
  326. #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
  327. #define __ALIGNED(x)
  328. #endif
  329. #ifndef __RESTRICT
  330. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  331. #define __RESTRICT
  332. #endif
  333. #else
  334. #error Unknown compiler.
  335. #endif
  336. #endif /* __CMSIS_COMPILER_H */