]> begriffs open source - cmsis/blob - CMSIS/Core/Include/cmsis_compiler.h
core: Allow virtualization of NVIC_SystemReset
[cmsis] / CMSIS / Core / Include / cmsis_compiler.h
1 /**************************************************************************//**
2  * @file     cmsis_compiler.h
3  * @brief    CMSIS compiler generic header file
4  * @version  V5.0.2
5  * @date     13. February 2017
6  ******************************************************************************/
7 /*
8  * Copyright (c) 2009-2017 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 (armclang)
39  */
40 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
41   #include "cmsis_armclang.h"
42
43
44 /*
45  * GNU Compiler
46  */
47 #elif defined ( __GNUC__ )
48   #include "cmsis_gcc.h"
49
50
51 /*
52  * IAR Compiler
53  */
54 #elif defined ( __ICCARM__ )
55
56   #ifndef   __ASM
57     #define __ASM                                  __asm
58   #endif
59   #ifndef   __INLINE
60     #define __INLINE                               inline
61   #endif
62   #ifndef   __STATIC_INLINE
63     #define __STATIC_INLINE                        static inline
64   #endif
65
66   #include <cmsis_iar.h>
67
68   #ifndef   __NO_RETURN
69     #define __NO_RETURN                            __noreturn
70   #endif
71   #ifndef   __USED
72     #define __USED                                 __root
73   #endif
74   #ifndef   __WEAK
75     #define __WEAK                                 __weak
76   #endif
77   #ifndef   __PACKED
78     #define __PACKED                               __packed
79   #endif
80   #ifndef   __PACKED_STRUCT
81     #define __PACKED_STRUCT                        __packed struct
82   #endif
83   #ifndef   __UNALIGNED_UINT32        /* deprecated */
84     __packed struct T_UINT32 { uint32_t v; };
85     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
86   #endif
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))
90   #endif
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)
94   #endif
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))
98   #endif
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)
102   #endif
103   #ifndef   __ALIGNED
104     #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
105     #define __ALIGNED(x)
106   #endif
107
108
109 /*
110  * TI ARM Compiler
111  */
112 #elif defined ( __TI_ARM__ )
113   #include <cmsis_ccs.h>
114
115   #ifndef   __ASM
116     #define __ASM                                  __asm
117   #endif
118   #ifndef   __INLINE
119     #define __INLINE                               inline
120   #endif
121   #ifndef   __STATIC_INLINE
122     #define __STATIC_INLINE                        static inline
123   #endif
124   #ifndef   __NO_RETURN
125     #define __NO_RETURN                            __attribute__((noreturn))
126   #endif
127   #ifndef   __USED
128     #define __USED                                 __attribute__((used))
129   #endif
130   #ifndef   __WEAK
131     #define __WEAK                                 __attribute__((weak))
132   #endif
133   #ifndef   __PACKED
134     #define __PACKED                               __attribute__((packed))
135   #endif
136   #ifndef   __PACKED_STRUCT
137     #define __PACKED_STRUCT                        struct __attribute__((packed))
138   #endif
139   #ifndef   __UNALIGNED_UINT32        /* deprecated */
140     struct __attribute__((packed)) T_UINT32 { uint32_t v; };
141     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
142   #endif
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))
146   #endif
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)
150   #endif
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))
154   #endif
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)
158   #endif
159   #ifndef   __ALIGNED
160     #define __ALIGNED(x)                           __attribute__((aligned(x)))
161   #endif
162
163
164 /*
165  * TASKING Compiler
166  */
167 #elif defined ( __TASKING__ )
168   /*
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.
172    */
173
174   #ifndef   __ASM
175     #define __ASM                                  __asm
176   #endif
177   #ifndef   __INLINE
178     #define __INLINE                               inline
179   #endif
180   #ifndef   __STATIC_INLINE
181     #define __STATIC_INLINE                        static inline
182   #endif
183   #ifndef   __NO_RETURN
184     #define __NO_RETURN                            __attribute__((noreturn))
185   #endif
186   #ifndef   __USED
187     #define __USED                                 __attribute__((used))
188   #endif
189   #ifndef   __WEAK
190     #define __WEAK                                 __attribute__((weak))
191   #endif
192   #ifndef   __PACKED
193     #define __PACKED                               __packed__
194   #endif
195   #ifndef   __PACKED_STRUCT
196     #define __PACKED_STRUCT                        struct __packed__
197   #endif
198   #ifndef   __UNALIGNED_UINT32        /* deprecated */
199     struct __packed__ T_UINT32 { uint32_t v; };
200     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
201   #endif
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))
205   #endif
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)
209   #endif
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))
213   #endif
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)
217   #endif
218   #ifndef   __ALIGNED
219     #define __ALIGNED(x)              __align(x)
220   #endif
221
222
223 /*
224  * COSMIC Compiler
225  */
226 #elif defined ( __CSMC__ )
227    #include <cmsis_csm.h>
228
229  #ifndef   __ASM
230     #define __ASM                                  _asm
231   #endif
232   #ifndef   __INLINE
233     #define __INLINE                               inline
234   #endif
235   #ifndef   __STATIC_INLINE
236     #define __STATIC_INLINE                        static inline
237   #endif
238   #ifndef   __NO_RETURN
239     // NO RETURN is automatically detected hence no warning here
240     #define __NO_RETURN
241   #endif
242   #ifndef   __USED
243     #warning No compiler specific solution for __USED. __USED is ignored.
244     #define __USED
245   #endif
246   #ifndef   __WEAK
247     #define __WEAK                                 __weak
248   #endif
249   #ifndef   __PACKED
250     #define __PACKED                               @packed
251   #endif
252   #ifndef   __PACKED_STRUCT
253     #define __PACKED_STRUCT                        @packed struct
254   #endif
255   #ifndef   __UNALIGNED_UINT32        /* deprecated */
256     @packed struct T_UINT32 { uint32_t v; };
257     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
258   #endif
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))
262   #endif
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)
266   #endif
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))
270   #endif
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)
274   #endif
275   #ifndef   __ALIGNED
276     #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
277     #define __ALIGNED(x)
278   #endif
279
280
281 #else
282   #error Unknown compiler.
283 #endif
284
285
286 #endif /* __CMSIS_COMPILER_H */
287