1 /**************************************************************************//**
2 * @file cmsis_compiler.h
3 * @brief CMSIS compiler generic header file
5 * @date 10. January 2018
6 ******************************************************************************/
8 * Copyright (c) 2009-2018 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"
53 #elif defined ( __GNUC__ )
54 #include "cmsis_gcc.h"
60 #elif defined ( __ICCARM__ )
61 #include <cmsis_iccarm.h>
67 #elif defined ( __TI_ARM__ )
68 #include <cmsis_ccs.h>
74 #define __INLINE inline
76 #ifndef __STATIC_INLINE
77 #define __STATIC_INLINE static inline
79 #ifndef __STATIC_FORCEINLINE
80 #define __STATIC_FORCEINLINE __STATIC_INLINE
83 #define __NO_RETURN __attribute__((noreturn))
86 #define __USED __attribute__((used))
89 #define __WEAK __attribute__((weak))
92 #define __PACKED __attribute__((packed))
94 #ifndef __PACKED_STRUCT
95 #define __PACKED_STRUCT struct __attribute__((packed))
97 #ifndef __PACKED_UNION
98 #define __PACKED_UNION union __attribute__((packed))
100 #ifndef __UNALIGNED_UINT32 /* deprecated */
101 struct __attribute__((packed)) T_UINT32 { uint32_t v; };
102 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
104 #ifndef __UNALIGNED_UINT16_WRITE
105 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
106 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
108 #ifndef __UNALIGNED_UINT16_READ
109 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
110 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
112 #ifndef __UNALIGNED_UINT32_WRITE
113 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
114 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
116 #ifndef __UNALIGNED_UINT32_READ
117 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
118 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
121 #define __ALIGNED(x) __attribute__((aligned(x)))
124 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
132 #elif defined ( __TASKING__ )
134 * The CMSIS functions have been implemented as intrinsics in the compiler.
135 * Please use "carm -?i" to get an up to date list of all intrinsics,
136 * Including the CMSIS ones.
143 #define __INLINE inline
145 #ifndef __STATIC_INLINE
146 #define __STATIC_INLINE static inline
148 #ifndef __STATIC_FORCEINLINE
149 #define __STATIC_FORCEINLINE __STATIC_INLINE
152 #define __NO_RETURN __attribute__((noreturn))
155 #define __USED __attribute__((used))
158 #define __WEAK __attribute__((weak))
161 #define __PACKED __packed__
163 #ifndef __PACKED_STRUCT
164 #define __PACKED_STRUCT struct __packed__
166 #ifndef __PACKED_UNION
167 #define __PACKED_UNION union __packed__
169 #ifndef __UNALIGNED_UINT32 /* deprecated */
170 struct __packed__ T_UINT32 { uint32_t v; };
171 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
173 #ifndef __UNALIGNED_UINT16_WRITE
174 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
175 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
177 #ifndef __UNALIGNED_UINT16_READ
178 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
179 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
181 #ifndef __UNALIGNED_UINT32_WRITE
182 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
183 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
185 #ifndef __UNALIGNED_UINT32_READ
186 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
187 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
190 #define __ALIGNED(x) __align(x)
193 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
201 #elif defined ( __CSMC__ )
202 #include <cmsis_csm.h>
208 #define __INLINE inline
210 #ifndef __STATIC_INLINE
211 #define __STATIC_INLINE static inline
213 #ifndef __STATIC_FORCEINLINE
214 #define __STATIC_FORCEINLINE __STATIC_INLINE
217 // NO RETURN is automatically detected hence no warning here
221 #warning No compiler specific solution for __USED. __USED is ignored.
225 #define __WEAK __weak
228 #define __PACKED @packed
230 #ifndef __PACKED_STRUCT
231 #define __PACKED_STRUCT @packed struct
233 #ifndef __PACKED_UNION
234 #define __PACKED_UNION @packed union
236 #ifndef __UNALIGNED_UINT32 /* deprecated */
237 @packed struct T_UINT32 { uint32_t v; };
238 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
240 #ifndef __UNALIGNED_UINT16_WRITE
241 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
242 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
244 #ifndef __UNALIGNED_UINT16_READ
245 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
246 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
248 #ifndef __UNALIGNED_UINT32_WRITE
249 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
250 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
252 #ifndef __UNALIGNED_UINT32_READ
253 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
254 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
257 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
261 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
267 #error Unknown compiler.
271 #endif /* __CMSIS_COMPILER_H */