2 * Copyright (c) 2009-2023 Arm Limited. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 * CMSIS Compiler Generic Header File
23 #ifndef __CMSIS_COMPILER_H
24 #define __CMSIS_COMPILER_H
29 * Arm Compiler above 6.10.1 (armclang)
31 #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
32 #if __ARM_ARCH_PROFILE == 'A'
33 #include "./a-profile/cmsis_armclang_a.h"
34 #elif __ARM_ARCH_PROFILE == 'R'
35 #include "./r-profile/cmsis_armclang_r.h"
36 #elif __ARM_ARCH_PROFILE == 'M'
37 #include "./m-profile/cmsis_armclang_m.h"
39 #error "Unknown Arm architecture profile"
43 * TI Arm Clang Compiler (tiarmclang)
45 #elif defined (__ti__)
46 #if __ARM_ARCH_PROFILE == 'A'
47 #error "Core-A is not supported for this compiler"
48 #elif __ARM_ARCH_PROFILE == 'R'
49 #error "Core-R is not supported for this compiler"
50 #elif __ARM_ARCH_PROFILE == 'M'
51 #include "m-profile/cmsis_tiarmclang_m.h"
53 #error "Unknown Arm architecture profile"
60 #elif defined ( __clang__ )
61 #if __ARM_ARCH_PROFILE == 'A'
62 #include "a-profile/cmsis_clang_a.h"
63 #elif __ARM_ARCH_PROFILE == 'R'
64 #include "r-profile/cmsis_clang_r.h"
65 #elif __ARM_ARCH_PROFILE == 'M'
66 #include "m-profile/cmsis_clang_m.h"
68 #error "Unknown Arm architecture profile"
75 #elif defined ( __GNUC__ )
76 #if __ARM_ARCH_PROFILE == 'A'
77 #include "a-profile/cmsis_gcc_a.h"
78 #elif __ARM_ARCH_PROFILE == 'R'
79 #include "r-profile/cmsis_gcc_r.h"
80 #elif __ARM_ARCH_PROFILE == 'M'
81 #include "m-profile/cmsis_gcc_m.h"
83 #error "Unknown Arm architecture profile"
90 #elif defined ( __ICCARM__ )
91 #if __ARM_ARCH_PROFILE == 'A'
92 #include "a-profile/cmsis_iccarm_a.h"
93 #elif __ARM_ARCH_PROFILE == 'R'
94 #include "r-profile/cmsis_iccarm_r.h"
95 #elif __ARM_ARCH_PROFILE == 'M'
96 #include "m-profile/cmsis_iccarm_m.h"
98 #error "Unknown Arm architecture profile"
103 * TI Arm Compiler (armcl)
105 #elif defined ( __TI_ARM__ )
106 #include <cmsis_ccs.h>
112 #define __INLINE inline
114 #ifndef __STATIC_INLINE
115 #define __STATIC_INLINE static inline
117 #ifndef __STATIC_FORCEINLINE
118 #define __STATIC_FORCEINLINE __STATIC_INLINE
121 #define __NO_RETURN __attribute__((noreturn))
124 #define __USED __attribute__((used))
127 #define __WEAK __attribute__((weak))
130 #define __PACKED __attribute__((packed))
132 #ifndef __PACKED_STRUCT
133 #define __PACKED_STRUCT struct __attribute__((packed))
135 #ifndef __PACKED_UNION
136 #define __PACKED_UNION union __attribute__((packed))
138 #ifndef __UNALIGNED_UINT16_WRITE
139 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
140 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
142 #ifndef __UNALIGNED_UINT16_READ
143 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
144 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
146 #ifndef __UNALIGNED_UINT32_WRITE
147 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
148 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
150 #ifndef __UNALIGNED_UINT32_READ
151 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
152 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
155 #define __ALIGNED(x) __attribute__((aligned(x)))
158 #define __RESTRICT __restrict
160 #ifndef __COMPILER_BARRIER
161 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
162 #define __COMPILER_BARRIER() (void)0
165 #define __NO_INIT __attribute__ ((section (".noinit")))
168 #define __ALIAS(x) __attribute__ ((alias(x)))
174 #elif defined ( __TASKING__ )
176 * The CMSIS functions have been implemented as intrinsics in the compiler.
177 * Please use "carm -?i" to get an up to date list of all intrinsics,
178 * Including the CMSIS ones.
185 #define __INLINE inline
187 #ifndef __STATIC_INLINE
188 #define __STATIC_INLINE static inline
190 #ifndef __STATIC_FORCEINLINE
191 #define __STATIC_FORCEINLINE __STATIC_INLINE
194 #define __NO_RETURN __attribute__((noreturn))
197 #define __USED __attribute__((used))
200 #define __WEAK __attribute__((weak))
203 #define __PACKED __packed__
205 #ifndef __PACKED_STRUCT
206 #define __PACKED_STRUCT struct __packed__
208 #ifndef __PACKED_UNION
209 #define __PACKED_UNION union __packed__
211 #ifndef __UNALIGNED_UINT16_WRITE
212 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
213 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
215 #ifndef __UNALIGNED_UINT16_READ
216 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
217 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
219 #ifndef __UNALIGNED_UINT32_WRITE
220 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
221 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
223 #ifndef __UNALIGNED_UINT32_READ
224 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
225 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
228 #define __ALIGNED(x) __align(x)
231 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
234 #ifndef __COMPILER_BARRIER
235 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
236 #define __COMPILER_BARRIER() (void)0
239 #define __NO_INIT __attribute__ ((section (".noinit")))
242 #define __ALIAS(x) __attribute__ ((alias(x)))
248 #elif defined ( __CSMC__ )
249 #include <cmsis_csm.h>
255 #define __INLINE inline
257 #ifndef __STATIC_INLINE
258 #define __STATIC_INLINE static inline
260 #ifndef __STATIC_FORCEINLINE
261 #define __STATIC_FORCEINLINE __STATIC_INLINE
264 // NO RETURN is automatically detected hence no warning here
268 #warning No compiler specific solution for __USED. __USED is ignored.
272 #define __WEAK __weak
275 #define __PACKED @packed
277 #ifndef __PACKED_STRUCT
278 #define __PACKED_STRUCT @packed struct
280 #ifndef __PACKED_UNION
281 #define __PACKED_UNION @packed union
283 #ifndef __UNALIGNED_UINT16_WRITE
284 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
285 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
287 #ifndef __UNALIGNED_UINT16_READ
288 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
289 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
291 #ifndef __UNALIGNED_UINT32_WRITE
292 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
293 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
295 #ifndef __UNALIGNED_UINT32_READ
296 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
297 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
300 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
304 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
307 #ifndef __COMPILER_BARRIER
308 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
309 #define __COMPILER_BARRIER() (void)0
312 #define __NO_INIT __attribute__ ((section (".noinit")))
315 #define __ALIAS(x) __attribute__ ((alias(x)))
319 #error Unknown compiler.
323 #endif /* __CMSIS_COMPILER_H */