cmsis_compiler.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**************************************************************************//**
  2. * @file cmsis_compiler.h
  3. * @brief CMSIS compiler generic header file
  4. * @version V5.0.1
  5. * @date 30. January 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. #ifndef __NO_RETURN
  57. #define __NO_RETURN __noreturn
  58. #endif
  59. #ifndef __USED
  60. #define __USED __root
  61. #endif
  62. #ifndef __WEAK
  63. #define __WEAK __weak
  64. #endif
  65. #ifndef __UNALIGNED_UINT32
  66. __packed struct T_UINT32 { uint32_t v; };
  67. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  68. #endif
  69. #ifndef __ALIGNED
  70. #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
  71. #define __ALIGNED(x)
  72. #endif
  73. #ifndef __PACKED
  74. #define __PACKED __packed
  75. #endif
  76. #ifndef __PACKED_STRUCT
  77. #define __PACKED_STRUCT __packed struct
  78. #endif
  79. /*
  80. * TI ARM Compiler
  81. */
  82. #elif defined ( __TI_ARM__ )
  83. #include <cmsis_ccs.h>
  84. #ifndef __ASM
  85. #define __ASM __asm
  86. #endif
  87. #ifndef __INLINE
  88. #define __INLINE inline
  89. #endif
  90. #ifndef __STATIC_INLINE
  91. #define __STATIC_INLINE static inline
  92. #endif
  93. #ifndef __NO_RETURN
  94. #define __NO_RETURN __attribute__((noreturn))
  95. #endif
  96. #ifndef __USED
  97. #define __USED __attribute__((used))
  98. #endif
  99. #ifndef __WEAK
  100. #define __WEAK __attribute__((weak))
  101. #endif
  102. #ifndef __UNALIGNED_UINT32
  103. struct __attribute__((packed)) T_UINT32 { uint32_t v; };
  104. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  105. #endif
  106. #ifndef __ALIGNED
  107. #define __ALIGNED(x) __attribute__((aligned(x)))
  108. #endif
  109. #ifndef __PACKED
  110. #define __PACKED __attribute__((packed))
  111. #endif
  112. #ifndef __PACKED_STRUCT
  113. #define __PACKED_STRUCT struct __attribute__((packed))
  114. #endif
  115. /*
  116. * TASKING Compiler
  117. */
  118. #elif defined ( __TASKING__ )
  119. /*
  120. * The CMSIS functions have been implemented as intrinsics in the compiler.
  121. * Please use "carm -?i" to get an up to date list of all intrinsics,
  122. * Including the CMSIS ones.
  123. */
  124. #ifndef __ASM
  125. #define __ASM __asm
  126. #endif
  127. #ifndef __INLINE
  128. #define __INLINE inline
  129. #endif
  130. #ifndef __STATIC_INLINE
  131. #define __STATIC_INLINE 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 __UNALIGNED_UINT32
  143. struct __packed__ T_UINT32 { uint32_t v; };
  144. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  145. #endif
  146. #ifndef __ALIGNED
  147. #define __ALIGNED(x) __align(x)
  148. #endif
  149. #ifndef __PACKED
  150. #define __PACKED __packed__
  151. #endif
  152. #ifndef __PACKED_STRUCT
  153. #define __PACKED_STRUCT struct __packed__
  154. #endif
  155. /*
  156. * COSMIC Compiler
  157. */
  158. #elif defined ( __CSMC__ )
  159. #include <cmsis_csm.h>
  160. #ifndef __ASM
  161. #define __ASM _asm
  162. #endif
  163. #ifndef __INLINE
  164. #define __INLINE inline
  165. #endif
  166. #ifndef __STATIC_INLINE
  167. #define __STATIC_INLINE static inline
  168. #endif
  169. #ifndef __NO_RETURN
  170. // NO RETURN is automatically detected hence no warning here
  171. #define __NO_RETURN
  172. #endif
  173. #ifndef __USED
  174. #warning No compiler specific solution for __USED. __USED is ignored.
  175. #define __USED
  176. #endif
  177. #ifndef __WEAK
  178. #define __WEAK __weak
  179. #endif
  180. #ifndef __UNALIGNED_UINT32
  181. @packed struct T_UINT32 { uint32_t v; };
  182. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  183. #endif
  184. #ifndef __ALIGNED
  185. #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
  186. #define __ALIGNED(x)
  187. #endif
  188. #ifndef __PACKED
  189. #define __PACKED @packed
  190. #endif
  191. #ifndef __PACKED_STRUCT
  192. #define __PACKED_STRUCT @packed struct
  193. #endif
  194. #else
  195. #error Unknown compiler.
  196. #endif
  197. #endif /* __CMSIS_COMPILER_H */