1 /**************************************************************************//**
3 * @brief CMSIS Cortex-M Core Function/Instruction Header File
5 * @date 20. October 2015
6 ******************************************************************************/
7 /* Copyright (c) 2009 - 2015 ARM LIMITED
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 - Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14 - Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
17 - Neither the name of ARM nor the names of its contributors may be used
18 to endorse or promote products derived from this software without
19 specific prior written permission.
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 POSSIBILITY OF SUCH DAMAGE.
32 ---------------------------------------------------------------------------*/
38 /* ignore some GCC warnings */
39 #if defined ( __GNUC__ )
40 #pragma GCC diagnostic push
41 #pragma GCC diagnostic ignored "-Wsign-conversion"
42 #pragma GCC diagnostic ignored "-Wconversion"
43 #pragma GCC diagnostic ignored "-Wunused-parameter"
47 /* ########################### Core Function Access ########################### */
48 /** \ingroup CMSIS_Core_FunctionInterface
49 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
54 \brief Enable IRQ Interrupts
55 \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
56 Can only be executed in Privileged modes.
58 __attribute__( ( always_inline
) ) __STATIC_INLINE
void __enable_irq(void)
60 __ASM
volatile ("cpsie i" : : : "memory");
65 \brief Disable IRQ Interrupts
66 \details Disables IRQ interrupts by setting the I-bit in the CPSR.
67 Can only be executed in Privileged modes.
69 __attribute__( ( always_inline
) ) __STATIC_INLINE
void __disable_irq(void)
71 __ASM
volatile ("cpsid i" : : : "memory");
76 \brief Get Control Register
77 \details Returns the content of the Control Register.
78 \return Control Register value
80 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __get_CONTROL(void)
84 __ASM
volatile ("MRS %0, control" : "=r" (result
) );
90 \brief Set Control Register
91 \details Writes the given value to the Control Register.
92 \param [in] control Control Register value to set
94 __attribute__( ( always_inline
) ) __STATIC_INLINE
void __set_CONTROL(uint32_t control
)
96 __ASM
volatile ("MSR control, %0" : : "r" (control
) : "memory");
101 \brief Get IPSR Register
102 \details Returns the content of the IPSR Register.
103 \return IPSR Register value
105 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __get_IPSR(void)
109 __ASM
volatile ("MRS %0, ipsr" : "=r" (result
) );
115 \brief Get APSR Register
116 \details Returns the content of the APSR Register.
117 \return APSR Register value
119 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __get_APSR(void)
123 __ASM
volatile ("MRS %0, apsr" : "=r" (result
) );
129 \brief Get xPSR Register
130 \details Returns the content of the xPSR Register.
132 \return xPSR Register value
134 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __get_xPSR(void)
138 __ASM
volatile ("MRS %0, xpsr" : "=r" (result
) );
144 \brief Get Process Stack Pointer
145 \details Returns the current value of the Process Stack Pointer (PSP).
146 \return PSP Register value
148 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __get_PSP(void)
150 register uint32_t result
;
152 __ASM
volatile ("MRS %0, psp\n" : "=r" (result
) );
158 \brief Set Process Stack Pointer
159 \details Assigns the given value to the Process Stack Pointer (PSP).
160 \param [in] topOfProcStack Process Stack Pointer value to set
162 __attribute__( ( always_inline
) ) __STATIC_INLINE
void __set_PSP(uint32_t topOfProcStack
)
164 __ASM
volatile ("MSR psp, %0\n" : : "r" (topOfProcStack
) : "sp");
169 \brief Get Main Stack Pointer
170 \details Returns the current value of the Main Stack Pointer (MSP).
171 \return MSP Register value
173 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __get_MSP(void)
175 register uint32_t result
;
177 __ASM
volatile ("MRS %0, msp\n" : "=r" (result
) );
183 \brief Set Main Stack Pointer
184 \details Assigns the given value to the Main Stack Pointer (MSP).
186 \param [in] topOfMainStack Main Stack Pointer value to set
188 __attribute__( ( always_inline
) ) __STATIC_INLINE
void __set_MSP(uint32_t topOfMainStack
)
190 __ASM
volatile ("MSR msp, %0\n" : : "r" (topOfMainStack
) : "sp");
195 \brief Get Priority Mask
196 \details Returns the current state of the priority mask bit from the Priority Mask Register.
197 \return Priority Mask value
199 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __get_PRIMASK(void)
203 __ASM
volatile ("MRS %0, primask" : "=r" (result
) );
209 \brief Set Priority Mask
210 \details Assigns the given value to the Priority Mask Register.
211 \param [in] priMask Priority Mask
213 __attribute__( ( always_inline
) ) __STATIC_INLINE
void __set_PRIMASK(uint32_t priMask
)
215 __ASM
volatile ("MSR primask, %0" : : "r" (priMask
) : "memory");
219 #if (__CORTEX_M >= 0x03U)
223 \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
224 Can only be executed in Privileged modes.
226 __attribute__( ( always_inline
) ) __STATIC_INLINE
void __enable_fault_irq(void)
228 __ASM
volatile ("cpsie f" : : : "memory");
234 \details Disables FIQ interrupts by setting the F-bit in the CPSR.
235 Can only be executed in Privileged modes.
237 __attribute__( ( always_inline
) ) __STATIC_INLINE
void __disable_fault_irq(void)
239 __ASM
volatile ("cpsid f" : : : "memory");
244 \brief Get Base Priority
245 \details Returns the current value of the Base Priority register.
246 \return Base Priority register value
248 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __get_BASEPRI(void)
252 __ASM
volatile ("MRS %0, basepri" : "=r" (result
) );
258 \brief Set Base Priority
259 \details Assigns the given value to the Base Priority register.
260 \param [in] basePri Base Priority value to set
262 __attribute__( ( always_inline
) ) __STATIC_INLINE
void __set_BASEPRI(uint32_t value
)
264 __ASM
volatile ("MSR basepri, %0" : : "r" (value
) : "memory");
269 \brief Set Base Priority with condition
270 \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
271 or the new value increases the BASEPRI priority level.
272 \param [in] basePri Base Priority value to set
274 __attribute__( ( always_inline
) ) __STATIC_INLINE
void __set_BASEPRI_MAX(uint32_t value
)
276 __ASM
volatile ("MSR basepri_max, %0" : : "r" (value
) : "memory");
281 \brief Get Fault Mask
282 \details Returns the current value of the Fault Mask register.
283 \return Fault Mask register value
285 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __get_FAULTMASK(void)
289 __ASM
volatile ("MRS %0, faultmask" : "=r" (result
) );
295 \brief Set Fault Mask
296 \details Assigns the given value to the Fault Mask register.
297 \param [in] faultMask Fault Mask value to set
299 __attribute__( ( always_inline
) ) __STATIC_INLINE
void __set_FAULTMASK(uint32_t faultMask
)
301 __ASM
volatile ("MSR faultmask, %0" : : "r" (faultMask
) : "memory");
304 #endif /* (__CORTEX_M >= 0x03U) */
307 #if (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U)
311 \details Returns the current value of the Floating Point Status/Control register.
312 \return Floating Point Status/Control register value
314 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __get_FPSCR(void)
316 #if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)
319 /* Empty asm statement works as a scheduling barrier */
321 __ASM
volatile ("VMRS %0, fpscr" : "=r" (result
) );
332 \details Assigns the given value to the Floating Point Status/Control register.
333 \param [in] fpscr Floating Point Status/Control value to set
335 __attribute__( ( always_inline
) ) __STATIC_INLINE
void __set_FPSCR(uint32_t fpscr
)
337 #if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)
338 /* Empty asm statement works as a scheduling barrier */
340 __ASM
volatile ("VMSR fpscr, %0" : : "r" (fpscr
) : "vfpcc");
345 #endif /* (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U) */
349 /*@} end of CMSIS_Core_RegAccFunctions */
352 /* ########################## Core Instruction Access ######################### */
353 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
354 Access to dedicated instructions
358 /* Define macros for porting to both thumb1 and thumb2.
359 * For thumb1, use low register (r0-r7), specified by constraint "l"
360 * Otherwise, use general registers, specified by constraint "r" */
361 #if defined (__thumb__) && !defined (__thumb2__)
362 #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
363 #define __CMSIS_GCC_USE_REG(r) "l" (r)
365 #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
366 #define __CMSIS_GCC_USE_REG(r) "r" (r)
371 \details No Operation does nothing. This instruction can be used for code alignment purposes.
373 __attribute__((always_inline
)) __STATIC_INLINE
void __NOP(void)
375 __ASM
volatile ("nop");
380 \brief Wait For Interrupt
381 \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
383 __attribute__((always_inline
)) __STATIC_INLINE
void __WFI(void)
385 __ASM
volatile ("wfi");
390 \brief Wait For Event
391 \details Wait For Event is a hint instruction that permits the processor to enter
392 a low-power state until one of a number of events occurs.
394 __attribute__((always_inline
)) __STATIC_INLINE
void __WFE(void)
396 __ASM
volatile ("wfe");
402 \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
404 __attribute__((always_inline
)) __STATIC_INLINE
void __SEV(void)
406 __ASM
volatile ("sev");
411 \brief Instruction Synchronization Barrier
412 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
413 so that all instructions following the ISB are fetched from cache or memory,
414 after the instruction has been completed.
416 __attribute__((always_inline
)) __STATIC_INLINE
void __ISB(void)
418 __ASM
volatile ("isb 0xF":::"memory");
423 \brief Data Synchronization Barrier
424 \details Acts as a special kind of Data Memory Barrier.
425 It completes when all explicit memory accesses before this instruction complete.
427 __attribute__((always_inline
)) __STATIC_INLINE
void __DSB(void)
429 __ASM
volatile ("dsb 0xF":::"memory");
434 \brief Data Memory Barrier
435 \details Ensures the apparent order of the explicit memory operations before
436 and after the instruction, without ensuring their completion.
438 __attribute__((always_inline
)) __STATIC_INLINE
void __DMB(void)
440 __ASM
volatile ("dmb 0xF":::"memory");
445 \brief Reverse byte order (32 bit)
446 \details Reverses the byte order in integer value.
447 \param [in] value Value to reverse
448 \return Reversed value
450 __attribute__((always_inline
)) __STATIC_INLINE
uint32_t __REV(uint32_t value
)
452 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
453 return __builtin_bswap32(value
);
457 __ASM
volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result
) : __CMSIS_GCC_USE_REG (value
) );
464 \brief Reverse byte order (16 bit)
465 \details Reverses the byte order in two unsigned short values.
466 \param [in] value Value to reverse
467 \return Reversed value
469 __attribute__((always_inline
)) __STATIC_INLINE
uint32_t __REV16(uint32_t value
)
473 __ASM
volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result
) : __CMSIS_GCC_USE_REG (value
) );
479 \brief Reverse byte order in signed short value
480 \details Reverses the byte order in a signed short value with sign extension to integer.
481 \param [in] value Value to reverse
482 \return Reversed value
484 __attribute__((always_inline
)) __STATIC_INLINE
int32_t __REVSH(int32_t value
)
486 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
487 return (short)__builtin_bswap16(value
);
491 __ASM
volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result
) : __CMSIS_GCC_USE_REG (value
) );
498 \brief Rotate Right in unsigned value (32 bit)
499 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
500 \param [in] value Value to rotate
501 \param [in] value Number of Bits to rotate
502 \return Rotated value
504 __attribute__((always_inline
)) __STATIC_INLINE
uint32_t __ROR(uint32_t op1
, uint32_t op2
)
506 return (op1
>> op2
) | (op1
<< (32U - op2
));
512 \details Causes the processor to enter Debug state.
513 Debug tools can use this to investigate system state when the instruction at a particular address is reached.
514 \param [in] value is ignored by the processor.
515 If required, a debugger can use it to store additional information about the breakpoint.
517 #define __BKPT(value) __ASM volatile ("bkpt "#value)
521 \brief Reverse bit order of value
522 \details Reverses the bit order of the given value.
523 \param [in] value Value to reverse
524 \return Reversed value
526 __attribute__((always_inline
)) __STATIC_INLINE
uint32_t __RBIT(uint32_t value
)
530 #if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)
531 __ASM
volatile ("rbit %0, %1" : "=r" (result
) : "r" (value
) );
533 int32_t s
= 4 /*sizeof(v)*/ * 8 - 1; /* extra shift needed at end */
535 result
= value
; /* r will be reversed bits of v; first get LSB of v */
536 for (value
>>= 1U; value
; value
>>= 1U)
539 result
|= value
& 1U;
542 result
<<= s
; /* shift when v's highest bits are zero */
549 \brief Count leading zeros
550 \details Counts the number of leading zeros of a data value.
551 \param [in] value Value to count the leading zeros
552 \return number of leading zeros in value
554 #define __CLZ __builtin_clz
557 #if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)
560 \brief LDR Exclusive (8 bit)
561 \details Executes a exclusive LDR instruction for 8 bit value.
562 \param [in] ptr Pointer to data
563 \return value of type uint8_t at (*ptr)
565 __attribute__((always_inline
)) __STATIC_INLINE
uint8_t __LDREXB(volatile uint8_t *addr
)
569 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
570 __ASM
volatile ("ldrexb %0, %1" : "=r" (result
) : "Q" (*addr
) );
572 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
573 accepted by assembler. So has to use following less efficient pattern.
575 __ASM
volatile ("ldrexb %0, [%1]" : "=r" (result
) : "r" (addr
) : "memory" );
577 return ((uint8_t) result
); /* Add explicit type cast here */
582 \brief LDR Exclusive (16 bit)
583 \details Executes a exclusive LDR instruction for 16 bit values.
584 \param [in] ptr Pointer to data
585 \return value of type uint16_t at (*ptr)
587 __attribute__((always_inline
)) __STATIC_INLINE
uint16_t __LDREXH(volatile uint16_t *addr
)
591 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
592 __ASM
volatile ("ldrexh %0, %1" : "=r" (result
) : "Q" (*addr
) );
594 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
595 accepted by assembler. So has to use following less efficient pattern.
597 __ASM
volatile ("ldrexh %0, [%1]" : "=r" (result
) : "r" (addr
) : "memory" );
599 return ((uint16_t) result
); /* Add explicit type cast here */
604 \brief LDR Exclusive (32 bit)
605 \details Executes a exclusive LDR instruction for 32 bit values.
606 \param [in] ptr Pointer to data
607 \return value of type uint32_t at (*ptr)
609 __attribute__((always_inline
)) __STATIC_INLINE
uint32_t __LDREXW(volatile uint32_t *addr
)
613 __ASM
volatile ("ldrex %0, %1" : "=r" (result
) : "Q" (*addr
) );
619 \brief STR Exclusive (8 bit)
620 \details Executes a exclusive STR instruction for 8 bit values.
621 \param [in] value Value to store
622 \param [in] ptr Pointer to location
623 \return 0 Function succeeded
624 \return 1 Function failed
626 __attribute__((always_inline
)) __STATIC_INLINE
uint32_t __STREXB(uint8_t value
, volatile uint8_t *addr
)
630 __ASM
volatile ("strexb %0, %2, %1" : "=&r" (result
), "=Q" (*addr
) : "r" ((uint32_t)value
) );
636 \brief STR Exclusive (16 bit)
637 \details Executes a exclusive STR instruction for 16 bit values.
638 \param [in] value Value to store
639 \param [in] ptr Pointer to location
640 \return 0 Function succeeded
641 \return 1 Function failed
643 __attribute__((always_inline
)) __STATIC_INLINE
uint32_t __STREXH(uint16_t value
, volatile uint16_t *addr
)
647 __ASM
volatile ("strexh %0, %2, %1" : "=&r" (result
), "=Q" (*addr
) : "r" ((uint32_t)value
) );
653 \brief STR Exclusive (32 bit)
654 \details Executes a exclusive STR instruction for 32 bit values.
655 \param [in] value Value to store
656 \param [in] ptr Pointer to location
657 \return 0 Function succeeded
658 \return 1 Function failed
660 __attribute__((always_inline
)) __STATIC_INLINE
uint32_t __STREXW(uint32_t value
, volatile uint32_t *addr
)
664 __ASM
volatile ("strex %0, %2, %1" : "=&r" (result
), "=Q" (*addr
) : "r" (value
) );
670 \brief Remove the exclusive lock
671 \details Removes the exclusive lock which is created by LDREX.
673 __attribute__((always_inline
)) __STATIC_INLINE
void __CLREX(void)
675 __ASM
volatile ("clrex" ::: "memory");
680 \brief Signed Saturate
681 \details Saturates a signed value.
682 \param [in] value Value to be saturated
683 \param [in] sat Bit position to saturate to (1..32)
684 \return Saturated value
686 #define __SSAT(ARG1,ARG2) \
688 uint32_t __RES, __ARG1 = (ARG1); \
689 __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
695 \brief Unsigned Saturate
696 \details Saturates an unsigned value.
697 \param [in] value Value to be saturated
698 \param [in] sat Bit position to saturate to (0..31)
699 \return Saturated value
701 #define __USAT(ARG1,ARG2) \
703 uint32_t __RES, __ARG1 = (ARG1); \
704 __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
710 \brief Rotate Right with Extend (32 bit)
711 \details Moves each bit of a bitstring right by one bit.
712 The carry input is shifted in at the left end of the bitstring.
713 \param [in] value Value to rotate
714 \return Rotated value
716 __attribute__((always_inline
)) __STATIC_INLINE
uint32_t __RRX(uint32_t value
)
720 __ASM
volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result
) : __CMSIS_GCC_USE_REG (value
) );
726 \brief LDRT Unprivileged (8 bit)
727 \details Executes a Unprivileged LDRT instruction for 8 bit value.
728 \param [in] ptr Pointer to data
729 \return value of type uint8_t at (*ptr)
731 __attribute__((always_inline
)) __STATIC_INLINE
uint8_t __LDRBT(volatile uint8_t *addr
)
735 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
736 __ASM
volatile ("ldrbt %0, %1" : "=r" (result
) : "Q" (*addr
) );
738 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
739 accepted by assembler. So has to use following less efficient pattern.
741 __ASM
volatile ("ldrbt %0, [%1]" : "=r" (result
) : "r" (addr
) : "memory" );
743 return ((uint8_t) result
); /* Add explicit type cast here */
748 \brief LDRT Unprivileged (16 bit)
749 \details Executes a Unprivileged LDRT instruction for 16 bit values.
750 \param [in] ptr Pointer to data
751 \return value of type uint16_t at (*ptr)
753 __attribute__((always_inline
)) __STATIC_INLINE
uint16_t __LDRHT(volatile uint16_t *addr
)
757 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
758 __ASM
volatile ("ldrht %0, %1" : "=r" (result
) : "Q" (*addr
) );
760 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
761 accepted by assembler. So has to use following less efficient pattern.
763 __ASM
volatile ("ldrht %0, [%1]" : "=r" (result
) : "r" (addr
) : "memory" );
765 return ((uint16_t) result
); /* Add explicit type cast here */
770 \brief LDRT Unprivileged (32 bit)
771 \details Executes a Unprivileged LDRT instruction for 32 bit values.
772 \param [in] ptr Pointer to data
773 \return value of type uint32_t at (*ptr)
775 __attribute__((always_inline
)) __STATIC_INLINE
uint32_t __LDRT(volatile uint32_t *addr
)
779 __ASM
volatile ("ldrt %0, %1" : "=r" (result
) : "Q" (*addr
) );
785 \brief STRT Unprivileged (8 bit)
786 \details Executes a Unprivileged STRT instruction for 8 bit values.
787 \param [in] value Value to store
788 \param [in] ptr Pointer to location
790 __attribute__((always_inline
)) __STATIC_INLINE
void __STRBT(uint8_t value
, volatile uint8_t *addr
)
792 __ASM
volatile ("strbt %1, %0" : "=Q" (*addr
) : "r" ((uint32_t)value
) );
797 \brief STRT Unprivileged (16 bit)
798 \details Executes a Unprivileged STRT instruction for 16 bit values.
799 \param [in] value Value to store
800 \param [in] ptr Pointer to location
802 __attribute__((always_inline
)) __STATIC_INLINE
void __STRHT(uint16_t value
, volatile uint16_t *addr
)
804 __ASM
volatile ("strht %1, %0" : "=Q" (*addr
) : "r" ((uint32_t)value
) );
809 \brief STRT Unprivileged (32 bit)
810 \details Executes a Unprivileged STRT instruction for 32 bit values.
811 \param [in] value Value to store
812 \param [in] ptr Pointer to location
814 __attribute__((always_inline
)) __STATIC_INLINE
void __STRT(uint32_t value
, volatile uint32_t *addr
)
816 __ASM
volatile ("strt %1, %0" : "=Q" (*addr
) : "r" (value
) );
819 #endif /* (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) */
821 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
824 /* ################### Compiler specific Intrinsics ########################### */
825 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
826 Access to dedicated SIMD instructions
830 #if (__CORTEX_M >= 0x04U) /* only for Cortex-M4 and above */
832 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SADD8(uint32_t op1
, uint32_t op2
)
836 __ASM
volatile ("sadd8 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
840 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __QADD8(uint32_t op1
, uint32_t op2
)
844 __ASM
volatile ("qadd8 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
848 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SHADD8(uint32_t op1
, uint32_t op2
)
852 __ASM
volatile ("shadd8 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
856 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UADD8(uint32_t op1
, uint32_t op2
)
860 __ASM
volatile ("uadd8 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
864 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UQADD8(uint32_t op1
, uint32_t op2
)
868 __ASM
volatile ("uqadd8 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
872 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UHADD8(uint32_t op1
, uint32_t op2
)
876 __ASM
volatile ("uhadd8 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
881 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SSUB8(uint32_t op1
, uint32_t op2
)
885 __ASM
volatile ("ssub8 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
889 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __QSUB8(uint32_t op1
, uint32_t op2
)
893 __ASM
volatile ("qsub8 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
897 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SHSUB8(uint32_t op1
, uint32_t op2
)
901 __ASM
volatile ("shsub8 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
905 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __USUB8(uint32_t op1
, uint32_t op2
)
909 __ASM
volatile ("usub8 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
913 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UQSUB8(uint32_t op1
, uint32_t op2
)
917 __ASM
volatile ("uqsub8 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
921 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UHSUB8(uint32_t op1
, uint32_t op2
)
925 __ASM
volatile ("uhsub8 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
930 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SADD16(uint32_t op1
, uint32_t op2
)
934 __ASM
volatile ("sadd16 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
938 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __QADD16(uint32_t op1
, uint32_t op2
)
942 __ASM
volatile ("qadd16 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
946 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SHADD16(uint32_t op1
, uint32_t op2
)
950 __ASM
volatile ("shadd16 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
954 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UADD16(uint32_t op1
, uint32_t op2
)
958 __ASM
volatile ("uadd16 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
962 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UQADD16(uint32_t op1
, uint32_t op2
)
966 __ASM
volatile ("uqadd16 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
970 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UHADD16(uint32_t op1
, uint32_t op2
)
974 __ASM
volatile ("uhadd16 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
978 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SSUB16(uint32_t op1
, uint32_t op2
)
982 __ASM
volatile ("ssub16 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
986 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __QSUB16(uint32_t op1
, uint32_t op2
)
990 __ASM
volatile ("qsub16 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
994 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SHSUB16(uint32_t op1
, uint32_t op2
)
998 __ASM
volatile ("shsub16 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1002 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __USUB16(uint32_t op1
, uint32_t op2
)
1006 __ASM
volatile ("usub16 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1010 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UQSUB16(uint32_t op1
, uint32_t op2
)
1014 __ASM
volatile ("uqsub16 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1018 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UHSUB16(uint32_t op1
, uint32_t op2
)
1022 __ASM
volatile ("uhsub16 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1026 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SASX(uint32_t op1
, uint32_t op2
)
1030 __ASM
volatile ("sasx %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1034 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __QASX(uint32_t op1
, uint32_t op2
)
1038 __ASM
volatile ("qasx %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1042 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SHASX(uint32_t op1
, uint32_t op2
)
1046 __ASM
volatile ("shasx %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1050 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UASX(uint32_t op1
, uint32_t op2
)
1054 __ASM
volatile ("uasx %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1058 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UQASX(uint32_t op1
, uint32_t op2
)
1062 __ASM
volatile ("uqasx %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1066 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UHASX(uint32_t op1
, uint32_t op2
)
1070 __ASM
volatile ("uhasx %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1074 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SSAX(uint32_t op1
, uint32_t op2
)
1078 __ASM
volatile ("ssax %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1082 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __QSAX(uint32_t op1
, uint32_t op2
)
1086 __ASM
volatile ("qsax %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1090 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SHSAX(uint32_t op1
, uint32_t op2
)
1094 __ASM
volatile ("shsax %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1098 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __USAX(uint32_t op1
, uint32_t op2
)
1102 __ASM
volatile ("usax %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1106 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UQSAX(uint32_t op1
, uint32_t op2
)
1110 __ASM
volatile ("uqsax %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1114 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UHSAX(uint32_t op1
, uint32_t op2
)
1118 __ASM
volatile ("uhsax %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1122 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __USAD8(uint32_t op1
, uint32_t op2
)
1126 __ASM
volatile ("usad8 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1130 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __USADA8(uint32_t op1
, uint32_t op2
, uint32_t op3
)
1134 __ASM
volatile ("usada8 %0, %1, %2, %3" : "=r" (result
) : "r" (op1
), "r" (op2
), "r" (op3
) );
1138 #define __SSAT16(ARG1,ARG2) \
1140 int32_t __RES, __ARG1 = (ARG1); \
1141 __ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
1145 #define __USAT16(ARG1,ARG2) \
1147 uint32_t __RES, __ARG1 = (ARG1); \
1148 __ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
1152 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UXTB16(uint32_t op1
)
1156 __ASM
volatile ("uxtb16 %0, %1" : "=r" (result
) : "r" (op1
));
1160 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __UXTAB16(uint32_t op1
, uint32_t op2
)
1164 __ASM
volatile ("uxtab16 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1168 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SXTB16(uint32_t op1
)
1172 __ASM
volatile ("sxtb16 %0, %1" : "=r" (result
) : "r" (op1
));
1176 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SXTAB16(uint32_t op1
, uint32_t op2
)
1180 __ASM
volatile ("sxtab16 %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1184 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SMUAD (uint32_t op1
, uint32_t op2
)
1188 __ASM
volatile ("smuad %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1192 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SMUADX (uint32_t op1
, uint32_t op2
)
1196 __ASM
volatile ("smuadx %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1200 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SMLAD (uint32_t op1
, uint32_t op2
, uint32_t op3
)
1204 __ASM
volatile ("smlad %0, %1, %2, %3" : "=r" (result
) : "r" (op1
), "r" (op2
), "r" (op3
) );
1208 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SMLADX (uint32_t op1
, uint32_t op2
, uint32_t op3
)
1212 __ASM
volatile ("smladx %0, %1, %2, %3" : "=r" (result
) : "r" (op1
), "r" (op2
), "r" (op3
) );
1216 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint64_t __SMLALD (uint32_t op1
, uint32_t op2
, uint64_t acc
)
1224 #ifndef __ARMEB__ /* Little endian */
1225 __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]) );
1226 #else /* Big endian */
1227 __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]) );
1233 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint64_t __SMLALDX (uint32_t op1
, uint32_t op2
, uint64_t acc
)
1241 #ifndef __ARMEB__ /* Little endian */
1242 __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]) );
1243 #else /* Big endian */
1244 __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]) );
1250 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SMUSD (uint32_t op1
, uint32_t op2
)
1254 __ASM
volatile ("smusd %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1258 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SMUSDX (uint32_t op1
, uint32_t op2
)
1262 __ASM
volatile ("smusdx %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1266 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SMLSD (uint32_t op1
, uint32_t op2
, uint32_t op3
)
1270 __ASM
volatile ("smlsd %0, %1, %2, %3" : "=r" (result
) : "r" (op1
), "r" (op2
), "r" (op3
) );
1274 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SMLSDX (uint32_t op1
, uint32_t op2
, uint32_t op3
)
1278 __ASM
volatile ("smlsdx %0, %1, %2, %3" : "=r" (result
) : "r" (op1
), "r" (op2
), "r" (op3
) );
1282 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint64_t __SMLSLD (uint32_t op1
, uint32_t op2
, uint64_t acc
)
1290 #ifndef __ARMEB__ /* Little endian */
1291 __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]) );
1292 #else /* Big endian */
1293 __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]) );
1299 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint64_t __SMLSLDX (uint32_t op1
, uint32_t op2
, uint64_t acc
)
1307 #ifndef __ARMEB__ /* Little endian */
1308 __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]) );
1309 #else /* Big endian */
1310 __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]) );
1316 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SEL (uint32_t op1
, uint32_t op2
)
1320 __ASM
volatile ("sel %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1324 __attribute__( ( always_inline
) ) __STATIC_INLINE
int32_t __QADD( int32_t op1
, int32_t op2
)
1328 __ASM
volatile ("qadd %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1332 __attribute__( ( always_inline
) ) __STATIC_INLINE
int32_t __QSUB( int32_t op1
, int32_t op2
)
1336 __ASM
volatile ("qsub %0, %1, %2" : "=r" (result
) : "r" (op1
), "r" (op2
) );
1340 #define __PKHBT(ARG1,ARG2,ARG3) \
1342 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
1343 __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
1347 #define __PKHTB(ARG1,ARG2,ARG3) \
1349 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
1351 __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \
1353 __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
1357 __attribute__( ( always_inline
) ) __STATIC_INLINE
uint32_t __SMMLA (int32_t op1
, int32_t op2
, int32_t op3
)
1361 __ASM
volatile ("smmla %0, %1, %2, %3" : "=r" (result
): "r" (op1
), "r" (op2
), "r" (op3
) );
1365 #endif /* (__CORTEX_M >= 0x04) */
1366 /*@} end of group CMSIS_SIMD_intrinsics */
1369 #if defined ( __GNUC__ )
1370 #pragma GCC diagnostic pop
1373 #endif /* __CMSIS_GCC_H */