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 __PACKED_UNION
100 #define __PACKED_UNION __packed union
102 #ifndef __UNALIGNED_UINT32 /* deprecated */
103 __packed struct T_UINT32 { uint32_t v; };
104 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
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 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
127 // Workaround for missing __CLZ intrinsic in
128 // various versions of the IAR compilers.
129 // __IAR_FEATURE_CLZ__ should be defined by
130 // the compiler that supports __CLZ internally.
131 #if (defined (__ARM_ARCH_6M__)) && (__ARM_ARCH_6M__ == 1) && (!defined (__IAR_FEATURE_CLZ__))
132 __STATIC_INLINE uint32_t __CLZ(uint32_t data)
134 if (data == 0u) { return 32u; }
137 uint32_t mask = 0x80000000;
139 while ((data & mask) == 0)
153 #elif defined ( __TI_ARM__ )
154 #include <cmsis_ccs.h>
160 #define __INLINE inline
162 #ifndef __STATIC_INLINE
163 #define __STATIC_INLINE static inline
166 #define __NO_RETURN __attribute__((noreturn))
169 #define __USED __attribute__((used))
172 #define __WEAK __attribute__((weak))
175 #define __PACKED __attribute__((packed))
177 #ifndef __PACKED_STRUCT
178 #define __PACKED_STRUCT struct __attribute__((packed))
180 #ifndef __PACKED_UNION
181 #define __PACKED_UNION union __attribute__((packed))
183 #ifndef __UNALIGNED_UINT32 /* deprecated */
184 struct __attribute__((packed)) T_UINT32 { uint32_t v; };
185 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
187 #ifndef __UNALIGNED_UINT16_WRITE
188 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
189 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
191 #ifndef __UNALIGNED_UINT16_READ
192 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
193 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
195 #ifndef __UNALIGNED_UINT32_WRITE
196 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
197 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
199 #ifndef __UNALIGNED_UINT32_READ
200 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
201 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
204 #define __ALIGNED(x) __attribute__((aligned(x)))
211 #elif defined ( __TASKING__ )
213 * The CMSIS functions have been implemented as intrinsics in the compiler.
214 * Please use "carm -?i" to get an up to date list of all intrinsics,
215 * Including the CMSIS ones.
222 #define __INLINE inline
224 #ifndef __STATIC_INLINE
225 #define __STATIC_INLINE static inline
228 #define __NO_RETURN __attribute__((noreturn))
231 #define __USED __attribute__((used))
234 #define __WEAK __attribute__((weak))
237 #define __PACKED __packed__
239 #ifndef __PACKED_STRUCT
240 #define __PACKED_STRUCT struct __packed__
242 #ifndef __PACKED_UNION
243 #define __PACKED_UNION union __packed__
245 #ifndef __UNALIGNED_UINT32 /* deprecated */
246 struct __packed__ T_UINT32 { uint32_t v; };
247 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
249 #ifndef __UNALIGNED_UINT16_WRITE
250 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
251 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
253 #ifndef __UNALIGNED_UINT16_READ
254 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
255 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
257 #ifndef __UNALIGNED_UINT32_WRITE
258 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
259 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
261 #ifndef __UNALIGNED_UINT32_READ
262 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
263 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
266 #define __ALIGNED(x) __align(x)
273 #elif defined ( __CSMC__ )
274 #include <cmsis_csm.h>
280 #define __INLINE inline
282 #ifndef __STATIC_INLINE
283 #define __STATIC_INLINE static inline
286 // NO RETURN is automatically detected hence no warning here
290 #warning No compiler specific solution for __USED. __USED is ignored.
294 #define __WEAK __weak
297 #define __PACKED @packed
299 #ifndef __PACKED_STRUCT
300 #define __PACKED_STRUCT @packed struct
302 #ifndef __PACKED_UNION
303 #define __PACKED_UNION @packed union
305 #ifndef __UNALIGNED_UINT32 /* deprecated */
306 @packed struct T_UINT32 { uint32_t v; };
307 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
309 #ifndef __UNALIGNED_UINT16_WRITE
310 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
311 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
313 #ifndef __UNALIGNED_UINT16_READ
314 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
315 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
317 #ifndef __UNALIGNED_UINT32_WRITE
318 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
319 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
321 #ifndef __UNALIGNED_UINT32_READ
322 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
323 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
326 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
332 #error Unknown compiler.
336 #endif /* __CMSIS_COMPILER_H */