1 /**************************************************************************//**
3 * @brief CMSIS compiler GCC header file
6 ******************************************************************************/
8 * Copyright (c) 2009-2021 Arm Limited. All rights reserved.
10 * SPDX-License-Identifier: Apache-2.0
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
16 * www.apache.org/licenses/LICENSE-2.0
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.
28 /* ignore some GCC warnings */
29 #pragma GCC diagnostic push
30 #pragma GCC diagnostic ignored "-Wsign-conversion"
31 #pragma GCC diagnostic ignored "-Wconversion"
32 #pragma GCC diagnostic ignored "-Wunused-parameter"
34 /* Fallback for __has_builtin */
36 #define __has_builtin(x) (0)
39 /* CMSIS compiler specific defines */
44 #define __INLINE inline
46 #ifndef __STATIC_INLINE
47 #define __STATIC_INLINE static inline
49 #ifndef __STATIC_FORCEINLINE
50 #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline
53 #define __NO_RETURN __attribute__((__noreturn__))
56 #define __USED __attribute__((used))
59 #define __WEAK __attribute__((weak))
62 #define __PACKED __attribute__((packed, aligned(1)))
64 #ifndef __PACKED_STRUCT
65 #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
67 #ifndef __PACKED_UNION
68 #define __PACKED_UNION union __attribute__((packed, aligned(1)))
70 #ifndef __UNALIGNED_UINT32 /* deprecated */
71 #pragma GCC diagnostic push
72 #pragma GCC diagnostic ignored "-Wpacked"
73 #pragma GCC diagnostic ignored "-Wattributes"
74 struct __attribute__((packed)) T_UINT32 { uint32_t v; };
75 #pragma GCC diagnostic pop
76 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
78 #ifndef __UNALIGNED_UINT16_WRITE
79 #pragma GCC diagnostic push
80 #pragma GCC diagnostic ignored "-Wpacked"
81 #pragma GCC diagnostic ignored "-Wattributes"
82 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
83 #pragma GCC diagnostic pop
84 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
86 #ifndef __UNALIGNED_UINT16_READ
87 #pragma GCC diagnostic push
88 #pragma GCC diagnostic ignored "-Wpacked"
89 #pragma GCC diagnostic ignored "-Wattributes"
90 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
91 #pragma GCC diagnostic pop
92 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
94 #ifndef __UNALIGNED_UINT32_WRITE
95 #pragma GCC diagnostic push
96 #pragma GCC diagnostic ignored "-Wpacked"
97 #pragma GCC diagnostic ignored "-Wattributes"
98 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
99 #pragma GCC diagnostic pop
100 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
102 #ifndef __UNALIGNED_UINT32_READ
103 #pragma GCC diagnostic push
104 #pragma GCC diagnostic ignored "-Wpacked"
105 #pragma GCC diagnostic ignored "-Wattributes"
106 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
107 #pragma GCC diagnostic pop
108 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
111 #define __ALIGNED(x) __attribute__((aligned(x)))
114 #define __RESTRICT __restrict
116 #ifndef __COMPILER_BARRIER
117 #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
120 /* ######################### Startup and Lowlevel Init ######################## */
122 #ifndef __PROGRAM_START
125 \brief Initializes data and bss sections
126 \details This default implementations initialized all data and additional bss
127 sections relying on .copy.table and .zero.table specified properly
128 in the used linker script.
131 __STATIC_FORCEINLINE __NO_RETURN void __cmsis_start(void)
133 extern void _start(void) __NO_RETURN;
146 extern const __copy_table_t __copy_table_start__;
147 extern const __copy_table_t __copy_table_end__;
148 extern const __zero_table_t __zero_table_start__;
149 extern const __zero_table_t __zero_table_end__;
151 for (__copy_table_t const* pTable = &__copy_table_start__; pTable < &__copy_table_end__; ++pTable) {
152 for(uint32_t i=0u; i<pTable->wlen; ++i) {
153 pTable->dest[i] = pTable->src[i];
157 for (__zero_table_t const* pTable = &__zero_table_start__; pTable < &__zero_table_end__; ++pTable) {
158 for(uint32_t i=0u; i<pTable->wlen; ++i) {
159 pTable->dest[i] = 0u;
166 #define __PROGRAM_START __cmsis_start
170 #define __INITIAL_SP __StackTop
173 #ifndef __STACK_LIMIT
174 #define __STACK_LIMIT __StackLimit
177 #ifndef __VECTOR_TABLE
178 #define __VECTOR_TABLE __Vectors
181 #ifndef __VECTOR_TABLE_ATTRIBUTE
182 #define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section(".vectors")))
185 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
187 #define __STACK_SEAL __StackSeal
190 #ifndef __TZ_STACK_SEAL_SIZE
191 #define __TZ_STACK_SEAL_SIZE 8U
194 #ifndef __TZ_STACK_SEAL_VALUE
195 #define __TZ_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5ULL
199 __STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) {
200 *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE;
205 /* ########################### Core Function Access ########################### */
206 /** \ingroup CMSIS_Core_FunctionInterface
207 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
212 \brief Enable IRQ Interrupts
213 \details Enables IRQ interrupts by clearing special-purpose register PRIMASK.
214 Can only be executed in Privileged modes.
216 __STATIC_FORCEINLINE void __enable_irq(void)
218 __ASM volatile ("cpsie i" : : : "memory");
223 \brief Disable IRQ Interrupts
224 \details Disables IRQ interrupts by setting special-purpose register PRIMASK.
225 Can only be executed in Privileged modes.
227 __STATIC_FORCEINLINE void __disable_irq(void)
229 __ASM volatile ("cpsid i" : : : "memory");
234 \brief Get Control Register
235 \details Returns the content of the Control Register.
236 \return Control Register value
238 __STATIC_FORCEINLINE uint32_t __get_CONTROL(void)
242 __ASM volatile ("MRS %0, control" : "=r" (result) );
247 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
249 \brief Get Control Register (non-secure)
250 \details Returns the content of the non-secure Control Register when in secure mode.
251 \return non-secure Control Register value
253 __STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void)
257 __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
264 \brief Set Control Register
265 \details Writes the given value to the Control Register.
266 \param [in] control Control Register value to set
268 __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
270 __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
274 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
276 \brief Set Control Register (non-secure)
277 \details Writes the given value to the non-secure Control Register when in secure state.
278 \param [in] control Control Register value to set
280 __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
282 __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
288 \brief Get IPSR Register
289 \details Returns the content of the IPSR Register.
290 \return IPSR Register value
292 __STATIC_FORCEINLINE uint32_t __get_IPSR(void)
296 __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
302 \brief Get APSR Register
303 \details Returns the content of the APSR Register.
304 \return APSR Register value
306 __STATIC_FORCEINLINE uint32_t __get_APSR(void)
310 __ASM volatile ("MRS %0, apsr" : "=r" (result) );
316 \brief Get xPSR Register
317 \details Returns the content of the xPSR Register.
318 \return xPSR Register value
320 __STATIC_FORCEINLINE uint32_t __get_xPSR(void)
324 __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
330 \brief Get Process Stack Pointer
331 \details Returns the current value of the Process Stack Pointer (PSP).
332 \return PSP Register value
334 __STATIC_FORCEINLINE uint32_t __get_PSP(void)
338 __ASM volatile ("MRS %0, psp" : "=r" (result) );
343 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
345 \brief Get Process Stack Pointer (non-secure)
346 \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
347 \return PSP Register value
349 __STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void)
353 __ASM volatile ("MRS %0, psp_ns" : "=r" (result) );
360 \brief Set Process Stack Pointer
361 \details Assigns the given value to the Process Stack Pointer (PSP).
362 \param [in] topOfProcStack Process Stack Pointer value to set
364 __STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack)
366 __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : );
370 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
372 \brief Set Process Stack Pointer (non-secure)
373 \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
374 \param [in] topOfProcStack Process Stack Pointer value to set
376 __STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
378 __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : );
384 \brief Get Main Stack Pointer
385 \details Returns the current value of the Main Stack Pointer (MSP).
386 \return MSP Register value
388 __STATIC_FORCEINLINE uint32_t __get_MSP(void)
392 __ASM volatile ("MRS %0, msp" : "=r" (result) );
397 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
399 \brief Get Main Stack Pointer (non-secure)
400 \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
401 \return MSP Register value
403 __STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void)
407 __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
414 \brief Set Main Stack Pointer
415 \details Assigns the given value to the Main Stack Pointer (MSP).
416 \param [in] topOfMainStack Main Stack Pointer value to set
418 __STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack)
420 __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : );
424 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
426 \brief Set Main Stack Pointer (non-secure)
427 \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
428 \param [in] topOfMainStack Main Stack Pointer value to set
430 __STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
432 __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : );
437 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
439 \brief Get Stack Pointer (non-secure)
440 \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
441 \return SP Register value
443 __STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void)
447 __ASM volatile ("MRS %0, sp_ns" : "=r" (result) );
453 \brief Set Stack Pointer (non-secure)
454 \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
455 \param [in] topOfStack Stack Pointer value to set
457 __STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack)
459 __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : );
465 \brief Get Priority Mask
466 \details Returns the current state of the priority mask bit from the Priority Mask Register.
467 \return Priority Mask value
469 __STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
473 __ASM volatile ("MRS %0, primask" : "=r" (result) );
478 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
480 \brief Get Priority Mask (non-secure)
481 \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
482 \return Priority Mask value
484 __STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void)
488 __ASM volatile ("MRS %0, primask_ns" : "=r" (result) );
495 \brief Set Priority Mask
496 \details Assigns the given value to the Priority Mask Register.
497 \param [in] priMask Priority Mask
499 __STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
501 __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
505 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
507 \brief Set Priority Mask (non-secure)
508 \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
509 \param [in] priMask Priority Mask
511 __STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
513 __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
518 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
519 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
520 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
523 \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK.
524 Can only be executed in Privileged modes.
526 __STATIC_FORCEINLINE void __enable_fault_irq(void)
528 __ASM volatile ("cpsie f" : : : "memory");
534 \details Disables FIQ interrupts by setting special-purpose register FAULTMASK.
535 Can only be executed in Privileged modes.
537 __STATIC_FORCEINLINE void __disable_fault_irq(void)
539 __ASM volatile ("cpsid f" : : : "memory");
544 \brief Get Base Priority
545 \details Returns the current value of the Base Priority register.
546 \return Base Priority register value
548 __STATIC_FORCEINLINE uint32_t __get_BASEPRI(void)
552 __ASM volatile ("MRS %0, basepri" : "=r" (result) );
557 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
559 \brief Get Base Priority (non-secure)
560 \details Returns the current value of the non-secure Base Priority register when in secure state.
561 \return Base Priority register value
563 __STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void)
567 __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
574 \brief Set Base Priority
575 \details Assigns the given value to the Base Priority register.
576 \param [in] basePri Base Priority value to set
578 __STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri)
580 __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
584 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
586 \brief Set Base Priority (non-secure)
587 \details Assigns the given value to the non-secure Base Priority register when in secure state.
588 \param [in] basePri Base Priority value to set
590 __STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
592 __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
598 \brief Set Base Priority with condition
599 \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
600 or the new value increases the BASEPRI priority level.
601 \param [in] basePri Base Priority value to set
603 __STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri)
605 __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
610 \brief Get Fault Mask
611 \details Returns the current value of the Fault Mask register.
612 \return Fault Mask register value
614 __STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void)
618 __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
623 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
625 \brief Get Fault Mask (non-secure)
626 \details Returns the current value of the non-secure Fault Mask register when in secure state.
627 \return Fault Mask register value
629 __STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void)
633 __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
640 \brief Set Fault Mask
641 \details Assigns the given value to the Fault Mask register.
642 \param [in] faultMask Fault Mask value to set
644 __STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask)
646 __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
650 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
652 \brief Set Fault Mask (non-secure)
653 \details Assigns the given value to the non-secure Fault Mask register when in secure state.
654 \param [in] faultMask Fault Mask value to set
656 __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
658 __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
662 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
663 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
664 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
667 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
668 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
671 \brief Get Process Stack Pointer Limit
672 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
673 Stack Pointer Limit register hence zero is returned always in non-secure
676 \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
677 \return PSPLIM Register value
679 __STATIC_FORCEINLINE uint32_t __get_PSPLIM(void)
681 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
682 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
683 // without main extensions, the non-secure PSPLIM is RAZ/WI
687 __ASM volatile ("MRS %0, psplim" : "=r" (result) );
692 #if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3))
694 \brief Get Process Stack Pointer Limit (non-secure)
695 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
696 Stack Pointer Limit register hence zero is returned always.
698 \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
699 \return PSPLIM Register value
701 __STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void)
703 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
704 // without main extensions, the non-secure PSPLIM is RAZ/WI
708 __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) );
716 \brief Set Process Stack Pointer Limit
717 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
718 Stack Pointer Limit register hence the write is silently ignored in non-secure
721 \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
722 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
724 __STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
726 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
727 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
728 // without main extensions, the non-secure PSPLIM is RAZ/WI
729 (void)ProcStackPtrLimit;
731 __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
736 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
738 \brief Set Process Stack Pointer (non-secure)
739 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
740 Stack Pointer Limit register hence the write is silently ignored.
742 \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
743 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
745 __STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
747 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
748 // without main extensions, the non-secure PSPLIM is RAZ/WI
749 (void)ProcStackPtrLimit;
751 __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
758 \brief Get Main Stack Pointer Limit
759 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
760 Stack Pointer Limit register hence zero is returned always in non-secure
763 \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
764 \return MSPLIM Register value
766 __STATIC_FORCEINLINE uint32_t __get_MSPLIM(void)
768 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
769 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
770 // without main extensions, the non-secure MSPLIM is RAZ/WI
774 __ASM volatile ("MRS %0, msplim" : "=r" (result) );
780 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
782 \brief Get Main Stack Pointer Limit (non-secure)
783 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
784 Stack Pointer Limit register hence zero is returned always.
786 \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
787 \return MSPLIM Register value
789 __STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void)
791 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
792 // without main extensions, the non-secure MSPLIM is RAZ/WI
796 __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
804 \brief Set Main Stack Pointer Limit
805 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
806 Stack Pointer Limit register hence the write is silently ignored in non-secure
809 \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
810 \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set
812 __STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
814 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
815 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
816 // without main extensions, the non-secure MSPLIM is RAZ/WI
817 (void)MainStackPtrLimit;
819 __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
824 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
826 \brief Set Main Stack Pointer Limit (non-secure)
827 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
828 Stack Pointer Limit register hence the write is silently ignored.
830 \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
831 \param [in] MainStackPtrLimit Main Stack Pointer value to set
833 __STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
835 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
836 // without main extensions, the non-secure MSPLIM is RAZ/WI
837 (void)MainStackPtrLimit;
839 __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
844 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
845 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
850 \details Returns the current value of the Floating Point Status/Control register.
851 \return Floating Point Status/Control register value
853 __STATIC_FORCEINLINE uint32_t __get_FPSCR(void)
855 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
856 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
857 #if __has_builtin(__builtin_arm_get_fpscr)
858 // Re-enable using built-in when GCC has been fixed
859 // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
860 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
861 return __builtin_arm_get_fpscr();
865 __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
876 \details Assigns the given value to the Floating Point Status/Control register.
877 \param [in] fpscr Floating Point Status/Control value to set
879 __STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr)
881 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
882 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
883 #if __has_builtin(__builtin_arm_set_fpscr)
884 // Re-enable using built-in when GCC has been fixed
885 // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
886 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
887 __builtin_arm_set_fpscr(fpscr);
889 __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory");
897 /*@} end of CMSIS_Core_RegAccFunctions */
900 /* ########################## Core Instruction Access ######################### */
901 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
902 Access to dedicated instructions
906 /* Define macros for porting to both thumb1 and thumb2.
907 * For thumb1, use low register (r0-r7), specified by constraint "l"
908 * Otherwise, use general registers, specified by constraint "r" */
909 #if defined (__thumb__) && !defined (__thumb2__)
910 #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
911 #define __CMSIS_GCC_RW_REG(r) "+l" (r)
912 #define __CMSIS_GCC_USE_REG(r) "l" (r)
914 #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
915 #define __CMSIS_GCC_RW_REG(r) "+r" (r)
916 #define __CMSIS_GCC_USE_REG(r) "r" (r)
921 \details No Operation does nothing. This instruction can be used for code alignment purposes.
923 #define __NOP() __ASM volatile ("nop")
926 \brief Wait For Interrupt
927 \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
929 #define __WFI() __ASM volatile ("wfi":::"memory")
933 \brief Wait For Event
934 \details Wait For Event is a hint instruction that permits the processor to enter
935 a low-power state until one of a number of events occurs.
937 #define __WFE() __ASM volatile ("wfe":::"memory")
942 \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
944 #define __SEV() __ASM volatile ("sev")
948 \brief Instruction Synchronization Barrier
949 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
950 so that all instructions following the ISB are fetched from cache or memory,
951 after the instruction has been completed.
953 __STATIC_FORCEINLINE void __ISB(void)
955 __ASM volatile ("isb 0xF":::"memory");
960 \brief Data Synchronization Barrier
961 \details Acts as a special kind of Data Memory Barrier.
962 It completes when all explicit memory accesses before this instruction complete.
964 __STATIC_FORCEINLINE void __DSB(void)
966 __ASM volatile ("dsb 0xF":::"memory");
971 \brief Data Memory Barrier
972 \details Ensures the apparent order of the explicit memory operations before
973 and after the instruction, without ensuring their completion.
975 __STATIC_FORCEINLINE void __DMB(void)
977 __ASM volatile ("dmb 0xF":::"memory");
982 \brief Reverse byte order (32 bit)
983 \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
984 \param [in] value Value to reverse
985 \return Reversed value
987 __STATIC_FORCEINLINE uint32_t __REV(uint32_t value)
989 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
990 return __builtin_bswap32(value);
994 __ASM ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
1001 \brief Reverse byte order (16 bit)
1002 \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
1003 \param [in] value Value to reverse
1004 \return Reversed value
1006 __STATIC_FORCEINLINE uint32_t __REV16(uint32_t value)
1010 __ASM ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
1016 \brief Reverse byte order (16 bit)
1017 \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
1018 \param [in] value Value to reverse
1019 \return Reversed value
1021 __STATIC_FORCEINLINE int16_t __REVSH(int16_t value)
1023 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1024 return (int16_t)__builtin_bswap16(value);
1028 __ASM ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
1035 \brief Rotate Right in unsigned value (32 bit)
1036 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
1037 \param [in] op1 Value to rotate
1038 \param [in] op2 Number of Bits to rotate
1039 \return Rotated value
1041 __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
1048 return (op1 >> op2) | (op1 << (32U - op2));
1054 \details Causes the processor to enter Debug state.
1055 Debug tools can use this to investigate system state when the instruction at a particular address is reached.
1056 \param [in] value is ignored by the processor.
1057 If required, a debugger can use it to store additional information about the breakpoint.
1059 #define __BKPT(value) __ASM volatile ("bkpt "#value)
1063 \brief Reverse bit order of value
1064 \details Reverses the bit order of the given value.
1065 \param [in] value Value to reverse
1066 \return Reversed value
1068 __STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value)
1072 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1073 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1074 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
1075 __ASM ("rbit %0, %1" : "=r" (result) : "r" (value) );
1077 uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */
1079 result = value; /* r will be reversed bits of v; first get LSB of v */
1080 for (value >>= 1U; value != 0U; value >>= 1U)
1083 result |= value & 1U;
1086 result <<= s; /* shift when v's highest bits are zero */
1093 \brief Count leading zeros
1094 \details Counts the number of leading zeros of a data value.
1095 \param [in] value Value to count the leading zeros
1096 \return number of leading zeros in value
1098 __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value)
1100 /* Even though __builtin_clz produces a CLZ instruction on ARM, formally
1101 __builtin_clz(0) is undefined behaviour, so handle this case specially.
1102 This guarantees ARM-compatible results if happening to compile on a non-ARM
1103 target, and ensures the compiler doesn't decide to activate any
1104 optimisations using the logic "value was passed to __builtin_clz, so it
1106 ARM GCC 7.3 and possibly earlier will optimise this test away, leaving a
1107 single CLZ instruction.
1113 return __builtin_clz(value);
1117 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1118 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1119 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1120 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
1122 \brief LDR Exclusive (8 bit)
1123 \details Executes a exclusive LDR instruction for 8 bit value.
1124 \param [in] ptr Pointer to data
1125 \return value of type uint8_t at (*ptr)
1127 __STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr)
1131 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1132 __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
1134 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
1135 accepted by assembler. So has to use following less efficient pattern.
1137 __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
1139 return ((uint8_t) result); /* Add explicit type cast here */
1144 \brief LDR Exclusive (16 bit)
1145 \details Executes a exclusive LDR instruction for 16 bit values.
1146 \param [in] ptr Pointer to data
1147 \return value of type uint16_t at (*ptr)
1149 __STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr)
1153 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1154 __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
1156 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
1157 accepted by assembler. So has to use following less efficient pattern.
1159 __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
1161 return ((uint16_t) result); /* Add explicit type cast here */
1166 \brief LDR Exclusive (32 bit)
1167 \details Executes a exclusive LDR instruction for 32 bit values.
1168 \param [in] ptr Pointer to data
1169 \return value of type uint32_t at (*ptr)
1171 __STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr)
1175 __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
1181 \brief STR Exclusive (8 bit)
1182 \details Executes a exclusive STR instruction for 8 bit values.
1183 \param [in] value Value to store
1184 \param [in] ptr Pointer to location
1185 \return 0 Function succeeded
1186 \return 1 Function failed
1188 __STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
1192 __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
1198 \brief STR Exclusive (16 bit)
1199 \details Executes a exclusive STR instruction for 16 bit values.
1200 \param [in] value Value to store
1201 \param [in] ptr Pointer to location
1202 \return 0 Function succeeded
1203 \return 1 Function failed
1205 __STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
1209 __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
1215 \brief STR Exclusive (32 bit)
1216 \details Executes a exclusive STR instruction for 32 bit values.
1217 \param [in] value Value to store
1218 \param [in] ptr Pointer to location
1219 \return 0 Function succeeded
1220 \return 1 Function failed
1222 __STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
1226 __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
1232 \brief Remove the exclusive lock
1233 \details Removes the exclusive lock which is created by LDREX.
1235 __STATIC_FORCEINLINE void __CLREX(void)
1237 __ASM volatile ("clrex" ::: "memory");
1240 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1241 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1242 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1243 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
1246 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1247 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1248 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
1250 \brief Signed Saturate
1251 \details Saturates a signed value.
1252 \param [in] ARG1 Value to be saturated
1253 \param [in] ARG2 Bit position to saturate to (1..32)
1254 \return Saturated value
1256 #define __SSAT(ARG1, ARG2) \
1259 int32_t __RES, __ARG1 = (ARG1); \
1260 __ASM volatile ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
1266 \brief Unsigned Saturate
1267 \details Saturates an unsigned value.
1268 \param [in] ARG1 Value to be saturated
1269 \param [in] ARG2 Bit position to saturate to (0..31)
1270 \return Saturated value
1272 #define __USAT(ARG1, ARG2) \
1275 uint32_t __RES, __ARG1 = (ARG1); \
1276 __ASM volatile ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
1282 \brief Rotate Right with Extend (32 bit)
1283 \details Moves each bit of a bitstring right by one bit.
1284 The carry input is shifted in at the left end of the bitstring.
1285 \param [in] value Value to rotate
1286 \return Rotated value
1288 __STATIC_FORCEINLINE uint32_t __RRX(uint32_t value)
1292 __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
1298 \brief LDRT Unprivileged (8 bit)
1299 \details Executes a Unprivileged LDRT instruction for 8 bit value.
1300 \param [in] ptr Pointer to data
1301 \return value of type uint8_t at (*ptr)
1303 __STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr)
1307 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1308 __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
1310 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
1311 accepted by assembler. So has to use following less efficient pattern.
1313 __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" );
1315 return ((uint8_t) result); /* Add explicit type cast here */
1320 \brief LDRT Unprivileged (16 bit)
1321 \details Executes a Unprivileged LDRT instruction for 16 bit values.
1322 \param [in] ptr Pointer to data
1323 \return value of type uint16_t at (*ptr)
1325 __STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr)
1329 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1330 __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
1332 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
1333 accepted by assembler. So has to use following less efficient pattern.
1335 __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" );
1337 return ((uint16_t) result); /* Add explicit type cast here */
1342 \brief LDRT Unprivileged (32 bit)
1343 \details Executes a Unprivileged LDRT instruction for 32 bit values.
1344 \param [in] ptr Pointer to data
1345 \return value of type uint32_t at (*ptr)
1347 __STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr)
1351 __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
1357 \brief STRT Unprivileged (8 bit)
1358 \details Executes a Unprivileged STRT instruction for 8 bit values.
1359 \param [in] value Value to store
1360 \param [in] ptr Pointer to location
1362 __STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
1364 __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1369 \brief STRT Unprivileged (16 bit)
1370 \details Executes a Unprivileged STRT instruction for 16 bit values.
1371 \param [in] value Value to store
1372 \param [in] ptr Pointer to location
1374 __STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
1376 __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1381 \brief STRT Unprivileged (32 bit)
1382 \details Executes a Unprivileged STRT instruction for 32 bit values.
1383 \param [in] value Value to store
1384 \param [in] ptr Pointer to location
1386 __STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
1388 __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
1391 #else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1392 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1393 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
1396 \brief Signed Saturate
1397 \details Saturates a signed value.
1398 \param [in] value Value to be saturated
1399 \param [in] sat Bit position to saturate to (1..32)
1400 \return Saturated value
1402 __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
1404 if ((sat >= 1U) && (sat <= 32U))
1406 const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
1407 const int32_t min = -1 - max ;
1421 \brief Unsigned Saturate
1422 \details Saturates an unsigned value.
1423 \param [in] value Value to be saturated
1424 \param [in] sat Bit position to saturate to (0..31)
1425 \return Saturated value
1427 __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
1431 const uint32_t max = ((1U << sat) - 1U);
1432 if (val > (int32_t)max)
1441 return (uint32_t)val;
1444 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1445 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1446 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
1449 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1450 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
1452 \brief Load-Acquire (8 bit)
1453 \details Executes a LDAB instruction for 8 bit value.
1454 \param [in] ptr Pointer to data
1455 \return value of type uint8_t at (*ptr)
1457 __STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr)
1461 __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
1462 return ((uint8_t) result);
1467 \brief Load-Acquire (16 bit)
1468 \details Executes a LDAH instruction for 16 bit values.
1469 \param [in] ptr Pointer to data
1470 \return value of type uint16_t at (*ptr)
1472 __STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr)
1476 __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
1477 return ((uint16_t) result);
1482 \brief Load-Acquire (32 bit)
1483 \details Executes a LDA instruction for 32 bit values.
1484 \param [in] ptr Pointer to data
1485 \return value of type uint32_t at (*ptr)
1487 __STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr)
1491 __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
1497 \brief Store-Release (8 bit)
1498 \details Executes a STLB instruction for 8 bit values.
1499 \param [in] value Value to store
1500 \param [in] ptr Pointer to location
1502 __STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
1504 __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
1509 \brief Store-Release (16 bit)
1510 \details Executes a STLH instruction for 16 bit values.
1511 \param [in] value Value to store
1512 \param [in] ptr Pointer to location
1514 __STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
1516 __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
1521 \brief Store-Release (32 bit)
1522 \details Executes a STL instruction for 32 bit values.
1523 \param [in] value Value to store
1524 \param [in] ptr Pointer to location
1526 __STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr)
1528 __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
1533 \brief Load-Acquire Exclusive (8 bit)
1534 \details Executes a LDAB exclusive instruction for 8 bit value.
1535 \param [in] ptr Pointer to data
1536 \return value of type uint8_t at (*ptr)
1538 __STATIC_FORCEINLINE uint8_t __LDAEXB(volatile uint8_t *ptr)
1542 __ASM volatile ("ldaexb %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
1543 return ((uint8_t) result);
1548 \brief Load-Acquire Exclusive (16 bit)
1549 \details Executes a LDAH exclusive instruction for 16 bit values.
1550 \param [in] ptr Pointer to data
1551 \return value of type uint16_t at (*ptr)
1553 __STATIC_FORCEINLINE uint16_t __LDAEXH(volatile uint16_t *ptr)
1557 __ASM volatile ("ldaexh %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
1558 return ((uint16_t) result);
1563 \brief Load-Acquire Exclusive (32 bit)
1564 \details Executes a LDA exclusive instruction for 32 bit values.
1565 \param [in] ptr Pointer to data
1566 \return value of type uint32_t at (*ptr)
1568 __STATIC_FORCEINLINE uint32_t __LDAEX(volatile uint32_t *ptr)
1572 __ASM volatile ("ldaex %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
1578 \brief Store-Release Exclusive (8 bit)
1579 \details Executes a STLB exclusive instruction for 8 bit values.
1580 \param [in] value Value to store
1581 \param [in] ptr Pointer to location
1582 \return 0 Function succeeded
1583 \return 1 Function failed
1585 __STATIC_FORCEINLINE uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr)
1589 __ASM volatile ("stlexb %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
1595 \brief Store-Release Exclusive (16 bit)
1596 \details Executes a STLH exclusive instruction for 16 bit values.
1597 \param [in] value Value to store
1598 \param [in] ptr Pointer to location
1599 \return 0 Function succeeded
1600 \return 1 Function failed
1602 __STATIC_FORCEINLINE uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr)
1606 __ASM volatile ("stlexh %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
1612 \brief Store-Release Exclusive (32 bit)
1613 \details Executes a STL exclusive instruction for 32 bit values.
1614 \param [in] value Value to store
1615 \param [in] ptr Pointer to location
1616 \return 0 Function succeeded
1617 \return 1 Function failed
1619 __STATIC_FORCEINLINE uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr)
1623 __ASM volatile ("stlex %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
1627 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1628 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
1630 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
1633 /* ################### Compiler specific Intrinsics ########################### */
1634 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
1635 Access to dedicated SIMD instructions
1639 #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
1641 __STATIC_FORCEINLINE uint32_t __SADD8(uint32_t op1, uint32_t op2)
1645 __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1649 __STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
1653 __ASM ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1657 __STATIC_FORCEINLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2)
1661 __ASM ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1665 __STATIC_FORCEINLINE uint32_t __UADD8(uint32_t op1, uint32_t op2)
1669 __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1673 __STATIC_FORCEINLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2)
1677 __ASM ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1681 __STATIC_FORCEINLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2)
1685 __ASM ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1690 __STATIC_FORCEINLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2)
1694 __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1698 __STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
1702 __ASM ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1706 __STATIC_FORCEINLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2)
1710 __ASM ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1714 __STATIC_FORCEINLINE uint32_t __USUB8(uint32_t op1, uint32_t op2)
1718 __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1722 __STATIC_FORCEINLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2)
1726 __ASM ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1730 __STATIC_FORCEINLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2)
1734 __ASM ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1739 __STATIC_FORCEINLINE uint32_t __SADD16(uint32_t op1, uint32_t op2)
1743 __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1747 __STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
1751 __ASM ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1755 __STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
1759 __ASM ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1763 __STATIC_FORCEINLINE uint32_t __UADD16(uint32_t op1, uint32_t op2)
1767 __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1771 __STATIC_FORCEINLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2)
1775 __ASM ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1779 __STATIC_FORCEINLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2)
1783 __ASM ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1787 __STATIC_FORCEINLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2)
1791 __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1795 __STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
1799 __ASM ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1803 __STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
1807 __ASM ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1811 __STATIC_FORCEINLINE uint32_t __USUB16(uint32_t op1, uint32_t op2)
1815 __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1819 __STATIC_FORCEINLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2)
1823 __ASM ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1827 __STATIC_FORCEINLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2)
1831 __ASM ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1835 __STATIC_FORCEINLINE uint32_t __SASX(uint32_t op1, uint32_t op2)
1839 __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1843 __STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
1847 __ASM ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1851 __STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
1855 __ASM ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1859 __STATIC_FORCEINLINE uint32_t __UASX(uint32_t op1, uint32_t op2)
1863 __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1867 __STATIC_FORCEINLINE uint32_t __UQASX(uint32_t op1, uint32_t op2)
1871 __ASM ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1875 __STATIC_FORCEINLINE uint32_t __UHASX(uint32_t op1, uint32_t op2)
1879 __ASM ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1883 __STATIC_FORCEINLINE uint32_t __SSAX(uint32_t op1, uint32_t op2)
1887 __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1891 __STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
1895 __ASM ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1899 __STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
1903 __ASM ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1907 __STATIC_FORCEINLINE uint32_t __USAX(uint32_t op1, uint32_t op2)
1911 __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1915 __STATIC_FORCEINLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2)
1919 __ASM ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1923 __STATIC_FORCEINLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2)
1927 __ASM ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1931 __STATIC_FORCEINLINE uint32_t __USAD8(uint32_t op1, uint32_t op2)
1935 __ASM ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1939 __STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3)
1943 __ASM ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1947 #define __SSAT16(ARG1, ARG2) \
1950 int32_t __RES, __ARG1 = (ARG1); \
1951 __ASM volatile ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
1955 #define __USAT16(ARG1, ARG2) \
1958 uint32_t __RES, __ARG1 = (ARG1); \
1959 __ASM volatile ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
1963 __STATIC_FORCEINLINE uint32_t __UXTB16(uint32_t op1)
1967 __ASM ("uxtb16 %0, %1" : "=r" (result) : "r" (op1));
1971 __STATIC_FORCEINLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2)
1975 __ASM ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1979 __STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1)
1983 __ASM ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
1987 __STATIC_FORCEINLINE uint32_t __SXTB16_RORn(uint32_t op1, uint32_t rotate)
1990 if (__builtin_constant_p(rotate) && ((rotate == 8U) || (rotate == 16U) || (rotate == 24U))) {
1991 __ASM volatile ("sxtb16 %0, %1, ROR %2" : "=r" (result) : "r" (op1), "i" (rotate) );
1993 result = __SXTB16(__ROR(op1, rotate)) ;
1998 __STATIC_FORCEINLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2)
2002 __ASM ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2006 __STATIC_FORCEINLINE uint32_t __SXTAB16_RORn(uint32_t op1, uint32_t op2, uint32_t rotate)
2009 if (__builtin_constant_p(rotate) && ((rotate == 8U) || (rotate == 16U) || (rotate == 24U))) {
2010 __ASM volatile ("sxtab16 %0, %1, %2, ROR %3" : "=r" (result) : "r" (op1) , "r" (op2) , "i" (rotate));
2012 result = __SXTAB16(op1, __ROR(op2, rotate));
2018 __STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
2022 __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2026 __STATIC_FORCEINLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
2030 __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2034 __STATIC_FORCEINLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
2038 __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
2042 __STATIC_FORCEINLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
2046 __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
2050 __STATIC_FORCEINLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
2058 #ifndef __ARMEB__ /* Little endian */
2059 __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
2060 #else /* Big endian */
2061 __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
2067 __STATIC_FORCEINLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
2075 #ifndef __ARMEB__ /* Little endian */
2076 __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
2077 #else /* Big endian */
2078 __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
2084 __STATIC_FORCEINLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
2088 __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2092 __STATIC_FORCEINLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
2096 __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2100 __STATIC_FORCEINLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3)
2104 __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
2108 __STATIC_FORCEINLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
2112 __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
2116 __STATIC_FORCEINLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc)
2124 #ifndef __ARMEB__ /* Little endian */
2125 __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
2126 #else /* Big endian */
2127 __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
2133 __STATIC_FORCEINLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc)
2141 #ifndef __ARMEB__ /* Little endian */
2142 __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
2143 #else /* Big endian */
2144 __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
2150 __STATIC_FORCEINLINE uint32_t __SEL (uint32_t op1, uint32_t op2)
2154 __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2158 __STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2)
2162 __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2166 __STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2)
2170 __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2175 #define __PKHBT(ARG1,ARG2,ARG3) \
2178 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
2179 __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
2183 #define __PKHTB(ARG1,ARG2,ARG3) \
2186 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
2188 __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \
2190 __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
2195 __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
2199 __ASM ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
2203 #endif /* (__ARM_FEATURE_DSP == 1) */
2204 /*@} end of group CMSIS_SIMD_intrinsics */
2207 #pragma GCC diagnostic pop
2209 #endif /* __CMSIS_GCC_H */