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 // IAR compilers prior 8.0
126 #if (__CORE__ == __ARM6M__) && (__VER__ < 8000000)
127 __STATIC_INLINE uint32_t __CLZ(uint32_t data)
129 if (data == 0u) { return 32u; }
132 uint32_t mask = 0x80000000;
134 while ((data & mask) == 0)
148 #elif defined ( __TI_ARM__ )
149 #include <cmsis_ccs.h>
155 #define __INLINE inline
157 #ifndef __STATIC_INLINE
158 #define __STATIC_INLINE static inline
161 #define __NO_RETURN __attribute__((noreturn))
164 #define __USED __attribute__((used))
167 #define __WEAK __attribute__((weak))
170 #define __PACKED __attribute__((packed))
172 #ifndef __PACKED_STRUCT
173 #define __PACKED_STRUCT struct __attribute__((packed))
175 #ifndef __UNALIGNED_UINT32 /* deprecated */
176 struct __attribute__((packed)) T_UINT32 { uint32_t v; };
177 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
179 #ifndef __UNALIGNED_UINT16_WRITE
180 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
181 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
183 #ifndef __UNALIGNED_UINT16_READ
184 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
185 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
187 #ifndef __UNALIGNED_UINT32_WRITE
188 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
189 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
191 #ifndef __UNALIGNED_UINT32_READ
192 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
193 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
196 #define __ALIGNED(x) __attribute__((aligned(x)))
203 #elif defined ( __TASKING__ )
205 * The CMSIS functions have been implemented as intrinsics in the compiler.
206 * Please use "carm -?i" to get an up to date list of all intrinsics,
207 * Including the CMSIS ones.
214 #define __INLINE inline
216 #ifndef __STATIC_INLINE
217 #define __STATIC_INLINE static inline
220 #define __NO_RETURN __attribute__((noreturn))
223 #define __USED __attribute__((used))
226 #define __WEAK __attribute__((weak))
229 #define __PACKED __packed__
231 #ifndef __PACKED_STRUCT
232 #define __PACKED_STRUCT struct __packed__
234 #ifndef __UNALIGNED_UINT32 /* deprecated */
235 struct __packed__ T_UINT32 { uint32_t v; };
236 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
238 #ifndef __UNALIGNED_UINT16_WRITE
239 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
240 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
242 #ifndef __UNALIGNED_UINT16_READ
243 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
244 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
246 #ifndef __UNALIGNED_UINT32_WRITE
247 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
248 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
250 #ifndef __UNALIGNED_UINT32_READ
251 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
252 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
255 #define __ALIGNED(x) __align(x)
262 #elif defined ( __CSMC__ )
263 #include <cmsis_csm.h>
269 #define __INLINE inline
271 #ifndef __STATIC_INLINE
272 #define __STATIC_INLINE static inline
275 // NO RETURN is automatically detected hence no warning here
279 #warning No compiler specific solution for __USED. __USED is ignored.
283 #define __WEAK __weak
286 #define __PACKED @packed
288 #ifndef __PACKED_STRUCT
289 #define __PACKED_STRUCT @packed struct
291 #ifndef __UNALIGNED_UINT32 /* deprecated */
292 @packed struct T_UINT32 { uint32_t v; };
293 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
295 #ifndef __UNALIGNED_UINT16_WRITE
296 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
297 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
299 #ifndef __UNALIGNED_UINT16_READ
300 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
301 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
303 #ifndef __UNALIGNED_UINT32_WRITE
304 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
305 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
307 #ifndef __UNALIGNED_UINT32_READ
308 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
309 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
312 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
318 #error Unknown compiler.
322 #endif /* __CMSIS_COMPILER_H */