]> begriffs open source - cmsis/blob - CMSIS/Core/Include/cmsis_iccarm.h
Handle name collisions between intrincs.h and cmsis_iccarm.h in EWARM 8.20
[cmsis] / CMSIS / Core / Include / cmsis_iccarm.h
1 /**************************************************************************//**
2  * @file     cmsis_iccarm.h
3  * @brief    CMSIS compiler ICCARM (IAR compiler) header file
4  * @version  V5.0.3
5  * @date     29. August 2017
6  ******************************************************************************/
7
8 //------------------------------------------------------------------------------
9 //
10 // Copyright (c) 2017 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 #ifndef __ALIGNED
44   #if __ICCARM_V8
45     #define __ALIGNED(x) __attribute__((aligned(x)))
46   #elif (__VER__ >= 7080000)
47     /* Needs IAR language extensions */
48     #define __ALIGNED(x) __attribute__((aligned(x)))
49   #else
50     #warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored.
51     #define __ALIGNED(x)
52   #endif
53 #endif
54
55
56 /* Define compiler macros for CPU architecture, used in CMSIS 5.
57  */
58 #if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__ || __ARM_ARCH_8M_BASE__ || __ARM_ARCH_8M_MAIN__
59 /* Macros already defined */
60 #else
61   #if defined(__ARM8M_MAINLINE__) || defined(__ARM8EM_MAINLINE__)
62     #define __ARM_ARCH_8M_MAIN__ 1
63   #elif defined(__ARM8M_BASELINE__)
64     #define __ARM_ARCH_8M_BASE__ 1
65   #elif defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M'
66     #if __ARM_ARCH == 6
67       #define __ARM_ARCH_6M__ 1
68     #elif __ARM_ARCH == 7
69       #if __ARM_FEATURE_DSP
70         #define __ARM_ARCH_7EM__ 1
71       #else
72         #define __ARM_ARCH_7M__ 1
73       #endif
74     #endif /* __ARM_ARCH */
75   #endif /* __ARM_ARCH_PROFILE == 'M' */
76 #endif
77
78 /* Alternativ core deduction for older ICCARM's */
79 #if !defined(__ARM_ARCH_6M__) && !defined(__ARM_ARCH_7M__) && !defined(__ARM_ARCH_7EM__) && \
80     !defined(__ARM_ARCH_8M_BASE__) && !defined(__ARM_ARCH_8M_MAIN__)
81   #if defined(__ARM6M__) && (__CORE__ == __ARM6M__)
82     #define __ARM_ARCH_6M__ 1
83   #elif defined(__ARM7M__) && (__CORE__ == __ARM7M__)
84     #define __ARM_ARCH_7M__ 1
85   #elif defined(__ARM7EM__) && (__CORE__ == __ARM7EM__)
86     #define __ARM_ARCH_7EM__  1
87   #elif defined(__ARM8M_BASELINE__) && (__CORE == __ARM8M_BASELINE__)
88     #define __ARM_ARCH_8M_BASE__ 1
89   #elif defined(__ARM8M_MAINLINE__) && (__CORE == __ARM8M_MAINLINE__)
90     #define __ARM_ARCH_8M_MAIN__ 1
91   #elif defined(__ARM8EM_MAINLINE__) && (__CORE == __ARM8EM_MAINLINE__)
92     #define __ARM_ARCH_8M_MAIN__ 1
93   #else
94     #error "Unknown target."
95   #endif
96 #endif
97
98
99
100 #if defined(__ARM_ARCH_6M__) && __ARM_ARCH_6M__==1
101   #define __IAR_M0_FAMILY  1
102 #elif defined(__ARM_ARCH_8M_BASE__) && __ARM_ARCH_8M_BASE__==1
103   #define __IAR_M0_FAMILY  1
104 #else
105   #define __IAR_M0_FAMILY  0
106 #endif
107
108
109 #ifndef __ASM
110   #define __ASM __asm
111 #endif
112
113 #ifndef __INLINE
114   #define __INLINE inline
115 #endif
116
117 #ifndef   __NO_RETURN
118   #if __ICCARM_V8
119     #define __NO_RETURN __attribute__((noreturn))
120   #else
121     #define __NO_RETURN _Pragma("object_attribute=__noreturn")
122   #endif
123 #endif
124
125 #ifndef   __PACKED
126   #if __ICCARM_V8
127     #define __PACKED __attribute__((packed, aligned(1)))
128   #else
129     /* Needs IAR language extensions */
130     #define __PACKED __packed
131   #endif
132 #endif
133
134 #ifndef   __PACKED_STRUCT
135   #if __ICCARM_V8
136     #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
137   #else
138     /* Needs IAR language extensions */
139     #define __PACKED_STRUCT __packed struct
140   #endif
141 #endif
142
143 #ifndef   __PACKED_UNION
144   #if __ICCARM_V8
145     #define __PACKED_UNION union __attribute__((packed, aligned(1)))
146   #else
147     /* Needs IAR language extensions */
148     #define __PACKED_UNION __packed union
149   #endif
150 #endif
151
152 #ifndef   __RESTRICT
153   #define __RESTRICT restrict
154 #endif
155
156
157 #ifndef   __STATIC_INLINE
158   #define __STATIC_INLINE static inline
159 #endif
160
161 #ifndef __UNALIGNED_UINT16_READ
162 #pragma language=save
163 #pragma language=extended
164 __IAR_FT uint16_t __iar_uint16_read(void const *ptr) {
165   return *(__packed uint16_t*)(ptr);
166 }
167 #pragma language=restore
168 #define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR)
169 #endif
170
171
172 #ifndef __UNALIGNED_UINT16_WRITE
173 #pragma language=save
174 #pragma language=extended
175 __IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val) {
176   *(__packed uint16_t*)(ptr) = val;;
177 }
178 #pragma language=restore
179 #define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL)
180 #endif
181
182 #ifndef __UNALIGNED_UINT32_READ
183 #pragma language=save
184 #pragma language=extended
185 __IAR_FT uint32_t __iar_uint32_read(void const *ptr) {
186   return *(__packed uint32_t*)(ptr);
187 }
188 #pragma language=restore
189 #define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR)
190 #endif
191
192 #ifndef __UNALIGNED_UINT32_WRITE
193 #pragma language=save
194 #pragma language=extended
195 __IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val) {
196   *(__packed uint32_t*)(ptr) = val;;
197 }
198 #pragma language=restore
199 #define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL)
200 #endif
201
202 #ifndef __UNALIGNED_UINT32   /* deprecated */
203 #pragma language=save
204 #pragma language=extended
205 __packed struct  __iar_u32 { uint32_t v; };
206 #pragma language=restore
207 #define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v)
208 #endif
209
210 #ifndef   __USED
211   #if __ICCARM_V8
212     #define __USED __attribute__((used))
213   #else
214     #define __USED _Pragma("__root")
215   #endif
216 #endif
217
218 #ifndef   __WEAK
219   #if __ICCARM_V8
220     #define __WEAK __attribute__((weak))
221   #else
222     #define __WEAK _Pragma("__weak")
223   #endif
224 #endif
225
226
227 #ifndef __ICCARM_INTRINSICS_VERSION__
228   #define __ICCARM_INTRINSICS_VERSION__  0
229 #endif
230
231 #if __ICCARM_INTRINSICS_VERSION__ == 2
232
233   #if defined(__CLZ)
234     #undef __CLZ
235   #endif
236   #if defined(__REVSH)
237     #undef __REVSH
238   #endif
239   #if defined(__RBIT)
240     #undef __RBIT
241   #endif
242   #if defined(__SSAT)
243     #undef __SSAT
244   #endif
245   #if defined(__USAT)
246     #undef __USAT
247   #endif
248
249   #include "iccarm_builtin.h"
250
251   #define __disable_fault_irq __iar_builtin_disable_fiq
252   #define __disable_irq       __iar_builtin_disable_interrupt
253   #define __enable_fault_irq  __iar_builtin_enable_fiq
254   #define __enable_irq        __iar_builtin_enable_interrupt
255   #define __arm_rsr                         __iar_builtin_rsr
256   #define __arm_wsr                         __iar_builtin_wsr
257
258
259   #define __get_APSR()                (__arm_rsr("APSR"))
260   #define __get_BASEPRI()             (__arm_rsr("BASEPRI"))
261   #define __get_CONTROL()             (__arm_rsr("CONTROL"))
262   #define __get_FAULTMASK()           (__arm_rsr("FAULTMASK"))
263
264   #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
265        (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     )
266     #define __get_FPSCR()             (__arm_rsr("FPSCR"))
267     #define __set_FPSCR(VALUE)        (__arm_wsr("FPSCR", (VALUE)))
268   #else
269     #define __get_FPSCR()             ( 0 )
270     #define __set_FPSCR(VALUE)        ((void)VALUE)
271   #endif
272
273   #define __get_IPSR()                (__arm_rsr("IPSR"))
274   #define __get_MSP()                 (__arm_rsr("MSP"))
275   #define __get_MSPLIM()              (__arm_rsr("MSPLIM"))
276   #define __get_PRIMASK()             (__arm_rsr("PRIMASK"))
277   #define __get_PSP()                 (__arm_rsr("PSP"))
278   #define __get_PSPLIM()              (__arm_rsr("PSPLIM"))
279   #define __get_xPSR()                (__arm_rsr("xPSR"))
280
281   #define __set_BASEPRI(VALUE)        (__arm_wsr("BASEPRI", (VALUE)))
282   #define __set_BASEPRI_MAX(VALUE)    (__arm_wsr("BASEPRI_MAX", (VALUE)))
283   #define __set_CONTROL(VALUE)        (__arm_wsr("CONTROL", (VALUE)))
284   #define __set_FAULTMASK(VALUE)      (__arm_wsr("FAULTMASK", (VALUE)))
285   #define __set_MSP(VALUE)            (__arm_wsr("MSP", (VALUE)))
286   #define __set_MSPLIM(VALUE)         (__arm_wsr("MSPLIM", (VALUE)))
287   #define __set_PRIMASK(VALUE)        (__arm_wsr("PRIMASK", (VALUE)))
288   #define __set_PSP(VALUE)            (__arm_wsr("PSP", (VALUE)))
289   #define __set_PSPLIM(VALUE)         (__arm_wsr("PSPLIM", (VALUE)))
290
291   #define __TZ_get_CONTROL_NS()       (__arm_rsr("CONTROL_NS"))
292   #define __TZ_set_CONTROL_NS(VALUE)  (__arm_wsr("CONTROL_NS", (VALUE)))
293   #define __TZ_get_PSP_NS()           (__arm_rsr("PSP_NS"))
294   #define __TZ_set_PSP_NS(VALUE)      (__arm_wsr("PSP_NS", (VALUE)))
295   #define __TZ_get_MSP_NS()           (__arm_rsr("MSP_NS"))
296   #define __TZ_set_MSP_NS(VALUE)      (__arm_wsr("MSP_NS", (VALUE)))
297   #define __TZ_get_SP_NS()            (__arm_rsr("SP_NS"))
298   #define __TZ_set_SP_NS(VALUE)       (__arm_wsr("SP_NS", (VALUE)))
299   #define __TZ_get_PRIMASK_NS()       (__arm_rsr("PRIMASK_NS"))
300   #define __TZ_set_PRIMASK_NS(VALUE)  (__arm_wsr("PRIMASK_NS", (VALUE)))
301   #define __TZ_get_BASEPRI_NS()       (__arm_rsr("BASEPRI_NS"))
302   #define __TZ_set_BASEPRI_NS(VALUE)  (__arm_wsr("BASEPRI_NS", (VALUE)))
303   #define __TZ_get_FAULTMASK_NS()     (__arm_rsr("FAULTMASK_NS"))
304   #define __TZ_set_FAULTMASK_NS(VALUE)(__arm_wsr("FAULTMASK_NS", (VALUE)))
305   #define __TZ_get_PSPLIM_NS()        (__arm_rsr("PSPLIM_NS"))
306   #define __TZ_set_PSPLIM_NS(VALUE)   (__arm_wsr("PSPLIM_NS", (VALUE)))
307   #define __TZ_get_MSPLIM_NS()        (__arm_rsr("MSPLIM_NS"))
308   #define __TZ_set_MSPLIM_NS(VALUE)   (__arm_wsr("MSPLIM_NS", (VALUE)))
309
310   #define __NOP    __iar_builtin_no_operation
311
312   __IAR_FT uint8_t __CLZ(uint32_t val) {
313     return __iar_builtin_CLZ(val);
314   }
315
316   #define __CLREX __iar_builtin_CLREX
317
318   #define __DMB   __iar_builtin_DMB
319   #define __DSB   __iar_builtin_DSB
320   #define __ISB   __iar_builtin_ISB
321
322   #define __LDREXB  __iar_builtin_LDREXB
323   #define __LDREXH  __iar_builtin_LDREXH
324   #define __LDREXW  __iar_builtin_LDREX
325
326   #define __RBIT    __iar_builtin_RBIT
327   #define __REV     __iar_builtin_REV
328   #define __REV16   __iar_builtin_REV16
329
330   __IAR_FT int32_t __REVSH(int32_t val) {
331     return __iar_builtin_REVSH((int16_t)val);
332   }
333
334   #define __ROR     __iar_builtin_ROR
335   #define __RRX     __iar_builtin_RRX
336
337   #define __SEV     __iar_builtin_SEV
338
339   #if !__IAR_M0_FAMILY
340     #define __SSAT    __iar_builtin_SSAT
341   #endif
342
343   #define __STREXB  __iar_builtin_STREXB
344   #define __STREXH  __iar_builtin_STREXH
345   #define __STREXW  __iar_builtin_STREX
346
347   #if !__IAR_M0_FAMILY
348     #define __USAT    __iar_builtin_USAT
349   #endif
350
351   #define __WFE     __iar_builtin_WFE
352   #define __WFI     __iar_builtin_WFI
353
354   #if __ARM_MEDIA__
355     #define __SADD8   __iar_builtin_SADD8
356     #define __QADD8   __iar_builtin_QADD8
357     #define __SHADD8  __iar_builtin_SHADD8
358     #define __UADD8   __iar_builtin_UADD8
359     #define __UQADD8  __iar_builtin_UQADD8
360     #define __UHADD8  __iar_builtin_UHADD8
361     #define __SSUB8   __iar_builtin_SSUB8
362     #define __QSUB8   __iar_builtin_QSUB8
363     #define __SHSUB8  __iar_builtin_SHSUB8
364     #define __USUB8   __iar_builtin_USUB8
365     #define __UQSUB8  __iar_builtin_UQSUB8
366     #define __UHSUB8  __iar_builtin_UHSUB8
367     #define __SADD16  __iar_builtin_SADD16
368     #define __QADD16  __iar_builtin_QADD16
369     #define __SHADD16 __iar_builtin_SHADD16
370     #define __UADD16  __iar_builtin_UADD16
371     #define __UQADD16 __iar_builtin_UQADD16
372     #define __UHADD16 __iar_builtin_UHADD16
373     #define __SSUB16  __iar_builtin_SSUB16
374     #define __QSUB16  __iar_builtin_QSUB16
375     #define __SHSUB16 __iar_builtin_SHSUB16
376     #define __USUB16  __iar_builtin_USUB16
377     #define __UQSUB16 __iar_builtin_UQSUB16
378     #define __UHSUB16 __iar_builtin_UHSUB16
379     #define __SASX    __iar_builtin_SASX
380     #define __QASX    __iar_builtin_QASX
381     #define __SHASX   __iar_builtin_SHASX
382     #define __UASX    __iar_builtin_UASX
383     #define __UQASX   __iar_builtin_UQASX
384     #define __UHASX   __iar_builtin_UHASX
385     #define __SSAX    __iar_builtin_SSAX
386     #define __QSAX    __iar_builtin_QSAX
387     #define __SHSAX   __iar_builtin_SHSAX
388     #define __USAX    __iar_builtin_USAX
389     #define __UQSAX   __iar_builtin_UQSAX
390     #define __UHSAX   __iar_builtin_UHSAX
391     #define __USAD8   __iar_builtin_USAD8
392     #define __USADA8  __iar_builtin_USADA8
393     #define __SSAT16  __iar_builtin_SSAT16
394     #define __USAT16  __iar_builtin_USAT16
395     #define __UXTB16  __iar_builtin_UXTB16
396     #define __UXTAB16 __iar_builtin_UXTAB16
397     #define __SXTB16  __iar_builtin_SXTB16
398     #define __SXTAB16 __iar_builtin_SXTAB16
399     #define __SMUAD   __iar_builtin_SMUAD
400     #define __SMUADX  __iar_builtin_SMUADX
401     #define __SMMLA   __iar_builtin_SMMLA
402     #define __SMLAD   __iar_builtin_SMLAD
403     #define __SMLADX  __iar_builtin_SMLADX
404     #define __SMLALD  __iar_builtin_SMLALD
405     #define __SMLALDX __iar_builtin_SMLALDX
406     #define __SMUSD   __iar_builtin_SMUSD
407     #define __SMUSDX  __iar_builtin_SMUSDX
408     #define __SMLSD   __iar_builtin_SMLSD
409     #define __SMLSDX  __iar_builtin_SMLSDX
410     #define __SMLSLD  __iar_builtin_SMLSLD
411     #define __SMLSLDX __iar_builtin_SMLSLDX
412     #define __SEL     __iar_builtin_SEL
413     #define __QADD    __iar_builtin_QADD
414     #define __QSUB    __iar_builtin_QSUB
415     #define __PKHBT   __iar_builtin_PKHBT
416     #define __PKHTB   __iar_builtin_PKHTB
417   #endif
418
419 #else /* __ICCARM_INTRINSICS_VERSION__ == 2 */
420
421   #if __IAR_M0_FAMILY
422    /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
423     #define __CLZ  __cmsis_iar_clz_not_active
424     #define __SSAT __cmsis_iar_ssat_not_active
425     #define __USAT __cmsis_iar_usat_not_active
426     #define __RBIT __cmsis_iar_rbit_not_active
427     #define __get_APSR  __cmsis_iar_get_APSR_not_active
428   #endif
429
430
431   #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
432          (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     ))
433     #define __get_FPSCR __cmsis_iar_get_FPSR_not_active
434     #define __set_FPSCR __cmsis_iar_set_FPSR_not_active
435   #endif
436
437   #include <intrinsics.h>
438
439   #if __IAR_M0_FAMILY
440    /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
441     #undef __CLZ
442     #undef __SSAT
443     #undef __USAT
444     #undef __RBIT
445     #undef __get_APSR
446
447     __STATIC_INLINE uint8_t __CLZ(uint32_t data) {
448       if (data == 0u) { return 32u; }
449
450       uint32_t count = 0;
451       uint32_t mask = 0x80000000;
452
453       while ((data & mask) == 0)
454       {
455         count += 1u;
456         mask = mask >> 1u;
457       }
458       return (count);
459     }
460
461     __STATIC_INLINE uint32_t __RBIT(uint32_t v) {
462       uint8_t sc = 31;
463       uint32_t r = v;
464       for (v >>= 1U; v; v >>= 1U)
465       {
466         r <<= 1U;
467         r |= v & 1U;
468         sc--;
469       }
470       return (r << sc);
471     }
472
473     __STATIC_INLINE  uint32_t __get_APSR(void) {
474       uint32_t res;
475       __asm("MRS      %0,APSR" : "=r" (res));
476       return res;
477     }
478
479   #endif
480
481   #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
482          (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     ))
483     #undef __get_FPSCR
484     #undef __set_FPSCR
485     #define __get_FPSCR()       (0)
486     #define __set_FPSCR(VALUE)  ((void)VALUE)
487   #endif
488
489   #pragma diag_suppress=Pe940
490   #pragma diag_suppress=Pe177
491
492   #define __enable_irq    __enable_interrupt
493   #define __disable_irq   __disable_interrupt
494   #define __NOP           __no_operation
495
496   #define __get_xPSR      __get_PSR
497
498   #if (!defined(__ARM_ARCH_6M__) || __ARM_ARCH_6M__==0)
499
500     __IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr) {
501       return __LDREX((unsigned long *)ptr);
502     }
503
504     __IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr) {
505       return __STREX(value, (unsigned long *)ptr);
506     }
507   #endif
508
509
510   /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
511   #if (__CORTEX_M >= 0x03)
512
513     __IAR_FT uint32_t __RRX(uint32_t value) {
514       uint32_t result;
515       __ASM("RRX      %0, %1" : "=r"(result) : "r" (value) : "cc");
516       return(result);
517     }
518
519     __IAR_FT void __set_BASEPRI_MAX(uint32_t value) {
520       __asm volatile("MSR      BASEPRI_MAX,%0"::"r" (value));
521     }
522
523
524     #define __enable_fault_irq  __enable_fiq
525     #define __disable_fault_irq __disable_fiq
526
527
528   #endif /* (__CORTEX_M >= 0x03) */
529
530   __IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2) {
531     return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2));
532   }
533
534   #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
535        (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    )
536
537     __IAR_FT uint32_t __TZ_get_CONTROL_NS(void) {
538       uint32_t res;
539       __asm volatile("MRS      %0,CONTROL_NS" : "=r" (res));
540       return res;
541     }
542
543     __IAR_FT void       __TZ_set_CONTROL_NS(uint32_t value) {
544       __asm volatile("MSR      CONTROL_NS,%0" :: "r" (value));
545     }
546
547     __IAR_FT uint32_t   __TZ_get_PSP_NS(void) {
548       uint32_t res;
549       __asm volatile("MRS      %0,PSP_NS" : "=r" (res));
550       return res;
551     }
552
553     __IAR_FT void       __TZ_set_PSP_NS(uint32_t value) {
554       __asm volatile("MSR      PSP_NS,%0" :: "r" (value));
555     }
556
557     __IAR_FT uint32_t   __TZ_get_MSP_NS(void) {
558       uint32_t res;
559       __asm volatile("MRS      %0,MSP_NS" : "=r" (res));
560       return res;
561     }
562
563     __IAR_FT void       __TZ_set_MSP_NS(uint32_t value) {
564       __asm volatile("MSR      MSP_NS,%0" :: "r" (value));
565     }
566
567     __IAR_FT uint32_t   __TZ_get_SP_NS(void) {
568       uint32_t res;
569       __asm volatile("MRS      %0,SP_NS" : "=r" (res));
570       return res;
571     }
572     __IAR_FT void       __TZ_set_SP_NS(uint32_t value) {
573       __asm volatile("MSR      SP_NS,%0" :: "r" (value));
574     }
575
576     __IAR_FT uint32_t   __TZ_get_PRIMASK_NS(void) {
577       uint32_t res;
578       __asm volatile("MRS      %0,PRIMASK_NS" : "=r" (res));
579       return res;
580     }
581
582     __IAR_FT void       __TZ_set_PRIMASK_NS(uint32_t value) {
583       __asm volatile("MSR      PRIMASK_NS,%0" :: "r" (value));
584     }
585
586     __IAR_FT uint32_t   __TZ_get_BASEPRI_NS(void) {
587       uint32_t res;
588       __asm volatile("MRS      %0,BASEPRI_NS" : "=r" (res));
589       return res;
590     }
591
592     __IAR_FT void       __TZ_set_BASEPRI_NS(uint32_t value) {
593       __asm volatile("MSR      BASEPRI_NS,%0" :: "r" (value));
594     }
595
596     __IAR_FT uint32_t   __TZ_get_FAULTMASK_NS(void) {
597       uint32_t res;
598       __asm volatile("MRS      %0,FAULTMASK_NS" : "=r" (res));
599       return res;
600     }
601
602     __IAR_FT void       __TZ_set_FAULTMASK_NS(uint32_t value) {
603       __asm volatile("MSR      FAULTMASK_NS,%0" :: "r" (value));
604     }
605
606     __IAR_FT uint32_t   __TZ_get_PSPLIM_NS(void) {
607       uint32_t res;
608       __asm volatile("MRS      %0,PSPLIM_NS" : "=r" (res));
609       return res;
610     }
611     __IAR_FT void       __TZ_set_PSPLIM_NS(uint32_t value) {
612       __asm volatile("MSR      PSPLIM_NS,%0" :: "r" (value));
613     }
614
615     __IAR_FT uint32_t   __TZ_get_MSPLIM_NS(void) {
616       uint32_t res;
617       __asm volatile("MRS      %0,MSPLIM_NS" : "=r" (res));
618       return res;
619     }
620
621     __IAR_FT void       __TZ_set_MSPLIM_NS(uint32_t value) {
622       __asm volatile("MSR      MSPLIM_NS,%0" :: "r" (value));
623     }
624
625   #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
626
627 #endif   /* __ICCARM_INTRINSICS_VERSION__ == 2 */
628
629 #define __BKPT(value)    __asm volatile ("BKPT     %0" : : "i"(value))
630
631 #if __IAR_M0_FAMILY
632   __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat) {
633     if ((sat >= 1U) && (sat <= 32U)) {
634       const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
635       const int32_t min = -1 - max ;
636       if (val > max) {
637         return max;
638       } else if (val < min) {
639         return min;
640       }
641     }
642     return val;
643   }
644
645   __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat) {
646     if (sat <= 31U) {
647       const uint32_t max = ((1U << sat) - 1U);
648       if (val > (int32_t)max) {
649         return max;
650       } else if (val < 0) {
651         return 0U;
652       }
653     }
654     return (uint32_t)val;
655   }
656 #endif
657
658 #if (__CORTEX_M >= 0x03)   /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
659
660   __IAR_FT uint8_t __LDRBT(volatile uint8_t *addr) {
661     uint32_t res;
662     __ASM("LDRBT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
663     return ((uint8_t)res);
664   }
665
666   __IAR_FT uint16_t __LDRHT(volatile uint16_t *addr) {
667     uint32_t res;
668     __ASM("LDRHT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
669     return ((uint16_t)res);
670   }
671
672   __IAR_FT uint32_t __LDRT(volatile uint32_t *addr) {
673     uint32_t res;
674     __ASM("LDRT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
675     return res;
676   }
677
678   __IAR_FT void __STRBT(uint8_t value, volatile uint8_t *addr) {
679     __ASM("STRBT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
680   }
681
682   __IAR_FT void __STRHT(uint16_t value, volatile uint16_t *addr) {
683     __ASM("STRHT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
684   }
685
686   __IAR_FT void __STRT(uint32_t value, volatile uint32_t *addr) {
687     __ASM("STRT %1, [%0]" : : "r" (addr), "r" (value) : "memory");
688   }
689
690 #endif /* (__CORTEX_M >= 0x03) */
691
692 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
693      (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    )
694
695
696   __IAR_FT uint8_t __LDAB(volatile uint8_t *ptr) {
697     uint32_t res;
698     __ASM volatile ("LDAB %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
699     return ((uint8_t)res);
700   }
701
702   __IAR_FT uint16_t __LDAH(volatile uint16_t *ptr) {
703     uint32_t res;
704     __ASM volatile ("LDAH %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
705     return ((uint16_t)res);
706   }
707
708   __IAR_FT uint32_t __LDA(volatile uint32_t *ptr) {
709     uint32_t res;
710     __ASM volatile ("LDA %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
711     return res;
712   }
713
714   __IAR_FT void __STLB(uint8_t value, volatile uint8_t *ptr) {
715     __ASM volatile ("STLB %1, [%0]" :: "r" (*ptr), "r" (value) : "memory");
716   }
717
718   __IAR_FT void __STLH(uint16_t value, volatile uint16_t *ptr) {
719     __ASM volatile ("STLH %1, [%0]" :: "r" (*ptr), "r" (value) : "memory");
720   }
721
722   __IAR_FT void __STL(uint32_t value, volatile uint32_t *ptr) {
723     __ASM volatile ("STL %1, [%0]" :: "r" (*ptr), "r" (value) : "memory");
724   }
725
726   __IAR_FT uint8_t __LDAEXB(volatile uint8_t *ptr) {
727     uint32_t res;
728     __ASM volatile ("LDAEXB %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
729     return ((uint8_t)res);
730   }
731
732   __IAR_FT uint16_t __LDAEXH(volatile uint16_t *ptr) {
733     uint32_t res;
734     __ASM volatile ("LDAEXH %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
735     return ((uint16_t)res);
736   }
737
738   __IAR_FT uint32_t __LDAEX(volatile uint32_t *ptr) {
739     uint32_t res;
740     __ASM volatile ("LDAEX %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
741     return res;
742   }
743
744   __IAR_FT uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr) {
745     uint32_t res;
746     __ASM volatile ("STLEXB %0, %2, [%1]" : "=r" (res) : "r" (*ptr), "r" (value) : "memory");
747     return res;
748   }
749
750   __IAR_FT uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr) {
751     uint32_t res;
752     __ASM volatile ("STLEXH %0, %2, [%1]" : "=r" (res) : "r" (*ptr), "r" (value) : "memory");
753     return res;
754   }
755
756   __IAR_FT uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr) {
757     uint32_t res;
758     __ASM volatile ("STLEX %0, %2, [%1]" : "=r" (res) : "r" (*ptr), "r" (value) : "memory");
759     return res;
760   }
761
762 #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
763
764 #undef __IAR_FT
765 #undef __IAR_M0_FAMILY
766 #undef __ICCARM_V8
767
768 #pragma diag_default=Pe940
769 #pragma diag_default=Pe177
770
771 #endif /* __CMSIS_ICCARM_H__ */