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__ )
60 #define __INLINE inline
62 #ifndef __STATIC_INLINE
63 #define __STATIC_INLINE static inline
66 #include <cmsis_iar.h>
69 #define __NO_RETURN __noreturn
78 #define __PACKED __packed
80 #ifndef __PACKED_STRUCT
81 #define __PACKED_STRUCT __packed struct
83 #ifndef __UNALIGNED_UINT32 /* deprecated */
84 __packed struct T_UINT32 { uint32_t v; };
85 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
87 #ifndef __UNALIGNED_UINT16_WRITE
88 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
89 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
91 #ifndef __UNALIGNED_UINT16_READ
92 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
93 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
95 #ifndef __UNALIGNED_UINT32_WRITE
96 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
97 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
99 #ifndef __UNALIGNED_UINT32_READ
100 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
101 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
104 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
108 // Workaround for missing __CLZ intrinsic in
109 // IAR compilers prior 8.0
110 #if (__CORE__ == __ARM6M__) && (__VER__ < 8000000)
111 __STATIC_INLINE uint32_t __CLZ(uint32_t data)
113 if (data == 0u) { return 32u; }
116 uint32_t mask = 0x80000000;
118 while ((data & mask) == 0)
132 #elif defined ( __TI_ARM__ )
133 #include <cmsis_ccs.h>
139 #define __INLINE inline
141 #ifndef __STATIC_INLINE
142 #define __STATIC_INLINE static inline
145 #define __NO_RETURN __attribute__((noreturn))
148 #define __USED __attribute__((used))
151 #define __WEAK __attribute__((weak))
154 #define __PACKED __attribute__((packed))
156 #ifndef __PACKED_STRUCT
157 #define __PACKED_STRUCT struct __attribute__((packed))
159 #ifndef __UNALIGNED_UINT32 /* deprecated */
160 struct __attribute__((packed)) T_UINT32 { uint32_t v; };
161 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
163 #ifndef __UNALIGNED_UINT16_WRITE
164 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
165 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
167 #ifndef __UNALIGNED_UINT16_READ
168 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
169 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
171 #ifndef __UNALIGNED_UINT32_WRITE
172 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
173 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
175 #ifndef __UNALIGNED_UINT32_READ
176 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
177 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
180 #define __ALIGNED(x) __attribute__((aligned(x)))
187 #elif defined ( __TASKING__ )
189 * The CMSIS functions have been implemented as intrinsics in the compiler.
190 * Please use "carm -?i" to get an up to date list of all intrinsics,
191 * Including the CMSIS ones.
198 #define __INLINE inline
200 #ifndef __STATIC_INLINE
201 #define __STATIC_INLINE static inline
204 #define __NO_RETURN __attribute__((noreturn))
207 #define __USED __attribute__((used))
210 #define __WEAK __attribute__((weak))
213 #define __PACKED __packed__
215 #ifndef __PACKED_STRUCT
216 #define __PACKED_STRUCT struct __packed__
218 #ifndef __UNALIGNED_UINT32 /* deprecated */
219 struct __packed__ T_UINT32 { uint32_t v; };
220 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
222 #ifndef __UNALIGNED_UINT16_WRITE
223 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
224 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
226 #ifndef __UNALIGNED_UINT16_READ
227 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
228 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
230 #ifndef __UNALIGNED_UINT32_WRITE
231 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
232 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
234 #ifndef __UNALIGNED_UINT32_READ
235 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
236 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
239 #define __ALIGNED(x) __align(x)
246 #elif defined ( __CSMC__ )
247 #include <cmsis_csm.h>
253 #define __INLINE inline
255 #ifndef __STATIC_INLINE
256 #define __STATIC_INLINE static inline
259 // NO RETURN is automatically detected hence no warning here
263 #warning No compiler specific solution for __USED. __USED is ignored.
267 #define __WEAK __weak
270 #define __PACKED @packed
272 #ifndef __PACKED_STRUCT
273 #define __PACKED_STRUCT @packed struct
275 #ifndef __UNALIGNED_UINT32 /* deprecated */
276 @packed struct T_UINT32 { uint32_t v; };
277 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
279 #ifndef __UNALIGNED_UINT16_WRITE
280 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
281 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
283 #ifndef __UNALIGNED_UINT16_READ
284 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
285 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
287 #ifndef __UNALIGNED_UINT32_WRITE
288 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
289 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
291 #ifndef __UNALIGNED_UINT32_READ
292 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
293 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
296 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
302 #error Unknown compiler.
306 #endif /* __CMSIS_COMPILER_H */