1 /**************************************************************************//**
2 * @file cmsis_compiler.h
3 * @brief CMSIS compiler generic header file
6 ******************************************************************************/
8 * Copyright (c) 2009-2023 Arm Limited. All rights reserved.
10 * SPDX-License-Identifier: Apache-2.0
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
16 * www.apache.org/licenses/LICENSE-2.0
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.
25 #ifndef __CMSIS_COMPILER_H
26 #define __CMSIS_COMPILER_H
33 #if defined ( __CC_ARM )
34 #include "cmsis_armcc.h"
38 * Arm Compiler 6.6 LTM (armclang)
40 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) && (__ARMCC_VERSION < 6100100)
41 #include "cmsis_armclang_ltm.h"
44 * Arm Compiler above 6.10.1 (armclang)
46 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
47 #include "cmsis_armclang.h"
50 * TI Arm Clang Compiler (tiarmclang)
52 #elif defined (__ti__)
53 #include "cmsis_tiarmclang.h"
59 #elif defined ( __clang__ )
60 #include "cmsis_clang.h"
66 #elif defined ( __GNUC__ )
67 #include "cmsis_gcc.h"
73 #elif defined ( __ICCARM__ )
74 #include <cmsis_iccarm.h>
78 * TI Arm Compiler (armcl)
80 #elif defined ( __TI_ARM__ )
81 #include <cmsis_ccs.h>
87 #define __INLINE inline
89 #ifndef __STATIC_INLINE
90 #define __STATIC_INLINE static inline
92 #ifndef __STATIC_FORCEINLINE
93 #define __STATIC_FORCEINLINE __STATIC_INLINE
96 #define __NO_RETURN __attribute__((noreturn))
99 #define __USED __attribute__((used))
102 #define __WEAK __attribute__((weak))
105 #define __PACKED __attribute__((packed))
107 #ifndef __PACKED_STRUCT
108 #define __PACKED_STRUCT struct __attribute__((packed))
110 #ifndef __PACKED_UNION
111 #define __PACKED_UNION union __attribute__((packed))
113 #ifndef __UNALIGNED_UINT32 /* deprecated */
114 struct __attribute__((packed)) T_UINT32 { uint32_t v; };
115 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
117 #ifndef __UNALIGNED_UINT16_WRITE
118 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
119 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
121 #ifndef __UNALIGNED_UINT16_READ
122 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
123 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
125 #ifndef __UNALIGNED_UINT32_WRITE
126 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
127 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
129 #ifndef __UNALIGNED_UINT32_READ
130 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
131 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
134 #define __ALIGNED(x) __attribute__((aligned(x)))
137 #define __RESTRICT __restrict
139 #ifndef __COMPILER_BARRIER
140 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
141 #define __COMPILER_BARRIER() (void)0
144 #define __NO_INIT __attribute__ ((section (".bss.noinit")))
147 #define __ALIAS(x) __attribute__ ((alias(x)))
153 #elif defined ( __TASKING__ )
155 * The CMSIS functions have been implemented as intrinsics in the compiler.
156 * Please use "carm -?i" to get an up to date list of all intrinsics,
157 * Including the CMSIS ones.
164 #define __INLINE inline
166 #ifndef __STATIC_INLINE
167 #define __STATIC_INLINE static inline
169 #ifndef __STATIC_FORCEINLINE
170 #define __STATIC_FORCEINLINE __STATIC_INLINE
173 #define __NO_RETURN __attribute__((noreturn))
176 #define __USED __attribute__((used))
179 #define __WEAK __attribute__((weak))
182 #define __PACKED __packed__
184 #ifndef __PACKED_STRUCT
185 #define __PACKED_STRUCT struct __packed__
187 #ifndef __PACKED_UNION
188 #define __PACKED_UNION union __packed__
190 #ifndef __UNALIGNED_UINT32 /* deprecated */
191 struct __packed__ T_UINT32 { uint32_t v; };
192 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
194 #ifndef __UNALIGNED_UINT16_WRITE
195 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
196 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
198 #ifndef __UNALIGNED_UINT16_READ
199 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
200 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
202 #ifndef __UNALIGNED_UINT32_WRITE
203 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
204 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
206 #ifndef __UNALIGNED_UINT32_READ
207 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
208 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
211 #define __ALIGNED(x) __align(x)
214 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
217 #ifndef __COMPILER_BARRIER
218 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
219 #define __COMPILER_BARRIER() (void)0
222 #define __NO_INIT __attribute__ ((section (".bss.noinit")))
225 #define __ALIAS(x) __attribute__ ((alias(x)))
231 #elif defined ( __CSMC__ )
232 #include <cmsis_csm.h>
238 #define __INLINE inline
240 #ifndef __STATIC_INLINE
241 #define __STATIC_INLINE static inline
243 #ifndef __STATIC_FORCEINLINE
244 #define __STATIC_FORCEINLINE __STATIC_INLINE
247 // NO RETURN is automatically detected hence no warning here
251 #warning No compiler specific solution for __USED. __USED is ignored.
255 #define __WEAK __weak
258 #define __PACKED @packed
260 #ifndef __PACKED_STRUCT
261 #define __PACKED_STRUCT @packed struct
263 #ifndef __PACKED_UNION
264 #define __PACKED_UNION @packed union
266 #ifndef __UNALIGNED_UINT32 /* deprecated */
267 @packed struct T_UINT32 { uint32_t v; };
268 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
270 #ifndef __UNALIGNED_UINT16_WRITE
271 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
272 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
274 #ifndef __UNALIGNED_UINT16_READ
275 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
276 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
278 #ifndef __UNALIGNED_UINT32_WRITE
279 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
280 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
282 #ifndef __UNALIGNED_UINT32_READ
283 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
284 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
287 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
291 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
294 #ifndef __COMPILER_BARRIER
295 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
296 #define __COMPILER_BARRIER() (void)0
299 #define __NO_INIT __attribute__ ((section (".bss.noinit")))
302 #define __ALIAS(x) __attribute__ ((alias(x)))
306 #error Unknown compiler.
310 #endif /* __CMSIS_COMPILER_H */