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.
112 #elif defined ( __TI_ARM__ )
113 #include <cmsis_ccs.h>
119 #define __INLINE inline
121 #ifndef __STATIC_INLINE
122 #define __STATIC_INLINE static inline
125 #define __NO_RETURN __attribute__((noreturn))
128 #define __USED __attribute__((used))
131 #define __WEAK __attribute__((weak))
134 #define __PACKED __attribute__((packed))
136 #ifndef __PACKED_STRUCT
137 #define __PACKED_STRUCT struct __attribute__((packed))
139 #ifndef __UNALIGNED_UINT32 /* deprecated */
140 struct __attribute__((packed)) T_UINT32 { uint32_t v; };
141 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
143 #ifndef __UNALIGNED_UINT16_WRITE
144 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
145 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
147 #ifndef __UNALIGNED_UINT16_READ
148 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
149 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
151 #ifndef __UNALIGNED_UINT32_WRITE
152 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
153 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
155 #ifndef __UNALIGNED_UINT32_READ
156 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
157 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
160 #define __ALIGNED(x) __attribute__((aligned(x)))
167 #elif defined ( __TASKING__ )
169 * The CMSIS functions have been implemented as intrinsics in the compiler.
170 * Please use "carm -?i" to get an up to date list of all intrinsics,
171 * Including the CMSIS ones.
178 #define __INLINE inline
180 #ifndef __STATIC_INLINE
181 #define __STATIC_INLINE static inline
184 #define __NO_RETURN __attribute__((noreturn))
187 #define __USED __attribute__((used))
190 #define __WEAK __attribute__((weak))
193 #define __PACKED __packed__
195 #ifndef __PACKED_STRUCT
196 #define __PACKED_STRUCT struct __packed__
198 #ifndef __UNALIGNED_UINT32 /* deprecated */
199 struct __packed__ T_UINT32 { uint32_t v; };
200 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
202 #ifndef __UNALIGNED_UINT16_WRITE
203 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
204 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
206 #ifndef __UNALIGNED_UINT16_READ
207 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
208 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
210 #ifndef __UNALIGNED_UINT32_WRITE
211 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
212 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
214 #ifndef __UNALIGNED_UINT32_READ
215 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
216 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
219 #define __ALIGNED(x) __align(x)
226 #elif defined ( __CSMC__ )
227 #include <cmsis_csm.h>
233 #define __INLINE inline
235 #ifndef __STATIC_INLINE
236 #define __STATIC_INLINE static inline
239 // NO RETURN is automatically detected hence no warning here
243 #warning No compiler specific solution for __USED. __USED is ignored.
247 #define __WEAK __weak
250 #define __PACKED @packed
252 #ifndef __PACKED_STRUCT
253 #define __PACKED_STRUCT @packed struct
255 #ifndef __UNALIGNED_UINT32 /* deprecated */
256 @packed struct T_UINT32 { uint32_t v; };
257 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
259 #ifndef __UNALIGNED_UINT16_WRITE
260 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
261 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
263 #ifndef __UNALIGNED_UINT16_READ
264 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
265 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
267 #ifndef __UNALIGNED_UINT32_WRITE
268 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
269 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
271 #ifndef __UNALIGNED_UINT32_READ
272 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
273 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
276 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
282 #error Unknown compiler.
286 #endif /* __CMSIS_COMPILER_H */