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
31 * Arm Compiler above 6.10.1 (armclang)
33 #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
34 #if __ARM_ARCH_PROFILE == 'A'
35 #include "./a-profile/cmsis_armclang_a.h"
36 #elif __ARM_ARCH_PROFILE == 'R'
37 #include "./r-profile/cmsis_armclang_r.h"
38 #elif __ARM_ARCH_PROFILE == 'M'
39 #include "./m-profile/cmsis_armclang_m.h"
41 #error "Unknown Arm architecture profile"
45 * TI Arm Clang Compiler (tiarmclang)
47 #elif defined (__ti__)
48 #if __ARM_ARCH_PROFILE == 'A'
49 #error "Core-A is not supported for this compiler"
50 #elif __ARM_ARCH_PROFILE == 'R'
51 #error "Core-R is not supported for this compiler"
52 #elif __ARM_ARCH_PROFILE == 'M'
53 #include "m-profile/cmsis_tiarmclang_m.h"
55 #error "Unknown Arm architecture profile"
62 #elif defined ( __clang__ )
63 #if __ARM_ARCH_PROFILE == 'A'
64 #include "a-profile/cmsis_clang_a.h"
65 #elif __ARM_ARCH_PROFILE == 'R'
66 #include "r-profile/cmsis_clang_r.h"
67 #elif __ARM_ARCH_PROFILE == 'M'
68 #include "m-profile/cmsis_clang_m.h"
70 #error "Unknown Arm architecture profile"
77 #elif defined ( __GNUC__ )
78 #if __ARM_ARCH_PROFILE == 'A'
79 #include "a-profile/cmsis_gcc_a.h"
80 #elif __ARM_ARCH_PROFILE == 'R'
81 #include "r-profile/cmsis_gcc_r.h"
82 #elif __ARM_ARCH_PROFILE == 'M'
83 #include "m-profile/cmsis_gcc_m.h"
85 #error "Unknown Arm architecture profile"
92 #elif defined ( __ICCARM__ )
93 #if __ARM_ARCH_PROFILE == 'A'
94 #include "a-profile/cmsis_iccarm_a.h"
95 #elif __ARM_ARCH_PROFILE == 'R'
96 #include "r-profile/cmsis_iccarm_r.h"
97 #elif __ARM_ARCH_PROFILE == 'M'
98 #include "m-profile/cmsis_iccarm_m.h"
100 #error "Unknown Arm architecture profile"
105 * TI Arm Compiler (armcl)
107 #elif defined ( __TI_ARM__ )
108 #include <cmsis_ccs.h>
114 #define __INLINE inline
116 #ifndef __STATIC_INLINE
117 #define __STATIC_INLINE static inline
119 #ifndef __STATIC_FORCEINLINE
120 #define __STATIC_FORCEINLINE __STATIC_INLINE
123 #define __NO_RETURN __attribute__((noreturn))
126 #define __USED __attribute__((used))
129 #define __WEAK __attribute__((weak))
132 #define __PACKED __attribute__((packed))
134 #ifndef __PACKED_STRUCT
135 #define __PACKED_STRUCT struct __attribute__((packed))
137 #ifndef __PACKED_UNION
138 #define __PACKED_UNION union __attribute__((packed))
140 #ifndef __UNALIGNED_UINT32 /* deprecated */
141 struct __attribute__((packed)) T_UINT32 { uint32_t v; };
142 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
144 #ifndef __UNALIGNED_UINT16_WRITE
145 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
146 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
148 #ifndef __UNALIGNED_UINT16_READ
149 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
150 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
152 #ifndef __UNALIGNED_UINT32_WRITE
153 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
154 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
156 #ifndef __UNALIGNED_UINT32_READ
157 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
158 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
161 #define __ALIGNED(x) __attribute__((aligned(x)))
164 #define __RESTRICT __restrict
166 #ifndef __COMPILER_BARRIER
167 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
168 #define __COMPILER_BARRIER() (void)0
171 #define __NO_INIT __attribute__ ((section (".bss.noinit")))
174 #define __ALIAS(x) __attribute__ ((alias(x)))
180 #elif defined ( __TASKING__ )
182 * The CMSIS functions have been implemented as intrinsics in the compiler.
183 * Please use "carm -?i" to get an up to date list of all intrinsics,
184 * Including the CMSIS ones.
191 #define __INLINE inline
193 #ifndef __STATIC_INLINE
194 #define __STATIC_INLINE static inline
196 #ifndef __STATIC_FORCEINLINE
197 #define __STATIC_FORCEINLINE __STATIC_INLINE
200 #define __NO_RETURN __attribute__((noreturn))
203 #define __USED __attribute__((used))
206 #define __WEAK __attribute__((weak))
209 #define __PACKED __packed__
211 #ifndef __PACKED_STRUCT
212 #define __PACKED_STRUCT struct __packed__
214 #ifndef __PACKED_UNION
215 #define __PACKED_UNION union __packed__
217 #ifndef __UNALIGNED_UINT32 /* deprecated */
218 struct __packed__ T_UINT32 { uint32_t v; };
219 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
221 #ifndef __UNALIGNED_UINT16_WRITE
222 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
223 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
225 #ifndef __UNALIGNED_UINT16_READ
226 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
227 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
229 #ifndef __UNALIGNED_UINT32_WRITE
230 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
231 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
233 #ifndef __UNALIGNED_UINT32_READ
234 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
235 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
238 #define __ALIGNED(x) __align(x)
241 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
244 #ifndef __COMPILER_BARRIER
245 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
246 #define __COMPILER_BARRIER() (void)0
249 #define __NO_INIT __attribute__ ((section (".bss.noinit")))
252 #define __ALIAS(x) __attribute__ ((alias(x)))
258 #elif defined ( __CSMC__ )
259 #include <cmsis_csm.h>
265 #define __INLINE inline
267 #ifndef __STATIC_INLINE
268 #define __STATIC_INLINE static inline
270 #ifndef __STATIC_FORCEINLINE
271 #define __STATIC_FORCEINLINE __STATIC_INLINE
274 // NO RETURN is automatically detected hence no warning here
278 #warning No compiler specific solution for __USED. __USED is ignored.
282 #define __WEAK __weak
285 #define __PACKED @packed
287 #ifndef __PACKED_STRUCT
288 #define __PACKED_STRUCT @packed struct
290 #ifndef __PACKED_UNION
291 #define __PACKED_UNION @packed union
293 #ifndef __UNALIGNED_UINT32 /* deprecated */
294 @packed struct T_UINT32 { uint32_t v; };
295 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
297 #ifndef __UNALIGNED_UINT16_WRITE
298 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
299 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
301 #ifndef __UNALIGNED_UINT16_READ
302 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
303 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
305 #ifndef __UNALIGNED_UINT32_WRITE
306 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
307 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
309 #ifndef __UNALIGNED_UINT32_READ
310 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
311 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
314 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
318 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
321 #ifndef __COMPILER_BARRIER
322 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
323 #define __COMPILER_BARRIER() (void)0
326 #define __NO_INIT __attribute__ ((section (".bss.noinit")))
329 #define __ALIAS(x) __attribute__ ((alias(x)))
333 #error Unknown compiler.
337 #endif /* __CMSIS_COMPILER_H */