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"
58 #elif defined ( __GNUC__ )
59 #include "cmsis_gcc.h"
65 #elif defined ( __ICCARM__ )
66 #include <cmsis_iccarm.h>
70 * TI Arm Compiler (armcl)
72 #elif defined ( __TI_ARM__ )
73 #include <cmsis_ccs.h>
79 #define __INLINE inline
81 #ifndef __STATIC_INLINE
82 #define __STATIC_INLINE static inline
84 #ifndef __STATIC_FORCEINLINE
85 #define __STATIC_FORCEINLINE __STATIC_INLINE
88 #define __NO_RETURN __attribute__((noreturn))
91 #define __USED __attribute__((used))
94 #define __WEAK __attribute__((weak))
97 #define __PACKED __attribute__((packed))
99 #ifndef __PACKED_STRUCT
100 #define __PACKED_STRUCT struct __attribute__((packed))
102 #ifndef __PACKED_UNION
103 #define __PACKED_UNION union __attribute__((packed))
105 #ifndef __UNALIGNED_UINT32 /* deprecated */
106 struct __attribute__((packed)) T_UINT32 { uint32_t v; };
107 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
109 #ifndef __UNALIGNED_UINT16_WRITE
110 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
111 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
113 #ifndef __UNALIGNED_UINT16_READ
114 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
115 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
117 #ifndef __UNALIGNED_UINT32_WRITE
118 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
119 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
121 #ifndef __UNALIGNED_UINT32_READ
122 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
123 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
126 #define __ALIGNED(x) __attribute__((aligned(x)))
129 #define __RESTRICT __restrict
131 #ifndef __COMPILER_BARRIER
132 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
133 #define __COMPILER_BARRIER() (void)0
136 #define __NO_INIT __attribute__ ((section (".bss.noinit")))
139 #define __ALIAS(x) __attribute__ ((alias(x)))
145 #elif defined ( __TASKING__ )
147 * The CMSIS functions have been implemented as intrinsics in the compiler.
148 * Please use "carm -?i" to get an up to date list of all intrinsics,
149 * Including the CMSIS ones.
156 #define __INLINE inline
158 #ifndef __STATIC_INLINE
159 #define __STATIC_INLINE static inline
161 #ifndef __STATIC_FORCEINLINE
162 #define __STATIC_FORCEINLINE __STATIC_INLINE
165 #define __NO_RETURN __attribute__((noreturn))
168 #define __USED __attribute__((used))
171 #define __WEAK __attribute__((weak))
174 #define __PACKED __packed__
176 #ifndef __PACKED_STRUCT
177 #define __PACKED_STRUCT struct __packed__
179 #ifndef __PACKED_UNION
180 #define __PACKED_UNION union __packed__
182 #ifndef __UNALIGNED_UINT32 /* deprecated */
183 struct __packed__ T_UINT32 { uint32_t v; };
184 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
186 #ifndef __UNALIGNED_UINT16_WRITE
187 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
188 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
190 #ifndef __UNALIGNED_UINT16_READ
191 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
192 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
194 #ifndef __UNALIGNED_UINT32_WRITE
195 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
196 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
198 #ifndef __UNALIGNED_UINT32_READ
199 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
200 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
203 #define __ALIGNED(x) __align(x)
206 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
209 #ifndef __COMPILER_BARRIER
210 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
211 #define __COMPILER_BARRIER() (void)0
214 #define __NO_INIT __attribute__ ((section (".bss.noinit")))
217 #define __ALIAS(x) __attribute__ ((alias(x)))
223 #elif defined ( __CSMC__ )
224 #include <cmsis_csm.h>
230 #define __INLINE inline
232 #ifndef __STATIC_INLINE
233 #define __STATIC_INLINE static inline
235 #ifndef __STATIC_FORCEINLINE
236 #define __STATIC_FORCEINLINE __STATIC_INLINE
239 // NO RETURN is automatically detected hence no warning here
243 #warning No compiler specific solution for __USED. __USED is ignored.
247 #define __WEAK __weak
250 #define __PACKED @packed
252 #ifndef __PACKED_STRUCT
253 #define __PACKED_STRUCT @packed struct
255 #ifndef __PACKED_UNION
256 #define __PACKED_UNION @packed union
258 #ifndef __UNALIGNED_UINT32 /* deprecated */
259 @packed struct T_UINT32 { uint32_t v; };
260 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
262 #ifndef __UNALIGNED_UINT16_WRITE
263 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
264 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
266 #ifndef __UNALIGNED_UINT16_READ
267 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
268 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
270 #ifndef __UNALIGNED_UINT32_WRITE
271 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
272 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
274 #ifndef __UNALIGNED_UINT32_READ
275 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
276 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
279 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
283 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
286 #ifndef __COMPILER_BARRIER
287 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
288 #define __COMPILER_BARRIER() (void)0
291 #define __NO_INIT __attribute__ ((section (".bss.noinit")))
294 #define __ALIAS(x) __attribute__ ((alias(x)))
298 #error Unknown compiler.
302 #endif /* __CMSIS_COMPILER_H */