]> begriffs open source - cmsis/blob - CMSIS/Core/Include/cmsis_iccarm.h
Core(M): Enhanced Startup and Lowlevel init provisions.
[cmsis] / CMSIS / Core / Include / cmsis_iccarm.h
1 /**************************************************************************//**
2  * @file     cmsis_iccarm.h
3  * @brief    CMSIS compiler ICCARM (IAR Compiler for Arm) header file
4  * @version  V5.1.0
5  * @date     08. May 2019
6  ******************************************************************************/
7
8 //------------------------------------------------------------------------------
9 //
10 // Copyright (c) 2017-2019 IAR Systems
11 // Copyright (c) 2017-2019 Arm Limited. All rights reserved. 
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License")
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //     http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the License is distributed on an "AS IS" BASIS,
20 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 // See the License for the specific language governing permissions and
22 // limitations under the License.
23 //
24 //------------------------------------------------------------------------------
25
26
27 #ifndef __CMSIS_ICCARM_H__
28 #define __CMSIS_ICCARM_H__
29
30 #ifndef __ICCARM__
31   #error This file should only be compiled by ICCARM
32 #endif
33
34 #pragma system_include
35
36 #define __IAR_FT _Pragma("inline=forced") __intrinsic
37
38 #if (__VER__ >= 8000000)
39   #define __ICCARM_V8 1
40 #else
41   #define __ICCARM_V8 0
42 #endif
43
44 #ifndef __ALIGNED
45   #if __ICCARM_V8
46     #define __ALIGNED(x) __attribute__((aligned(x)))
47   #elif (__VER__ >= 7080000)
48     /* Needs IAR language extensions */
49     #define __ALIGNED(x) __attribute__((aligned(x)))
50   #else
51     #warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored.
52     #define __ALIGNED(x)
53   #endif
54 #endif
55
56
57 /* Define compiler macros for CPU architecture, used in CMSIS 5.
58  */
59 #if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__ || __ARM_ARCH_8M_BASE__ || __ARM_ARCH_8M_MAIN__
60 /* Macros already defined */
61 #else
62   #if defined(__ARM8M_MAINLINE__) || defined(__ARM8EM_MAINLINE__)
63     #define __ARM_ARCH_8M_MAIN__ 1
64   #elif defined(__ARM8M_BASELINE__)
65     #define __ARM_ARCH_8M_BASE__ 1
66   #elif defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M'
67     #if __ARM_ARCH == 6
68       #define __ARM_ARCH_6M__ 1
69     #elif __ARM_ARCH == 7
70       #if __ARM_FEATURE_DSP
71         #define __ARM_ARCH_7EM__ 1
72       #else
73         #define __ARM_ARCH_7M__ 1
74       #endif
75     #endif /* __ARM_ARCH */
76   #endif /* __ARM_ARCH_PROFILE == 'M' */
77 #endif
78
79 /* Alternativ core deduction for older ICCARM's */
80 #if !defined(__ARM_ARCH_6M__) && !defined(__ARM_ARCH_7M__) && !defined(__ARM_ARCH_7EM__) && \
81     !defined(__ARM_ARCH_8M_BASE__) && !defined(__ARM_ARCH_8M_MAIN__)
82   #if defined(__ARM6M__) && (__CORE__ == __ARM6M__)
83     #define __ARM_ARCH_6M__ 1
84   #elif defined(__ARM7M__) && (__CORE__ == __ARM7M__)
85     #define __ARM_ARCH_7M__ 1
86   #elif defined(__ARM7EM__) && (__CORE__ == __ARM7EM__)
87     #define __ARM_ARCH_7EM__  1
88   #elif defined(__ARM8M_BASELINE__) && (__CORE == __ARM8M_BASELINE__)
89     #define __ARM_ARCH_8M_BASE__ 1
90   #elif defined(__ARM8M_MAINLINE__) && (__CORE == __ARM8M_MAINLINE__)
91     #define __ARM_ARCH_8M_MAIN__ 1
92   #elif defined(__ARM8EM_MAINLINE__) && (__CORE == __ARM8EM_MAINLINE__)
93     #define __ARM_ARCH_8M_MAIN__ 1
94   #else
95     #error "Unknown target."
96   #endif
97 #endif
98
99
100
101 #if defined(__ARM_ARCH_6M__) && __ARM_ARCH_6M__==1
102   #define __IAR_M0_FAMILY  1
103 #elif defined(__ARM_ARCH_8M_BASE__) && __ARM_ARCH_8M_BASE__==1
104   #define __IAR_M0_FAMILY  1
105 #else
106   #define __IAR_M0_FAMILY  0
107 #endif
108
109
110 #ifndef __ASM
111   #define __ASM __asm
112 #endif
113
114 #ifndef __INLINE
115   #define __INLINE inline
116 #endif
117
118 #ifndef   __NO_RETURN
119   #if __ICCARM_V8
120     #define __NO_RETURN __attribute__((__noreturn__))
121   #else
122     #define __NO_RETURN _Pragma("object_attribute=__noreturn")
123   #endif
124 #endif
125
126 #ifndef   __PACKED
127   #if __ICCARM_V8
128     #define __PACKED __attribute__((packed, aligned(1)))
129   #else
130     /* Needs IAR language extensions */
131     #define __PACKED __packed
132   #endif
133 #endif
134
135 #ifndef   __PACKED_STRUCT
136   #if __ICCARM_V8
137     #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
138   #else
139     /* Needs IAR language extensions */
140     #define __PACKED_STRUCT __packed struct
141   #endif
142 #endif
143
144 #ifndef   __PACKED_UNION
145   #if __ICCARM_V8
146     #define __PACKED_UNION union __attribute__((packed, aligned(1)))
147   #else
148     /* Needs IAR language extensions */
149     #define __PACKED_UNION __packed union
150   #endif
151 #endif
152
153 #ifndef   __RESTRICT
154   #if __ICCARM_V8
155     #define __RESTRICT            __restrict
156   #else
157     /* Needs IAR language extensions */
158     #define __RESTRICT            restrict
159   #endif
160 #endif
161
162 #ifndef   __STATIC_INLINE
163   #define __STATIC_INLINE       static inline
164 #endif
165
166 #ifndef   __FORCEINLINE
167   #define __FORCEINLINE         _Pragma("inline=forced")
168 #endif
169
170 #ifndef   __STATIC_FORCEINLINE
171   #define __STATIC_FORCEINLINE  __FORCEINLINE __STATIC_INLINE
172 #endif
173
174 #ifndef __UNALIGNED_UINT16_READ
175 #pragma language=save
176 #pragma language=extended
177 __IAR_FT uint16_t __iar_uint16_read(void const *ptr)
178 {
179   return *(__packed uint16_t*)(ptr);
180 }
181 #pragma language=restore
182 #define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR)
183 #endif
184
185
186 #ifndef __UNALIGNED_UINT16_WRITE
187 #pragma language=save
188 #pragma language=extended
189 __IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val)
190 {
191   *(__packed uint16_t*)(ptr) = val;;
192 }
193 #pragma language=restore
194 #define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL)
195 #endif
196
197 #ifndef __UNALIGNED_UINT32_READ
198 #pragma language=save
199 #pragma language=extended
200 __IAR_FT uint32_t __iar_uint32_read(void const *ptr)
201 {
202   return *(__packed uint32_t*)(ptr);
203 }
204 #pragma language=restore
205 #define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR)
206 #endif
207
208 #ifndef __UNALIGNED_UINT32_WRITE
209 #pragma language=save
210 #pragma language=extended
211 __IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val)
212 {
213   *(__packed uint32_t*)(ptr) = val;;
214 }
215 #pragma language=restore
216 #define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL)
217 #endif
218
219 #ifndef __UNALIGNED_UINT32   /* deprecated */
220 #pragma language=save
221 #pragma language=extended
222 __packed struct  __iar_u32 { uint32_t v; };
223 #pragma language=restore
224 #define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v)
225 #endif
226
227 #ifndef   __USED
228   #if __ICCARM_V8
229     #define __USED __attribute__((used))
230   #else
231     #define __USED _Pragma("__root")
232   #endif
233 #endif
234
235 #ifndef   __WEAK
236   #if __ICCARM_V8
237     #define __WEAK __attribute__((weak))
238   #else
239     #define __WEAK _Pragma("__weak")
240   #endif
241 #endif
242
243 #ifndef __PROGRAM_START
244 #define __PROGRAM_START           __iar_program_start
245 #endif
246
247 #ifndef __INITIAL_SP
248 #define __INITIAL_SP              CSTACK$$Limit
249 #endif
250
251 #ifndef __STACK_LIMIT
252 #define __STACK_LIMIT             CSTACK$$Base
253 #endif
254
255 #ifndef __VECTOR_TABLE
256 #define __VECTOR_TABLE            __vector_table
257 #endif
258
259 #ifndef __VECTOR_TABLE_ATTRIBUTE
260 #define __VECTOR_TABLE_ATTRIBUTE  @".intvec"
261 #endif
262
263 #ifndef __ICCARM_INTRINSICS_VERSION__
264   #define __ICCARM_INTRINSICS_VERSION__  0
265 #endif
266
267 #if __ICCARM_INTRINSICS_VERSION__ == 2
268
269   #if defined(__CLZ)
270     #undef __CLZ
271   #endif
272   #if defined(__REVSH)
273     #undef __REVSH
274   #endif
275   #if defined(__RBIT)
276     #undef __RBIT
277   #endif
278   #if defined(__SSAT)
279     #undef __SSAT
280   #endif
281   #if defined(__USAT)
282     #undef __USAT
283   #endif
284
285   #include "iccarm_builtin.h"
286
287   #define __disable_fault_irq __iar_builtin_disable_fiq
288   #define __disable_irq       __iar_builtin_disable_interrupt
289   #define __enable_fault_irq  __iar_builtin_enable_fiq
290   #define __enable_irq        __iar_builtin_enable_interrupt
291   #define __arm_rsr           __iar_builtin_rsr
292   #define __arm_wsr           __iar_builtin_wsr
293
294
295   #define __get_APSR()                (__arm_rsr("APSR"))
296   #define __get_BASEPRI()             (__arm_rsr("BASEPRI"))
297   #define __get_CONTROL()             (__arm_rsr("CONTROL"))
298   #define __get_FAULTMASK()           (__arm_rsr("FAULTMASK"))
299
300   #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
301        (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     )
302     #define __get_FPSCR()             (__arm_rsr("FPSCR"))
303     #define __set_FPSCR(VALUE)        (__arm_wsr("FPSCR", (VALUE)))
304   #else
305     #define __get_FPSCR()             ( 0 )
306     #define __set_FPSCR(VALUE)        ((void)VALUE)
307   #endif
308
309   #define __get_IPSR()                (__arm_rsr("IPSR"))
310   #define __get_MSP()                 (__arm_rsr("MSP"))
311   #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
312        (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
313     // without main extensions, the non-secure MSPLIM is RAZ/WI
314     #define __get_MSPLIM()            (0U)
315   #else
316     #define __get_MSPLIM()            (__arm_rsr("MSPLIM"))
317   #endif
318   #define __get_PRIMASK()             (__arm_rsr("PRIMASK"))
319   #define __get_PSP()                 (__arm_rsr("PSP"))
320
321   #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
322        (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
323     // without main extensions, the non-secure PSPLIM is RAZ/WI
324     #define __get_PSPLIM()            (0U)
325   #else
326     #define __get_PSPLIM()            (__arm_rsr("PSPLIM"))
327   #endif
328
329   #define __get_xPSR()                (__arm_rsr("xPSR"))
330
331   #define __set_BASEPRI(VALUE)        (__arm_wsr("BASEPRI", (VALUE)))
332   #define __set_BASEPRI_MAX(VALUE)    (__arm_wsr("BASEPRI_MAX", (VALUE)))
333   #define __set_CONTROL(VALUE)        (__arm_wsr("CONTROL", (VALUE)))
334   #define __set_FAULTMASK(VALUE)      (__arm_wsr("FAULTMASK", (VALUE)))
335   #define __set_MSP(VALUE)            (__arm_wsr("MSP", (VALUE)))
336
337   #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
338        (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
339     // without main extensions, the non-secure MSPLIM is RAZ/WI
340     #define __set_MSPLIM(VALUE)       ((void)(VALUE))
341   #else
342     #define __set_MSPLIM(VALUE)       (__arm_wsr("MSPLIM", (VALUE)))
343   #endif
344   #define __set_PRIMASK(VALUE)        (__arm_wsr("PRIMASK", (VALUE)))
345   #define __set_PSP(VALUE)            (__arm_wsr("PSP", (VALUE)))
346   #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
347        (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
348     // without main extensions, the non-secure PSPLIM is RAZ/WI
349     #define __set_PSPLIM(VALUE)       ((void)(VALUE))
350   #else
351     #define __set_PSPLIM(VALUE)       (__arm_wsr("PSPLIM", (VALUE)))
352   #endif
353
354   #define __TZ_get_CONTROL_NS()       (__arm_rsr("CONTROL_NS"))
355   #define __TZ_set_CONTROL_NS(VALUE)  (__arm_wsr("CONTROL_NS", (VALUE)))
356   #define __TZ_get_PSP_NS()           (__arm_rsr("PSP_NS"))
357   #define __TZ_set_PSP_NS(VALUE)      (__arm_wsr("PSP_NS", (VALUE)))
358   #define __TZ_get_MSP_NS()           (__arm_rsr("MSP_NS"))
359   #define __TZ_set_MSP_NS(VALUE)      (__arm_wsr("MSP_NS", (VALUE)))
360   #define __TZ_get_SP_NS()            (__arm_rsr("SP_NS"))
361   #define __TZ_set_SP_NS(VALUE)       (__arm_wsr("SP_NS", (VALUE)))
362   #define __TZ_get_PRIMASK_NS()       (__arm_rsr("PRIMASK_NS"))
363   #define __TZ_set_PRIMASK_NS(VALUE)  (__arm_wsr("PRIMASK_NS", (VALUE)))
364   #define __TZ_get_BASEPRI_NS()       (__arm_rsr("BASEPRI_NS"))
365   #define __TZ_set_BASEPRI_NS(VALUE)  (__arm_wsr("BASEPRI_NS", (VALUE)))
366   #define __TZ_get_FAULTMASK_NS()     (__arm_rsr("FAULTMASK_NS"))
367   #define __TZ_set_FAULTMASK_NS(VALUE)(__arm_wsr("FAULTMASK_NS", (VALUE)))
368
369   #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
370        (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
371     // without main extensions, the non-secure PSPLIM is RAZ/WI
372     #define __TZ_get_PSPLIM_NS()      (0U)
373     #define __TZ_set_PSPLIM_NS(VALUE) ((void)(VALUE))
374   #else
375     #define __TZ_get_PSPLIM_NS()      (__arm_rsr("PSPLIM_NS"))
376     #define __TZ_set_PSPLIM_NS(VALUE) (__arm_wsr("PSPLIM_NS", (VALUE)))
377   #endif
378
379   #define __TZ_get_MSPLIM_NS()        (__arm_rsr("MSPLIM_NS"))
380   #define __TZ_set_MSPLIM_NS(VALUE)   (__arm_wsr("MSPLIM_NS", (VALUE)))
381
382   #define __NOP     __iar_builtin_no_operation
383
384   #define __CLZ     __iar_builtin_CLZ
385   #define __CLREX   __iar_builtin_CLREX
386
387   #define __DMB     __iar_builtin_DMB
388   #define __DSB     __iar_builtin_DSB
389   #define __ISB     __iar_builtin_ISB
390
391   #define __LDREXB  __iar_builtin_LDREXB
392   #define __LDREXH  __iar_builtin_LDREXH
393   #define __LDREXW  __iar_builtin_LDREX
394
395   #define __RBIT    __iar_builtin_RBIT
396   #define __REV     __iar_builtin_REV
397   #define __REV16   __iar_builtin_REV16
398
399   __IAR_FT int16_t __REVSH(int16_t val)
400   {
401     return (int16_t) __iar_builtin_REVSH(val);
402   }
403
404   #define __ROR     __iar_builtin_ROR
405   #define __RRX     __iar_builtin_RRX
406
407   #define __SEV     __iar_builtin_SEV
408
409   #if !__IAR_M0_FAMILY
410     #define __SSAT    __iar_builtin_SSAT
411   #endif
412
413   #define __STREXB  __iar_builtin_STREXB
414   #define __STREXH  __iar_builtin_STREXH
415   #define __STREXW  __iar_builtin_STREX
416
417   #if !__IAR_M0_FAMILY
418     #define __USAT    __iar_builtin_USAT
419   #endif
420
421   #define __WFE     __iar_builtin_WFE
422   #define __WFI     __iar_builtin_WFI
423
424   #if __ARM_MEDIA__
425     #define __SADD8   __iar_builtin_SADD8
426     #define __QADD8   __iar_builtin_QADD8
427     #define __SHADD8  __iar_builtin_SHADD8
428     #define __UADD8   __iar_builtin_UADD8
429     #define __UQADD8  __iar_builtin_UQADD8
430     #define __UHADD8  __iar_builtin_UHADD8
431     #define __SSUB8   __iar_builtin_SSUB8
432     #define __QSUB8   __iar_builtin_QSUB8
433     #define __SHSUB8  __iar_builtin_SHSUB8
434     #define __USUB8   __iar_builtin_USUB8
435     #define __UQSUB8  __iar_builtin_UQSUB8
436     #define __UHSUB8  __iar_builtin_UHSUB8
437     #define __SADD16  __iar_builtin_SADD16
438     #define __QADD16  __iar_builtin_QADD16
439     #define __SHADD16 __iar_builtin_SHADD16
440     #define __UADD16  __iar_builtin_UADD16
441     #define __UQADD16 __iar_builtin_UQADD16
442     #define __UHADD16 __iar_builtin_UHADD16
443     #define __SSUB16  __iar_builtin_SSUB16
444     #define __QSUB16  __iar_builtin_QSUB16
445     #define __SHSUB16 __iar_builtin_SHSUB16
446     #define __USUB16  __iar_builtin_USUB16
447     #define __UQSUB16 __iar_builtin_UQSUB16
448     #define __UHSUB16 __iar_builtin_UHSUB16
449     #define __SASX    __iar_builtin_SASX
450     #define __QASX    __iar_builtin_QASX
451     #define __SHASX   __iar_builtin_SHASX
452     #define __UASX    __iar_builtin_UASX
453     #define __UQASX   __iar_builtin_UQASX
454     #define __UHASX   __iar_builtin_UHASX
455     #define __SSAX    __iar_builtin_SSAX
456     #define __QSAX    __iar_builtin_QSAX
457     #define __SHSAX   __iar_builtin_SHSAX
458     #define __USAX    __iar_builtin_USAX
459     #define __UQSAX   __iar_builtin_UQSAX
460     #define __UHSAX   __iar_builtin_UHSAX
461     #define __USAD8   __iar_builtin_USAD8
462     #define __USADA8  __iar_builtin_USADA8
463     #define __SSAT16  __iar_builtin_SSAT16
464     #define __USAT16  __iar_builtin_USAT16
465     #define __UXTB16  __iar_builtin_UXTB16
466     #define __UXTAB16 __iar_builtin_UXTAB16
467     #define __SXTB16  __iar_builtin_SXTB16
468     #define __SXTAB16 __iar_builtin_SXTAB16
469     #define __SMUAD   __iar_builtin_SMUAD
470     #define __SMUADX  __iar_builtin_SMUADX
471     #define __SMMLA   __iar_builtin_SMMLA
472     #define __SMLAD   __iar_builtin_SMLAD
473     #define __SMLADX  __iar_builtin_SMLADX
474     #define __SMLALD  __iar_builtin_SMLALD
475     #define __SMLALDX __iar_builtin_SMLALDX
476     #define __SMUSD   __iar_builtin_SMUSD
477     #define __SMUSDX  __iar_builtin_SMUSDX
478     #define __SMLSD   __iar_builtin_SMLSD
479     #define __SMLSDX  __iar_builtin_SMLSDX
480     #define __SMLSLD  __iar_builtin_SMLSLD
481     #define __SMLSLDX __iar_builtin_SMLSLDX
482     #define __SEL     __iar_builtin_SEL
483     #define __QADD    __iar_builtin_QADD
484     #define __QSUB    __iar_builtin_QSUB
485     #define __PKHBT   __iar_builtin_PKHBT
486     #define __PKHTB   __iar_builtin_PKHTB
487   #endif
488
489 #else /* __ICCARM_INTRINSICS_VERSION__ == 2 */
490
491   #if __IAR_M0_FAMILY
492    /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
493     #define __CLZ  __cmsis_iar_clz_not_active
494     #define __SSAT __cmsis_iar_ssat_not_active
495     #define __USAT __cmsis_iar_usat_not_active
496     #define __RBIT __cmsis_iar_rbit_not_active
497     #define __get_APSR  __cmsis_iar_get_APSR_not_active
498   #endif
499
500
501   #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
502          (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     ))
503     #define __get_FPSCR __cmsis_iar_get_FPSR_not_active
504     #define __set_FPSCR __cmsis_iar_set_FPSR_not_active
505   #endif
506
507   #ifdef __INTRINSICS_INCLUDED
508   #error intrinsics.h is already included previously!
509   #endif
510
511   #include <intrinsics.h>
512
513   #if __IAR_M0_FAMILY
514    /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
515     #undef __CLZ
516     #undef __SSAT
517     #undef __USAT
518     #undef __RBIT
519     #undef __get_APSR
520
521     __STATIC_INLINE uint8_t __CLZ(uint32_t data)
522     {
523       if (data == 0U) { return 32U; }
524
525       uint32_t count = 0U;
526       uint32_t mask = 0x80000000U;
527
528       while ((data & mask) == 0U)
529       {
530         count += 1U;
531         mask = mask >> 1U;
532       }
533       return count;
534     }
535
536     __STATIC_INLINE uint32_t __RBIT(uint32_t v)
537     {
538       uint8_t sc = 31U;
539       uint32_t r = v;
540       for (v >>= 1U; v; v >>= 1U)
541       {
542         r <<= 1U;
543         r |= v & 1U;
544         sc--;
545       }
546       return (r << sc);
547     }
548
549     __STATIC_INLINE  uint32_t __get_APSR(void)
550     {
551       uint32_t res;
552       __asm("MRS      %0,APSR" : "=r" (res));
553       return res;
554     }
555
556   #endif
557
558   #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
559          (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     ))
560     #undef __get_FPSCR
561     #undef __set_FPSCR
562     #define __get_FPSCR()       (0)
563     #define __set_FPSCR(VALUE)  ((void)VALUE)
564   #endif
565
566   #pragma diag_suppress=Pe940
567   #pragma diag_suppress=Pe177
568
569   #define __enable_irq    __enable_interrupt
570   #define __disable_irq   __disable_interrupt
571   #define __NOP           __no_operation
572
573   #define __get_xPSR      __get_PSR
574
575   #if (!defined(__ARM_ARCH_6M__) || __ARM_ARCH_6M__==0)
576
577     __IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr)
578     {
579       return __LDREX((unsigned long *)ptr);
580     }
581
582     __IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr)
583     {
584       return __STREX(value, (unsigned long *)ptr);
585     }
586   #endif
587
588
589   /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
590   #if (__CORTEX_M >= 0x03)
591
592     __IAR_FT uint32_t __RRX(uint32_t value)
593     {
594       uint32_t result;
595       __ASM("RRX      %0, %1" : "=r"(result) : "r" (value) : "cc");
596       return(result);
597     }
598
599     __IAR_FT void __set_BASEPRI_MAX(uint32_t value)
600     {
601       __asm volatile("MSR      BASEPRI_MAX,%0"::"r" (value));
602     }
603
604
605     #define __enable_fault_irq  __enable_fiq
606     #define __disable_fault_irq __disable_fiq
607
608
609   #endif /* (__CORTEX_M >= 0x03) */
610
611   __IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2)
612   {
613     return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2));
614   }
615
616   #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
617        (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    )
618
619    __IAR_FT uint32_t __get_MSPLIM(void)
620     {
621       uint32_t res;
622     #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
623          (!defined (__ARM_FEATURE_CMSE  ) || (__ARM_FEATURE_CMSE   < 3)))
624       // without main extensions, the non-secure MSPLIM is RAZ/WI
625       res = 0U;
626     #else
627       __asm volatile("MRS      %0,MSPLIM" : "=r" (res));
628     #endif
629       return res;
630     }
631
632     __IAR_FT void   __set_MSPLIM(uint32_t value)
633     {
634     #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
635          (!defined (__ARM_FEATURE_CMSE  ) || (__ARM_FEATURE_CMSE   < 3)))
636       // without main extensions, the non-secure MSPLIM is RAZ/WI
637       (void)value;
638     #else
639       __asm volatile("MSR      MSPLIM,%0" :: "r" (value));
640     #endif
641     }
642
643     __IAR_FT uint32_t __get_PSPLIM(void)
644     {
645       uint32_t res;
646     #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
647          (!defined (__ARM_FEATURE_CMSE  ) || (__ARM_FEATURE_CMSE   < 3)))
648       // without main extensions, the non-secure PSPLIM is RAZ/WI
649       res = 0U;
650     #else
651       __asm volatile("MRS      %0,PSPLIM" : "=r" (res));
652     #endif
653       return res;
654     }
655
656     __IAR_FT void   __set_PSPLIM(uint32_t value)
657     {
658     #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
659          (!defined (__ARM_FEATURE_CMSE  ) || (__ARM_FEATURE_CMSE   < 3)))
660       // without main extensions, the non-secure PSPLIM is RAZ/WI
661       (void)value;
662     #else
663       __asm volatile("MSR      PSPLIM,%0" :: "r" (value));
664     #endif
665     }
666
667     __IAR_FT uint32_t __TZ_get_CONTROL_NS(void)
668     {
669       uint32_t res;
670       __asm volatile("MRS      %0,CONTROL_NS" : "=r" (res));
671       return res;
672     }
673
674     __IAR_FT void   __TZ_set_CONTROL_NS(uint32_t value)
675     {
676       __asm volatile("MSR      CONTROL_NS,%0" :: "r" (value));
677     }
678
679     __IAR_FT uint32_t   __TZ_get_PSP_NS(void)
680     {
681       uint32_t res;
682       __asm volatile("MRS      %0,PSP_NS" : "=r" (res));
683       return res;
684     }
685
686     __IAR_FT void   __TZ_set_PSP_NS(uint32_t value)
687     {
688       __asm volatile("MSR      PSP_NS,%0" :: "r" (value));
689     }
690
691     __IAR_FT uint32_t   __TZ_get_MSP_NS(void)
692     {
693       uint32_t res;
694       __asm volatile("MRS      %0,MSP_NS" : "=r" (res));
695       return res;
696     }
697
698     __IAR_FT void   __TZ_set_MSP_NS(uint32_t value)
699     {
700       __asm volatile("MSR      MSP_NS,%0" :: "r" (value));
701     }
702
703     __IAR_FT uint32_t   __TZ_get_SP_NS(void)
704     {
705       uint32_t res;
706       __asm volatile("MRS      %0,SP_NS" : "=r" (res));
707       return res;
708     }
709     __IAR_FT void   __TZ_set_SP_NS(uint32_t value)
710     {
711       __asm volatile("MSR      SP_NS,%0" :: "r" (value));
712     }
713
714     __IAR_FT uint32_t   __TZ_get_PRIMASK_NS(void)
715     {
716       uint32_t res;
717       __asm volatile("MRS      %0,PRIMASK_NS" : "=r" (res));
718       return res;
719     }
720
721     __IAR_FT void   __TZ_set_PRIMASK_NS(uint32_t value)
722     {
723       __asm volatile("MSR      PRIMASK_NS,%0" :: "r" (value));
724     }
725
726     __IAR_FT uint32_t   __TZ_get_BASEPRI_NS(void)
727     {
728       uint32_t res;
729       __asm volatile("MRS      %0,BASEPRI_NS" : "=r" (res));
730       return res;
731     }
732
733     __IAR_FT void   __TZ_set_BASEPRI_NS(uint32_t value)
734     {
735       __asm volatile("MSR      BASEPRI_NS,%0" :: "r" (value));
736     }
737
738     __IAR_FT uint32_t   __TZ_get_FAULTMASK_NS(void)
739     {
740       uint32_t res;
741       __asm volatile("MRS      %0,FAULTMASK_NS" : "=r" (res));
742       return res;
743     }
744
745     __IAR_FT void   __TZ_set_FAULTMASK_NS(uint32_t value)
746     {
747       __asm volatile("MSR      FAULTMASK_NS,%0" :: "r" (value));
748     }
749
750     __IAR_FT uint32_t   __TZ_get_PSPLIM_NS(void)
751     {
752       uint32_t res;
753     #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
754          (!defined (__ARM_FEATURE_CMSE  ) || (__ARM_FEATURE_CMSE   < 3)))
755       // without main extensions, the non-secure PSPLIM is RAZ/WI
756       res = 0U;
757     #else
758       __asm volatile("MRS      %0,PSPLIM_NS" : "=r" (res));
759     #endif
760       return res;
761     }
762
763     __IAR_FT void   __TZ_set_PSPLIM_NS(uint32_t value)
764     {
765     #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
766          (!defined (__ARM_FEATURE_CMSE  ) || (__ARM_FEATURE_CMSE   < 3)))
767       // without main extensions, the non-secure PSPLIM is RAZ/WI
768       (void)value;
769     #else
770       __asm volatile("MSR      PSPLIM_NS,%0" :: "r" (value));
771     #endif
772     }
773
774     __IAR_FT uint32_t   __TZ_get_MSPLIM_NS(void)
775     {
776       uint32_t res;
777       __asm volatile("MRS      %0,MSPLIM_NS" : "=r" (res));
778       return res;
779     }
780
781     __IAR_FT void   __TZ_set_MSPLIM_NS(uint32_t value)
782     {
783       __asm volatile("MSR      MSPLIM_NS,%0" :: "r" (value));
784     }
785
786   #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
787
788 #endif   /* __ICCARM_INTRINSICS_VERSION__ == 2 */
789
790 #define __BKPT(value)    __asm volatile ("BKPT     %0" : : "i"(value))
791
792 #if __IAR_M0_FAMILY
793   __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat)
794   {
795     if ((sat >= 1U) && (sat <= 32U))
796     {
797       const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
798       const int32_t min = -1 - max ;
799       if (val > max)
800       {
801         return max;
802       }
803       else if (val < min)
804       {
805         return min;
806       }
807     }
808     return val;
809   }
810
811   __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat)
812   {
813     if (sat <= 31U)
814     {
815       const uint32_t max = ((1U << sat) - 1U);
816       if (val > (int32_t)max)
817       {
818         return max;
819       }
820       else if (val < 0)
821       {
822         return 0U;
823       }
824     }
825     return (uint32_t)val;
826   }
827 #endif
828
829 #if (__CORTEX_M >= 0x03)   /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
830
831   __IAR_FT uint8_t __LDRBT(volatile uint8_t *addr)
832   {
833     uint32_t res;
834     __ASM("LDRBT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
835     return ((uint8_t)res);
836   }
837
838   __IAR_FT uint16_t __LDRHT(volatile uint16_t *addr)
839   {
840     uint32_t res;
841     __ASM("LDRHT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
842     return ((uint16_t)res);
843   }
844
845   __IAR_FT uint32_t __LDRT(volatile uint32_t *addr)
846   {
847     uint32_t res;
848     __ASM("LDRT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
849     return res;
850   }
851
852   __IAR_FT void __STRBT(uint8_t value, volatile uint8_t *addr)
853   {
854     __ASM("STRBT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
855   }
856
857   __IAR_FT void __STRHT(uint16_t value, volatile uint16_t *addr)
858   {
859     __ASM("STRHT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
860   }
861
862   __IAR_FT void __STRT(uint32_t value, volatile uint32_t *addr)
863   {
864     __ASM("STRT %1, [%0]" : : "r" (addr), "r" (value) : "memory");
865   }
866
867 #endif /* (__CORTEX_M >= 0x03) */
868
869 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
870      (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    )
871
872
873   __IAR_FT uint8_t __LDAB(volatile uint8_t *ptr)
874   {
875     uint32_t res;
876     __ASM volatile ("LDAB %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
877     return ((uint8_t)res);
878   }
879
880   __IAR_FT uint16_t __LDAH(volatile uint16_t *ptr)
881   {
882     uint32_t res;
883     __ASM volatile ("LDAH %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
884     return ((uint16_t)res);
885   }
886
887   __IAR_FT uint32_t __LDA(volatile uint32_t *ptr)
888   {
889     uint32_t res;
890     __ASM volatile ("LDA %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
891     return res;
892   }
893
894   __IAR_FT void __STLB(uint8_t value, volatile uint8_t *ptr)
895   {
896     __ASM volatile ("STLB %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
897   }
898
899   __IAR_FT void __STLH(uint16_t value, volatile uint16_t *ptr)
900   {
901     __ASM volatile ("STLH %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
902   }
903
904   __IAR_FT void __STL(uint32_t value, volatile uint32_t *ptr)
905   {
906     __ASM volatile ("STL %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
907   }
908
909   __IAR_FT uint8_t __LDAEXB(volatile uint8_t *ptr)
910   {
911     uint32_t res;
912     __ASM volatile ("LDAEXB %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
913     return ((uint8_t)res);
914   }
915
916   __IAR_FT uint16_t __LDAEXH(volatile uint16_t *ptr)
917   {
918     uint32_t res;
919     __ASM volatile ("LDAEXH %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
920     return ((uint16_t)res);
921   }
922
923   __IAR_FT uint32_t __LDAEX(volatile uint32_t *ptr)
924   {
925     uint32_t res;
926     __ASM volatile ("LDAEX %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
927     return res;
928   }
929
930   __IAR_FT uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr)
931   {
932     uint32_t res;
933     __ASM volatile ("STLEXB %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
934     return res;
935   }
936
937   __IAR_FT uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr)
938   {
939     uint32_t res;
940     __ASM volatile ("STLEXH %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
941     return res;
942   }
943
944   __IAR_FT uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr)
945   {
946     uint32_t res;
947     __ASM volatile ("STLEX %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
948     return res;
949   }
950
951 #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
952
953 #undef __IAR_FT
954 #undef __IAR_M0_FAMILY
955 #undef __ICCARM_V8
956
957 #pragma diag_default=Pe940
958 #pragma diag_default=Pe177
959
960 #endif /* __CMSIS_ICCARM_H__ */