cmsis_compiler.h 8.2 KB

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