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 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
131 // Workaround for missing __CLZ intrinsic in
132 // various versions of the IAR compilers.
133 // __IAR_FEATURE_CLZ__ should be defined by
134 // the compiler that supports __CLZ internally.
135 #if (defined (__ARM_ARCH_6M__)) && (__ARM_ARCH_6M__ == 1) && (!defined (__IAR_FEATURE_CLZ__))
136 __STATIC_INLINE uint32_t __CLZ(uint32_t data)
138 if (data == 0u) { return 32u; }
141 uint32_t mask = 0x80000000;
143 while ((data & mask) == 0)
157 #elif defined ( __TI_ARM__ )
158 #include <cmsis_ccs.h>
164 #define __INLINE inline
166 #ifndef __STATIC_INLINE
167 #define __STATIC_INLINE static inline
170 #define __NO_RETURN __attribute__((noreturn))
173 #define __USED __attribute__((used))
176 #define __WEAK __attribute__((weak))
179 #define __PACKED __attribute__((packed))
181 #ifndef __PACKED_STRUCT
182 #define __PACKED_STRUCT struct __attribute__((packed))
184 #ifndef __PACKED_UNION
185 #define __PACKED_UNION union __attribute__((packed))
187 #ifndef __UNALIGNED_UINT32 /* deprecated */
188 struct __attribute__((packed)) T_UINT32 { uint32_t v; };
189 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
191 #ifndef __UNALIGNED_UINT16_WRITE
192 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
193 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
195 #ifndef __UNALIGNED_UINT16_READ
196 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
197 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
199 #ifndef __UNALIGNED_UINT32_WRITE
200 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
201 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
203 #ifndef __UNALIGNED_UINT32_READ
204 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
205 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
208 #define __ALIGNED(x) __attribute__((aligned(x)))
211 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
219 #elif defined ( __TASKING__ )
221 * The CMSIS functions have been implemented as intrinsics in the compiler.
222 * Please use "carm -?i" to get an up to date list of all intrinsics,
223 * Including the CMSIS ones.
230 #define __INLINE inline
232 #ifndef __STATIC_INLINE
233 #define __STATIC_INLINE static inline
236 #define __NO_RETURN __attribute__((noreturn))
239 #define __USED __attribute__((used))
242 #define __WEAK __attribute__((weak))
245 #define __PACKED __packed__
247 #ifndef __PACKED_STRUCT
248 #define __PACKED_STRUCT struct __packed__
250 #ifndef __PACKED_UNION
251 #define __PACKED_UNION union __packed__
253 #ifndef __UNALIGNED_UINT32 /* deprecated */
254 struct __packed__ T_UINT32 { uint32_t v; };
255 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
257 #ifndef __UNALIGNED_UINT16_WRITE
258 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
259 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
261 #ifndef __UNALIGNED_UINT16_READ
262 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
263 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
265 #ifndef __UNALIGNED_UINT32_WRITE
266 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
267 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
269 #ifndef __UNALIGNED_UINT32_READ
270 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
271 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
274 #define __ALIGNED(x) __align(x)
277 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
285 #elif defined ( __CSMC__ )
286 #include <cmsis_csm.h>
292 #define __INLINE inline
294 #ifndef __STATIC_INLINE
295 #define __STATIC_INLINE static inline
298 // NO RETURN is automatically detected hence no warning here
302 #warning No compiler specific solution for __USED. __USED is ignored.
306 #define __WEAK __weak
309 #define __PACKED @packed
311 #ifndef __PACKED_STRUCT
312 #define __PACKED_STRUCT @packed struct
314 #ifndef __PACKED_UNION
315 #define __PACKED_UNION @packed union
317 #ifndef __UNALIGNED_UINT32 /* deprecated */
318 @packed struct T_UINT32 { uint32_t v; };
319 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
321 #ifndef __UNALIGNED_UINT16_WRITE
322 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
323 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
325 #ifndef __UNALIGNED_UINT16_READ
326 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
327 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
329 #ifndef __UNALIGNED_UINT32_WRITE
330 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
331 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
333 #ifndef __UNALIGNED_UINT32_READ
334 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
335 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
338 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
342 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
348 #error Unknown compiler.
352 #endif /* __CMSIS_COMPILER_H */