]> begriffs open source - cmsis/blob - CMSIS/Core_A/Include/cmsis_iccarm.h
IAR: IAR compilation problem with __RESTRICT define (7.80)
[cmsis] / CMSIS / Core_A / Include / cmsis_iccarm.h
1 /**************************************************************************//**
2  * @file     cmsis_iccarm.h
3  * @brief    CMSIS compiler ICCARM (IAR Compiler for Arm) header file
4  * @version  V5.0.6
5  * @date     02. March 2018
6  ******************************************************************************/
7
8 //------------------------------------------------------------------------------
9 //
10 // Copyright (c) 2017-2018 IAR Systems
11 //
12 // Licensed under the Apache License, Version 2.0 (the "License")
13 // you may not use this file except in compliance with the License.
14 // You may obtain a copy of the License at
15 //     http://www.apache.org/licenses/LICENSE-2.0
16 //
17 // Unless required by applicable law or agreed to in writing, software
18 // distributed under the License is distributed on an "AS IS" BASIS,
19 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 // See the License for the specific language governing permissions and
21 // limitations under the License.
22 //
23 //------------------------------------------------------------------------------
24
25
26 #ifndef __CMSIS_ICCARM_H__
27 #define __CMSIS_ICCARM_H__
28
29 #ifndef __ICCARM__
30   #error This file should only be compiled by ICCARM
31 #endif
32
33 #pragma system_include
34
35 #define __IAR_FT _Pragma("inline=forced") __intrinsic
36
37 #if (__VER__ >= 8000000)
38   #define __ICCARM_V8 1
39 #else
40   #define __ICCARM_V8 0
41 #endif
42
43 #pragma language=extended
44
45 #ifndef __ALIGNED
46   #if __ICCARM_V8
47     #define __ALIGNED(x) __attribute__((aligned(x)))
48   #elif (__VER__ >= 7080000)
49     /* Needs IAR language extensions */
50     #define __ALIGNED(x) __attribute__((aligned(x)))
51   #else
52     #warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored.
53     #define __ALIGNED(x)
54   #endif
55 #endif
56
57
58 /* Define compiler macros for CPU architecture, used in CMSIS 5.
59  */
60 #if __ARM_ARCH_7A__
61 /* Macro already defined */
62 #else
63   #if defined(__ARM7A__)
64     #define __ARM_ARCH_7A__ 1
65   #endif
66 #endif
67
68 #ifndef __ASM
69   #define __ASM __asm
70 #endif
71
72 #ifndef __INLINE
73   #define __INLINE inline
74 #endif
75
76 #ifndef   __NO_RETURN
77   #if __ICCARM_V8
78     #define __NO_RETURN __attribute__((__noreturn__))
79   #else
80     #define __NO_RETURN _Pragma("object_attribute=__noreturn")
81   #endif
82 #endif
83
84 #ifndef   __PACKED
85   /* Needs IAR language extensions */
86   #if __ICCARM_V8
87     #define __PACKED __attribute__((packed, aligned(1)))
88   #else
89     #define __PACKED __packed
90   #endif
91 #endif
92
93 #ifndef   __PACKED_STRUCT
94   /* Needs IAR language extensions */
95   #if __ICCARM_V8
96     #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
97   #else
98     #define __PACKED_STRUCT __packed struct
99   #endif
100 #endif
101
102 #ifndef   __PACKED_UNION
103   /* Needs IAR language extensions */
104   #if __ICCARM_V8
105     #define __PACKED_UNION union __attribute__((packed, aligned(1)))
106   #else
107     #define __PACKED_UNION __packed union
108   #endif
109 #endif
110
111 #ifndef   __RESTRICT
112   #if __ICCARM_V8
113     #define __RESTRICT            __restrict
114   #else
115     /* Needs IAR language extensions */
116     #define __RESTRICT            restrict
117   #endif
118 #endif
119
120 #ifndef   __STATIC_INLINE
121   #define __STATIC_INLINE       static inline
122 #endif
123
124 #ifndef   __FORCEINLINE
125   #define __FORCEINLINE         _Pragma("inline=forced")
126 #endif
127
128 #ifndef   __STATIC_FORCEINLINE
129   #define __STATIC_FORCEINLINE  __FORCEINLINE __STATIC_INLINE
130 #endif
131
132 #ifndef   CMSIS_DEPRECATED
133   #define CMSIS_DEPRECATED      __attribute__((deprecated))
134 #endif
135
136 #ifndef __UNALIGNED_UINT16_READ
137   #pragma language=save
138   #pragma language=extended
139   __IAR_FT uint16_t __iar_uint16_read(void const *ptr)
140   {
141     return *(__packed uint16_t*)(ptr);
142   }
143   #pragma language=restore
144   #define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR)
145 #endif
146
147
148 #ifndef __UNALIGNED_UINT16_WRITE
149   #pragma language=save
150   #pragma language=extended
151   __IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val)
152   {
153     *(__packed uint16_t*)(ptr) = val;;
154   }
155   #pragma language=restore
156   #define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL)
157 #endif
158
159 #ifndef __UNALIGNED_UINT32_READ
160   #pragma language=save
161   #pragma language=extended
162   __IAR_FT uint32_t __iar_uint32_read(void const *ptr)
163   {
164     return *(__packed uint32_t*)(ptr);
165   }
166   #pragma language=restore
167   #define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR)
168 #endif
169
170 #ifndef __UNALIGNED_UINT32_WRITE
171   #pragma language=save
172   #pragma language=extended
173   __IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val)
174   {
175     *(__packed uint32_t*)(ptr) = val;;
176   }
177   #pragma language=restore
178   #define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL)
179 #endif
180
181 #if 0
182 #ifndef __UNALIGNED_UINT32   /* deprecated */
183   #pragma language=save
184   #pragma language=extended
185   __packed struct  __iar_u32 { uint32_t v; };
186   #pragma language=restore
187   #define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v)
188 #endif
189 #endif
190
191 #ifndef   __USED
192   #if __ICCARM_V8
193     #define __USED __attribute__((used))
194   #else
195     #define __USED _Pragma("__root")
196   #endif
197 #endif
198
199 #ifndef   __WEAK
200   #if __ICCARM_V8
201     #define __WEAK __attribute__((weak))
202   #else
203     #define __WEAK _Pragma("__weak")
204   #endif
205 #endif
206
207
208 #ifndef __ICCARM_INTRINSICS_VERSION__
209   #define __ICCARM_INTRINSICS_VERSION__  0
210 #endif
211
212 #if __ICCARM_INTRINSICS_VERSION__ == 2
213
214   #if defined(__CLZ)
215     #undef __CLZ
216   #endif
217   #if defined(__REVSH)
218     #undef __REVSH
219   #endif
220   #if defined(__RBIT)
221     #undef __RBIT
222   #endif
223   #if defined(__SSAT)
224     #undef __SSAT
225   #endif
226   #if defined(__USAT)
227     #undef __USAT
228   #endif
229
230   #include "iccarm_builtin.h"
231
232   #define __enable_irq        __iar_builtin_enable_interrupt
233   #define __disable_irq       __iar_builtin_disable_interrupt
234   #define __enable_fault_irq    __iar_builtin_enable_fiq
235   #define __disable_fault_irq   __iar_builtin_disable_fiq
236   #define __arm_rsr           __iar_builtin_rsr
237   #define __arm_wsr           __iar_builtin_wsr
238
239   #if __FPU_PRESENT
240     #define __get_FPSCR()             (__arm_rsr("FPSCR"))
241   #else
242     #define __get_FPSCR()             ( 0 )
243   #endif
244
245   #define __set_FPSCR(VALUE)          (__arm_wsr("FPSCR", VALUE))
246
247   #define __get_CPSR()                (__arm_rsr("CPSR"))
248   #define __get_mode()                (__get_CPSR() & 0x1FU)
249
250   #define __set_CPSR(VALUE)           (__arm_wsr("CPSR", (VALUE)))
251   #define __set_mode(VALUE)           (__arm_wsr("CPSR_c", (VALUE)))
252
253
254   #define __get_FPEXC()       (__arm_rsr("FPEXC"))
255   #define __set_FPEXC(VALUE)    (__arm_wsr("FPEXC", VALUE))
256
257   #define __get_CP(cp, op1, RT, CRn, CRm, op2) \
258     ((RT) = __arm_rsr("p" # cp ":" # op1 ":c" # CRn ":c" # CRm ":" # op2))
259
260   #define __set_CP(cp, op1, RT, CRn, CRm, op2) \
261     (__arm_wsr("p" # cp ":" # op1 ":c" # CRn ":c" # CRm ":" # op2, (RT)))
262
263   #define __get_CP64(cp, op1, Rt, CRm) \
264     __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm  : "=r" (Rt) : : "memory" )
265
266   #define __set_CP64(cp, op1, Rt, CRm) \
267     __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm  : : "r" (Rt) : "memory" )
268
269   #include "cmsis_cp15.h"
270
271   #define __NOP     __iar_builtin_no_operation
272
273   #define __CLZ     __iar_builtin_CLZ
274   #define __CLREX   __iar_builtin_CLREX
275
276   #define __DMB     __iar_builtin_DMB
277   #define __DSB     __iar_builtin_DSB
278   #define __ISB     __iar_builtin_ISB
279
280   #define __LDREXB  __iar_builtin_LDREXB
281   #define __LDREXH  __iar_builtin_LDREXH
282   #define __LDREXW  __iar_builtin_LDREX
283
284   #define __RBIT    __iar_builtin_RBIT
285   #define __REV     __iar_builtin_REV
286   #define __REV16   __iar_builtin_REV16
287
288   __IAR_FT int16_t __REVSH(int16_t val)
289   {
290     return (int16_t) __iar_builtin_REVSH(val);
291   }
292
293   #define __ROR     __iar_builtin_ROR
294   #define __RRX     __iar_builtin_RRX
295
296   #define __SEV     __iar_builtin_SEV
297
298   #define __SSAT    __iar_builtin_SSAT
299
300   #define __STREXB  __iar_builtin_STREXB
301   #define __STREXH  __iar_builtin_STREXH
302   #define __STREXW  __iar_builtin_STREX
303
304   #define __USAT    __iar_builtin_USAT
305
306   #define __WFE     __iar_builtin_WFE
307   #define __WFI     __iar_builtin_WFI
308
309   #define __SADD8   __iar_builtin_SADD8
310   #define __QADD8   __iar_builtin_QADD8
311   #define __SHADD8  __iar_builtin_SHADD8
312   #define __UADD8   __iar_builtin_UADD8
313   #define __UQADD8  __iar_builtin_UQADD8
314   #define __UHADD8  __iar_builtin_UHADD8
315   #define __SSUB8   __iar_builtin_SSUB8
316   #define __QSUB8   __iar_builtin_QSUB8
317   #define __SHSUB8  __iar_builtin_SHSUB8
318   #define __USUB8   __iar_builtin_USUB8
319   #define __UQSUB8  __iar_builtin_UQSUB8
320   #define __UHSUB8  __iar_builtin_UHSUB8
321   #define __SADD16  __iar_builtin_SADD16
322   #define __QADD16  __iar_builtin_QADD16
323   #define __SHADD16 __iar_builtin_SHADD16
324   #define __UADD16  __iar_builtin_UADD16
325   #define __UQADD16 __iar_builtin_UQADD16
326   #define __UHADD16 __iar_builtin_UHADD16
327   #define __SSUB16  __iar_builtin_SSUB16
328   #define __QSUB16  __iar_builtin_QSUB16
329   #define __SHSUB16 __iar_builtin_SHSUB16
330   #define __USUB16  __iar_builtin_USUB16
331   #define __UQSUB16 __iar_builtin_UQSUB16
332   #define __UHSUB16 __iar_builtin_UHSUB16
333   #define __SASX    __iar_builtin_SASX
334   #define __QASX    __iar_builtin_QASX
335   #define __SHASX   __iar_builtin_SHASX
336   #define __UASX    __iar_builtin_UASX
337   #define __UQASX   __iar_builtin_UQASX
338   #define __UHASX   __iar_builtin_UHASX
339   #define __SSAX    __iar_builtin_SSAX
340   #define __QSAX    __iar_builtin_QSAX
341   #define __SHSAX   __iar_builtin_SHSAX
342   #define __USAX    __iar_builtin_USAX
343   #define __UQSAX   __iar_builtin_UQSAX
344   #define __UHSAX   __iar_builtin_UHSAX
345   #define __USAD8   __iar_builtin_USAD8
346   #define __USADA8  __iar_builtin_USADA8
347   #define __SSAT16  __iar_builtin_SSAT16
348   #define __USAT16  __iar_builtin_USAT16
349   #define __UXTB16  __iar_builtin_UXTB16
350   #define __UXTAB16 __iar_builtin_UXTAB16
351   #define __SXTB16  __iar_builtin_SXTB16
352   #define __SXTAB16 __iar_builtin_SXTAB16
353   #define __SMUAD   __iar_builtin_SMUAD
354   #define __SMUADX  __iar_builtin_SMUADX
355   #define __SMMLA   __iar_builtin_SMMLA
356   #define __SMLAD   __iar_builtin_SMLAD
357   #define __SMLADX  __iar_builtin_SMLADX
358   #define __SMLALD  __iar_builtin_SMLALD
359   #define __SMLALDX __iar_builtin_SMLALDX
360   #define __SMUSD   __iar_builtin_SMUSD
361   #define __SMUSDX  __iar_builtin_SMUSDX
362   #define __SMLSD   __iar_builtin_SMLSD
363   #define __SMLSDX  __iar_builtin_SMLSDX
364   #define __SMLSLD  __iar_builtin_SMLSLD
365   #define __SMLSLDX __iar_builtin_SMLSLDX
366   #define __SEL     __iar_builtin_SEL
367   #define __QADD    __iar_builtin_QADD
368   #define __QSUB    __iar_builtin_QSUB
369   #define __PKHBT   __iar_builtin_PKHBT
370   #define __PKHTB   __iar_builtin_PKHTB
371
372 #else /* __ICCARM_INTRINSICS_VERSION__ == 2 */
373
374   #if !__FPU_PRESENT
375   #define __get_FPSCR __cmsis_iar_get_FPSR_not_active
376   #endif
377
378   #ifdef __INTRINSICS_INCLUDED
379   #error intrinsics.h is already included previously!
380   #endif
381
382   #include <intrinsics.h>
383
384   #if !__FPU_PRESENT
385   #define __get_FPSCR() (0)
386   #endif
387
388   #pragma diag_suppress=Pe940
389   #pragma diag_suppress=Pe177
390
391   #define __enable_irq        __enable_interrupt
392   #define __disable_irq       __disable_interrupt
393   #define __enable_fault_irq    __enable_fiq
394   #define __disable_fault_irq   __disable_fiq
395   #define __NOP               __no_operation
396
397   #define __get_xPSR          __get_PSR
398
399   __IAR_FT void __set_mode(uint32_t mode)
400   {
401     __ASM volatile("MSR  cpsr_c, %0" : : "r" (mode) : "memory");
402   }
403
404   __IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr)
405   {
406     return __LDREX((unsigned long *)ptr);
407   }
408
409   __IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr)
410   {
411     return __STREX(value, (unsigned long *)ptr);
412   }
413
414
415   __IAR_FT uint32_t __RRX(uint32_t value)
416   {
417     uint32_t result;
418     __ASM("RRX      %0, %1" : "=r"(result) : "r" (value) : "cc");
419     return(result);
420   }
421
422
423   __IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2)
424   {
425     return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2));
426   }
427
428   __IAR_FT uint32_t __get_FPEXC(void)
429   {
430   #if (__FPU_PRESENT == 1)
431     uint32_t result;
432     __ASM volatile("VMRS %0, fpexc" : "=r" (result) : : "memory");
433     return(result);
434   #else
435     return(0);
436   #endif
437   }
438
439   __IAR_FT void __set_FPEXC(uint32_t fpexc)
440   {
441   #if (__FPU_PRESENT == 1)
442     __ASM volatile ("VMSR fpexc, %0" : : "r" (fpexc) : "memory");
443   #endif
444   }
445
446
447   #define __get_CP(cp, op1, Rt, CRn, CRm, op2) \
448     __ASM volatile("MRC p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : "=r" (Rt) : : "memory" )
449   #define __set_CP(cp, op1, Rt, CRn, CRm, op2) \
450     __ASM volatile("MCR p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : : "r" (Rt) : "memory" )
451   #define __get_CP64(cp, op1, Rt, CRm) \
452     __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm  : "=r" (Rt) : : "memory" )
453   #define __set_CP64(cp, op1, Rt, CRm) \
454     __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm  : : "r" (Rt) : "memory" )
455
456   #include "cmsis_cp15.h"
457
458 #endif   /* __ICCARM_INTRINSICS_VERSION__ == 2 */
459
460 #define __BKPT(value)    __asm volatile ("BKPT     %0" : : "i"(value))
461
462
463 __IAR_FT uint32_t __get_SP_usr(void)
464 {
465   uint32_t cpsr;
466   uint32_t result;
467   __ASM volatile(
468     "MRS     %0, cpsr   \n"
469     "CPS     #0x1F      \n" // no effect in USR mode
470     "MOV     %1, sp     \n"
471     "MSR     cpsr_c, %2 \n" // no effect in USR mode
472     "ISB" :  "=r"(cpsr), "=r"(result) : "r"(cpsr) : "memory"
473    );
474   return result;
475 }
476
477 __IAR_FT void __set_SP_usr(uint32_t topOfProcStack)
478 {
479   uint32_t cpsr;
480   __ASM volatile(
481     "MRS     %0, cpsr   \n"
482     "CPS     #0x1F      \n" // no effect in USR mode
483     "MOV     sp, %1     \n"
484     "MSR     cpsr_c, %2 \n" // no effect in USR mode
485     "ISB" : "=r"(cpsr) : "r" (topOfProcStack), "r"(cpsr) : "memory"
486    );
487 }
488
489 #define __get_mode()                (__get_CPSR() & 0x1FU)
490
491 __STATIC_INLINE
492 void __FPU_Enable(void)
493 {
494   __ASM volatile(
495     //Permit access to VFP/NEON, registers by modifying CPACR
496     "        MRC     p15,0,R1,c1,c0,2  \n"
497     "        ORR     R1,R1,#0x00F00000 \n"
498     "        MCR     p15,0,R1,c1,c0,2  \n"
499
500     //Ensure that subsequent instructions occur in the context of VFP/NEON access permitted
501     "        ISB                       \n"
502
503     //Enable VFP/NEON
504     "        VMRS    R1,FPEXC          \n"
505     "        ORR     R1,R1,#0x40000000 \n"
506     "        VMSR    FPEXC,R1          \n"
507
508     //Initialise VFP/NEON registers to 0
509     "        MOV     R2,#0             \n"
510
511     //Initialise D16 registers to 0
512     "        VMOV    D0, R2,R2         \n"
513     "        VMOV    D1, R2,R2         \n"
514     "        VMOV    D2, R2,R2         \n"
515     "        VMOV    D3, R2,R2         \n"
516     "        VMOV    D4, R2,R2         \n"
517     "        VMOV    D5, R2,R2         \n"
518     "        VMOV    D6, R2,R2         \n"
519     "        VMOV    D7, R2,R2         \n"
520     "        VMOV    D8, R2,R2         \n"
521     "        VMOV    D9, R2,R2         \n"
522     "        VMOV    D10,R2,R2         \n"
523     "        VMOV    D11,R2,R2         \n"
524     "        VMOV    D12,R2,R2         \n"
525     "        VMOV    D13,R2,R2         \n"
526     "        VMOV    D14,R2,R2         \n"
527     "        VMOV    D15,R2,R2         \n"
528
529 #ifdef __ARM_ADVANCED_SIMD__
530     //Initialise D32 registers to 0
531     "        VMOV    D16,R2,R2         \n"
532     "        VMOV    D17,R2,R2         \n"
533     "        VMOV    D18,R2,R2         \n"
534     "        VMOV    D19,R2,R2         \n"
535     "        VMOV    D20,R2,R2         \n"
536     "        VMOV    D21,R2,R2         \n"
537     "        VMOV    D22,R2,R2         \n"
538     "        VMOV    D23,R2,R2         \n"
539     "        VMOV    D24,R2,R2         \n"
540     "        VMOV    D25,R2,R2         \n"
541     "        VMOV    D26,R2,R2         \n"
542     "        VMOV    D27,R2,R2         \n"
543     "        VMOV    D28,R2,R2         \n"
544     "        VMOV    D29,R2,R2         \n"
545     "        VMOV    D30,R2,R2         \n"
546     "        VMOV    D31,R2,R2         \n"
547 #endif
548
549     //Initialise FPSCR to a known state
550     "        VMRS    R2,FPSCR          \n"
551     "        MOV32   R3,#0x00086060    \n" //Mask off all bits that do not have to be preserved. Non-preserved bits can/should be zero.
552     "        AND     R2,R2,R3          \n"
553     "        VMSR    FPSCR,R2          \n");
554 }
555
556
557
558 #undef __IAR_FT
559 #undef __ICCARM_V8
560
561 #pragma diag_default=Pe940
562 #pragma diag_default=Pe177
563
564 #endif /* __CMSIS_ICCARM_H__ */