]> begriffs open source - cmsis/blob - CMSIS/Core/Include/cmsis_armclang.h
CMSIS-Core: update function description for __enable[_fault]_irq, __disable[_fault...
[cmsis] / CMSIS / Core / Include / cmsis_armclang.h
1 /**************************************************************************//**
2  * @file     cmsis_armclang.h
3  * @brief    CMSIS compiler armclang (Arm Compiler 6) header file
4  * @version  V5.4.1
5  * @date     19. March 2021
6  ******************************************************************************/
7 /*
8  * Copyright (c) 2009-2021 Arm Limited. All rights reserved.
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  *
12  * Licensed under the Apache License, Version 2.0 (the License); you may
13  * not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * 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, WITHOUT
20  * 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 /*lint -esym(9058, IRQn)*/ /* disable MISRA 2012 Rule 2.4 for IRQn */
26
27 #ifndef __CMSIS_ARMCLANG_H
28 #define __CMSIS_ARMCLANG_H
29
30 #pragma clang system_header   /* treat file as system include file */
31
32 #ifndef __ARM_COMPAT_H
33 #include <arm_compat.h>    /* Compatibility header for Arm Compiler 5 intrinsics */
34 #endif
35
36 /* CMSIS compiler specific defines */
37 #ifndef   __ASM
38   #define __ASM                                  __asm
39 #endif
40 #ifndef   __INLINE
41   #define __INLINE                               __inline
42 #endif
43 #ifndef   __STATIC_INLINE
44   #define __STATIC_INLINE                        static __inline
45 #endif
46 #ifndef   __STATIC_FORCEINLINE
47   #define __STATIC_FORCEINLINE                   __attribute__((always_inline)) static __inline
48 #endif
49 #ifndef   __NO_RETURN
50   #define __NO_RETURN                            __attribute__((__noreturn__))
51 #endif
52 #ifndef   __USED
53   #define __USED                                 __attribute__((used))
54 #endif
55 #ifndef   __WEAK
56   #define __WEAK                                 __attribute__((weak))
57 #endif
58 #ifndef   __PACKED
59   #define __PACKED                               __attribute__((packed, aligned(1)))
60 #endif
61 #ifndef   __PACKED_STRUCT
62   #define __PACKED_STRUCT                        struct __attribute__((packed, aligned(1)))
63 #endif
64 #ifndef   __PACKED_UNION
65   #define __PACKED_UNION                         union __attribute__((packed, aligned(1)))
66 #endif
67 #ifndef   __UNALIGNED_UINT32        /* deprecated */
68   #pragma clang diagnostic push
69   #pragma clang diagnostic ignored "-Wpacked"
70 /*lint -esym(9058, T_UINT32)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32 */
71   struct __attribute__((packed)) T_UINT32 { uint32_t v; };
72   #pragma clang diagnostic pop
73   #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
74 #endif
75 #ifndef   __UNALIGNED_UINT16_WRITE
76   #pragma clang diagnostic push
77   #pragma clang diagnostic ignored "-Wpacked"
78 /*lint -esym(9058, T_UINT16_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_WRITE */
79   __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
80   #pragma clang diagnostic pop
81   #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
82 #endif
83 #ifndef   __UNALIGNED_UINT16_READ
84   #pragma clang diagnostic push
85   #pragma clang diagnostic ignored "-Wpacked"
86 /*lint -esym(9058, T_UINT16_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_READ */
87   __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
88   #pragma clang diagnostic pop
89   #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
90 #endif
91 #ifndef   __UNALIGNED_UINT32_WRITE
92   #pragma clang diagnostic push
93   #pragma clang diagnostic ignored "-Wpacked"
94 /*lint -esym(9058, T_UINT32_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_WRITE */
95   __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
96   #pragma clang diagnostic pop
97   #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
98 #endif
99 #ifndef   __UNALIGNED_UINT32_READ
100   #pragma clang diagnostic push
101   #pragma clang diagnostic ignored "-Wpacked"
102 /*lint -esym(9058, T_UINT32_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_READ */
103   __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
104   #pragma clang diagnostic pop
105   #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
106 #endif
107 #ifndef   __ALIGNED
108   #define __ALIGNED(x)                           __attribute__((aligned(x)))
109 #endif
110 #ifndef   __RESTRICT
111   #define __RESTRICT                             __restrict
112 #endif
113 #ifndef   __COMPILER_BARRIER
114   #define __COMPILER_BARRIER()                   __ASM volatile("":::"memory")
115 #endif
116
117 /* #########################  Startup and Lowlevel Init  ######################## */
118
119 #ifndef __PROGRAM_START
120 #define __PROGRAM_START           __main
121 #endif
122
123 #ifndef __INITIAL_SP
124 #define __INITIAL_SP              Image$$ARM_LIB_STACK$$ZI$$Limit
125 #endif
126
127 #ifndef __STACK_LIMIT
128 #define __STACK_LIMIT             Image$$ARM_LIB_STACK$$ZI$$Base
129 #endif
130
131 #ifndef __VECTOR_TABLE
132 #define __VECTOR_TABLE            __Vectors
133 #endif
134
135 #ifndef __VECTOR_TABLE_ATTRIBUTE
136 #define __VECTOR_TABLE_ATTRIBUTE  __attribute__((used, section("RESET")))
137 #endif
138
139 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
140 #ifndef __STACK_SEAL
141 #define __STACK_SEAL              Image$$STACKSEAL$$ZI$$Base
142 #endif
143
144 #ifndef __TZ_STACK_SEAL_SIZE
145 #define __TZ_STACK_SEAL_SIZE      8U
146 #endif
147
148 #ifndef __TZ_STACK_SEAL_VALUE
149 #define __TZ_STACK_SEAL_VALUE     0xFEF5EDA5FEF5EDA5ULL
150 #endif
151
152
153 __STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) {
154   *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE;
155 }
156 #endif
157
158
159 /* ###########################  Core Function Access  ########################### */
160 /** \ingroup  CMSIS_Core_FunctionInterface
161     \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
162   @{
163  */
164
165 /**
166   \brief   Enable IRQ Interrupts
167   \details Enables IRQ interrupts by clearing special-purpose register PRIMASK.
168            Can only be executed in Privileged modes.
169  */
170 /* intrinsic void __enable_irq();  see arm_compat.h */
171
172
173 /**
174   \brief   Disable IRQ Interrupts
175   \details Disables IRQ interrupts by setting special-purpose register PRIMASK.
176            Can only be executed in Privileged modes.
177  */
178 /* intrinsic void __disable_irq();  see arm_compat.h */
179
180
181 /**
182   \brief   Get Control Register
183   \details Returns the content of the Control Register.
184   \return               Control Register value
185  */
186 __STATIC_FORCEINLINE uint32_t __get_CONTROL(void)
187 {
188   uint32_t result;
189
190   __ASM volatile ("MRS %0, control" : "=r" (result) );
191   return(result);
192 }
193
194
195 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
196 /**
197   \brief   Get Control Register (non-secure)
198   \details Returns the content of the non-secure Control Register when in secure mode.
199   \return               non-secure Control Register value
200  */
201 __STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void)
202 {
203   uint32_t result;
204
205   __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
206   return(result);
207 }
208 #endif
209
210
211 /**
212   \brief   Set Control Register
213   \details Writes the given value to the Control Register.
214   \param [in]    control  Control Register value to set
215  */
216 __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
217 {
218   __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
219 }
220
221
222 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
223 /**
224   \brief   Set Control Register (non-secure)
225   \details Writes the given value to the non-secure Control Register when in secure state.
226   \param [in]    control  Control Register value to set
227  */
228 __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
229 {
230   __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
231 }
232 #endif
233
234
235 /**
236   \brief   Get IPSR Register
237   \details Returns the content of the IPSR Register.
238   \return               IPSR Register value
239  */
240 __STATIC_FORCEINLINE uint32_t __get_IPSR(void)
241 {
242   uint32_t result;
243
244   __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
245   return(result);
246 }
247
248
249 /**
250   \brief   Get APSR Register
251   \details Returns the content of the APSR Register.
252   \return               APSR Register value
253  */
254 __STATIC_FORCEINLINE uint32_t __get_APSR(void)
255 {
256   uint32_t result;
257
258   __ASM volatile ("MRS %0, apsr" : "=r" (result) );
259   return(result);
260 }
261
262
263 /**
264   \brief   Get xPSR Register
265   \details Returns the content of the xPSR Register.
266   \return               xPSR Register value
267  */
268 __STATIC_FORCEINLINE uint32_t __get_xPSR(void)
269 {
270   uint32_t result;
271
272   __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
273   return(result);
274 }
275
276
277 /**
278   \brief   Get Process Stack Pointer
279   \details Returns the current value of the Process Stack Pointer (PSP).
280   \return               PSP Register value
281  */
282 __STATIC_FORCEINLINE uint32_t __get_PSP(void)
283 {
284   uint32_t result;
285
286   __ASM volatile ("MRS %0, psp"  : "=r" (result) );
287   return(result);
288 }
289
290
291 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
292 /**
293   \brief   Get Process Stack Pointer (non-secure)
294   \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
295   \return               PSP Register value
296  */
297 __STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void)
298 {
299   uint32_t result;
300
301   __ASM volatile ("MRS %0, psp_ns"  : "=r" (result) );
302   return(result);
303 }
304 #endif
305
306
307 /**
308   \brief   Set Process Stack Pointer
309   \details Assigns the given value to the Process Stack Pointer (PSP).
310   \param [in]    topOfProcStack  Process Stack Pointer value to set
311  */
312 __STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack)
313 {
314   __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : );
315 }
316
317
318 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
319 /**
320   \brief   Set Process Stack Pointer (non-secure)
321   \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
322   \param [in]    topOfProcStack  Process Stack Pointer value to set
323  */
324 __STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
325 {
326   __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : );
327 }
328 #endif
329
330
331 /**
332   \brief   Get Main Stack Pointer
333   \details Returns the current value of the Main Stack Pointer (MSP).
334   \return               MSP Register value
335  */
336 __STATIC_FORCEINLINE uint32_t __get_MSP(void)
337 {
338   uint32_t result;
339
340   __ASM volatile ("MRS %0, msp" : "=r" (result) );
341   return(result);
342 }
343
344
345 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
346 /**
347   \brief   Get Main Stack Pointer (non-secure)
348   \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
349   \return               MSP Register value
350  */
351 __STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void)
352 {
353   uint32_t result;
354
355   __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
356   return(result);
357 }
358 #endif
359
360
361 /**
362   \brief   Set Main Stack Pointer
363   \details Assigns the given value to the Main Stack Pointer (MSP).
364   \param [in]    topOfMainStack  Main Stack Pointer value to set
365  */
366 __STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack)
367 {
368   __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : );
369 }
370
371
372 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
373 /**
374   \brief   Set Main Stack Pointer (non-secure)
375   \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
376   \param [in]    topOfMainStack  Main Stack Pointer value to set
377  */
378 __STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
379 {
380   __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : );
381 }
382 #endif
383
384
385 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
386 /**
387   \brief   Get Stack Pointer (non-secure)
388   \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
389   \return               SP Register value
390  */
391 __STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void)
392 {
393   uint32_t result;
394
395   __ASM volatile ("MRS %0, sp_ns" : "=r" (result) );
396   return(result);
397 }
398
399
400 /**
401   \brief   Set Stack Pointer (non-secure)
402   \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
403   \param [in]    topOfStack  Stack Pointer value to set
404  */
405 __STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack)
406 {
407   __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : );
408 }
409 #endif
410
411
412 /**
413   \brief   Get Priority Mask
414   \details Returns the current state of the priority mask bit from the Priority Mask Register.
415   \return               Priority Mask value
416  */
417 __STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
418 {
419   uint32_t result;
420
421   __ASM volatile ("MRS %0, primask" : "=r" (result) );
422   return(result);
423 }
424
425
426 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
427 /**
428   \brief   Get Priority Mask (non-secure)
429   \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
430   \return               Priority Mask value
431  */
432 __STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void)
433 {
434   uint32_t result;
435
436   __ASM volatile ("MRS %0, primask_ns" : "=r" (result) );
437   return(result);
438 }
439 #endif
440
441
442 /**
443   \brief   Set Priority Mask
444   \details Assigns the given value to the Priority Mask Register.
445   \param [in]    priMask  Priority Mask
446  */
447 __STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
448 {
449   __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
450 }
451
452
453 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
454 /**
455   \brief   Set Priority Mask (non-secure)
456   \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
457   \param [in]    priMask  Priority Mask
458  */
459 __STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
460 {
461   __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
462 }
463 #endif
464
465
466 #if ((defined (__ARM_ARCH_7M__       ) && (__ARM_ARCH_7M__        == 1)) || \
467      (defined (__ARM_ARCH_7EM__      ) && (__ARM_ARCH_7EM__       == 1)) || \
468      (defined (__ARM_ARCH_8M_MAIN__  ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
469      (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1))     )
470 /**
471   \brief   Enable FIQ
472   \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK.
473            Can only be executed in Privileged modes.
474  */
475 #define __enable_fault_irq                __enable_fiq   /* see arm_compat.h */
476
477
478 /**
479   \brief   Disable FIQ
480   \details Disables FIQ interrupts by setting special-purpose register FAULTMASK.
481            Can only be executed in Privileged modes.
482  */
483 #define __disable_fault_irq               __disable_fiq   /* see arm_compat.h */
484
485
486 /**
487   \brief   Get Base Priority
488   \details Returns the current value of the Base Priority register.
489   \return               Base Priority register value
490  */
491 __STATIC_FORCEINLINE uint32_t __get_BASEPRI(void)
492 {
493   uint32_t result;
494
495   __ASM volatile ("MRS %0, basepri" : "=r" (result) );
496   return(result);
497 }
498
499
500 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
501 /**
502   \brief   Get Base Priority (non-secure)
503   \details Returns the current value of the non-secure Base Priority register when in secure state.
504   \return               Base Priority register value
505  */
506 __STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void)
507 {
508   uint32_t result;
509
510   __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
511   return(result);
512 }
513 #endif
514
515
516 /**
517   \brief   Set Base Priority
518   \details Assigns the given value to the Base Priority register.
519   \param [in]    basePri  Base Priority value to set
520  */
521 __STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri)
522 {
523   __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
524 }
525
526
527 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
528 /**
529   \brief   Set Base Priority (non-secure)
530   \details Assigns the given value to the non-secure Base Priority register when in secure state.
531   \param [in]    basePri  Base Priority value to set
532  */
533 __STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
534 {
535   __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
536 }
537 #endif
538
539
540 /**
541   \brief   Set Base Priority with condition
542   \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
543            or the new value increases the BASEPRI priority level.
544   \param [in]    basePri  Base Priority value to set
545  */
546 __STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri)
547 {
548   __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
549 }
550
551
552 /**
553   \brief   Get Fault Mask
554   \details Returns the current value of the Fault Mask register.
555   \return               Fault Mask register value
556  */
557 __STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void)
558 {
559   uint32_t result;
560
561   __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
562   return(result);
563 }
564
565
566 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
567 /**
568   \brief   Get Fault Mask (non-secure)
569   \details Returns the current value of the non-secure Fault Mask register when in secure state.
570   \return               Fault Mask register value
571  */
572 __STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void)
573 {
574   uint32_t result;
575
576   __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
577   return(result);
578 }
579 #endif
580
581
582 /**
583   \brief   Set Fault Mask
584   \details Assigns the given value to the Fault Mask register.
585   \param [in]    faultMask  Fault Mask value to set
586  */
587 __STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask)
588 {
589   __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
590 }
591
592
593 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
594 /**
595   \brief   Set Fault Mask (non-secure)
596   \details Assigns the given value to the non-secure Fault Mask register when in secure state.
597   \param [in]    faultMask  Fault Mask value to set
598  */
599 __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
600 {
601   __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
602 }
603 #endif
604
605 #endif /* ((defined (__ARM_ARCH_7M__       ) && (__ARM_ARCH_7M__        == 1)) || \
606            (defined (__ARM_ARCH_7EM__      ) && (__ARM_ARCH_7EM__       == 1)) || \
607            (defined (__ARM_ARCH_8M_MAIN__  ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
608            (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1))     ) */
609
610
611 #if ((defined (__ARM_ARCH_8M_MAIN__  ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
612      (defined (__ARM_ARCH_8M_BASE__  ) && (__ARM_ARCH_8M_BASE__   == 1)) || \
613      (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1))     )
614
615 /**
616   \brief   Get Process Stack Pointer Limit
617   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
618   Stack Pointer Limit register hence zero is returned always in non-secure
619   mode.
620
621   \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
622   \return               PSPLIM Register value
623  */
624 __STATIC_FORCEINLINE uint32_t __get_PSPLIM(void)
625 {
626 #if (!((defined (__ARM_ARCH_8M_MAIN__   ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
627        (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1))   ) && \
628     (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
629     // without main extensions, the non-secure PSPLIM is RAZ/WI
630   return 0U;
631 #else
632   uint32_t result;
633   __ASM volatile ("MRS %0, psplim"  : "=r" (result) );
634   return result;
635 #endif
636 }
637
638 #if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3))
639 /**
640   \brief   Get Process Stack Pointer Limit (non-secure)
641   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
642   Stack Pointer Limit register hence zero is returned always in non-secure
643   mode.
644
645   \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
646   \return               PSPLIM Register value
647  */
648 __STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void)
649 {
650 #if (!((defined (__ARM_ARCH_8M_MAIN__   ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
651        (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1))   ) )
652   // without main extensions, the non-secure PSPLIM is RAZ/WI
653   return 0U;
654 #else
655   uint32_t result;
656   __ASM volatile ("MRS %0, psplim_ns"  : "=r" (result) );
657   return result;
658 #endif
659 }
660 #endif
661
662
663 /**
664   \brief   Set Process Stack Pointer Limit
665   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
666   Stack Pointer Limit register hence the write is silently ignored in non-secure
667   mode.
668
669   \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
670   \param [in]    ProcStackPtrLimit  Process Stack Pointer Limit value to set
671  */
672 __STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
673 {
674 #if (!((defined (__ARM_ARCH_8M_MAIN__   ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
675        (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1))   ) && \
676     (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
677   // without main extensions, the non-secure PSPLIM is RAZ/WI
678   (void)ProcStackPtrLimit;
679 #else
680   __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
681 #endif
682 }
683
684
685 #if (defined (__ARM_FEATURE_CMSE  ) && (__ARM_FEATURE_CMSE   == 3))
686 /**
687   \brief   Set Process Stack Pointer (non-secure)
688   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
689   Stack Pointer Limit register hence the write is silently ignored in non-secure
690   mode.
691
692   \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
693   \param [in]    ProcStackPtrLimit  Process Stack Pointer Limit value to set
694  */
695 __STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
696 {
697 #if (!((defined (__ARM_ARCH_8M_MAIN__   ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
698        (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1))   ) )
699   // without main extensions, the non-secure PSPLIM is RAZ/WI
700   (void)ProcStackPtrLimit;
701 #else
702   __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
703 #endif
704 }
705 #endif
706
707
708 /**
709   \brief   Get Main Stack Pointer Limit
710   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
711   Stack Pointer Limit register hence zero is returned always.
712
713   \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
714   \return               MSPLIM Register value
715  */
716 __STATIC_FORCEINLINE uint32_t __get_MSPLIM(void)
717 {
718 #if (!((defined (__ARM_ARCH_8M_MAIN__   ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
719        (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1))   ) && \
720     (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
721   // without main extensions, the non-secure MSPLIM is RAZ/WI
722   return 0U;
723 #else
724   uint32_t result;
725   __ASM volatile ("MRS %0, msplim" : "=r" (result) );
726   return result;
727 #endif
728 }
729
730
731 #if (defined (__ARM_FEATURE_CMSE  ) && (__ARM_FEATURE_CMSE   == 3))
732 /**
733   \brief   Get Main Stack Pointer Limit (non-secure)
734   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
735   Stack Pointer Limit register hence zero is returned always.
736
737   \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
738   \return               MSPLIM Register value
739  */
740 __STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void)
741 {
742 #if (!((defined (__ARM_ARCH_8M_MAIN__   ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
743        (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1))   ) )
744   // without main extensions, the non-secure MSPLIM is RAZ/WI
745   return 0U;
746 #else
747   uint32_t result;
748   __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
749   return result;
750 #endif
751 }
752 #endif
753
754
755 /**
756   \brief   Set Main Stack Pointer Limit
757   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
758   Stack Pointer Limit register hence the write is silently ignored.
759
760   \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
761   \param [in]    MainStackPtrLimit  Main Stack Pointer Limit value to set
762  */
763 __STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
764 {
765 #if (!((defined (__ARM_ARCH_8M_MAIN__   ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
766        (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1))   ) && \
767     (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
768   // without main extensions, the non-secure MSPLIM is RAZ/WI
769   (void)MainStackPtrLimit;
770 #else
771   __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
772 #endif
773 }
774
775
776 #if (defined (__ARM_FEATURE_CMSE  ) && (__ARM_FEATURE_CMSE   == 3))
777 /**
778   \brief   Set Main Stack Pointer Limit (non-secure)
779   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
780   Stack Pointer Limit register hence the write is silently ignored.
781
782   \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
783   \param [in]    MainStackPtrLimit  Main Stack Pointer value to set
784  */
785 __STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
786 {
787 #if (!((defined (__ARM_ARCH_8M_MAIN__   ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
788        (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1))   ) )
789   // without main extensions, the non-secure MSPLIM is RAZ/WI
790   (void)MainStackPtrLimit;
791 #else
792   __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
793 #endif
794 }
795 #endif
796
797 #endif /* ((defined (__ARM_ARCH_8M_MAIN__  ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
798            (defined (__ARM_ARCH_8M_BASE__  ) && (__ARM_ARCH_8M_BASE__   == 1)) || \
799            (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1))     ) */
800
801 /**
802   \brief   Get FPSCR
803   \details Returns the current value of the Floating Point Status/Control register.
804   \return               Floating Point Status/Control register value
805  */
806 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
807      (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     )
808 #define __get_FPSCR      (uint32_t)__builtin_arm_get_fpscr
809 #else
810 #define __get_FPSCR()      ((uint32_t)0U)
811 #endif
812
813 /**
814   \brief   Set FPSCR
815   \details Assigns the given value to the Floating Point Status/Control register.
816   \param [in]    fpscr  Floating Point Status/Control value to set
817  */
818 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
819      (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     )
820 #define __set_FPSCR      __builtin_arm_set_fpscr
821 #else
822 #define __set_FPSCR(x)      ((void)(x))
823 #endif
824
825
826 /*@} end of CMSIS_Core_RegAccFunctions */
827
828
829 /* ##########################  Core Instruction Access  ######################### */
830 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
831   Access to dedicated instructions
832   @{
833 */
834
835 /* Define macros for porting to both thumb1 and thumb2.
836  * For thumb1, use low register (r0-r7), specified by constraint "l"
837  * Otherwise, use general registers, specified by constraint "r" */
838 #if defined (__thumb__) && !defined (__thumb2__)
839 #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
840 #define __CMSIS_GCC_RW_REG(r) "+l" (r)
841 #define __CMSIS_GCC_USE_REG(r) "l" (r)
842 #else
843 #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
844 #define __CMSIS_GCC_RW_REG(r) "+r" (r)
845 #define __CMSIS_GCC_USE_REG(r) "r" (r)
846 #endif
847
848 /**
849   \brief   No Operation
850   \details No Operation does nothing. This instruction can be used for code alignment purposes.
851  */
852 #define __NOP          __builtin_arm_nop
853
854 /**
855   \brief   Wait For Interrupt
856   \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
857  */
858 #define __WFI          __builtin_arm_wfi
859
860
861 /**
862   \brief   Wait For Event
863   \details Wait For Event is a hint instruction that permits the processor to enter
864            a low-power state until one of a number of events occurs.
865  */
866 #define __WFE          __builtin_arm_wfe
867
868
869 /**
870   \brief   Send Event
871   \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
872  */
873 #define __SEV          __builtin_arm_sev
874
875
876 /**
877   \brief   Instruction Synchronization Barrier
878   \details Instruction Synchronization Barrier flushes the pipeline in the processor,
879            so that all instructions following the ISB are fetched from cache or memory,
880            after the instruction has been completed.
881  */
882 #define __ISB()        __builtin_arm_isb(0xF)
883
884 /**
885   \brief   Data Synchronization Barrier
886   \details Acts as a special kind of Data Memory Barrier.
887            It completes when all explicit memory accesses before this instruction complete.
888  */
889 #define __DSB()        __builtin_arm_dsb(0xF)
890
891
892 /**
893   \brief   Data Memory Barrier
894   \details Ensures the apparent order of the explicit memory operations before
895            and after the instruction, without ensuring their completion.
896  */
897 #define __DMB()        __builtin_arm_dmb(0xF)
898
899
900 /**
901   \brief   Reverse byte order (32 bit)
902   \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
903   \param [in]    value  Value to reverse
904   \return               Reversed value
905  */
906 #define __REV(value)   __builtin_bswap32(value)
907
908
909 /**
910   \brief   Reverse byte order (16 bit)
911   \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
912   \param [in]    value  Value to reverse
913   \return               Reversed value
914  */
915 #define __REV16(value) __ROR(__REV(value), 16)
916
917
918 /**
919   \brief   Reverse byte order (16 bit)
920   \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
921   \param [in]    value  Value to reverse
922   \return               Reversed value
923  */
924 #define __REVSH(value) (int16_t)__builtin_bswap16(value)
925
926
927 /**
928   \brief   Rotate Right in unsigned value (32 bit)
929   \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
930   \param [in]    op1  Value to rotate
931   \param [in]    op2  Number of Bits to rotate
932   \return               Rotated value
933  */
934 __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
935 {
936   op2 %= 32U;
937   if (op2 == 0U)
938   {
939     return op1;
940   }
941   return (op1 >> op2) | (op1 << (32U - op2));
942 }
943
944
945 /**
946   \brief   Breakpoint
947   \details Causes the processor to enter Debug state.
948            Debug tools can use this to investigate system state when the instruction at a particular address is reached.
949   \param [in]    value  is ignored by the processor.
950                  If required, a debugger can use it to store additional information about the breakpoint.
951  */
952 #define __BKPT(value)     __ASM volatile ("bkpt "#value)
953
954
955 /**
956   \brief   Reverse bit order of value
957   \details Reverses the bit order of the given value.
958   \param [in]    value  Value to reverse
959   \return               Reversed value
960  */
961 #define __RBIT            __builtin_arm_rbit
962
963 /**
964   \brief   Count leading zeros
965   \details Counts the number of leading zeros of a data value.
966   \param [in]  value  Value to count the leading zeros
967   \return             number of leading zeros in value
968  */
969 __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value)
970 {
971   /* Even though __builtin_clz produces a CLZ instruction on ARM, formally
972      __builtin_clz(0) is undefined behaviour, so handle this case specially.
973      This guarantees ARM-compatible results if happening to compile on a non-ARM
974      target, and ensures the compiler doesn't decide to activate any
975      optimisations using the logic "value was passed to __builtin_clz, so it
976      is non-zero".
977      ARM Compiler 6.10 and possibly earlier will optimise this test away, leaving a
978      single CLZ instruction.
979    */
980   if (value == 0U)
981   {
982     return 32U;
983   }
984   return __builtin_clz(value);
985 }
986
987
988 #if ((defined (__ARM_ARCH_7M__       ) && (__ARM_ARCH_7M__        == 1)) || \
989      (defined (__ARM_ARCH_7EM__      ) && (__ARM_ARCH_7EM__       == 1)) || \
990      (defined (__ARM_ARCH_8M_MAIN__  ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
991      (defined (__ARM_ARCH_8M_BASE__  ) && (__ARM_ARCH_8M_BASE__   == 1)) || \
992      (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1))     )
993
994 /**
995   \brief   LDR Exclusive (8 bit)
996   \details Executes a exclusive LDR instruction for 8 bit value.
997   \param [in]    ptr  Pointer to data
998   \return             value of type uint8_t at (*ptr)
999  */
1000 #define __LDREXB        (uint8_t)__builtin_arm_ldrex
1001
1002
1003 /**
1004   \brief   LDR Exclusive (16 bit)
1005   \details Executes a exclusive LDR instruction for 16 bit values.
1006   \param [in]    ptr  Pointer to data
1007   \return        value of type uint16_t at (*ptr)
1008  */
1009 #define __LDREXH        (uint16_t)__builtin_arm_ldrex
1010
1011
1012 /**
1013   \brief   LDR Exclusive (32 bit)
1014   \details Executes a exclusive LDR instruction for 32 bit values.
1015   \param [in]    ptr  Pointer to data
1016   \return        value of type uint32_t at (*ptr)
1017  */
1018 #define __LDREXW        (uint32_t)__builtin_arm_ldrex
1019
1020
1021 /**
1022   \brief   STR Exclusive (8 bit)
1023   \details Executes a exclusive STR instruction for 8 bit values.
1024   \param [in]  value  Value to store
1025   \param [in]    ptr  Pointer to location
1026   \return          0  Function succeeded
1027   \return          1  Function failed
1028  */
1029 #define __STREXB        (uint32_t)__builtin_arm_strex
1030
1031
1032 /**
1033   \brief   STR Exclusive (16 bit)
1034   \details Executes a exclusive STR instruction for 16 bit values.
1035   \param [in]  value  Value to store
1036   \param [in]    ptr  Pointer to location
1037   \return          0  Function succeeded
1038   \return          1  Function failed
1039  */
1040 #define __STREXH        (uint32_t)__builtin_arm_strex
1041
1042
1043 /**
1044   \brief   STR Exclusive (32 bit)
1045   \details Executes a exclusive STR instruction for 32 bit values.
1046   \param [in]  value  Value to store
1047   \param [in]    ptr  Pointer to location
1048   \return          0  Function succeeded
1049   \return          1  Function failed
1050  */
1051 #define __STREXW        (uint32_t)__builtin_arm_strex
1052
1053
1054 /**
1055   \brief   Remove the exclusive lock
1056   \details Removes the exclusive lock which is created by LDREX.
1057  */
1058 #define __CLREX             __builtin_arm_clrex
1059
1060 #endif /* ((defined (__ARM_ARCH_7M__       ) && (__ARM_ARCH_7M__        == 1)) || \
1061            (defined (__ARM_ARCH_7EM__      ) && (__ARM_ARCH_7EM__       == 1)) || \
1062            (defined (__ARM_ARCH_8M_MAIN__  ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
1063            (defined (__ARM_ARCH_8M_BASE__  ) && (__ARM_ARCH_8M_BASE__   == 1)) || \
1064            (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1))     ) */
1065
1066
1067 #if ((defined (__ARM_ARCH_7M__       ) && (__ARM_ARCH_7M__        == 1)) || \
1068      (defined (__ARM_ARCH_7EM__      ) && (__ARM_ARCH_7EM__       == 1)) || \
1069      (defined (__ARM_ARCH_8M_MAIN__  ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
1070      (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1))     )
1071
1072 /**
1073   \brief   Signed Saturate
1074   \details Saturates a signed value.
1075   \param [in]  value  Value to be saturated
1076   \param [in]    sat  Bit position to saturate to (1..32)
1077   \return             Saturated value
1078  */
1079 #define __SSAT             __builtin_arm_ssat
1080
1081
1082 /**
1083   \brief   Unsigned Saturate
1084   \details Saturates an unsigned value.
1085   \param [in]  value  Value to be saturated
1086   \param [in]    sat  Bit position to saturate to (0..31)
1087   \return             Saturated value
1088  */
1089 #define __USAT             __builtin_arm_usat
1090
1091
1092 /**
1093   \brief   Rotate Right with Extend (32 bit)
1094   \details Moves each bit of a bitstring right by one bit.
1095            The carry input is shifted in at the left end of the bitstring.
1096   \param [in]    value  Value to rotate
1097   \return               Rotated value
1098  */
1099 __STATIC_FORCEINLINE uint32_t __RRX(uint32_t value)
1100 {
1101   uint32_t result;
1102
1103   __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
1104   return(result);
1105 }
1106
1107
1108 /**
1109   \brief   LDRT Unprivileged (8 bit)
1110   \details Executes a Unprivileged LDRT instruction for 8 bit value.
1111   \param [in]    ptr  Pointer to data
1112   \return             value of type uint8_t at (*ptr)
1113  */
1114 __STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr)
1115 {
1116   uint32_t result;
1117
1118   __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
1119   return ((uint8_t) result);    /* Add explicit type cast here */
1120 }
1121
1122
1123 /**
1124   \brief   LDRT Unprivileged (16 bit)
1125   \details Executes a Unprivileged LDRT instruction for 16 bit values.
1126   \param [in]    ptr  Pointer to data
1127   \return        value of type uint16_t at (*ptr)
1128  */
1129 __STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr)
1130 {
1131   uint32_t result;
1132
1133   __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
1134   return ((uint16_t) result);    /* Add explicit type cast here */
1135 }
1136
1137
1138 /**
1139   \brief   LDRT Unprivileged (32 bit)
1140   \details Executes a Unprivileged LDRT instruction for 32 bit values.
1141   \param [in]    ptr  Pointer to data
1142   \return        value of type uint32_t at (*ptr)
1143  */
1144 __STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr)
1145 {
1146   uint32_t result;
1147
1148   __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
1149   return(result);
1150 }
1151
1152
1153 /**
1154   \brief   STRT Unprivileged (8 bit)
1155   \details Executes a Unprivileged STRT instruction for 8 bit values.
1156   \param [in]  value  Value to store
1157   \param [in]    ptr  Pointer to location
1158  */
1159 __STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
1160 {
1161   __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1162 }
1163
1164
1165 /**
1166   \brief   STRT Unprivileged (16 bit)
1167   \details Executes a Unprivileged STRT instruction for 16 bit values.
1168   \param [in]  value  Value to store
1169   \param [in]    ptr  Pointer to location
1170  */
1171 __STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
1172 {
1173   __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1174 }
1175
1176
1177 /**
1178   \brief   STRT Unprivileged (32 bit)
1179   \details Executes a Unprivileged STRT instruction for 32 bit values.
1180   \param [in]  value  Value to store
1181   \param [in]    ptr  Pointer to location
1182  */
1183 __STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
1184 {
1185   __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
1186 }
1187
1188 #else /* ((defined (__ARM_ARCH_7M__       ) && (__ARM_ARCH_7M__        == 1)) || \
1189           (defined (__ARM_ARCH_7EM__      ) && (__ARM_ARCH_7EM__       == 1)) || \
1190           (defined (__ARM_ARCH_8M_MAIN__  ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
1191           (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1))     ) */
1192
1193 /**
1194   \brief   Signed Saturate
1195   \details Saturates a signed value.
1196   \param [in]  value  Value to be saturated
1197   \param [in]    sat  Bit position to saturate to (1..32)
1198   \return             Saturated value
1199  */
1200 __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
1201 {
1202   if ((sat >= 1U) && (sat <= 32U))
1203   {
1204     const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
1205     const int32_t min = -1 - max ;
1206     if (val > max)
1207     {
1208       return max;
1209     }
1210     else if (val < min)
1211     {
1212       return min;
1213     }
1214   }
1215   return val;
1216 }
1217
1218 /**
1219   \brief   Unsigned Saturate
1220   \details Saturates an unsigned value.
1221   \param [in]  value  Value to be saturated
1222   \param [in]    sat  Bit position to saturate to (0..31)
1223   \return             Saturated value
1224  */
1225 __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
1226 {
1227   if (sat <= 31U)
1228   {
1229     const uint32_t max = ((1U << sat) - 1U);
1230     if (val > (int32_t)max)
1231     {
1232       return max;
1233     }
1234     else if (val < 0)
1235     {
1236       return 0U;
1237     }
1238   }
1239   return (uint32_t)val;
1240 }
1241
1242 #endif /* ((defined (__ARM_ARCH_7M__       ) && (__ARM_ARCH_7M__        == 1)) || \
1243            (defined (__ARM_ARCH_7EM__      ) && (__ARM_ARCH_7EM__       == 1)) || \
1244            (defined (__ARM_ARCH_8M_MAIN__  ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
1245            (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1))     ) */
1246
1247
1248 #if ((defined (__ARM_ARCH_8M_MAIN__  ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
1249      (defined (__ARM_ARCH_8M_BASE__  ) && (__ARM_ARCH_8M_BASE__   == 1)) || \
1250      (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1))     )
1251
1252 /**
1253   \brief   Load-Acquire (8 bit)
1254   \details Executes a LDAB instruction for 8 bit value.
1255   \param [in]    ptr  Pointer to data
1256   \return             value of type uint8_t at (*ptr)
1257  */
1258 __STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr)
1259 {
1260   uint32_t result;
1261
1262   __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
1263   return ((uint8_t) result);
1264 }
1265
1266
1267 /**
1268   \brief   Load-Acquire (16 bit)
1269   \details Executes a LDAH instruction for 16 bit values.
1270   \param [in]    ptr  Pointer to data
1271   \return        value of type uint16_t at (*ptr)
1272  */
1273 __STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr)
1274 {
1275   uint32_t result;
1276
1277   __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
1278   return ((uint16_t) result);
1279 }
1280
1281
1282 /**
1283   \brief   Load-Acquire (32 bit)
1284   \details Executes a LDA instruction for 32 bit values.
1285   \param [in]    ptr  Pointer to data
1286   \return        value of type uint32_t at (*ptr)
1287  */
1288 __STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr)
1289 {
1290   uint32_t result;
1291
1292   __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
1293   return(result);
1294 }
1295
1296
1297 /**
1298   \brief   Store-Release (8 bit)
1299   \details Executes a STLB instruction for 8 bit values.
1300   \param [in]  value  Value to store
1301   \param [in]    ptr  Pointer to location
1302  */
1303 __STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
1304 {
1305   __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
1306 }
1307
1308
1309 /**
1310   \brief   Store-Release (16 bit)
1311   \details Executes a STLH instruction for 16 bit values.
1312   \param [in]  value  Value to store
1313   \param [in]    ptr  Pointer to location
1314  */
1315 __STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
1316 {
1317   __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
1318 }
1319
1320
1321 /**
1322   \brief   Store-Release (32 bit)
1323   \details Executes a STL instruction for 32 bit values.
1324   \param [in]  value  Value to store
1325   \param [in]    ptr  Pointer to location
1326  */
1327 __STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr)
1328 {
1329   __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
1330 }
1331
1332
1333 /**
1334   \brief   Load-Acquire Exclusive (8 bit)
1335   \details Executes a LDAB exclusive instruction for 8 bit value.
1336   \param [in]    ptr  Pointer to data
1337   \return             value of type uint8_t at (*ptr)
1338  */
1339 #define     __LDAEXB                 (uint8_t)__builtin_arm_ldaex
1340
1341
1342 /**
1343   \brief   Load-Acquire Exclusive (16 bit)
1344   \details Executes a LDAH exclusive instruction for 16 bit values.
1345   \param [in]    ptr  Pointer to data
1346   \return        value of type uint16_t at (*ptr)
1347  */
1348 #define     __LDAEXH                 (uint16_t)__builtin_arm_ldaex
1349
1350
1351 /**
1352   \brief   Load-Acquire Exclusive (32 bit)
1353   \details Executes a LDA exclusive instruction for 32 bit values.
1354   \param [in]    ptr  Pointer to data
1355   \return        value of type uint32_t at (*ptr)
1356  */
1357 #define     __LDAEX                  (uint32_t)__builtin_arm_ldaex
1358
1359
1360 /**
1361   \brief   Store-Release Exclusive (8 bit)
1362   \details Executes a STLB exclusive instruction for 8 bit values.
1363   \param [in]  value  Value to store
1364   \param [in]    ptr  Pointer to location
1365   \return          0  Function succeeded
1366   \return          1  Function failed
1367  */
1368 #define     __STLEXB                 (uint32_t)__builtin_arm_stlex
1369
1370
1371 /**
1372   \brief   Store-Release Exclusive (16 bit)
1373   \details Executes a STLH exclusive instruction for 16 bit values.
1374   \param [in]  value  Value to store
1375   \param [in]    ptr  Pointer to location
1376   \return          0  Function succeeded
1377   \return          1  Function failed
1378  */
1379 #define     __STLEXH                 (uint32_t)__builtin_arm_stlex
1380
1381
1382 /**
1383   \brief   Store-Release Exclusive (32 bit)
1384   \details Executes a STL exclusive instruction for 32 bit values.
1385   \param [in]  value  Value to store
1386   \param [in]    ptr  Pointer to location
1387   \return          0  Function succeeded
1388   \return          1  Function failed
1389  */
1390 #define     __STLEX                  (uint32_t)__builtin_arm_stlex
1391
1392 #endif /* ((defined (__ARM_ARCH_8M_MAIN__  ) && (__ARM_ARCH_8M_MAIN__   == 1)) || \
1393            (defined (__ARM_ARCH_8M_BASE__  ) && (__ARM_ARCH_8M_BASE__   == 1)) || \
1394            (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1))     ) */
1395
1396 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
1397
1398
1399 /* ###################  Compiler specific Intrinsics  ########################### */
1400 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
1401   Access to dedicated SIMD instructions
1402   @{
1403 */
1404
1405 #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
1406
1407 #define     __SADD8                 __builtin_arm_sadd8
1408 #define     __QADD8                 __builtin_arm_qadd8
1409 #define     __SHADD8                __builtin_arm_shadd8
1410 #define     __UADD8                 __builtin_arm_uadd8
1411 #define     __UQADD8                __builtin_arm_uqadd8
1412 #define     __UHADD8                __builtin_arm_uhadd8
1413 #define     __SSUB8                 __builtin_arm_ssub8
1414 #define     __QSUB8                 __builtin_arm_qsub8
1415 #define     __SHSUB8                __builtin_arm_shsub8
1416 #define     __USUB8                 __builtin_arm_usub8
1417 #define     __UQSUB8                __builtin_arm_uqsub8
1418 #define     __UHSUB8                __builtin_arm_uhsub8
1419 #define     __SADD16                __builtin_arm_sadd16
1420 #define     __QADD16                __builtin_arm_qadd16
1421 #define     __SHADD16               __builtin_arm_shadd16
1422 #define     __UADD16                __builtin_arm_uadd16
1423 #define     __UQADD16               __builtin_arm_uqadd16
1424 #define     __UHADD16               __builtin_arm_uhadd16
1425 #define     __SSUB16                __builtin_arm_ssub16
1426 #define     __QSUB16                __builtin_arm_qsub16
1427 #define     __SHSUB16               __builtin_arm_shsub16
1428 #define     __USUB16                __builtin_arm_usub16
1429 #define     __UQSUB16               __builtin_arm_uqsub16
1430 #define     __UHSUB16               __builtin_arm_uhsub16
1431 #define     __SASX                  __builtin_arm_sasx
1432 #define     __QASX                  __builtin_arm_qasx
1433 #define     __SHASX                 __builtin_arm_shasx
1434 #define     __UASX                  __builtin_arm_uasx
1435 #define     __UQASX                 __builtin_arm_uqasx
1436 #define     __UHASX                 __builtin_arm_uhasx
1437 #define     __SSAX                  __builtin_arm_ssax
1438 #define     __QSAX                  __builtin_arm_qsax
1439 #define     __SHSAX                 __builtin_arm_shsax
1440 #define     __USAX                  __builtin_arm_usax
1441 #define     __UQSAX                 __builtin_arm_uqsax
1442 #define     __UHSAX                 __builtin_arm_uhsax
1443 #define     __USAD8                 __builtin_arm_usad8
1444 #define     __USADA8                __builtin_arm_usada8
1445 #define     __SSAT16                __builtin_arm_ssat16
1446 #define     __USAT16                __builtin_arm_usat16
1447 #define     __UXTB16                __builtin_arm_uxtb16
1448 #define     __UXTAB16               __builtin_arm_uxtab16
1449 #define     __SXTB16                __builtin_arm_sxtb16
1450 #define     __SXTAB16               __builtin_arm_sxtab16
1451 #define     __SMUAD                 __builtin_arm_smuad
1452 #define     __SMUADX                __builtin_arm_smuadx
1453 #define     __SMLAD                 __builtin_arm_smlad
1454 #define     __SMLADX                __builtin_arm_smladx
1455 #define     __SMLALD                __builtin_arm_smlald
1456 #define     __SMLALDX               __builtin_arm_smlaldx
1457 #define     __SMUSD                 __builtin_arm_smusd
1458 #define     __SMUSDX                __builtin_arm_smusdx
1459 #define     __SMLSD                 __builtin_arm_smlsd
1460 #define     __SMLSDX                __builtin_arm_smlsdx
1461 #define     __SMLSLD                __builtin_arm_smlsld
1462 #define     __SMLSLDX               __builtin_arm_smlsldx
1463 #define     __SEL                   __builtin_arm_sel
1464 #define     __QADD                  __builtin_arm_qadd
1465 #define     __QSUB                  __builtin_arm_qsub
1466
1467 #define __PKHBT(ARG1,ARG2,ARG3)          ( ((((uint32_t)(ARG1))          ) & 0x0000FFFFUL) |  \
1468                                            ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL)  )
1469
1470 #define __PKHTB(ARG1,ARG2,ARG3)          ( ((((uint32_t)(ARG1))          ) & 0xFFFF0000UL) |  \
1471                                            ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL)  )
1472
1473 #define __SXTB16_RORn(ARG1, ARG2)        __SXTB16(__ROR(ARG1, ARG2))
1474
1475 #define __SXTAB16_RORn(ARG1, ARG2, ARG3) __SXTAB16(ARG1, __ROR(ARG2, ARG3))
1476
1477 __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
1478 {
1479   int32_t result;
1480
1481   __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r"  (op1), "r" (op2), "r" (op3) );
1482   return(result);
1483 }
1484
1485 #endif /* (__ARM_FEATURE_DSP == 1) */
1486 /*@} end of group CMSIS_SIMD_intrinsics */
1487
1488
1489 #endif /* __CMSIS_ARMCLANG_H */