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 #include "cmsis_armclang.h"
35 * TI Arm Clang Compiler (tiarmclang)
37 #elif defined (__ti__)
38 #include "cmsis_tiarmclang.h"
44 #elif defined ( __clang__ )
45 #include "cmsis_clang.h"
51 #elif defined ( __GNUC__ )
52 #include "cmsis_gcc.h"
58 #elif defined ( __ICCARM__ )
59 #if __ARM_ARCH_PROFILE == 'A'
60 #include "a-profile/cmsis_iccarm_a.h"
61 #elif __ARM_ARCH_PROFILE == 'R'
62 #include "r-profile/cmsis_iccarm_r.h"
63 #elif __ARM_ARCH_PROFILE == 'M'
64 #include "m-profile/cmsis_iccarm_m.h"
66 #error "Unknown Arm architecture profile"
71 * TI Arm Compiler (armcl)
73 #elif defined ( __TI_ARM__ )
74 #include <cmsis_ccs.h>
80 #define __INLINE inline
82 #ifndef __STATIC_INLINE
83 #define __STATIC_INLINE static inline
85 #ifndef __STATIC_FORCEINLINE
86 #define __STATIC_FORCEINLINE __STATIC_INLINE
89 #define __NO_RETURN __attribute__((noreturn))
92 #define __USED __attribute__((used))
95 #define __WEAK __attribute__((weak))
98 #define __PACKED __attribute__((packed))
100 #ifndef __PACKED_STRUCT
101 #define __PACKED_STRUCT struct __attribute__((packed))
103 #ifndef __PACKED_UNION
104 #define __PACKED_UNION union __attribute__((packed))
106 #ifndef __UNALIGNED_UINT16_WRITE
107 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
108 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
110 #ifndef __UNALIGNED_UINT16_READ
111 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
112 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
114 #ifndef __UNALIGNED_UINT32_WRITE
115 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
116 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
118 #ifndef __UNALIGNED_UINT32_READ
119 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
120 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
123 #define __ALIGNED(x) __attribute__((aligned(x)))
126 #define __RESTRICT __restrict
128 #ifndef __COMPILER_BARRIER
129 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
130 #define __COMPILER_BARRIER() (void)0
133 #define __NO_INIT __attribute__ ((section (".noinit")))
136 #define __ALIAS(x) __attribute__ ((alias(x)))
142 #elif defined ( __TASKING__ )
144 * The CMSIS functions have been implemented as intrinsics in the compiler.
145 * Please use "carm -?i" to get an up to date list of all intrinsics,
146 * Including the CMSIS ones.
153 #define __INLINE inline
155 #ifndef __STATIC_INLINE
156 #define __STATIC_INLINE static inline
158 #ifndef __STATIC_FORCEINLINE
159 #define __STATIC_FORCEINLINE __STATIC_INLINE
162 #define __NO_RETURN __attribute__((noreturn))
165 #define __USED __attribute__((used))
168 #define __WEAK __attribute__((weak))
171 #define __PACKED __packed__
173 #ifndef __PACKED_STRUCT
174 #define __PACKED_STRUCT struct __packed__
176 #ifndef __PACKED_UNION
177 #define __PACKED_UNION union __packed__
179 #ifndef __UNALIGNED_UINT16_WRITE
180 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
181 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
183 #ifndef __UNALIGNED_UINT16_READ
184 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
185 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
187 #ifndef __UNALIGNED_UINT32_WRITE
188 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
189 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
191 #ifndef __UNALIGNED_UINT32_READ
192 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
193 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
196 #define __ALIGNED(x) __align(x)
199 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
202 #ifndef __COMPILER_BARRIER
203 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
204 #define __COMPILER_BARRIER() (void)0
207 #define __NO_INIT __attribute__ ((section (".noinit")))
210 #define __ALIAS(x) __attribute__ ((alias(x)))
216 #elif defined ( __CSMC__ )
217 #include <cmsis_csm.h>
223 #define __INLINE inline
225 #ifndef __STATIC_INLINE
226 #define __STATIC_INLINE static inline
228 #ifndef __STATIC_FORCEINLINE
229 #define __STATIC_FORCEINLINE __STATIC_INLINE
232 // NO RETURN is automatically detected hence no warning here
236 #warning No compiler specific solution for __USED. __USED is ignored.
240 #define __WEAK __weak
243 #define __PACKED @packed
245 #ifndef __PACKED_STRUCT
246 #define __PACKED_STRUCT @packed struct
248 #ifndef __PACKED_UNION
249 #define __PACKED_UNION @packed union
251 #ifndef __UNALIGNED_UINT16_WRITE
252 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
253 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
255 #ifndef __UNALIGNED_UINT16_READ
256 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
257 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
259 #ifndef __UNALIGNED_UINT32_WRITE
260 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
261 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
263 #ifndef __UNALIGNED_UINT32_READ
264 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
265 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
268 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
272 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
275 #ifndef __COMPILER_BARRIER
276 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
277 #define __COMPILER_BARRIER() (void)0
280 #define __NO_INIT __attribute__ ((section (".noinit")))
283 #define __ALIAS(x) __attribute__ ((alias(x)))
287 #error Unknown compiler.
291 #endif /* __CMSIS_COMPILER_H */