You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmsis_compiler.h 8.5KB

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