1 /**************************************************************************//**
2 * @file cmsis_compiler.h
3 * @brief CMSIS compiler generic header file
5 * @date 13. February 2017
6 ******************************************************************************/
8 * Copyright (c) 2009-2017 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 (armclang)
40 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
41 #include "cmsis_armclang.h"
47 #elif defined ( __GNUC__ )
48 #include "cmsis_gcc.h"
54 #elif defined ( __ICCARM__ )
61 #define __INLINE inline
63 #ifndef __STATIC_INLINE
64 #define __STATIC_INLINE static inline
67 #include <cmsis_iar.h>
69 /* CMSIS compiler control architecture macros */
70 #if (__CORE__ == __ARM6M__) || (__CORE__ == __ARM6SM__)
71 #ifndef __ARM_ARCH_6M__
72 #define __ARM_ARCH_6M__ 1
74 #elif (__CORE__ == __ARM7M__)
75 #ifndef __ARM_ARCH_7M__
76 #define __ARM_ARCH_7M__ 1
78 #elif (__CORE__ == __ARM7EM__)
79 #ifndef __ARM_ARCH_7EM__
80 #define __ARM_ARCH_7EM__ 1
85 #define __NO_RETURN __noreturn
94 #define __PACKED __packed
96 #ifndef __PACKED_STRUCT
97 #define __PACKED_STRUCT __packed struct
99 #ifndef __UNALIGNED_UINT32 /* deprecated */
100 __packed struct T_UINT32 { uint32_t v; };
101 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
103 #ifndef __UNALIGNED_UINT16_WRITE
104 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
105 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
107 #ifndef __UNALIGNED_UINT16_READ
108 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
109 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
111 #ifndef __UNALIGNED_UINT32_WRITE
112 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
113 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
115 #ifndef __UNALIGNED_UINT32_READ
116 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
117 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
120 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
124 // Workaround for missing __CLZ intrinsic in
125 // various versions of the IAR compilers.
126 // __IAR_FEATURE_CLZ__ should be defined by
127 // the compiler that supports __CLZ internally.
128 #if __ARM_ARCH_6M__ && !__IAR_FEATURE_CLZ__
129 __STATIC_INLINE uint32_t __CLZ(uint32_t data)
131 if (data == 0u) { return 32u; }
134 uint32_t mask = 0x80000000;
136 while ((data & mask) == 0)
150 #elif defined ( __TI_ARM__ )
151 #include <cmsis_ccs.h>
157 #define __INLINE inline
159 #ifndef __STATIC_INLINE
160 #define __STATIC_INLINE static inline
163 #define __NO_RETURN __attribute__((noreturn))
166 #define __USED __attribute__((used))
169 #define __WEAK __attribute__((weak))
172 #define __PACKED __attribute__((packed))
174 #ifndef __PACKED_STRUCT
175 #define __PACKED_STRUCT struct __attribute__((packed))
177 #ifndef __UNALIGNED_UINT32 /* deprecated */
178 struct __attribute__((packed)) T_UINT32 { uint32_t v; };
179 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
181 #ifndef __UNALIGNED_UINT16_WRITE
182 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
183 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
185 #ifndef __UNALIGNED_UINT16_READ
186 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
187 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
189 #ifndef __UNALIGNED_UINT32_WRITE
190 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
191 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
193 #ifndef __UNALIGNED_UINT32_READ
194 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
195 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
198 #define __ALIGNED(x) __attribute__((aligned(x)))
205 #elif defined ( __TASKING__ )
207 * The CMSIS functions have been implemented as intrinsics in the compiler.
208 * Please use "carm -?i" to get an up to date list of all intrinsics,
209 * Including the CMSIS ones.
216 #define __INLINE inline
218 #ifndef __STATIC_INLINE
219 #define __STATIC_INLINE static inline
222 #define __NO_RETURN __attribute__((noreturn))
225 #define __USED __attribute__((used))
228 #define __WEAK __attribute__((weak))
231 #define __PACKED __packed__
233 #ifndef __PACKED_STRUCT
234 #define __PACKED_STRUCT struct __packed__
236 #ifndef __UNALIGNED_UINT32 /* deprecated */
237 struct __packed__ 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 #define __ALIGNED(x) __align(x)
264 #elif defined ( __CSMC__ )
265 #include <cmsis_csm.h>
271 #define __INLINE inline
273 #ifndef __STATIC_INLINE
274 #define __STATIC_INLINE static inline
277 // NO RETURN is automatically detected hence no warning here
281 #warning No compiler specific solution for __USED. __USED is ignored.
285 #define __WEAK __weak
288 #define __PACKED @packed
290 #ifndef __PACKED_STRUCT
291 #define __PACKED_STRUCT @packed struct
293 #ifndef __UNALIGNED_UINT32 /* deprecated */
294 @packed struct T_UINT32 { uint32_t v; };
295 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
297 #ifndef __UNALIGNED_UINT16_WRITE
298 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
299 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
301 #ifndef __UNALIGNED_UINT16_READ
302 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
303 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
305 #ifndef __UNALIGNED_UINT32_WRITE
306 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
307 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
309 #ifndef __UNALIGNED_UINT32_READ
310 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
311 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
314 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
320 #error Unknown compiler.
324 #endif /* __CMSIS_COMPILER_H */