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