1 /**************************************************************************//**
3 * @brief CMSIS compiler GCC header file
6 ******************************************************************************/
8 * Copyright (c) 2009-2018 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
118 /* ########################### Core Function Access ########################### */
119 /** \ingroup CMSIS_Core_FunctionInterface
120 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
125 \brief Enable IRQ Interrupts
126 \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
127 Can only be executed in Privileged modes.
129 __STATIC_FORCEINLINE void __enable_irq(void)
131 __ASM volatile ("cpsie i" : : : "memory");
136 \brief Disable IRQ Interrupts
137 \details Disables IRQ interrupts by setting the I-bit in the CPSR.
138 Can only be executed in Privileged modes.
140 __STATIC_FORCEINLINE void __disable_irq(void)
142 __ASM volatile ("cpsid i" : : : "memory");
147 \brief Get Control Register
148 \details Returns the content of the Control Register.
149 \return Control Register value
151 __STATIC_FORCEINLINE uint32_t __get_CONTROL(void)
155 __ASM volatile ("MRS %0, control" : "=r" (result) );
160 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
162 \brief Get Control Register (non-secure)
163 \details Returns the content of the non-secure Control Register when in secure mode.
164 \return non-secure Control Register value
166 __STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void)
170 __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
177 \brief Set Control Register
178 \details Writes the given value to the Control Register.
179 \param [in] control Control Register value to set
181 __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
183 __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
187 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
189 \brief Set Control Register (non-secure)
190 \details Writes the given value to the non-secure Control Register when in secure state.
191 \param [in] control Control Register value to set
193 __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
195 __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
201 \brief Get IPSR Register
202 \details Returns the content of the IPSR Register.
203 \return IPSR Register value
205 __STATIC_FORCEINLINE uint32_t __get_IPSR(void)
209 __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
215 \brief Get APSR Register
216 \details Returns the content of the APSR Register.
217 \return APSR Register value
219 __STATIC_FORCEINLINE uint32_t __get_APSR(void)
223 __ASM volatile ("MRS %0, apsr" : "=r" (result) );
229 \brief Get xPSR Register
230 \details Returns the content of the xPSR Register.
231 \return xPSR Register value
233 __STATIC_FORCEINLINE uint32_t __get_xPSR(void)
237 __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
243 \brief Get Process Stack Pointer
244 \details Returns the current value of the Process Stack Pointer (PSP).
245 \return PSP Register value
247 __STATIC_FORCEINLINE uint32_t __get_PSP(void)
251 __ASM volatile ("MRS %0, psp" : "=r" (result) );
256 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
258 \brief Get Process Stack Pointer (non-secure)
259 \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
260 \return PSP Register value
262 __STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void)
266 __ASM volatile ("MRS %0, psp_ns" : "=r" (result) );
273 \brief Set Process Stack Pointer
274 \details Assigns the given value to the Process Stack Pointer (PSP).
275 \param [in] topOfProcStack Process Stack Pointer value to set
277 __STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack)
279 __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : );
283 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
285 \brief Set Process Stack Pointer (non-secure)
286 \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
287 \param [in] topOfProcStack Process Stack Pointer value to set
289 __STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
291 __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : );
297 \brief Get Main Stack Pointer
298 \details Returns the current value of the Main Stack Pointer (MSP).
299 \return MSP Register value
301 __STATIC_FORCEINLINE uint32_t __get_MSP(void)
305 __ASM volatile ("MRS %0, msp" : "=r" (result) );
310 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
312 \brief Get Main Stack Pointer (non-secure)
313 \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
314 \return MSP Register value
316 __STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void)
320 __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
327 \brief Set Main Stack Pointer
328 \details Assigns the given value to the Main Stack Pointer (MSP).
329 \param [in] topOfMainStack Main Stack Pointer value to set
331 __STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack)
333 __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : );
337 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
339 \brief Set Main Stack Pointer (non-secure)
340 \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
341 \param [in] topOfMainStack Main Stack Pointer value to set
343 __STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
345 __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : );
350 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
352 \brief Get Stack Pointer (non-secure)
353 \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
354 \return SP Register value
356 __STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void)
360 __ASM volatile ("MRS %0, sp_ns" : "=r" (result) );
366 \brief Set Stack Pointer (non-secure)
367 \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
368 \param [in] topOfStack Stack Pointer value to set
370 __STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack)
372 __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : );
378 \brief Get Priority Mask
379 \details Returns the current state of the priority mask bit from the Priority Mask Register.
380 \return Priority Mask value
382 __STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
386 __ASM volatile ("MRS %0, primask" : "=r" (result) :: "memory");
391 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
393 \brief Get Priority Mask (non-secure)
394 \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
395 \return Priority Mask value
397 __STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void)
401 __ASM volatile ("MRS %0, primask_ns" : "=r" (result) :: "memory");
408 \brief Set Priority Mask
409 \details Assigns the given value to the Priority Mask Register.
410 \param [in] priMask Priority Mask
412 __STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
414 __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
418 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
420 \brief Set Priority Mask (non-secure)
421 \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
422 \param [in] priMask Priority Mask
424 __STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
426 __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
431 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
432 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
433 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
436 \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
437 Can only be executed in Privileged modes.
439 __STATIC_FORCEINLINE void __enable_fault_irq(void)
441 __ASM volatile ("cpsie f" : : : "memory");
447 \details Disables FIQ interrupts by setting the F-bit in the CPSR.
448 Can only be executed in Privileged modes.
450 __STATIC_FORCEINLINE void __disable_fault_irq(void)
452 __ASM volatile ("cpsid f" : : : "memory");
457 \brief Get Base Priority
458 \details Returns the current value of the Base Priority register.
459 \return Base Priority register value
461 __STATIC_FORCEINLINE uint32_t __get_BASEPRI(void)
465 __ASM volatile ("MRS %0, basepri" : "=r" (result) );
470 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
472 \brief Get Base Priority (non-secure)
473 \details Returns the current value of the non-secure Base Priority register when in secure state.
474 \return Base Priority register value
476 __STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void)
480 __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
487 \brief Set Base Priority
488 \details Assigns the given value to the Base Priority register.
489 \param [in] basePri Base Priority value to set
491 __STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri)
493 __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
497 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
499 \brief Set Base Priority (non-secure)
500 \details Assigns the given value to the non-secure Base Priority register when in secure state.
501 \param [in] basePri Base Priority value to set
503 __STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
505 __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
511 \brief Set Base Priority with condition
512 \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
513 or the new value increases the BASEPRI priority level.
514 \param [in] basePri Base Priority value to set
516 __STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri)
518 __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
523 \brief Get Fault Mask
524 \details Returns the current value of the Fault Mask register.
525 \return Fault Mask register value
527 __STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void)
531 __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
536 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
538 \brief Get Fault Mask (non-secure)
539 \details Returns the current value of the non-secure Fault Mask register when in secure state.
540 \return Fault Mask register value
542 __STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void)
546 __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
553 \brief Set Fault Mask
554 \details Assigns the given value to the Fault Mask register.
555 \param [in] faultMask Fault Mask value to set
557 __STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask)
559 __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
563 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
565 \brief Set Fault Mask (non-secure)
566 \details Assigns the given value to the non-secure Fault Mask register when in secure state.
567 \param [in] faultMask Fault Mask value to set
569 __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
571 __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
575 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
576 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
577 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
580 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
581 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
584 \brief Get Process Stack Pointer Limit
585 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
586 Stack Pointer Limit register hence zero is returned always in non-secure
589 \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
590 \return PSPLIM Register value
592 __STATIC_FORCEINLINE uint32_t __get_PSPLIM(void)
594 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
595 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
596 // without main extensions, the non-secure PSPLIM is RAZ/WI
600 __ASM volatile ("MRS %0, psplim" : "=r" (result) );
605 #if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3))
607 \brief Get Process Stack Pointer Limit (non-secure)
608 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
609 Stack Pointer Limit register hence zero is returned always.
611 \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
612 \return PSPLIM Register value
614 __STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void)
616 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
617 // without main extensions, the non-secure PSPLIM is RAZ/WI
621 __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) );
629 \brief Set Process Stack Pointer Limit
630 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
631 Stack Pointer Limit register hence the write is silently ignored in non-secure
634 \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
635 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
637 __STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
639 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
640 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
641 // without main extensions, the non-secure PSPLIM is RAZ/WI
642 (void)ProcStackPtrLimit;
644 __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
649 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
651 \brief Set Process Stack Pointer (non-secure)
652 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
653 Stack Pointer Limit register hence the write is silently ignored.
655 \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
656 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
658 __STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
660 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
661 // without main extensions, the non-secure PSPLIM is RAZ/WI
662 (void)ProcStackPtrLimit;
664 __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
671 \brief Get Main 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 Main Stack Pointer Limit (MSPLIM).
677 \return MSPLIM Register value
679 __STATIC_FORCEINLINE uint32_t __get_MSPLIM(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 MSPLIM is RAZ/WI
687 __ASM volatile ("MRS %0, msplim" : "=r" (result) );
693 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
695 \brief Get Main Stack Pointer Limit (non-secure)
696 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
697 Stack Pointer Limit register hence zero is returned always.
699 \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
700 \return MSPLIM Register value
702 __STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void)
704 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
705 // without main extensions, the non-secure MSPLIM is RAZ/WI
709 __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
717 \brief Set Main Stack Pointer Limit
718 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
719 Stack Pointer Limit register hence the write is silently ignored in non-secure
722 \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
723 \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set
725 __STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
727 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
728 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
729 // without main extensions, the non-secure MSPLIM is RAZ/WI
730 (void)MainStackPtrLimit;
732 __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
737 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
739 \brief Set Main Stack Pointer Limit (non-secure)
740 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
741 Stack Pointer Limit register hence the write is silently ignored.
743 \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
744 \param [in] MainStackPtrLimit Main Stack Pointer value to set
746 __STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
748 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
749 // without main extensions, the non-secure MSPLIM is RAZ/WI
750 (void)MainStackPtrLimit;
752 __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
757 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
758 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
763 \details Returns the current value of the Floating Point Status/Control register.
764 \return Floating Point Status/Control register value
766 __STATIC_FORCEINLINE uint32_t __get_FPSCR(void)
768 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
769 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
770 #if __has_builtin(__builtin_arm_get_fpscr)
771 // Re-enable using built-in when GCC has been fixed
772 // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
773 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
774 return __builtin_arm_get_fpscr();
778 __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
789 \details Assigns the given value to the Floating Point Status/Control register.
790 \param [in] fpscr Floating Point Status/Control value to set
792 __STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr)
794 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
795 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
796 #if __has_builtin(__builtin_arm_set_fpscr)
797 // Re-enable using built-in when GCC has been fixed
798 // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
799 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
800 __builtin_arm_set_fpscr(fpscr);
802 __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory");
810 /*@} end of CMSIS_Core_RegAccFunctions */
813 /* ########################## Core Instruction Access ######################### */
814 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
815 Access to dedicated instructions
819 /* Define macros for porting to both thumb1 and thumb2.
820 * For thumb1, use low register (r0-r7), specified by constraint "l"
821 * Otherwise, use general registers, specified by constraint "r" */
822 #if defined (__thumb__) && !defined (__thumb2__)
823 #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
824 #define __CMSIS_GCC_RW_REG(r) "+l" (r)
825 #define __CMSIS_GCC_USE_REG(r) "l" (r)
827 #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
828 #define __CMSIS_GCC_RW_REG(r) "+r" (r)
829 #define __CMSIS_GCC_USE_REG(r) "r" (r)
834 \details No Operation does nothing. This instruction can be used for code alignment purposes.
836 #define __NOP() __ASM volatile ("nop")
839 \brief Wait For Interrupt
840 \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
842 #define __WFI() __ASM volatile ("wfi")
846 \brief Wait For Event
847 \details Wait For Event is a hint instruction that permits the processor to enter
848 a low-power state until one of a number of events occurs.
850 #define __WFE() __ASM volatile ("wfe")
855 \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
857 #define __SEV() __ASM volatile ("sev")
861 \brief Instruction Synchronization Barrier
862 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
863 so that all instructions following the ISB are fetched from cache or memory,
864 after the instruction has been completed.
866 __STATIC_FORCEINLINE void __ISB(void)
868 __ASM volatile ("isb 0xF":::"memory");
873 \brief Data Synchronization Barrier
874 \details Acts as a special kind of Data Memory Barrier.
875 It completes when all explicit memory accesses before this instruction complete.
877 __STATIC_FORCEINLINE void __DSB(void)
879 __ASM volatile ("dsb 0xF":::"memory");
884 \brief Data Memory Barrier
885 \details Ensures the apparent order of the explicit memory operations before
886 and after the instruction, without ensuring their completion.
888 __STATIC_FORCEINLINE void __DMB(void)
890 __ASM volatile ("dmb 0xF":::"memory");
895 \brief Reverse byte order (32 bit)
896 \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
897 \param [in] value Value to reverse
898 \return Reversed value
900 __STATIC_FORCEINLINE uint32_t __REV(uint32_t value)
902 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
903 return __builtin_bswap32(value);
907 __ASM volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
914 \brief Reverse byte order (16 bit)
915 \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
916 \param [in] value Value to reverse
917 \return Reversed value
919 __STATIC_FORCEINLINE uint32_t __REV16(uint32_t value)
923 __ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
929 \brief Reverse byte order (16 bit)
930 \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
931 \param [in] value Value to reverse
932 \return Reversed value
934 __STATIC_FORCEINLINE int16_t __REVSH(int16_t value)
936 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
937 return (int16_t)__builtin_bswap16(value);
941 __ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
948 \brief Rotate Right in unsigned value (32 bit)
949 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
950 \param [in] op1 Value to rotate
951 \param [in] op2 Number of Bits to rotate
952 \return Rotated value
954 __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
961 return (op1 >> op2) | (op1 << (32U - op2));
967 \details Causes the processor to enter Debug state.
968 Debug tools can use this to investigate system state when the instruction at a particular address is reached.
969 \param [in] value is ignored by the processor.
970 If required, a debugger can use it to store additional information about the breakpoint.
972 #define __BKPT(value) __ASM volatile ("bkpt "#value)
976 \brief Reverse bit order of value
977 \details Reverses the bit order of the given value.
978 \param [in] value Value to reverse
979 \return Reversed value
981 __STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value)
985 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
986 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
987 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
988 __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
990 uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */
992 result = value; /* r will be reversed bits of v; first get LSB of v */
993 for (value >>= 1U; value != 0U; value >>= 1U)
996 result |= value & 1U;
999 result <<= s; /* shift when v's highest bits are zero */
1006 \brief Count leading zeros
1007 \details Counts the number of leading zeros of a data value.
1008 \param [in] value Value to count the leading zeros
1009 \return number of leading zeros in value
1011 #define __CLZ (uint8_t)__builtin_clz
1014 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1015 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1016 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1017 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
1019 \brief LDR Exclusive (8 bit)
1020 \details Executes a exclusive LDR instruction for 8 bit value.
1021 \param [in] ptr Pointer to data
1022 \return value of type uint8_t at (*ptr)
1024 __STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr)
1028 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1029 __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
1031 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
1032 accepted by assembler. So has to use following less efficient pattern.
1034 __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
1036 return ((uint8_t) result); /* Add explicit type cast here */
1041 \brief LDR Exclusive (16 bit)
1042 \details Executes a exclusive LDR instruction for 16 bit values.
1043 \param [in] ptr Pointer to data
1044 \return value of type uint16_t at (*ptr)
1046 __STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr)
1050 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1051 __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
1053 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
1054 accepted by assembler. So has to use following less efficient pattern.
1056 __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
1058 return ((uint16_t) result); /* Add explicit type cast here */
1063 \brief LDR Exclusive (32 bit)
1064 \details Executes a exclusive LDR instruction for 32 bit values.
1065 \param [in] ptr Pointer to data
1066 \return value of type uint32_t at (*ptr)
1068 __STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr)
1072 __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
1078 \brief STR Exclusive (8 bit)
1079 \details Executes a exclusive STR instruction for 8 bit values.
1080 \param [in] value Value to store
1081 \param [in] ptr Pointer to location
1082 \return 0 Function succeeded
1083 \return 1 Function failed
1085 __STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
1089 __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
1095 \brief STR Exclusive (16 bit)
1096 \details Executes a exclusive STR instruction for 16 bit values.
1097 \param [in] value Value to store
1098 \param [in] ptr Pointer to location
1099 \return 0 Function succeeded
1100 \return 1 Function failed
1102 __STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
1106 __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
1112 \brief STR Exclusive (32 bit)
1113 \details Executes a exclusive STR instruction for 32 bit values.
1114 \param [in] value Value to store
1115 \param [in] ptr Pointer to location
1116 \return 0 Function succeeded
1117 \return 1 Function failed
1119 __STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
1123 __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
1129 \brief Remove the exclusive lock
1130 \details Removes the exclusive lock which is created by LDREX.
1132 __STATIC_FORCEINLINE void __CLREX(void)
1134 __ASM volatile ("clrex" ::: "memory");
1137 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1138 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1139 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1140 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
1143 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1144 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1145 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
1147 \brief Signed Saturate
1148 \details Saturates a signed value.
1149 \param [in] ARG1 Value to be saturated
1150 \param [in] ARG2 Bit position to saturate to (1..32)
1151 \return Saturated value
1153 #define __SSAT(ARG1,ARG2) \
1156 int32_t __RES, __ARG1 = (ARG1); \
1157 __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
1163 \brief Unsigned Saturate
1164 \details Saturates an unsigned value.
1165 \param [in] ARG1 Value to be saturated
1166 \param [in] ARG2 Bit position to saturate to (0..31)
1167 \return Saturated value
1169 #define __USAT(ARG1,ARG2) \
1172 uint32_t __RES, __ARG1 = (ARG1); \
1173 __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
1179 \brief Rotate Right with Extend (32 bit)
1180 \details Moves each bit of a bitstring right by one bit.
1181 The carry input is shifted in at the left end of the bitstring.
1182 \param [in] value Value to rotate
1183 \return Rotated value
1185 __STATIC_FORCEINLINE uint32_t __RRX(uint32_t value)
1189 __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
1195 \brief LDRT Unprivileged (8 bit)
1196 \details Executes a Unprivileged LDRT instruction for 8 bit value.
1197 \param [in] ptr Pointer to data
1198 \return value of type uint8_t at (*ptr)
1200 __STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr)
1204 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1205 __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
1207 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
1208 accepted by assembler. So has to use following less efficient pattern.
1210 __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" );
1212 return ((uint8_t) result); /* Add explicit type cast here */
1217 \brief LDRT Unprivileged (16 bit)
1218 \details Executes a Unprivileged LDRT instruction for 16 bit values.
1219 \param [in] ptr Pointer to data
1220 \return value of type uint16_t at (*ptr)
1222 __STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr)
1226 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1227 __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
1229 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
1230 accepted by assembler. So has to use following less efficient pattern.
1232 __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" );
1234 return ((uint16_t) result); /* Add explicit type cast here */
1239 \brief LDRT Unprivileged (32 bit)
1240 \details Executes a Unprivileged LDRT instruction for 32 bit values.
1241 \param [in] ptr Pointer to data
1242 \return value of type uint32_t at (*ptr)
1244 __STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr)
1248 __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
1254 \brief STRT Unprivileged (8 bit)
1255 \details Executes a Unprivileged STRT instruction for 8 bit values.
1256 \param [in] value Value to store
1257 \param [in] ptr Pointer to location
1259 __STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
1261 __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1266 \brief STRT Unprivileged (16 bit)
1267 \details Executes a Unprivileged STRT instruction for 16 bit values.
1268 \param [in] value Value to store
1269 \param [in] ptr Pointer to location
1271 __STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
1273 __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1278 \brief STRT Unprivileged (32 bit)
1279 \details Executes a Unprivileged STRT instruction for 32 bit values.
1280 \param [in] value Value to store
1281 \param [in] ptr Pointer to location
1283 __STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
1285 __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
1288 #else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1289 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1290 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
1293 \brief Signed Saturate
1294 \details Saturates a signed value.
1295 \param [in] value Value to be saturated
1296 \param [in] sat Bit position to saturate to (1..32)
1297 \return Saturated value
1299 __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
1301 if ((sat >= 1U) && (sat <= 32U))
1303 const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
1304 const int32_t min = -1 - max ;
1318 \brief Unsigned Saturate
1319 \details Saturates an unsigned value.
1320 \param [in] value Value to be saturated
1321 \param [in] sat Bit position to saturate to (0..31)
1322 \return Saturated value
1324 __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
1328 const uint32_t max = ((1U << sat) - 1U);
1329 if (val > (int32_t)max)
1338 return (uint32_t)val;
1341 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1342 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1343 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
1346 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1347 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
1349 \brief Load-Acquire (8 bit)
1350 \details Executes a LDAB instruction for 8 bit value.
1351 \param [in] ptr Pointer to data
1352 \return value of type uint8_t at (*ptr)
1354 __STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr)
1358 __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) );
1359 return ((uint8_t) result);
1364 \brief Load-Acquire (16 bit)
1365 \details Executes a LDAH instruction for 16 bit values.
1366 \param [in] ptr Pointer to data
1367 \return value of type uint16_t at (*ptr)
1369 __STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr)
1373 __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) );
1374 return ((uint16_t) result);
1379 \brief Load-Acquire (32 bit)
1380 \details Executes a LDA instruction for 32 bit values.
1381 \param [in] ptr Pointer to data
1382 \return value of type uint32_t at (*ptr)
1384 __STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr)
1388 __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) );
1394 \brief Store-Release (8 bit)
1395 \details Executes a STLB instruction for 8 bit values.
1396 \param [in] value Value to store
1397 \param [in] ptr Pointer to location
1399 __STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
1401 __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1406 \brief Store-Release (16 bit)
1407 \details Executes a STLH instruction for 16 bit values.
1408 \param [in] value Value to store
1409 \param [in] ptr Pointer to location
1411 __STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
1413 __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1418 \brief Store-Release (32 bit)
1419 \details Executes a STL instruction for 32 bit values.
1420 \param [in] value Value to store
1421 \param [in] ptr Pointer to location
1423 __STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr)
1425 __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1430 \brief Load-Acquire Exclusive (8 bit)
1431 \details Executes a LDAB exclusive instruction for 8 bit value.
1432 \param [in] ptr Pointer to data
1433 \return value of type uint8_t at (*ptr)
1435 __STATIC_FORCEINLINE uint8_t __LDAEXB(volatile uint8_t *ptr)
1439 __ASM volatile ("ldaexb %0, %1" : "=r" (result) : "Q" (*ptr) );
1440 return ((uint8_t) result);
1445 \brief Load-Acquire Exclusive (16 bit)
1446 \details Executes a LDAH exclusive instruction for 16 bit values.
1447 \param [in] ptr Pointer to data
1448 \return value of type uint16_t at (*ptr)
1450 __STATIC_FORCEINLINE uint16_t __LDAEXH(volatile uint16_t *ptr)
1454 __ASM volatile ("ldaexh %0, %1" : "=r" (result) : "Q" (*ptr) );
1455 return ((uint16_t) result);
1460 \brief Load-Acquire Exclusive (32 bit)
1461 \details Executes a LDA exclusive instruction for 32 bit values.
1462 \param [in] ptr Pointer to data
1463 \return value of type uint32_t at (*ptr)
1465 __STATIC_FORCEINLINE uint32_t __LDAEX(volatile uint32_t *ptr)
1469 __ASM volatile ("ldaex %0, %1" : "=r" (result) : "Q" (*ptr) );
1475 \brief Store-Release Exclusive (8 bit)
1476 \details Executes a STLB exclusive instruction for 8 bit values.
1477 \param [in] value Value to store
1478 \param [in] ptr Pointer to location
1479 \return 0 Function succeeded
1480 \return 1 Function failed
1482 __STATIC_FORCEINLINE uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr)
1486 __ASM volatile ("stlexb %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) );
1492 \brief Store-Release Exclusive (16 bit)
1493 \details Executes a STLH exclusive instruction for 16 bit values.
1494 \param [in] value Value to store
1495 \param [in] ptr Pointer to location
1496 \return 0 Function succeeded
1497 \return 1 Function failed
1499 __STATIC_FORCEINLINE uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr)
1503 __ASM volatile ("stlexh %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) );
1509 \brief Store-Release Exclusive (32 bit)
1510 \details Executes a STL exclusive instruction for 32 bit values.
1511 \param [in] value Value to store
1512 \param [in] ptr Pointer to location
1513 \return 0 Function succeeded
1514 \return 1 Function failed
1516 __STATIC_FORCEINLINE uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr)
1520 __ASM volatile ("stlex %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) );
1524 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1525 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
1527 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
1530 /* ################### Compiler specific Intrinsics ########################### */
1531 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
1532 Access to dedicated SIMD instructions
1536 #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
1538 __STATIC_FORCEINLINE uint32_t __SADD8(uint32_t op1, uint32_t op2)
1542 __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1546 __STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
1550 __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1554 __STATIC_FORCEINLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2)
1558 __ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1562 __STATIC_FORCEINLINE uint32_t __UADD8(uint32_t op1, uint32_t op2)
1566 __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1570 __STATIC_FORCEINLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2)
1574 __ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1578 __STATIC_FORCEINLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2)
1582 __ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1587 __STATIC_FORCEINLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2)
1591 __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1595 __STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
1599 __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1603 __STATIC_FORCEINLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2)
1607 __ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1611 __STATIC_FORCEINLINE uint32_t __USUB8(uint32_t op1, uint32_t op2)
1615 __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1619 __STATIC_FORCEINLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2)
1623 __ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1627 __STATIC_FORCEINLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2)
1631 __ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1636 __STATIC_FORCEINLINE uint32_t __SADD16(uint32_t op1, uint32_t op2)
1640 __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1644 __STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
1648 __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1652 __STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
1656 __ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1660 __STATIC_FORCEINLINE uint32_t __UADD16(uint32_t op1, uint32_t op2)
1664 __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1668 __STATIC_FORCEINLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2)
1672 __ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1676 __STATIC_FORCEINLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2)
1680 __ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1684 __STATIC_FORCEINLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2)
1688 __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1692 __STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
1696 __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1700 __STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
1704 __ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1708 __STATIC_FORCEINLINE uint32_t __USUB16(uint32_t op1, uint32_t op2)
1712 __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1716 __STATIC_FORCEINLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2)
1720 __ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1724 __STATIC_FORCEINLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2)
1728 __ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1732 __STATIC_FORCEINLINE uint32_t __SASX(uint32_t op1, uint32_t op2)
1736 __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1740 __STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
1744 __ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1748 __STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
1752 __ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1756 __STATIC_FORCEINLINE uint32_t __UASX(uint32_t op1, uint32_t op2)
1760 __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1764 __STATIC_FORCEINLINE uint32_t __UQASX(uint32_t op1, uint32_t op2)
1768 __ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1772 __STATIC_FORCEINLINE uint32_t __UHASX(uint32_t op1, uint32_t op2)
1776 __ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1780 __STATIC_FORCEINLINE uint32_t __SSAX(uint32_t op1, uint32_t op2)
1784 __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1788 __STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
1792 __ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1796 __STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
1800 __ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1804 __STATIC_FORCEINLINE uint32_t __USAX(uint32_t op1, uint32_t op2)
1808 __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1812 __STATIC_FORCEINLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2)
1816 __ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1820 __STATIC_FORCEINLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2)
1824 __ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1828 __STATIC_FORCEINLINE uint32_t __USAD8(uint32_t op1, uint32_t op2)
1832 __ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1836 __STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3)
1840 __ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1844 #define __SSAT16(ARG1,ARG2) \
1846 int32_t __RES, __ARG1 = (ARG1); \
1847 __ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
1851 #define __USAT16(ARG1,ARG2) \
1853 uint32_t __RES, __ARG1 = (ARG1); \
1854 __ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
1858 __STATIC_FORCEINLINE uint32_t __UXTB16(uint32_t op1)
1862 __ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1));
1866 __STATIC_FORCEINLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2)
1870 __ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1874 __STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1)
1878 __ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
1882 __STATIC_FORCEINLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2)
1886 __ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1890 __STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
1894 __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1898 __STATIC_FORCEINLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
1902 __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1906 __STATIC_FORCEINLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
1910 __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1914 __STATIC_FORCEINLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
1918 __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1922 __STATIC_FORCEINLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
1930 #ifndef __ARMEB__ /* Little endian */
1931 __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]) );
1932 #else /* Big endian */
1933 __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]) );
1939 __STATIC_FORCEINLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
1947 #ifndef __ARMEB__ /* Little endian */
1948 __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]) );
1949 #else /* Big endian */
1950 __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]) );
1956 __STATIC_FORCEINLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
1960 __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1964 __STATIC_FORCEINLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
1968 __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1972 __STATIC_FORCEINLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3)
1976 __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1980 __STATIC_FORCEINLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
1984 __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1988 __STATIC_FORCEINLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc)
1996 #ifndef __ARMEB__ /* Little endian */
1997 __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]) );
1998 #else /* Big endian */
1999 __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]) );
2005 __STATIC_FORCEINLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc)
2013 #ifndef __ARMEB__ /* Little endian */
2014 __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]) );
2015 #else /* Big endian */
2016 __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]) );
2022 __STATIC_FORCEINLINE uint32_t __SEL (uint32_t op1, uint32_t op2)
2026 __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2030 __STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2)
2034 __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2038 __STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2)
2042 __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2047 #define __PKHBT(ARG1,ARG2,ARG3) \
2049 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
2050 __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
2054 #define __PKHTB(ARG1,ARG2,ARG3) \
2056 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
2058 __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \
2060 __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
2065 #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
2066 ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
2068 #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
2069 ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
2071 __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
2075 __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
2079 #endif /* (__ARM_FEATURE_DSP == 1) */
2080 /*@} end of group CMSIS_SIMD_intrinsics */
2083 #pragma GCC diagnostic pop
2085 #endif /* __CMSIS_GCC_H */