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