]> begriffs open source - cmsis/blob - CMSIS/Core/Include/cmsis_iccarm.h
Core: Fixed MISRA warnings.
[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   #define __CLZ     __iar_builtin_CLZ  
313   #define __CLREX   __iar_builtin_CLREX
314
315   #define __DMB     __iar_builtin_DMB
316   #define __DSB     __iar_builtin_DSB
317   #define __ISB     __iar_builtin_ISB
318
319   #define __LDREXB  __iar_builtin_LDREXB
320   #define __LDREXH  __iar_builtin_LDREXH
321   #define __LDREXW  __iar_builtin_LDREX
322
323   #define __RBIT    __iar_builtin_RBIT
324   #define __REV     __iar_builtin_REV
325   #define __REV16   __iar_builtin_REV16
326   #define __REVSH   __iar_builtin_REVSH
327
328   #define __ROR     __iar_builtin_ROR
329   #define __RRX     __iar_builtin_RRX
330
331   #define __SEV     __iar_builtin_SEV
332
333   #if !__IAR_M0_FAMILY
334     #define __SSAT    __iar_builtin_SSAT
335   #endif
336
337   #define __STREXB  __iar_builtin_STREXB
338   #define __STREXH  __iar_builtin_STREXH
339   #define __STREXW  __iar_builtin_STREX
340
341   #if !__IAR_M0_FAMILY
342     #define __USAT    __iar_builtin_USAT
343   #endif
344
345   #define __WFE     __iar_builtin_WFE
346   #define __WFI     __iar_builtin_WFI
347
348   #if __ARM_MEDIA__
349     #define __SADD8   __iar_builtin_SADD8
350     #define __QADD8   __iar_builtin_QADD8
351     #define __SHADD8  __iar_builtin_SHADD8
352     #define __UADD8   __iar_builtin_UADD8
353     #define __UQADD8  __iar_builtin_UQADD8
354     #define __UHADD8  __iar_builtin_UHADD8
355     #define __SSUB8   __iar_builtin_SSUB8
356     #define __QSUB8   __iar_builtin_QSUB8
357     #define __SHSUB8  __iar_builtin_SHSUB8
358     #define __USUB8   __iar_builtin_USUB8
359     #define __UQSUB8  __iar_builtin_UQSUB8
360     #define __UHSUB8  __iar_builtin_UHSUB8
361     #define __SADD16  __iar_builtin_SADD16
362     #define __QADD16  __iar_builtin_QADD16
363     #define __SHADD16 __iar_builtin_SHADD16
364     #define __UADD16  __iar_builtin_UADD16
365     #define __UQADD16 __iar_builtin_UQADD16
366     #define __UHADD16 __iar_builtin_UHADD16
367     #define __SSUB16  __iar_builtin_SSUB16
368     #define __QSUB16  __iar_builtin_QSUB16
369     #define __SHSUB16 __iar_builtin_SHSUB16
370     #define __USUB16  __iar_builtin_USUB16
371     #define __UQSUB16 __iar_builtin_UQSUB16
372     #define __UHSUB16 __iar_builtin_UHSUB16
373     #define __SASX    __iar_builtin_SASX
374     #define __QASX    __iar_builtin_QASX
375     #define __SHASX   __iar_builtin_SHASX
376     #define __UASX    __iar_builtin_UASX
377     #define __UQASX   __iar_builtin_UQASX
378     #define __UHASX   __iar_builtin_UHASX
379     #define __SSAX    __iar_builtin_SSAX
380     #define __QSAX    __iar_builtin_QSAX
381     #define __SHSAX   __iar_builtin_SHSAX
382     #define __USAX    __iar_builtin_USAX
383     #define __UQSAX   __iar_builtin_UQSAX
384     #define __UHSAX   __iar_builtin_UHSAX
385     #define __USAD8   __iar_builtin_USAD8
386     #define __USADA8  __iar_builtin_USADA8
387     #define __SSAT16  __iar_builtin_SSAT16
388     #define __USAT16  __iar_builtin_USAT16
389     #define __UXTB16  __iar_builtin_UXTB16
390     #define __UXTAB16 __iar_builtin_UXTAB16
391     #define __SXTB16  __iar_builtin_SXTB16
392     #define __SXTAB16 __iar_builtin_SXTAB16
393     #define __SMUAD   __iar_builtin_SMUAD
394     #define __SMUADX  __iar_builtin_SMUADX
395     #define __SMMLA   __iar_builtin_SMMLA
396     #define __SMLAD   __iar_builtin_SMLAD
397     #define __SMLADX  __iar_builtin_SMLADX
398     #define __SMLALD  __iar_builtin_SMLALD
399     #define __SMLALDX __iar_builtin_SMLALDX
400     #define __SMUSD   __iar_builtin_SMUSD
401     #define __SMUSDX  __iar_builtin_SMUSDX
402     #define __SMLSD   __iar_builtin_SMLSD
403     #define __SMLSDX  __iar_builtin_SMLSDX
404     #define __SMLSLD  __iar_builtin_SMLSLD
405     #define __SMLSLDX __iar_builtin_SMLSLDX
406     #define __SEL     __iar_builtin_SEL
407     #define __QADD    __iar_builtin_QADD
408     #define __QSUB    __iar_builtin_QSUB
409     #define __PKHBT   __iar_builtin_PKHBT
410     #define __PKHTB   __iar_builtin_PKHTB
411   #endif
412
413 #else /* __ICCARM_INTRINSICS_VERSION__ == 2 */
414
415   #if __IAR_M0_FAMILY
416    /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
417     #define __CLZ  __cmsis_iar_clz_not_active
418     #define __SSAT __cmsis_iar_ssat_not_active
419     #define __USAT __cmsis_iar_usat_not_active
420     #define __RBIT __cmsis_iar_rbit_not_active
421     #define __get_APSR  __cmsis_iar_get_APSR_not_active
422   #endif
423
424
425   #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
426          (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     ))
427     #define __get_FPSCR __cmsis_iar_get_FPSR_not_active
428     #define __set_FPSCR __cmsis_iar_set_FPSR_not_active
429   #endif
430
431   #include <intrinsics.h>
432
433   #if __IAR_M0_FAMILY
434    /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
435     #undef __CLZ
436     #undef __SSAT
437     #undef __USAT
438     #undef __RBIT
439     #undef __get_APSR
440
441     __STATIC_INLINE uint8_t __CLZ(uint32_t data) {
442       if (data == 0u) { return 32u; }
443
444       uint32_t count = 0U;
445       uint32_t mask = 0x80000000U;
446
447       while ((data & mask) == 0U)
448       {
449         count += 1U;
450         mask = mask >> 1U;
451       }
452       return count;
453     }
454
455     __STATIC_INLINE uint32_t __RBIT(uint32_t v) {
456       uint8_t sc = 31U;
457       uint32_t r = v;
458       for (v >>= 1U; v; v >>= 1U)
459       {
460         r <<= 1U;
461         r |= v & 1U;
462         sc--;
463       }
464       return (r << sc);
465     }
466
467     __STATIC_INLINE  uint32_t __get_APSR(void) {
468       uint32_t res;
469       __asm("MRS      %0,APSR" : "=r" (res));
470       return res;
471     }
472
473   #endif
474
475   #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
476          (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     ))
477     #undef __get_FPSCR
478     #undef __set_FPSCR
479     #define __get_FPSCR()       (0)
480     #define __set_FPSCR(VALUE)  ((void)VALUE)
481   #endif
482
483   #pragma diag_suppress=Pe940
484   #pragma diag_suppress=Pe177
485
486   #define __enable_irq    __enable_interrupt
487   #define __disable_irq   __disable_interrupt
488   #define __NOP           __no_operation
489
490   #define __get_xPSR      __get_PSR
491
492   #if (!defined(__ARM_ARCH_6M__) || __ARM_ARCH_6M__==0)
493
494     __IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr) {
495       return __LDREX((unsigned long *)ptr);
496     }
497
498     __IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr) {
499       return __STREX(value, (unsigned long *)ptr);
500     }
501   #endif
502
503
504   /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
505   #if (__CORTEX_M >= 0x03)
506
507     __IAR_FT uint32_t __RRX(uint32_t value) {
508       uint32_t result;
509       __ASM("RRX      %0, %1" : "=r"(result) : "r" (value) : "cc");
510       return(result);
511     }
512
513     __IAR_FT void __set_BASEPRI_MAX(uint32_t value) {
514       __asm volatile("MSR      BASEPRI_MAX,%0"::"r" (value));
515     }
516
517
518     #define __enable_fault_irq  __enable_fiq
519     #define __disable_fault_irq __disable_fiq
520
521
522   #endif /* (__CORTEX_M >= 0x03) */
523
524   __IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2) {
525     return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2));
526   }
527
528   #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
529        (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    )
530
531     __IAR_FT uint32_t __TZ_get_CONTROL_NS(void) {
532       uint32_t res;
533       __asm volatile("MRS      %0,CONTROL_NS" : "=r" (res));
534       return res;
535     }
536
537     __IAR_FT void       __TZ_set_CONTROL_NS(uint32_t value) {
538       __asm volatile("MSR      CONTROL_NS,%0" :: "r" (value));
539     }
540
541     __IAR_FT uint32_t   __TZ_get_PSP_NS(void) {
542       uint32_t res;
543       __asm volatile("MRS      %0,PSP_NS" : "=r" (res));
544       return res;
545     }
546
547     __IAR_FT void       __TZ_set_PSP_NS(uint32_t value) {
548       __asm volatile("MSR      PSP_NS,%0" :: "r" (value));
549     }
550
551     __IAR_FT uint32_t   __TZ_get_MSP_NS(void) {
552       uint32_t res;
553       __asm volatile("MRS      %0,MSP_NS" : "=r" (res));
554       return res;
555     }
556
557     __IAR_FT void       __TZ_set_MSP_NS(uint32_t value) {
558       __asm volatile("MSR      MSP_NS,%0" :: "r" (value));
559     }
560
561     __IAR_FT uint32_t   __TZ_get_SP_NS(void) {
562       uint32_t res;
563       __asm volatile("MRS      %0,SP_NS" : "=r" (res));
564       return res;
565     }
566     __IAR_FT void       __TZ_set_SP_NS(uint32_t value) {
567       __asm volatile("MSR      SP_NS,%0" :: "r" (value));
568     }
569
570     __IAR_FT uint32_t   __TZ_get_PRIMASK_NS(void) {
571       uint32_t res;
572       __asm volatile("MRS      %0,PRIMASK_NS" : "=r" (res));
573       return res;
574     }
575
576     __IAR_FT void       __TZ_set_PRIMASK_NS(uint32_t value) {
577       __asm volatile("MSR      PRIMASK_NS,%0" :: "r" (value));
578     }
579
580     __IAR_FT uint32_t   __TZ_get_BASEPRI_NS(void) {
581       uint32_t res;
582       __asm volatile("MRS      %0,BASEPRI_NS" : "=r" (res));
583       return res;
584     }
585
586     __IAR_FT void       __TZ_set_BASEPRI_NS(uint32_t value) {
587       __asm volatile("MSR      BASEPRI_NS,%0" :: "r" (value));
588     }
589
590     __IAR_FT uint32_t   __TZ_get_FAULTMASK_NS(void) {
591       uint32_t res;
592       __asm volatile("MRS      %0,FAULTMASK_NS" : "=r" (res));
593       return res;
594     }
595
596     __IAR_FT void       __TZ_set_FAULTMASK_NS(uint32_t value) {
597       __asm volatile("MSR      FAULTMASK_NS,%0" :: "r" (value));
598     }
599
600     __IAR_FT uint32_t   __TZ_get_PSPLIM_NS(void) {
601       uint32_t res;
602       __asm volatile("MRS      %0,PSPLIM_NS" : "=r" (res));
603       return res;
604     }
605     __IAR_FT void       __TZ_set_PSPLIM_NS(uint32_t value) {
606       __asm volatile("MSR      PSPLIM_NS,%0" :: "r" (value));
607     }
608
609     __IAR_FT uint32_t   __TZ_get_MSPLIM_NS(void) {
610       uint32_t res;
611       __asm volatile("MRS      %0,MSPLIM_NS" : "=r" (res));
612       return res;
613     }
614
615     __IAR_FT void       __TZ_set_MSPLIM_NS(uint32_t value) {
616       __asm volatile("MSR      MSPLIM_NS,%0" :: "r" (value));
617     }
618
619   #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
620
621 #endif   /* __ICCARM_INTRINSICS_VERSION__ == 2 */
622
623 #define __BKPT(value)    __asm volatile ("BKPT     %0" : : "i"(value))
624
625 #if __IAR_M0_FAMILY
626   __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat) {
627     if ((sat >= 1U) && (sat <= 32U)) {
628       const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
629       const int32_t min = -1 - max ;
630       if (val > max) {
631         return max;
632       } else if (val < min) {
633         return min;
634       }
635     }
636     return val;
637   }
638
639   __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat) {
640     if (sat <= 31U) {
641       const uint32_t max = ((1U << sat) - 1U);
642       if (val > (int32_t)max) {
643         return max;
644       } else if (val < 0) {
645         return 0U;
646       }
647     }
648     return (uint32_t)val;
649   }
650 #endif
651
652 #if (__CORTEX_M >= 0x03)   /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
653
654   __IAR_FT uint8_t __LDRBT(volatile uint8_t *addr) {
655     uint32_t res;
656     __ASM("LDRBT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
657     return ((uint8_t)res);
658   }
659
660   __IAR_FT uint16_t __LDRHT(volatile uint16_t *addr) {
661     uint32_t res;
662     __ASM("LDRHT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
663     return ((uint16_t)res);
664   }
665
666   __IAR_FT uint32_t __LDRT(volatile uint32_t *addr) {
667     uint32_t res;
668     __ASM("LDRT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
669     return res;
670   }
671
672   __IAR_FT void __STRBT(uint8_t value, volatile uint8_t *addr) {
673     __ASM("STRBT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
674   }
675
676   __IAR_FT void __STRHT(uint16_t value, volatile uint16_t *addr) {
677     __ASM("STRHT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
678   }
679
680   __IAR_FT void __STRT(uint32_t value, volatile uint32_t *addr) {
681     __ASM("STRT %1, [%0]" : : "r" (addr), "r" (value) : "memory");
682   }
683
684 #endif /* (__CORTEX_M >= 0x03) */
685
686 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
687      (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    )
688
689
690   __IAR_FT uint8_t __LDAB(volatile uint8_t *ptr) {
691     uint32_t res;
692     __ASM volatile ("LDAB %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
693     return ((uint8_t)res);
694   }
695
696   __IAR_FT uint16_t __LDAH(volatile uint16_t *ptr) {
697     uint32_t res;
698     __ASM volatile ("LDAH %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
699     return ((uint16_t)res);
700   }
701
702   __IAR_FT uint32_t __LDA(volatile uint32_t *ptr) {
703     uint32_t res;
704     __ASM volatile ("LDA %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
705     return res;
706   }
707
708   __IAR_FT void __STLB(uint8_t value, volatile uint8_t *ptr) {
709     __ASM volatile ("STLB %1, [%0]" :: "r" (*ptr), "r" (value) : "memory");
710   }
711
712   __IAR_FT void __STLH(uint16_t value, volatile uint16_t *ptr) {
713     __ASM volatile ("STLH %1, [%0]" :: "r" (*ptr), "r" (value) : "memory");
714   }
715
716   __IAR_FT void __STL(uint32_t value, volatile uint32_t *ptr) {
717     __ASM volatile ("STL %1, [%0]" :: "r" (*ptr), "r" (value) : "memory");
718   }
719
720   __IAR_FT uint8_t __LDAEXB(volatile uint8_t *ptr) {
721     uint32_t res;
722     __ASM volatile ("LDAEXB %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
723     return ((uint8_t)res);
724   }
725
726   __IAR_FT uint16_t __LDAEXH(volatile uint16_t *ptr) {
727     uint32_t res;
728     __ASM volatile ("LDAEXH %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
729     return ((uint16_t)res);
730   }
731
732   __IAR_FT uint32_t __LDAEX(volatile uint32_t *ptr) {
733     uint32_t res;
734     __ASM volatile ("LDAEX %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory");
735     return res;
736   }
737
738   __IAR_FT uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr) {
739     uint32_t res;
740     __ASM volatile ("STLEXB %0, %2, [%1]" : "=r" (res) : "r" (*ptr), "r" (value) : "memory");
741     return res;
742   }
743
744   __IAR_FT uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr) {
745     uint32_t res;
746     __ASM volatile ("STLEXH %0, %2, [%1]" : "=r" (res) : "r" (*ptr), "r" (value) : "memory");
747     return res;
748   }
749
750   __IAR_FT uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr) {
751     uint32_t res;
752     __ASM volatile ("STLEX %0, %2, [%1]" : "=r" (res) : "r" (*ptr), "r" (value) : "memory");
753     return res;
754   }
755
756 #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
757
758 #undef __IAR_FT
759 #undef __IAR_M0_FAMILY
760 #undef __ICCARM_V8
761
762 #pragma diag_default=Pe940
763 #pragma diag_default=Pe177
764
765 #endif /* __CMSIS_ICCARM_H__ */