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