cmsis_compiler.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /**************************************************************************//**
  2. * @file cmsis_compiler.h
  3. * @brief CMSIS compiler generic header file
  4. * @version V5.1.0
  5. * @date 09. October 2018
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2009-2018 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.6 LTM (armclang)
  34. */
  35. #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) && (__ARMCC_VERSION < 6100100)
  36. #include "cmsis_armclang_ltm.h"
  37. /*
  38. * Arm Compiler above 6.10.1 (armclang)
  39. */
  40. #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
  41. #include "cmsis_armclang.h"
  42. /*
  43. * GNU Compiler
  44. */
  45. #elif defined ( __GNUC__ )
  46. #include "cmsis_gcc.h"
  47. /*
  48. * IAR Compiler
  49. */
  50. #elif defined ( __ICCARM__ )
  51. #include <cmsis_iccarm.h>
  52. /*
  53. * TI Arm Compiler
  54. */
  55. #elif defined ( __TI_ARM__ )
  56. #include <cmsis_ccs.h>
  57. #ifndef __ASM
  58. #define __ASM __asm
  59. #endif
  60. #ifndef __INLINE
  61. #define __INLINE inline
  62. #endif
  63. #ifndef __STATIC_INLINE
  64. #define __STATIC_INLINE static inline
  65. #endif
  66. #ifndef __STATIC_FORCEINLINE
  67. #define __STATIC_FORCEINLINE __STATIC_INLINE
  68. #endif
  69. #ifndef __NO_RETURN
  70. #define __NO_RETURN __attribute__((noreturn))
  71. #endif
  72. #ifndef __USED
  73. #define __USED __attribute__((used))
  74. #endif
  75. #ifndef __WEAK
  76. #define __WEAK __attribute__((weak))
  77. #endif
  78. #ifndef __PACKED
  79. #define __PACKED __attribute__((packed))
  80. #endif
  81. #ifndef __PACKED_STRUCT
  82. #define __PACKED_STRUCT struct __attribute__((packed))
  83. #endif
  84. #ifndef __PACKED_UNION
  85. #define __PACKED_UNION union __attribute__((packed))
  86. #endif
  87. #ifndef __UNALIGNED_UINT32 /* deprecated */
  88. struct __attribute__((packed)) T_UINT32 { uint32_t v; };
  89. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  90. #endif
  91. #ifndef __UNALIGNED_UINT16_WRITE
  92. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  93. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
  94. #endif
  95. #ifndef __UNALIGNED_UINT16_READ
  96. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  97. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  98. #endif
  99. #ifndef __UNALIGNED_UINT32_WRITE
  100. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  101. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  102. #endif
  103. #ifndef __UNALIGNED_UINT32_READ
  104. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  105. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  106. #endif
  107. #ifndef __ALIGNED
  108. #define __ALIGNED(x) __attribute__((aligned(x)))
  109. #endif
  110. #ifndef __RESTRICT
  111. #define __RESTRICT __restrict
  112. #endif
  113. /*
  114. * TASKING Compiler
  115. */
  116. #elif defined ( __TASKING__ )
  117. /*
  118. * The CMSIS functions have been implemented as intrinsics in the compiler.
  119. * Please use "carm -?i" to get an up to date list of all intrinsics,
  120. * Including the CMSIS ones.
  121. */
  122. #ifndef __ASM
  123. #define __ASM __asm
  124. #endif
  125. #ifndef __INLINE
  126. #define __INLINE inline
  127. #endif
  128. #ifndef __STATIC_INLINE
  129. #define __STATIC_INLINE static inline
  130. #endif
  131. #ifndef __STATIC_FORCEINLINE
  132. #define __STATIC_FORCEINLINE __STATIC_INLINE
  133. #endif
  134. #ifndef __NO_RETURN
  135. #define __NO_RETURN __attribute__((noreturn))
  136. #endif
  137. #ifndef __USED
  138. #define __USED __attribute__((used))
  139. #endif
  140. #ifndef __WEAK
  141. #define __WEAK __attribute__((weak))
  142. #endif
  143. #ifndef __PACKED
  144. #define __PACKED __packed__
  145. #endif
  146. #ifndef __PACKED_STRUCT
  147. #define __PACKED_STRUCT struct __packed__
  148. #endif
  149. #ifndef __PACKED_UNION
  150. #define __PACKED_UNION union __packed__
  151. #endif
  152. #ifndef __UNALIGNED_UINT32 /* deprecated */
  153. struct __packed__ T_UINT32 { uint32_t v; };
  154. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  155. #endif
  156. #ifndef __UNALIGNED_UINT16_WRITE
  157. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  158. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  159. #endif
  160. #ifndef __UNALIGNED_UINT16_READ
  161. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  162. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  163. #endif
  164. #ifndef __UNALIGNED_UINT32_WRITE
  165. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  166. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  167. #endif
  168. #ifndef __UNALIGNED_UINT32_READ
  169. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  170. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  171. #endif
  172. #ifndef __ALIGNED
  173. #define __ALIGNED(x) __align(x)
  174. #endif
  175. #ifndef __RESTRICT
  176. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  177. #define __RESTRICT
  178. #endif
  179. /*
  180. * COSMIC Compiler
  181. */
  182. #elif defined ( __CSMC__ )
  183. #include <cmsis_csm.h>
  184. #ifndef __ASM
  185. #define __ASM _asm
  186. #endif
  187. #ifndef __INLINE
  188. #define __INLINE inline
  189. #endif
  190. #ifndef __STATIC_INLINE
  191. #define __STATIC_INLINE static inline
  192. #endif
  193. #ifndef __STATIC_FORCEINLINE
  194. #define __STATIC_FORCEINLINE __STATIC_INLINE
  195. #endif
  196. #ifndef __NO_RETURN
  197. // NO RETURN is automatically detected hence no warning here
  198. #define __NO_RETURN
  199. #endif
  200. #ifndef __USED
  201. #warning No compiler specific solution for __USED. __USED is ignored.
  202. #define __USED
  203. #endif
  204. #ifndef __WEAK
  205. #define __WEAK __weak
  206. #endif
  207. #ifndef __PACKED
  208. #define __PACKED @packed
  209. #endif
  210. #ifndef __PACKED_STRUCT
  211. #define __PACKED_STRUCT @packed struct
  212. #endif
  213. #ifndef __PACKED_UNION
  214. #define __PACKED_UNION @packed union
  215. #endif
  216. #ifndef __UNALIGNED_UINT32 /* deprecated */
  217. @packed struct T_UINT32 { uint32_t v; };
  218. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  219. #endif
  220. #ifndef __UNALIGNED_UINT16_WRITE
  221. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  222. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  223. #endif
  224. #ifndef __UNALIGNED_UINT16_READ
  225. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  226. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  227. #endif
  228. #ifndef __UNALIGNED_UINT32_WRITE
  229. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  230. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  231. #endif
  232. #ifndef __UNALIGNED_UINT32_READ
  233. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  234. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  235. #endif
  236. #ifndef __ALIGNED
  237. #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
  238. #define __ALIGNED(x)
  239. #endif
  240. #ifndef __RESTRICT
  241. #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
  242. #define __RESTRICT
  243. #endif
  244. #else
  245. #error Unknown compiler.
  246. #endif
  247. #endif /* __CMSIS_COMPILER_H */