]> begriffs open source - cmsis/blob - CMSIS/Core/Include/cmsis_iccarm.h
RTX5: Enhanced documentation for osRtxErrorStackUnderflow to state this error is...
[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 {
166   return *(__packed uint16_t*)(ptr);
167 }
168 #pragma language=restore
169 #define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR)
170 #endif
171
172
173 #ifndef __UNALIGNED_UINT16_WRITE
174 #pragma language=save
175 #pragma language=extended
176 __IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val)
177 {
178   *(__packed uint16_t*)(ptr) = val;;
179 }
180 #pragma language=restore
181 #define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL)
182 #endif
183
184 #ifndef __UNALIGNED_UINT32_READ
185 #pragma language=save
186 #pragma language=extended
187 __IAR_FT uint32_t __iar_uint32_read(void const *ptr)
188 {
189   return *(__packed uint32_t*)(ptr);
190 }
191 #pragma language=restore
192 #define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR)
193 #endif
194
195 #ifndef __UNALIGNED_UINT32_WRITE
196 #pragma language=save
197 #pragma language=extended
198 __IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val)
199 {
200   *(__packed uint32_t*)(ptr) = val;;
201 }
202 #pragma language=restore
203 #define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL)
204 #endif
205
206 #ifndef __UNALIGNED_UINT32   /* deprecated */
207 #pragma language=save
208 #pragma language=extended
209 __packed struct  __iar_u32 { uint32_t v; };
210 #pragma language=restore
211 #define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v)
212 #endif
213
214 #ifndef   __USED
215   #if __ICCARM_V8
216     #define __USED __attribute__((used))
217   #else
218     #define __USED _Pragma("__root")
219   #endif
220 #endif
221
222 #ifndef   __WEAK
223   #if __ICCARM_V8
224     #define __WEAK __attribute__((weak))
225   #else
226     #define __WEAK _Pragma("__weak")
227   #endif
228 #endif
229
230
231 #ifndef __ICCARM_INTRINSICS_VERSION__
232   #define __ICCARM_INTRINSICS_VERSION__  0
233 #endif
234
235 #if __ICCARM_INTRINSICS_VERSION__ == 2
236
237   #if defined(__CLZ)
238     #undef __CLZ
239   #endif
240   #if defined(__REVSH)
241     #undef __REVSH
242   #endif
243   #if defined(__RBIT)
244     #undef __RBIT
245   #endif
246   #if defined(__SSAT)
247     #undef __SSAT
248   #endif
249   #if defined(__USAT)
250     #undef __USAT
251   #endif
252
253   #include "iccarm_builtin.h"
254
255   #define __disable_fault_irq __iar_builtin_disable_fiq
256   #define __disable_irq       __iar_builtin_disable_interrupt
257   #define __enable_fault_irq  __iar_builtin_enable_fiq
258   #define __enable_irq        __iar_builtin_enable_interrupt
259   #define __arm_rsr           __iar_builtin_rsr
260   #define __arm_wsr           __iar_builtin_wsr
261
262
263   #define __get_APSR()                (__arm_rsr("APSR"))
264   #define __get_BASEPRI()             (__arm_rsr("BASEPRI"))
265   #define __get_CONTROL()             (__arm_rsr("CONTROL"))
266   #define __get_FAULTMASK()           (__arm_rsr("FAULTMASK"))
267
268   #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
269        (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     )
270     #define __get_FPSCR()             (__arm_rsr("FPSCR"))
271     #define __set_FPSCR(VALUE)        (__arm_wsr("FPSCR", (VALUE)))
272   #else
273     #define __get_FPSCR()             ( 0 )
274     #define __set_FPSCR(VALUE)        ((void)VALUE)
275   #endif
276
277   #define __get_IPSR()                (__arm_rsr("IPSR"))
278   #define __get_MSP()                 (__arm_rsr("MSP"))
279   #define __get_MSPLIM()              (__arm_rsr("MSPLIM"))
280   #define __get_PRIMASK()             (__arm_rsr("PRIMASK"))
281   #define __get_PSP()                 (__arm_rsr("PSP"))
282   #define __get_PSPLIM()              (__arm_rsr("PSPLIM"))
283   #define __get_xPSR()                (__arm_rsr("xPSR"))
284
285   #define __set_BASEPRI(VALUE)        (__arm_wsr("BASEPRI", (VALUE)))
286   #define __set_BASEPRI_MAX(VALUE)    (__arm_wsr("BASEPRI_MAX", (VALUE)))
287   #define __set_CONTROL(VALUE)        (__arm_wsr("CONTROL", (VALUE)))
288   #define __set_FAULTMASK(VALUE)      (__arm_wsr("FAULTMASK", (VALUE)))
289   #define __set_MSP(VALUE)            (__arm_wsr("MSP", (VALUE)))
290   #define __set_MSPLIM(VALUE)         (__arm_wsr("MSPLIM", (VALUE)))
291   #define __set_PRIMASK(VALUE)        (__arm_wsr("PRIMASK", (VALUE)))
292   #define __set_PSP(VALUE)            (__arm_wsr("PSP", (VALUE)))
293   #define __set_PSPLIM(VALUE)         (__arm_wsr("PSPLIM", (VALUE)))
294
295   #define __TZ_get_CONTROL_NS()       (__arm_rsr("CONTROL_NS"))
296   #define __TZ_set_CONTROL_NS(VALUE)  (__arm_wsr("CONTROL_NS", (VALUE)))
297   #define __TZ_get_PSP_NS()           (__arm_rsr("PSP_NS"))
298   #define __TZ_set_PSP_NS(VALUE)      (__arm_wsr("PSP_NS", (VALUE)))
299   #define __TZ_get_MSP_NS()           (__arm_rsr("MSP_NS"))
300   #define __TZ_set_MSP_NS(VALUE)      (__arm_wsr("MSP_NS", (VALUE)))
301   #define __TZ_get_SP_NS()            (__arm_rsr("SP_NS"))
302   #define __TZ_set_SP_NS(VALUE)       (__arm_wsr("SP_NS", (VALUE)))
303   #define __TZ_get_PRIMASK_NS()       (__arm_rsr("PRIMASK_NS"))
304   #define __TZ_set_PRIMASK_NS(VALUE)  (__arm_wsr("PRIMASK_NS", (VALUE)))
305   #define __TZ_get_BASEPRI_NS()       (__arm_rsr("BASEPRI_NS"))
306   #define __TZ_set_BASEPRI_NS(VALUE)  (__arm_wsr("BASEPRI_NS", (VALUE)))
307   #define __TZ_get_FAULTMASK_NS()     (__arm_rsr("FAULTMASK_NS"))
308   #define __TZ_set_FAULTMASK_NS(VALUE)(__arm_wsr("FAULTMASK_NS", (VALUE)))
309   #define __TZ_get_PSPLIM_NS()        (__arm_rsr("PSPLIM_NS"))
310   #define __TZ_set_PSPLIM_NS(VALUE)   (__arm_wsr("PSPLIM_NS", (VALUE)))
311   #define __TZ_get_MSPLIM_NS()        (__arm_rsr("MSPLIM_NS"))
312   #define __TZ_set_MSPLIM_NS(VALUE)   (__arm_wsr("MSPLIM_NS", (VALUE)))
313
314   #define __NOP     __iar_builtin_no_operation
315
316   #define __CLZ     __iar_builtin_CLZ
317   #define __CLREX   __iar_builtin_CLREX
318
319   #define __DMB     __iar_builtin_DMB
320   #define __DSB     __iar_builtin_DSB
321   #define __ISB     __iar_builtin_ISB
322
323   #define __LDREXB  __iar_builtin_LDREXB
324   #define __LDREXH  __iar_builtin_LDREXH
325   #define __LDREXW  __iar_builtin_LDREX
326
327   #define __RBIT    __iar_builtin_RBIT
328   #define __REV     __iar_builtin_REV
329   #define __REV16   __iar_builtin_REV16
330
331   __IAR_FT int16_t __REVSH(int16_t val)
332   {
333     return (int16_t) __iar_builtin_REVSH(val);
334   }
335
336   #define __ROR     __iar_builtin_ROR
337   #define __RRX     __iar_builtin_RRX
338
339   #define __SEV     __iar_builtin_SEV
340
341   #if !__IAR_M0_FAMILY
342     #define __SSAT    __iar_builtin_SSAT
343   #endif
344
345   #define __STREXB  __iar_builtin_STREXB
346   #define __STREXH  __iar_builtin_STREXH
347   #define __STREXW  __iar_builtin_STREX
348
349   #if !__IAR_M0_FAMILY
350     #define __USAT    __iar_builtin_USAT
351   #endif
352
353   #define __WFE     __iar_builtin_WFE
354   #define __WFI     __iar_builtin_WFI
355
356   #if __ARM_MEDIA__
357     #define __SADD8   __iar_builtin_SADD8
358     #define __QADD8   __iar_builtin_QADD8
359     #define __SHADD8  __iar_builtin_SHADD8
360     #define __UADD8   __iar_builtin_UADD8
361     #define __UQADD8  __iar_builtin_UQADD8
362     #define __UHADD8  __iar_builtin_UHADD8
363     #define __SSUB8   __iar_builtin_SSUB8
364     #define __QSUB8   __iar_builtin_QSUB8
365     #define __SHSUB8  __iar_builtin_SHSUB8
366     #define __USUB8   __iar_builtin_USUB8
367     #define __UQSUB8  __iar_builtin_UQSUB8
368     #define __UHSUB8  __iar_builtin_UHSUB8
369     #define __SADD16  __iar_builtin_SADD16
370     #define __QADD16  __iar_builtin_QADD16
371     #define __SHADD16 __iar_builtin_SHADD16
372     #define __UADD16  __iar_builtin_UADD16
373     #define __UQADD16 __iar_builtin_UQADD16
374     #define __UHADD16 __iar_builtin_UHADD16
375     #define __SSUB16  __iar_builtin_SSUB16
376     #define __QSUB16  __iar_builtin_QSUB16
377     #define __SHSUB16 __iar_builtin_SHSUB16
378     #define __USUB16  __iar_builtin_USUB16
379     #define __UQSUB16 __iar_builtin_UQSUB16
380     #define __UHSUB16 __iar_builtin_UHSUB16
381     #define __SASX    __iar_builtin_SASX
382     #define __QASX    __iar_builtin_QASX
383     #define __SHASX   __iar_builtin_SHASX
384     #define __UASX    __iar_builtin_UASX
385     #define __UQASX   __iar_builtin_UQASX
386     #define __UHASX   __iar_builtin_UHASX
387     #define __SSAX    __iar_builtin_SSAX
388     #define __QSAX    __iar_builtin_QSAX
389     #define __SHSAX   __iar_builtin_SHSAX
390     #define __USAX    __iar_builtin_USAX
391     #define __UQSAX   __iar_builtin_UQSAX
392     #define __UHSAX   __iar_builtin_UHSAX
393     #define __USAD8   __iar_builtin_USAD8
394     #define __USADA8  __iar_builtin_USADA8
395     #define __SSAT16  __iar_builtin_SSAT16
396     #define __USAT16  __iar_builtin_USAT16
397     #define __UXTB16  __iar_builtin_UXTB16
398     #define __UXTAB16 __iar_builtin_UXTAB16
399     #define __SXTB16  __iar_builtin_SXTB16
400     #define __SXTAB16 __iar_builtin_SXTAB16
401     #define __SMUAD   __iar_builtin_SMUAD
402     #define __SMUADX  __iar_builtin_SMUADX
403     #define __SMMLA   __iar_builtin_SMMLA
404     #define __SMLAD   __iar_builtin_SMLAD
405     #define __SMLADX  __iar_builtin_SMLADX
406     #define __SMLALD  __iar_builtin_SMLALD
407     #define __SMLALDX __iar_builtin_SMLALDX
408     #define __SMUSD   __iar_builtin_SMUSD
409     #define __SMUSDX  __iar_builtin_SMUSDX
410     #define __SMLSD   __iar_builtin_SMLSD
411     #define __SMLSDX  __iar_builtin_SMLSDX
412     #define __SMLSLD  __iar_builtin_SMLSLD
413     #define __SMLSLDX __iar_builtin_SMLSLDX
414     #define __SEL     __iar_builtin_SEL
415     #define __QADD    __iar_builtin_QADD
416     #define __QSUB    __iar_builtin_QSUB
417     #define __PKHBT   __iar_builtin_PKHBT
418     #define __PKHTB   __iar_builtin_PKHTB
419   #endif
420
421 #else /* __ICCARM_INTRINSICS_VERSION__ == 2 */
422
423   #if __IAR_M0_FAMILY
424    /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
425     #define __CLZ  __cmsis_iar_clz_not_active
426     #define __SSAT __cmsis_iar_ssat_not_active
427     #define __USAT __cmsis_iar_usat_not_active
428     #define __RBIT __cmsis_iar_rbit_not_active
429     #define __get_APSR  __cmsis_iar_get_APSR_not_active
430   #endif
431
432
433   #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
434          (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     ))
435     #define __get_FPSCR __cmsis_iar_get_FPSR_not_active
436     #define __set_FPSCR __cmsis_iar_set_FPSR_not_active
437   #endif
438
439   #ifdef __INTRINSICS_INCLUDED
440   #error intrinsics.h is already included previously!
441   #endif
442
443   #include <intrinsics.h>
444
445   #if __IAR_M0_FAMILY
446    /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
447     #undef __CLZ
448     #undef __SSAT
449     #undef __USAT
450     #undef __RBIT
451     #undef __get_APSR
452
453     __STATIC_INLINE uint8_t __CLZ(uint32_t data)
454     {
455       if (data == 0U) { return 32U; }
456
457       uint32_t count = 0U;
458       uint32_t mask = 0x80000000U;
459
460       while ((data & mask) == 0U)
461       {
462         count += 1U;
463         mask = mask >> 1U;
464       }
465       return count;
466     }
467
468     __STATIC_INLINE uint32_t __RBIT(uint32_t v)
469     {
470       uint8_t sc = 31U;
471       uint32_t r = v;
472       for (v >>= 1U; v; v >>= 1U)
473       {
474         r <<= 1U;
475         r |= v & 1U;
476         sc--;
477       }
478       return (r << sc);
479     }
480
481     __STATIC_INLINE  uint32_t __get_APSR(void)
482     {
483       uint32_t res;
484       __asm("MRS      %0,APSR" : "=r" (res));
485       return res;
486     }
487
488   #endif
489
490   #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
491          (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     ))
492     #undef __get_FPSCR
493     #undef __set_FPSCR
494     #define __get_FPSCR()       (0)
495     #define __set_FPSCR(VALUE)  ((void)VALUE)
496   #endif
497
498   #pragma diag_suppress=Pe940
499   #pragma diag_suppress=Pe177
500
501   #define __enable_irq    __enable_interrupt
502   #define __disable_irq   __disable_interrupt
503   #define __NOP           __no_operation
504
505   #define __get_xPSR      __get_PSR
506
507   #if (!defined(__ARM_ARCH_6M__) || __ARM_ARCH_6M__==0)
508
509     __IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr)
510     {
511       return __LDREX((unsigned long *)ptr);
512     }
513
514     __IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr)
515     {
516       return __STREX(value, (unsigned long *)ptr);
517     }
518   #endif
519
520
521   /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
522   #if (__CORTEX_M >= 0x03)
523
524     __IAR_FT uint32_t __RRX(uint32_t value)
525     {
526       uint32_t result;
527       __ASM("RRX      %0, %1" : "=r"(result) : "r" (value) : "cc");
528       return(result);
529     }
530
531     __IAR_FT void __set_BASEPRI_MAX(uint32_t value)
532     {
533       __asm volatile("MSR      BASEPRI_MAX,%0"::"r" (value));
534     }
535
536
537     #define __enable_fault_irq  __enable_fiq
538     #define __disable_fault_irq __disable_fiq
539
540
541   #endif /* (__CORTEX_M >= 0x03) */
542
543   __IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2)
544   {
545     return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2));
546   }
547
548   #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
549        (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    )
550
551    __IAR_FT uint32_t __get_MSPLIM(void)
552     {
553       uint32_t res;
554     #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
555          (!defined (__ARM_FEATURE_CMSE  ) || (__ARM_FEATURE_CMSE   < 3)))
556       // without main extensions, the non-secure MSPLIM is RAZ/WI
557       res = 0U;
558     #else
559       __asm volatile("MRS      %0,MSPLIM" : "=r" (res));
560     #endif
561       return res;
562     }
563
564     __IAR_FT void   __set_MSPLIM(uint32_t value)
565     {
566     #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
567          (!defined (__ARM_FEATURE_CMSE  ) || (__ARM_FEATURE_CMSE   < 3)))
568       // without main extensions, the non-secure MSPLIM is RAZ/WI
569       (void)value;
570     #else
571       __asm volatile("MSR      MSPLIM,%0" :: "r" (value));
572     #endif
573     }
574
575     __IAR_FT uint32_t __get_PSPLIM(void)
576     {
577       uint32_t res;
578     #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
579          (!defined (__ARM_FEATURE_CMSE  ) || (__ARM_FEATURE_CMSE   < 3)))
580       // without main extensions, the non-secure PSPLIM is RAZ/WI
581       res = 0U;
582     #else
583       __asm volatile("MRS      %0,PSPLIM" : "=r" (res));
584     #endif
585       return res;
586     }
587
588     __IAR_FT void   __set_PSPLIM(uint32_t value)
589     {
590     #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
591          (!defined (__ARM_FEATURE_CMSE  ) || (__ARM_FEATURE_CMSE   < 3)))
592       // without main extensions, the non-secure PSPLIM is RAZ/WI
593       (void)value;
594     #else
595       __asm volatile("MSR      PSPLIM,%0" :: "r" (value));
596     #endif
597     }
598
599     __IAR_FT uint32_t __TZ_get_CONTROL_NS(void)
600     {
601       uint32_t res;
602       __asm volatile("MRS      %0,CONTROL_NS" : "=r" (res));
603       return res;
604     }
605
606     __IAR_FT void   __TZ_set_CONTROL_NS(uint32_t value)
607     {
608       __asm volatile("MSR      CONTROL_NS,%0" :: "r" (value));
609     }
610
611     __IAR_FT uint32_t   __TZ_get_PSP_NS(void)
612     {
613       uint32_t res;
614       __asm volatile("MRS      %0,PSP_NS" : "=r" (res));
615       return res;
616     }
617
618     __IAR_FT void   __TZ_set_PSP_NS(uint32_t value)
619     {
620       __asm volatile("MSR      PSP_NS,%0" :: "r" (value));
621     }
622
623     __IAR_FT uint32_t   __TZ_get_MSP_NS(void)
624     {
625       uint32_t res;
626       __asm volatile("MRS      %0,MSP_NS" : "=r" (res));
627       return res;
628     }
629
630     __IAR_FT void   __TZ_set_MSP_NS(uint32_t value)
631     {
632       __asm volatile("MSR      MSP_NS,%0" :: "r" (value));
633     }
634
635     __IAR_FT uint32_t   __TZ_get_SP_NS(void)
636     {
637       uint32_t res;
638       __asm volatile("MRS      %0,SP_NS" : "=r" (res));
639       return res;
640     }
641     __IAR_FT void   __TZ_set_SP_NS(uint32_t value)
642     {
643       __asm volatile("MSR      SP_NS,%0" :: "r" (value));
644     }
645
646     __IAR_FT uint32_t   __TZ_get_PRIMASK_NS(void)
647     {
648       uint32_t res;
649       __asm volatile("MRS      %0,PRIMASK_NS" : "=r" (res));
650       return res;
651     }
652
653     __IAR_FT void   __TZ_set_PRIMASK_NS(uint32_t value)
654     {
655       __asm volatile("MSR      PRIMASK_NS,%0" :: "r" (value));
656     }
657
658     __IAR_FT uint32_t   __TZ_get_BASEPRI_NS(void)
659     {
660       uint32_t res;
661       __asm volatile("MRS      %0,BASEPRI_NS" : "=r" (res));
662       return res;
663     }
664
665     __IAR_FT void   __TZ_set_BASEPRI_NS(uint32_t value)
666     {
667       __asm volatile("MSR      BASEPRI_NS,%0" :: "r" (value));
668     }
669
670     __IAR_FT uint32_t   __TZ_get_FAULTMASK_NS(void)
671     {
672       uint32_t res;
673       __asm volatile("MRS      %0,FAULTMASK_NS" : "=r" (res));
674       return res;
675     }
676
677     __IAR_FT void   __TZ_set_FAULTMASK_NS(uint32_t value)
678     {
679       __asm volatile("MSR      FAULTMASK_NS,%0" :: "r" (value));
680     }
681
682     __IAR_FT uint32_t   __TZ_get_PSPLIM_NS(void)
683     {
684       uint32_t res;
685       __asm volatile("MRS      %0,PSPLIM_NS" : "=r" (res));
686       return res;
687     }
688     __IAR_FT void   __TZ_set_PSPLIM_NS(uint32_t value)
689     {
690       __asm volatile("MSR      PSPLIM_NS,%0" :: "r" (value));
691     }
692
693     __IAR_FT uint32_t   __TZ_get_MSPLIM_NS(void)
694     {
695       uint32_t res;
696       __asm volatile("MRS      %0,MSPLIM_NS" : "=r" (res));
697       return res;
698     }
699
700     __IAR_FT void   __TZ_set_MSPLIM_NS(uint32_t value)
701     {
702       __asm volatile("MSR      MSPLIM_NS,%0" :: "r" (value));
703     }
704
705   #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
706
707 #endif   /* __ICCARM_INTRINSICS_VERSION__ == 2 */
708
709 #define __BKPT(value)    __asm volatile ("BKPT     %0" : : "i"(value))
710
711 #if __IAR_M0_FAMILY
712   __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat)
713   {
714     if ((sat >= 1U) && (sat <= 32U))
715     {
716       const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
717       const int32_t min = -1 - max ;
718       if (val > max)
719       {
720         return max;
721       }
722       else if (val < min)
723       {
724         return min;
725       }
726     }
727     return val;
728   }
729
730   __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat)
731   {
732     if (sat <= 31U)
733     {
734       const uint32_t max = ((1U << sat) - 1U);
735       if (val > (int32_t)max)
736       {
737         return max;
738       }
739       else if (val < 0)
740       {
741         return 0U;
742       }
743     }
744     return (uint32_t)val;
745   }
746 #endif
747
748 #if (__CORTEX_M >= 0x03)   /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
749
750   __IAR_FT uint8_t __LDRBT(volatile uint8_t *addr)
751   {
752     uint32_t res;
753     __ASM("LDRBT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
754     return ((uint8_t)res);
755   }
756
757   __IAR_FT uint16_t __LDRHT(volatile uint16_t *addr)
758   {
759     uint32_t res;
760     __ASM("LDRHT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
761     return ((uint16_t)res);
762   }
763
764   __IAR_FT uint32_t __LDRT(volatile uint32_t *addr)
765   {
766     uint32_t res;
767     __ASM("LDRT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
768     return res;
769   }
770
771   __IAR_FT void __STRBT(uint8_t value, volatile uint8_t *addr)
772   {
773     __ASM("STRBT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
774   }
775
776   __IAR_FT void __STRHT(uint16_t value, volatile uint16_t *addr)
777   {
778     __ASM("STRHT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
779   }
780
781   __IAR_FT void __STRT(uint32_t value, volatile uint32_t *addr)
782   {
783     __ASM("STRT %1, [%0]" : : "r" (addr), "r" (value) : "memory");
784   }
785
786 #endif /* (__CORTEX_M >= 0x03) */
787
788 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
789      (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    )
790
791
792   __IAR_FT uint8_t __LDAB(volatile uint8_t *ptr)
793   {
794     uint32_t res;
795     __ASM volatile ("LDAB %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
796     return ((uint8_t)res);
797   }
798
799   __IAR_FT uint16_t __LDAH(volatile uint16_t *ptr)
800   {
801     uint32_t res;
802     __ASM volatile ("LDAH %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
803     return ((uint16_t)res);
804   }
805
806   __IAR_FT uint32_t __LDA(volatile uint32_t *ptr)
807   {
808     uint32_t res;
809     __ASM volatile ("LDA %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
810     return res;
811   }
812
813   __IAR_FT void __STLB(uint8_t value, volatile uint8_t *ptr)
814   {
815     __ASM volatile ("STLB %1, [%0]" :: "r" (*ptr), "r" (value) : "memory");
816   }
817
818   __IAR_FT void __STLH(uint16_t value, volatile uint16_t *ptr)
819   {
820     __ASM volatile ("STLH %1, [%0]" :: "r" (*ptr), "r" (value) : "memory");
821   }
822
823   __IAR_FT void __STL(uint32_t value, volatile uint32_t *ptr)
824   {
825     __ASM volatile ("STL %1, [%0]" :: "r" (*ptr), "r" (value) : "memory");
826   }
827
828   __IAR_FT uint8_t __LDAEXB(volatile uint8_t *ptr)
829   {
830     uint32_t res;
831     __ASM volatile ("LDAEXB %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
832     return ((uint8_t)res);
833   }
834
835   __IAR_FT uint16_t __LDAEXH(volatile uint16_t *ptr)
836   {
837     uint32_t res;
838     __ASM volatile ("LDAEXH %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
839     return ((uint16_t)res);
840   }
841
842   __IAR_FT uint32_t __LDAEX(volatile uint32_t *ptr)
843   {
844     uint32_t res;
845     __ASM volatile ("LDAEX %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
846     return res;
847   }
848
849   __IAR_FT uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr)
850   {
851     uint32_t res;
852     __ASM volatile ("STLEXB %0, %2, [%1]" : "=r" (res) : "r" (*ptr), "r" (value) : "memory");
853     return res;
854   }
855
856   __IAR_FT uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr)
857   {
858     uint32_t res;
859     __ASM volatile ("STLEXH %0, %2, [%1]" : "=r" (res) : "r" (*ptr), "r" (value) : "memory");
860     return res;
861   }
862
863   __IAR_FT uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr)
864   {
865     uint32_t res;
866     __ASM volatile ("STLEX %0, %2, [%1]" : "=r" (res) : "r" (*ptr), "r" (value) : "memory");
867     return res;
868   }
869
870 #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
871
872 #undef __IAR_FT
873 #undef __IAR_M0_FAMILY
874 #undef __ICCARM_V8
875
876 #pragma diag_default=Pe940
877 #pragma diag_default=Pe177
878
879 #endif /* __CMSIS_ICCARM_H__ */