]> begriffs open source - cmsis/blob - CMSIS/Core/Include/cmsis_compiler.h
Reworked CMSIS-Core(M) and Core(A) docs for CMSIS 6. (#47)
[cmsis] / CMSIS / Core / Include / cmsis_compiler.h
1 /**************************************************************************//**
2  * @file     cmsis_compiler.h
3  * @brief    CMSIS compiler generic header file
4  * @version  V6.0.0
5  * @date     27. July 2023
6  ******************************************************************************/
7 /*
8  * Copyright (c) 2009-2023 Arm Limited. All rights reserved.
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  *
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
15  *
16  * www.apache.org/licenses/LICENSE-2.0
17  *
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.
23  */
24
25 #ifndef __CMSIS_COMPILER_H
26 #define __CMSIS_COMPILER_H
27
28 #include <stdint.h>
29
30 /*
31  * Arm Compiler above 6.10.1 (armclang)
32  */
33 #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
34   #if __ARM_ARCH_PROFILE == 'A'
35     #include "./a-profile/cmsis_armclang_a.h"
36   #elif __ARM_ARCH_PROFILE == 'R'
37     #include "./r-profile/cmsis_armclang_r.h"
38   #elif __ARM_ARCH_PROFILE == 'M'
39     #include "./m-profile/cmsis_armclang_m.h"
40   #else
41     #error "Unknown Arm architecture profile"
42   #endif
43
44 /*
45  * TI Arm Clang Compiler (tiarmclang)
46  */
47 #elif defined (__ti__)
48   #if __ARM_ARCH_PROFILE == 'A'
49     #error "Core-A is not supported for this compiler"
50   #elif __ARM_ARCH_PROFILE == 'R'
51     #error "Core-R is not supported for this compiler"
52   #elif __ARM_ARCH_PROFILE == 'M'
53     #include "m-profile/cmsis_tiarmclang_m.h"
54   #else
55     #error "Unknown Arm architecture profile"
56   #endif
57
58
59 /*
60  * LLVM/Clang Compiler
61  */
62 #elif defined ( __clang__ )
63   #if __ARM_ARCH_PROFILE == 'A'
64     #include "a-profile/cmsis_clang_a.h"
65   #elif __ARM_ARCH_PROFILE == 'R'
66     #include "r-profile/cmsis_clang_r.h"
67   #elif __ARM_ARCH_PROFILE == 'M'
68     #include "m-profile/cmsis_clang_m.h"
69   #else
70     #error "Unknown Arm architecture profile"
71   #endif
72
73
74 /*
75  * GNU Compiler
76  */
77 #elif defined ( __GNUC__ )
78   #if __ARM_ARCH_PROFILE == 'A'
79     #include "a-profile/cmsis_gcc_a.h"
80   #elif __ARM_ARCH_PROFILE == 'R'
81     #include "r-profile/cmsis_gcc_r.h"
82   #elif __ARM_ARCH_PROFILE == 'M'
83     #include "m-profile/cmsis_gcc_m.h"
84   #else
85     #error "Unknown Arm architecture profile"
86   #endif
87
88
89 /*
90  * IAR Compiler
91  */
92 #elif defined ( __ICCARM__ )
93   #if __ARM_ARCH_PROFILE == 'A'
94     #include "a-profile/cmsis_iccarm_a.h"
95   #elif __ARM_ARCH_PROFILE == 'R'
96     #include "r-profile/cmsis_iccarm_r.h"
97   #elif __ARM_ARCH_PROFILE == 'M'
98     #include "m-profile/cmsis_iccarm_m.h"
99   #else
100     #error "Unknown Arm architecture profile"
101   #endif
102
103
104 /*
105  * TI Arm Compiler (armcl)
106  */
107 #elif defined ( __TI_ARM__ )
108   #include <cmsis_ccs.h>
109
110   #ifndef   __ASM
111     #define __ASM                                  __asm
112   #endif
113   #ifndef   __INLINE
114     #define __INLINE                               inline
115   #endif
116   #ifndef   __STATIC_INLINE
117     #define __STATIC_INLINE                        static inline
118   #endif
119   #ifndef   __STATIC_FORCEINLINE
120     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
121   #endif
122   #ifndef   __NO_RETURN
123     #define __NO_RETURN                            __attribute__((noreturn))
124   #endif
125   #ifndef   __USED
126     #define __USED                                 __attribute__((used))
127   #endif
128   #ifndef   __WEAK
129     #define __WEAK                                 __attribute__((weak))
130   #endif
131   #ifndef   __PACKED
132     #define __PACKED                               __attribute__((packed))
133   #endif
134   #ifndef   __PACKED_STRUCT
135     #define __PACKED_STRUCT                        struct __attribute__((packed))
136   #endif
137   #ifndef   __PACKED_UNION
138     #define __PACKED_UNION                         union __attribute__((packed))
139   #endif
140   #ifndef   __UNALIGNED_UINT32        /* deprecated */
141     struct __attribute__((packed)) T_UINT32 { uint32_t v; };
142     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
143   #endif
144   #ifndef   __UNALIGNED_UINT16_WRITE
145     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
146     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
147   #endif
148   #ifndef   __UNALIGNED_UINT16_READ
149     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
150     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
151   #endif
152   #ifndef   __UNALIGNED_UINT32_WRITE
153     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
154     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
155   #endif
156   #ifndef   __UNALIGNED_UINT32_READ
157     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
158     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
159   #endif
160   #ifndef   __ALIGNED
161     #define __ALIGNED(x)                           __attribute__((aligned(x)))
162   #endif
163   #ifndef   __RESTRICT
164     #define __RESTRICT                             __restrict
165   #endif
166   #ifndef   __COMPILER_BARRIER
167     #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
168     #define __COMPILER_BARRIER()                   (void)0
169   #endif
170   #ifndef __NO_INIT
171     #define __NO_INIT                              __attribute__ ((section (".bss.noinit")))
172   #endif
173   #ifndef __ALIAS
174     #define __ALIAS(x)                             __attribute__ ((alias(x)))
175   #endif
176
177 /*
178  * TASKING Compiler
179  */
180 #elif defined ( __TASKING__ )
181   /*
182    * The CMSIS functions have been implemented as intrinsics in the compiler.
183    * Please use "carm -?i" to get an up to date list of all intrinsics,
184    * Including the CMSIS ones.
185    */
186
187   #ifndef   __ASM
188     #define __ASM                                  __asm
189   #endif
190   #ifndef   __INLINE
191     #define __INLINE                               inline
192   #endif
193   #ifndef   __STATIC_INLINE
194     #define __STATIC_INLINE                        static inline
195   #endif
196   #ifndef   __STATIC_FORCEINLINE
197     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
198   #endif
199   #ifndef   __NO_RETURN
200     #define __NO_RETURN                            __attribute__((noreturn))
201   #endif
202   #ifndef   __USED
203     #define __USED                                 __attribute__((used))
204   #endif
205   #ifndef   __WEAK
206     #define __WEAK                                 __attribute__((weak))
207   #endif
208   #ifndef   __PACKED
209     #define __PACKED                               __packed__
210   #endif
211   #ifndef   __PACKED_STRUCT
212     #define __PACKED_STRUCT                        struct __packed__
213   #endif
214   #ifndef   __PACKED_UNION
215     #define __PACKED_UNION                         union __packed__
216   #endif
217   #ifndef   __UNALIGNED_UINT32        /* deprecated */
218     struct __packed__ T_UINT32 { uint32_t v; };
219     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
220   #endif
221   #ifndef   __UNALIGNED_UINT16_WRITE
222     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
223     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
224   #endif
225   #ifndef   __UNALIGNED_UINT16_READ
226     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
227     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
228   #endif
229   #ifndef   __UNALIGNED_UINT32_WRITE
230     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
231     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
232   #endif
233   #ifndef   __UNALIGNED_UINT32_READ
234     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
235     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
236   #endif
237   #ifndef   __ALIGNED
238     #define __ALIGNED(x)                           __align(x)
239   #endif
240   #ifndef   __RESTRICT
241     #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
242     #define __RESTRICT
243   #endif
244   #ifndef   __COMPILER_BARRIER
245     #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
246     #define __COMPILER_BARRIER()                   (void)0
247   #endif
248   #ifndef __NO_INIT
249     #define __NO_INIT                              __attribute__ ((section (".bss.noinit")))
250   #endif
251   #ifndef __ALIAS
252     #define __ALIAS(x)                             __attribute__ ((alias(x)))
253   #endif
254
255 /*
256  * COSMIC Compiler
257  */
258 #elif defined ( __CSMC__ )
259    #include <cmsis_csm.h>
260
261  #ifndef   __ASM
262     #define __ASM                                  _asm
263   #endif
264   #ifndef   __INLINE
265     #define __INLINE                               inline
266   #endif
267   #ifndef   __STATIC_INLINE
268     #define __STATIC_INLINE                        static inline
269   #endif
270   #ifndef   __STATIC_FORCEINLINE
271     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
272   #endif
273   #ifndef   __NO_RETURN
274     // NO RETURN is automatically detected hence no warning here
275     #define __NO_RETURN
276   #endif
277   #ifndef   __USED
278     #warning No compiler specific solution for __USED. __USED is ignored.
279     #define __USED
280   #endif
281   #ifndef   __WEAK
282     #define __WEAK                                 __weak
283   #endif
284   #ifndef   __PACKED
285     #define __PACKED                               @packed
286   #endif
287   #ifndef   __PACKED_STRUCT
288     #define __PACKED_STRUCT                        @packed struct
289   #endif
290   #ifndef   __PACKED_UNION
291     #define __PACKED_UNION                         @packed union
292   #endif
293   #ifndef   __UNALIGNED_UINT32        /* deprecated */
294     @packed struct T_UINT32 { uint32_t v; };
295     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
296   #endif
297   #ifndef   __UNALIGNED_UINT16_WRITE
298     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
299     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
300   #endif
301   #ifndef   __UNALIGNED_UINT16_READ
302     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
303     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
304   #endif
305   #ifndef   __UNALIGNED_UINT32_WRITE
306     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
307     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
308   #endif
309   #ifndef   __UNALIGNED_UINT32_READ
310     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
311     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
312   #endif
313   #ifndef   __ALIGNED
314     #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
315     #define __ALIGNED(x)
316   #endif
317   #ifndef   __RESTRICT
318     #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
319     #define __RESTRICT
320   #endif
321   #ifndef   __COMPILER_BARRIER
322     #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
323     #define __COMPILER_BARRIER()                   (void)0
324   #endif
325   #ifndef __NO_INIT
326     #define __NO_INIT                              __attribute__ ((section (".bss.noinit")))
327   #endif
328   #ifndef __ALIAS
329     #define __ALIAS(x)                             __attribute__ ((alias(x)))
330   #endif
331
332 #else
333   #error Unknown compiler.
334 #endif
335
336
337 #endif /* __CMSIS_COMPILER_H */
338