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