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 #include "cmsis_iccarm.h"
63 * TI Arm Compiler (armcl)
65 #elif defined ( __TI_ARM__ )
66 #include <cmsis_ccs.h>
72 #define __INLINE inline
74 #ifndef __STATIC_INLINE
75 #define __STATIC_INLINE static inline
77 #ifndef __STATIC_FORCEINLINE
78 #define __STATIC_FORCEINLINE __STATIC_INLINE
81 #define __NO_RETURN __attribute__((noreturn))
84 #define __USED __attribute__((used))
87 #define __WEAK __attribute__((weak))
90 #define __PACKED __attribute__((packed))
92 #ifndef __PACKED_STRUCT
93 #define __PACKED_STRUCT struct __attribute__((packed))
95 #ifndef __PACKED_UNION
96 #define __PACKED_UNION union __attribute__((packed))
98 #ifndef __UNALIGNED_UINT16_WRITE
99 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
100 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
102 #ifndef __UNALIGNED_UINT16_READ
103 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
104 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
106 #ifndef __UNALIGNED_UINT32_WRITE
107 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
108 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
110 #ifndef __UNALIGNED_UINT32_READ
111 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
112 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
115 #define __ALIGNED(x) __attribute__((aligned(x)))
118 #define __RESTRICT __restrict
120 #ifndef __COMPILER_BARRIER
121 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
122 #define __COMPILER_BARRIER() (void)0
125 #define __NO_INIT __attribute__ ((section (".noinit")))
128 #define __ALIAS(x) __attribute__ ((alias(x)))
134 #elif defined ( __TASKING__ )
136 * The CMSIS functions have been implemented as intrinsics in the compiler.
137 * Please use "carm -?i" to get an up to date list of all intrinsics,
138 * Including the CMSIS ones.
145 #define __INLINE inline
147 #ifndef __STATIC_INLINE
148 #define __STATIC_INLINE static inline
150 #ifndef __STATIC_FORCEINLINE
151 #define __STATIC_FORCEINLINE __STATIC_INLINE
154 #define __NO_RETURN __attribute__((noreturn))
157 #define __USED __attribute__((used))
160 #define __WEAK __attribute__((weak))
163 #define __PACKED __packed__
165 #ifndef __PACKED_STRUCT
166 #define __PACKED_STRUCT struct __packed__
168 #ifndef __PACKED_UNION
169 #define __PACKED_UNION union __packed__
171 #ifndef __UNALIGNED_UINT16_WRITE
172 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
173 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
175 #ifndef __UNALIGNED_UINT16_READ
176 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
177 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
179 #ifndef __UNALIGNED_UINT32_WRITE
180 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
181 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
183 #ifndef __UNALIGNED_UINT32_READ
184 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
185 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
188 #define __ALIGNED(x) __align(x)
191 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
194 #ifndef __COMPILER_BARRIER
195 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
196 #define __COMPILER_BARRIER() (void)0
199 #define __NO_INIT __attribute__ ((section (".noinit")))
202 #define __ALIAS(x) __attribute__ ((alias(x)))
208 #elif defined ( __CSMC__ )
209 #include <cmsis_csm.h>
215 #define __INLINE inline
217 #ifndef __STATIC_INLINE
218 #define __STATIC_INLINE static inline
220 #ifndef __STATIC_FORCEINLINE
221 #define __STATIC_FORCEINLINE __STATIC_INLINE
224 // NO RETURN is automatically detected hence no warning here
228 #warning No compiler specific solution for __USED. __USED is ignored.
232 #define __WEAK __weak
235 #define __PACKED @packed
237 #ifndef __PACKED_STRUCT
238 #define __PACKED_STRUCT @packed struct
240 #ifndef __PACKED_UNION
241 #define __PACKED_UNION @packed union
243 #ifndef __UNALIGNED_UINT16_WRITE
244 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
245 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
247 #ifndef __UNALIGNED_UINT16_READ
248 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
249 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
251 #ifndef __UNALIGNED_UINT32_WRITE
252 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
253 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
255 #ifndef __UNALIGNED_UINT32_READ
256 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
257 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
260 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
264 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
267 #ifndef __COMPILER_BARRIER
268 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
269 #define __COMPILER_BARRIER() (void)0
272 #define __NO_INIT __attribute__ ((section (".noinit")))
275 #define __ALIAS(x) __attribute__ ((alias(x)))
279 #error Unknown compiler.
283 #endif /* __CMSIS_COMPILER_H */