cmsis_compiler.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /**************************************************************************//**
  2. * @file cmsis_compiler.h
  3. * @brief CMSIS compiler specific macros, functions, instructions
  4. * @version V1.00
  5. * @date 22. Feb 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. /*
  77. * TI ARM Compiler
  78. */
  79. #elif defined ( __TI_ARM__ )
  80. #include <cmsis_ccs.h>
  81. #ifndef __ASM
  82. #define __ASM __asm
  83. #endif
  84. #ifndef __INLINE
  85. #define __INLINE inline
  86. #endif
  87. #ifndef __STATIC_INLINE
  88. #define __STATIC_INLINE static inline
  89. #endif
  90. #ifndef __NO_RETURN
  91. #define __NO_RETURN __attribute__((noreturn))
  92. #endif
  93. #ifndef __USED
  94. #define __USED __attribute__((used))
  95. #endif
  96. #ifndef __WEAK
  97. #define __WEAK __attribute__((weak))
  98. #endif
  99. #ifndef __UNALIGNED_UINT32
  100. struct __attribute__((packed)) T_UINT32 { uint32_t v; };
  101. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  102. #endif
  103. #ifndef __ALIGNED
  104. #define __ALIGNED(x) __attribute__((aligned(x)))
  105. #endif
  106. #ifndef __PACKED
  107. #define __PACKED __attribute__((packed))
  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 __NO_RETURN
  128. #define __NO_RETURN __attribute__((noreturn))
  129. #endif
  130. #ifndef __USED
  131. #define __USED __attribute__((used))
  132. #endif
  133. #ifndef __WEAK
  134. #define __WEAK __attribute__((weak))
  135. #endif
  136. #ifndef __UNALIGNED_UINT32
  137. struct __packed__ T_UINT32 { uint32_t v; };
  138. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  139. #endif
  140. #ifndef __ALIGNED
  141. #define __ALIGNED(x) __align(x)
  142. #endif
  143. #ifndef __PACKED
  144. #define __PACKED __packed__
  145. #endif
  146. /*
  147. * COSMIC Compiler
  148. */
  149. #elif defined ( __CSMC__ )
  150. #include <cmsis_csm.h>
  151. #ifndef __ASM
  152. #define __ASM _asm
  153. #endif
  154. #ifndef __INLINE
  155. #define __INLINE inline
  156. #endif
  157. #ifndef __STATIC_INLINE
  158. #define __STATIC_INLINE static inline
  159. #endif
  160. #ifndef __NO_RETURN
  161. // NO RETURN is automatically detected hence no warning here
  162. #define __NO_RETURN
  163. #endif
  164. #ifndef __USED
  165. #warning No compiler specific solution for __USED. __USED is ignored.
  166. #define __USED
  167. #endif
  168. #ifndef __WEAK
  169. #define __WEAK __weak
  170. #endif
  171. #ifndef __UNALIGNED_UINT32
  172. @packed struct T_UINT32 { uint32_t v; };
  173. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  174. #endif
  175. #ifndef __ALIGNED
  176. #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
  177. #define __ALIGNED(x)
  178. #endif
  179. #ifndef __PACKED
  180. #define __PACKED @packed
  181. #endif
  182. #else
  183. #error Unknown compiler.
  184. #endif
  185. #endif /* __CMSIS_COMPILER_H */