1 /*
2  * Copyright (c) 2009-2023 Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 /*
20  * CMSIS Compiler Generic Header File
21  */
22 
23 #ifndef __CMSIS_COMPILER_H
24 #define __CMSIS_COMPILER_H
25 
26 #include <stdint.h>
27 
28 /*
29  * Arm Compiler above 6.10.1 (armclang)
30  */
31 #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
32   #include "cmsis_armclang.h"
33 
34 /*
35  * TI Arm Clang Compiler (tiarmclang)
36  */
37 #elif defined (__ti__)
38   #include "cmsis_tiarmclang.h"
39 
40 
41 /*
42  * LLVM/Clang Compiler
43  */
44 #elif defined ( __clang__ )
45   #include "cmsis_clang.h"
46 
47 
48 /*
49  * GNU Compiler
50  */
51 #elif defined ( __GNUC__ )
52   #include "cmsis_gcc.h"
53 
54 
55 /*
56  * IAR Compiler
57  */
58 #elif defined ( __ICCARM__ )
59   #include "cmsis_iccarm.h"
60 
61 
62 /*
63  * TI Arm Compiler (armcl)
64  */
65 #elif defined ( __TI_ARM__ )
66   #include <cmsis_ccs.h>
67 
68   #ifndef   __ASM
69     #define __ASM                                  __asm
70   #endif
71   #ifndef   __INLINE
72     #define __INLINE                               inline
73   #endif
74   #ifndef   __STATIC_INLINE
75     #define __STATIC_INLINE                        static inline
76   #endif
77   #ifndef   __STATIC_FORCEINLINE
78     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
79   #endif
80   #ifndef   __NO_RETURN
81     #define __NO_RETURN                            __attribute__((noreturn))
82   #endif
83   #ifndef   __USED
84     #define __USED                                 __attribute__((used))
85   #endif
86   #ifndef   __WEAK
87     #define __WEAK                                 __attribute__((weak))
88   #endif
89   #ifndef   __PACKED
90     #define __PACKED                               __attribute__((packed))
91   #endif
92   #ifndef   __PACKED_STRUCT
93     #define __PACKED_STRUCT                        struct __attribute__((packed))
94   #endif
95   #ifndef   __PACKED_UNION
96     #define __PACKED_UNION                         union __attribute__((packed))
97   #endif
98   #ifndef   __UNALIGNED_UINT16_WRITE
99     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
100     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
101   #endif
102   #ifndef   __UNALIGNED_UINT16_READ
103     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
104     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
105   #endif
106   #ifndef   __UNALIGNED_UINT32_WRITE
107     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
108     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
109   #endif
110   #ifndef   __UNALIGNED_UINT32_READ
111     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
112     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
113   #endif
114   #ifndef   __ALIGNED
115     #define __ALIGNED(x)                           __attribute__((aligned(x)))
116   #endif
117   #ifndef   __RESTRICT
118     #define __RESTRICT                             __restrict
119   #endif
120   #ifndef   __COMPILER_BARRIER
121     #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
122     #define __COMPILER_BARRIER()                   (void)0
123   #endif
124   #ifndef __NO_INIT
125     #define __NO_INIT                              __attribute__ ((section (".noinit")))
126   #endif
127   #ifndef __ALIAS
128     #define __ALIAS(x)                             __attribute__ ((alias(x)))
129   #endif
130 
131 /*
132  * TASKING Compiler
133  */
134 #elif defined ( __TASKING__ )
135   /*
136    * The CMSIS functions have been implemented as intrinsics in the compiler.
137    * Please use "carm -?i" to get an up to date list of all intrinsics,
138    * Including the CMSIS ones.
139    */
140 
141   #ifndef   __ASM
142     #define __ASM                                  __asm
143   #endif
144   #ifndef   __INLINE
145     #define __INLINE                               inline
146   #endif
147   #ifndef   __STATIC_INLINE
148     #define __STATIC_INLINE                        static inline
149   #endif
150   #ifndef   __STATIC_FORCEINLINE
151     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
152   #endif
153   #ifndef   __NO_RETURN
154     #define __NO_RETURN                            __attribute__((noreturn))
155   #endif
156   #ifndef   __USED
157     #define __USED                                 __attribute__((used))
158   #endif
159   #ifndef   __WEAK
160     #define __WEAK                                 __attribute__((weak))
161   #endif
162   #ifndef   __PACKED
163     #define __PACKED                               __packed__
164   #endif
165   #ifndef   __PACKED_STRUCT
166     #define __PACKED_STRUCT                        struct __packed__
167   #endif
168   #ifndef   __PACKED_UNION
169     #define __PACKED_UNION                         union __packed__
170   #endif
171   #ifndef   __UNALIGNED_UINT16_WRITE
172     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
173     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
174   #endif
175   #ifndef   __UNALIGNED_UINT16_READ
176     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
177     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
178   #endif
179   #ifndef   __UNALIGNED_UINT32_WRITE
180     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
181     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
182   #endif
183   #ifndef   __UNALIGNED_UINT32_READ
184     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
185     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
186   #endif
187   #ifndef   __ALIGNED
188     #define __ALIGNED(x)                           __align(x)
189   #endif
190   #ifndef   __RESTRICT
191     #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
192     #define __RESTRICT
193   #endif
194   #ifndef   __COMPILER_BARRIER
195     #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
196     #define __COMPILER_BARRIER()                   (void)0
197   #endif
198   #ifndef __NO_INIT
199     #define __NO_INIT                              __attribute__ ((section (".noinit")))
200   #endif
201   #ifndef __ALIAS
202     #define __ALIAS(x)                             __attribute__ ((alias(x)))
203   #endif
204 
205 /*
206  * COSMIC Compiler
207  */
208 #elif defined ( __CSMC__ )
209    #include <cmsis_csm.h>
210 
211  #ifndef   __ASM
212     #define __ASM                                  _asm
213   #endif
214   #ifndef   __INLINE
215     #define __INLINE                               inline
216   #endif
217   #ifndef   __STATIC_INLINE
218     #define __STATIC_INLINE                        static inline
219   #endif
220   #ifndef   __STATIC_FORCEINLINE
221     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
222   #endif
223   #ifndef   __NO_RETURN
224     // NO RETURN is automatically detected hence no warning here
225     #define __NO_RETURN
226   #endif
227   #ifndef   __USED
228     #warning No compiler specific solution for __USED. __USED is ignored.
229     #define __USED
230   #endif
231   #ifndef   __WEAK
232     #define __WEAK                                 __weak
233   #endif
234   #ifndef   __PACKED
235     #define __PACKED                               @packed
236   #endif
237   #ifndef   __PACKED_STRUCT
238     #define __PACKED_STRUCT                        @packed struct
239   #endif
240   #ifndef   __PACKED_UNION
241     #define __PACKED_UNION                         @packed union
242   #endif
243   #ifndef   __UNALIGNED_UINT16_WRITE
244     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
245     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
246   #endif
247   #ifndef   __UNALIGNED_UINT16_READ
248     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
249     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
250   #endif
251   #ifndef   __UNALIGNED_UINT32_WRITE
252     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
253     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
254   #endif
255   #ifndef   __UNALIGNED_UINT32_READ
256     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
257     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
258   #endif
259   #ifndef   __ALIGNED
260     #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
261     #define __ALIGNED(x)
262   #endif
263   #ifndef   __RESTRICT
264     #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
265     #define __RESTRICT
266   #endif
267   #ifndef   __COMPILER_BARRIER
268     #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
269     #define __COMPILER_BARRIER()                   (void)0
270   #endif
271   #ifndef __NO_INIT
272     #define __NO_INIT                              __attribute__ ((section (".noinit")))
273   #endif
274   #ifndef __ALIAS
275     #define __ALIAS(x)                             __attribute__ ((alias(x)))
276   #endif
277 
278 #else
279   #error Unknown compiler.
280 #endif
281 
282 
283 #endif /* __CMSIS_COMPILER_H */
284 
285