]> begriffs open source - cmsis/blob - CMSIS/Core/Include/cmsis_compiler.h
Core(M): Capitalize ETM register definition macros (#1604).
[cmsis] / CMSIS / Core / Include / cmsis_compiler.h
1 /**************************************************************************//**
2  * @file     cmsis_compiler.h
3  * @brief    CMSIS compiler generic header file
4  * @version  V5.2.0
5  * @date     20. January 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 4/5
32  */
33 #if   defined ( __CC_ARM )
34   #include "cmsis_armcc.h"
35
36
37 /*
38  * Arm Compiler 6.6 LTM (armclang)
39  */
40 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) && (__ARMCC_VERSION < 6100100)
41   #include "cmsis_armclang_ltm.h"
42
43   /*
44  * Arm Compiler above 6.10.1 (armclang)
45  */
46 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
47   #include "cmsis_armclang.h"
48
49
50 /*
51  * GNU Compiler
52  */
53 #elif defined ( __GNUC__ )
54   #include "cmsis_gcc.h"
55
56
57 /*
58  * IAR Compiler
59  */
60 #elif defined ( __ICCARM__ )
61   #include <cmsis_iccarm.h>
62
63
64 /*
65  * TI Arm Compiler
66  */
67 #elif defined ( __TI_ARM__ )
68   #include <cmsis_ccs.h>
69
70   #ifndef   __ASM
71     #define __ASM                                  __asm
72   #endif
73   #ifndef   __INLINE
74     #define __INLINE                               inline
75   #endif
76   #ifndef   __STATIC_INLINE
77     #define __STATIC_INLINE                        static inline
78   #endif
79   #ifndef   __STATIC_FORCEINLINE
80     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
81   #endif
82   #ifndef   __NO_RETURN
83     #define __NO_RETURN                            __attribute__((noreturn))
84   #endif
85   #ifndef   __USED
86     #define __USED                                 __attribute__((used))
87   #endif
88   #ifndef   __WEAK
89     #define __WEAK                                 __attribute__((weak))
90   #endif
91   #ifndef   __PACKED
92     #define __PACKED                               __attribute__((packed))
93   #endif
94   #ifndef   __PACKED_STRUCT
95     #define __PACKED_STRUCT                        struct __attribute__((packed))
96   #endif
97   #ifndef   __PACKED_UNION
98     #define __PACKED_UNION                         union __attribute__((packed))
99   #endif
100   #ifndef   __UNALIGNED_UINT32        /* deprecated */
101     struct __attribute__((packed)) T_UINT32 { uint32_t v; };
102     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
103   #endif
104   #ifndef   __UNALIGNED_UINT16_WRITE
105     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
106     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
107   #endif
108   #ifndef   __UNALIGNED_UINT16_READ
109     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
110     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
111   #endif
112   #ifndef   __UNALIGNED_UINT32_WRITE
113     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
114     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
115   #endif
116   #ifndef   __UNALIGNED_UINT32_READ
117     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
118     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
119   #endif
120   #ifndef   __ALIGNED
121     #define __ALIGNED(x)                           __attribute__((aligned(x)))
122   #endif
123   #ifndef   __RESTRICT
124     #define __RESTRICT                             __restrict
125   #endif
126   #ifndef   __COMPILER_BARRIER
127     #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
128     #define __COMPILER_BARRIER()                   (void)0
129   #endif
130   #ifndef __NO_INIT
131     #define __NO_INIT                              __attribute__ ((section (".bss.noinit")))
132   #endif
133   #ifndef __ALIAS
134     #define __ALIAS(x)                             __attribute__ ((alias(x)))
135   #endif
136
137 /*
138  * TASKING Compiler
139  */
140 #elif defined ( __TASKING__ )
141   /*
142    * The CMSIS functions have been implemented as intrinsics in the compiler.
143    * Please use "carm -?i" to get an up to date list of all intrinsics,
144    * Including the CMSIS ones.
145    */
146
147   #ifndef   __ASM
148     #define __ASM                                  __asm
149   #endif
150   #ifndef   __INLINE
151     #define __INLINE                               inline
152   #endif
153   #ifndef   __STATIC_INLINE
154     #define __STATIC_INLINE                        static inline
155   #endif
156   #ifndef   __STATIC_FORCEINLINE
157     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
158   #endif
159   #ifndef   __NO_RETURN
160     #define __NO_RETURN                            __attribute__((noreturn))
161   #endif
162   #ifndef   __USED
163     #define __USED                                 __attribute__((used))
164   #endif
165   #ifndef   __WEAK
166     #define __WEAK                                 __attribute__((weak))
167   #endif
168   #ifndef   __PACKED
169     #define __PACKED                               __packed__
170   #endif
171   #ifndef   __PACKED_STRUCT
172     #define __PACKED_STRUCT                        struct __packed__
173   #endif
174   #ifndef   __PACKED_UNION
175     #define __PACKED_UNION                         union __packed__
176   #endif
177   #ifndef   __UNALIGNED_UINT32        /* deprecated */
178     struct __packed__ T_UINT32 { uint32_t v; };
179     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
180   #endif
181   #ifndef   __UNALIGNED_UINT16_WRITE
182     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
183     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
184   #endif
185   #ifndef   __UNALIGNED_UINT16_READ
186     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
187     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
188   #endif
189   #ifndef   __UNALIGNED_UINT32_WRITE
190     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
191     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
192   #endif
193   #ifndef   __UNALIGNED_UINT32_READ
194     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
195     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
196   #endif
197   #ifndef   __ALIGNED
198     #define __ALIGNED(x)              __align(x)
199   #endif
200   #ifndef   __RESTRICT
201     #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
202     #define __RESTRICT
203   #endif
204   #ifndef   __COMPILER_BARRIER
205     #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
206     #define __COMPILER_BARRIER()                   (void)0
207   #endif
208   #ifndef __NO_INIT
209     #define __NO_INIT                              __attribute__ ((section (".bss.noinit")))
210   #endif
211   #ifndef __ALIAS
212     #define __ALIAS(x)                             __attribute__ ((alias(x)))
213   #endif
214
215 /*
216  * COSMIC Compiler
217  */
218 #elif defined ( __CSMC__ )
219    #include <cmsis_csm.h>
220
221  #ifndef   __ASM
222     #define __ASM                                  _asm
223   #endif
224   #ifndef   __INLINE
225     #define __INLINE                               inline
226   #endif
227   #ifndef   __STATIC_INLINE
228     #define __STATIC_INLINE                        static inline
229   #endif
230   #ifndef   __STATIC_FORCEINLINE
231     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
232   #endif
233   #ifndef   __NO_RETURN
234     // NO RETURN is automatically detected hence no warning here
235     #define __NO_RETURN
236   #endif
237   #ifndef   __USED
238     #warning No compiler specific solution for __USED. __USED is ignored.
239     #define __USED
240   #endif
241   #ifndef   __WEAK
242     #define __WEAK                                 __weak
243   #endif
244   #ifndef   __PACKED
245     #define __PACKED                               @packed
246   #endif
247   #ifndef   __PACKED_STRUCT
248     #define __PACKED_STRUCT                        @packed struct
249   #endif
250   #ifndef   __PACKED_UNION
251     #define __PACKED_UNION                         @packed union
252   #endif
253   #ifndef   __UNALIGNED_UINT32        /* deprecated */
254     @packed struct T_UINT32 { uint32_t v; };
255     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
256   #endif
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))
260   #endif
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)
264   #endif
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))
268   #endif
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)
272   #endif
273   #ifndef   __ALIGNED
274     #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
275     #define __ALIGNED(x)
276   #endif
277   #ifndef   __RESTRICT
278     #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
279     #define __RESTRICT
280   #endif
281   #ifndef   __COMPILER_BARRIER
282     #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
283     #define __COMPILER_BARRIER()                   (void)0
284   #endif
285   #ifndef __NO_INIT
286     #define __NO_INIT                              __attribute__ ((section (".bss.noinit")))
287   #endif
288   #ifndef __ALIAS
289     #define __ALIAS(x)                             __attribute__ ((alias(x)))
290   #endif
291
292 #else
293   #error Unknown compiler.
294 #endif
295
296
297 #endif /* __CMSIS_COMPILER_H */
298