1 /**************************************************************************//**
\r
3 * @brief CMSIS Cortex-M Core Function/Instruction Header File
\r
5 * @date 02. March 2016
\r
6 ******************************************************************************/
\r
8 * Copyright (c) 2009-2016 ARM Limited. All rights reserved.
\r
10 * SPDX-License-Identifier: Apache-2.0
\r
12 * Licensed under the Apache License, Version 2.0 (the License); you may
\r
13 * not use this file except in compliance with the License.
\r
14 * You may obtain a copy of the License at
\r
16 * http://www.apache.org/licenses/LICENSE-2.0
\r
18 * Unless required by applicable law or agreed to in writing, software
\r
19 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
\r
20 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
21 * See the License for the specific language governing permissions and
\r
22 * limitations under the License.
\r
25 #ifndef __CMSIS_GCC_H
\r
26 #define __CMSIS_GCC_H
\r
28 /* ignore some GCC warnings */
\r
29 #if defined ( __GNUC__ )
\r
30 #pragma GCC diagnostic push
\r
31 #pragma GCC diagnostic ignored "-Wsign-conversion"
\r
32 #pragma GCC diagnostic ignored "-Wconversion"
\r
33 #pragma GCC diagnostic ignored "-Wunused-parameter"
\r
37 /* ########################### Core Function Access ########################### */
\r
38 /** \ingroup CMSIS_Core_FunctionInterface
\r
39 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
\r
44 \brief Enable IRQ Interrupts
\r
45 \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
\r
46 Can only be executed in Privileged modes.
\r
48 __attribute__((always_inline)) __STATIC_INLINE void __enable_irq(void)
\r
50 __ASM volatile ("cpsie i" : : : "memory");
\r
55 \brief Disable IRQ Interrupts
\r
56 \details Disables IRQ interrupts by setting the I-bit in the CPSR.
\r
57 Can only be executed in Privileged modes.
\r
59 __attribute__((always_inline)) __STATIC_INLINE void __disable_irq(void)
\r
61 __ASM volatile ("cpsid i" : : : "memory");
\r
66 \brief Get Control Register
\r
67 \details Returns the content of the Control Register.
\r
68 \return Control Register value
\r
70 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_CONTROL(void)
\r
74 __ASM volatile ("MRS %0, control" : "=r" (result) );
\r
80 \brief Set Control Register
\r
81 \details Writes the given value to the Control Register.
\r
82 \param [in] control Control Register value to set
\r
84 __attribute__((always_inline)) __STATIC_INLINE void __set_CONTROL(uint32_t control)
\r
86 __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
\r
91 \brief Get IPSR Register
\r
92 \details Returns the content of the IPSR Register.
\r
93 \return IPSR Register value
\r
95 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_IPSR(void)
\r
99 __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
\r
105 \brief Get APSR Register
\r
106 \details Returns the content of the APSR Register.
\r
107 \return APSR Register value
\r
109 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_APSR(void)
\r
113 __ASM volatile ("MRS %0, apsr" : "=r" (result) );
\r
119 \brief Get xPSR Register
\r
120 \details Returns the content of the xPSR Register.
\r
121 \return xPSR Register value
\r
123 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_xPSR(void)
\r
127 __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
\r
133 \brief Get Process Stack Pointer
\r
134 \details Returns the current value of the Process Stack Pointer (PSP).
\r
135 \return PSP Register value
\r
137 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_PSP(void)
\r
139 register uint32_t result;
\r
141 __ASM volatile ("MRS %0, psp" : "=r" (result) );
\r
147 \brief Set Process Stack Pointer
\r
148 \details Assigns the given value to the Process Stack Pointer (PSP).
\r
149 \param [in] topOfProcStack Process Stack Pointer value to set
\r
151 __attribute__((always_inline)) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
\r
153 __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : "sp");
\r
158 \brief Get Main Stack Pointer
\r
159 \details Returns the current value of the Main Stack Pointer (MSP).
\r
160 \return MSP Register value
\r
162 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_MSP(void)
\r
164 register uint32_t result;
\r
166 __ASM volatile ("MRS %0, msp" : "=r" (result) );
\r
172 \brief Set Main Stack Pointer
\r
173 \details Assigns the given value to the Main Stack Pointer (MSP).
\r
174 \param [in] topOfMainStack Main Stack Pointer value to set
\r
176 __attribute__((always_inline)) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
\r
178 __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : "sp");
\r
183 \brief Get Priority Mask
\r
184 \details Returns the current state of the priority mask bit from the Priority Mask Register.
\r
185 \return Priority Mask value
\r
187 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_PRIMASK(void)
\r
191 __ASM volatile ("MRS %0, primask" : "=r" (result) );
\r
197 \brief Set Priority Mask
\r
198 \details Assigns the given value to the Priority Mask Register.
\r
199 \param [in] priMask Priority Mask
\r
201 __attribute__((always_inline)) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
\r
203 __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
\r
207 #if (defined (__CORTEX_M) && (__CORTEX_M >= 0x03U) || (defined (__CORTEX_SC) && (__CORTEX_SC >= 300U)))
\r
211 \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
\r
212 Can only be executed in Privileged modes.
\r
214 __attribute__((always_inline)) __STATIC_INLINE void __enable_fault_irq(void)
\r
216 __ASM volatile ("cpsie f" : : : "memory");
\r
222 \details Disables FIQ interrupts by setting the F-bit in the CPSR.
\r
223 Can only be executed in Privileged modes.
\r
225 __attribute__((always_inline)) __STATIC_INLINE void __disable_fault_irq(void)
\r
227 __ASM volatile ("cpsid f" : : : "memory");
\r
232 \brief Get Base Priority
\r
233 \details Returns the current value of the Base Priority register.
\r
234 \return Base Priority register value
\r
236 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_BASEPRI(void)
\r
240 __ASM volatile ("MRS %0, basepri" : "=r" (result) );
\r
246 \brief Set Base Priority
\r
247 \details Assigns the given value to the Base Priority register.
\r
248 \param [in] basePri Base Priority value to set
\r
250 __attribute__((always_inline)) __STATIC_INLINE void __set_BASEPRI(uint32_t value)
\r
252 __ASM volatile ("MSR basepri, %0" : : "r" (value) : "memory");
\r
257 \brief Set Base Priority with condition
\r
258 \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
\r
259 or the new value increases the BASEPRI priority level.
\r
260 \param [in] basePri Base Priority value to set
\r
262 __attribute__((always_inline)) __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t value)
\r
264 __ASM volatile ("MSR basepri_max, %0" : : "r" (value) : "memory");
\r
269 \brief Get Fault Mask
\r
270 \details Returns the current value of the Fault Mask register.
\r
271 \return Fault Mask register value
\r
273 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_FAULTMASK(void)
\r
277 __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
\r
283 \brief Set Fault Mask
\r
284 \details Assigns the given value to the Fault Mask register.
\r
285 \param [in] faultMask Fault Mask value to set
\r
287 __attribute__((always_inline)) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
\r
289 __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
\r
292 #endif /* (defined (__CORTEX_M) && (__CORTEX_M >= 0x03U) || (defined (__CORTEX_SC) && (__CORTEX_SC >= 300U))) */
\r
295 #if (defined (__CORTEX_M) && ((__CORTEX_M == 0x04U) || (__CORTEX_SC == 0x07U)))
\r
299 \details Returns the current value of the Floating Point Status/Control register.
\r
300 \return Floating Point Status/Control register value
\r
302 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_FPSCR(void)
\r
304 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && (defined (__FPU_USED) && (__FPU_USED == 1U)))
\r
307 __ASM volatile (""); /* Empty asm statement works as a scheduling barrier */
\r
308 __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
\r
309 __ASM volatile ("");
\r
319 \details Assigns the given value to the Floating Point Status/Control register.
\r
320 \param [in] fpscr Floating Point Status/Control value to set
\r
322 __attribute__((always_inline)) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
\r
324 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && (defined (__FPU_USED) && (__FPU_USED == 1U)))
\r
325 __ASM volatile (""); /* Empty asm statement works as a scheduling barrier */
\r
326 __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc");
\r
327 __ASM volatile ("");
\r
331 #endif /* (defined (__CORTEX_M) && ((__CORTEX_M == 0x04U) || (__CORTEX_SC == 0x07U))) */
\r
335 /*@} end of CMSIS_Core_RegAccFunctions */
\r
338 /* ########################## Core Instruction Access ######################### */
\r
339 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
\r
340 Access to dedicated instructions
\r
344 /* Define macros for porting to both thumb1 and thumb2.
\r
345 * For thumb1, use low register (r0-r7), specified by constraint "l"
\r
346 * Otherwise, use general registers, specified by constraint "r" */
\r
347 #if defined (__thumb__) && !defined (__thumb2__)
\r
348 #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
\r
349 #define __CMSIS_GCC_USE_REG(r) "l" (r)
\r
351 #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
\r
352 #define __CMSIS_GCC_USE_REG(r) "r" (r)
\r
356 \brief No Operation
\r
357 \details No Operation does nothing. This instruction can be used for code alignment purposes.
\r
359 __attribute__((always_inline)) __STATIC_INLINE void __NOP(void)
\r
361 __ASM volatile ("nop");
\r
366 \brief Wait For Interrupt
\r
367 \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
\r
369 __attribute__((always_inline)) __STATIC_INLINE void __WFI(void)
\r
371 __ASM volatile ("wfi");
\r
376 \brief Wait For Event
\r
377 \details Wait For Event is a hint instruction that permits the processor to enter
\r
378 a low-power state until one of a number of events occurs.
\r
380 __attribute__((always_inline)) __STATIC_INLINE void __WFE(void)
\r
382 __ASM volatile ("wfe");
\r
388 \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
\r
390 __attribute__((always_inline)) __STATIC_INLINE void __SEV(void)
\r
392 __ASM volatile ("sev");
\r
397 \brief Instruction Synchronization Barrier
\r
398 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
\r
399 so that all instructions following the ISB are fetched from cache or memory,
\r
400 after the instruction has been completed.
\r
402 __attribute__((always_inline)) __STATIC_INLINE void __ISB(void)
\r
404 __ASM volatile ("isb 0xF":::"memory");
\r
409 \brief Data Synchronization Barrier
\r
410 \details Acts as a special kind of Data Memory Barrier.
\r
411 It completes when all explicit memory accesses before this instruction complete.
\r
413 __attribute__((always_inline)) __STATIC_INLINE void __DSB(void)
\r
415 __ASM volatile ("dsb 0xF":::"memory");
\r
420 \brief Data Memory Barrier
\r
421 \details Ensures the apparent order of the explicit memory operations before
\r
422 and after the instruction, without ensuring their completion.
\r
424 __attribute__((always_inline)) __STATIC_INLINE void __DMB(void)
\r
426 __ASM volatile ("dmb 0xF":::"memory");
\r
431 \brief Reverse byte order (32 bit)
\r
432 \details Reverses the byte order in integer value.
\r
433 \param [in] value Value to reverse
\r
434 \return Reversed value
\r
436 __attribute__((always_inline)) __STATIC_INLINE uint32_t __REV(uint32_t value)
\r
438 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
\r
439 return __builtin_bswap32(value);
\r
443 __ASM volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
\r
450 \brief Reverse byte order (16 bit)
\r
451 \details Reverses the byte order in two unsigned short values.
\r
452 \param [in] value Value to reverse
\r
453 \return Reversed value
\r
455 __attribute__((always_inline)) __STATIC_INLINE uint32_t __REV16(uint32_t value)
\r
459 __ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
\r
465 \brief Reverse byte order in signed short value
\r
466 \details Reverses the byte order in a signed short value with sign extension to integer.
\r
467 \param [in] value Value to reverse
\r
468 \return Reversed value
\r
470 __attribute__((always_inline)) __STATIC_INLINE int32_t __REVSH(int32_t value)
\r
472 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
\r
473 return (short)__builtin_bswap16(value);
\r
477 __ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
\r
484 \brief Rotate Right in unsigned value (32 bit)
\r
485 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
\r
486 \param [in] op1 Value to rotate
\r
487 \param [in] op2 Number of Bits to rotate
\r
488 \return Rotated value
\r
490 __attribute__((always_inline)) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
\r
492 return (op1 >> op2) | (op1 << (32U - op2));
\r
498 \details Causes the processor to enter Debug state.
\r
499 Debug tools can use this to investigate system state when the instruction at a particular address is reached.
\r
500 \param [in] value is ignored by the processor.
\r
501 If required, a debugger can use it to store additional information about the breakpoint.
\r
503 #define __BKPT(value) __ASM volatile ("bkpt "#value)
\r
507 \brief Reverse bit order of value
\r
508 \details Reverses the bit order of the given value.
\r
509 \param [in] value Value to reverse
\r
510 \return Reversed value
\r
512 __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
\r
516 #if (defined (__CORTEX_M) && (__CORTEX_M >= 0x03U) || (defined (__CORTEX_SC) && (__CORTEX_SC >= 300U)))
\r
517 __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
\r
519 int32_t s = 4 /*sizeof(v)*/ * 8 - 1; /* extra shift needed at end */
\r
521 result = value; /* r will be reversed bits of v; first get LSB of v */
\r
522 for (value >>= 1U; value; value >>= 1U)
\r
525 result |= value & 1U;
\r
528 result <<= s; /* shift when v's highest bits are zero */
\r
535 \brief Count leading zeros
\r
536 \details Counts the number of leading zeros of a data value.
\r
537 \param [in] value Value to count the leading zeros
\r
538 \return number of leading zeros in value
\r
540 #define __CLZ __builtin_clz
\r
543 #if (defined (__CORTEX_M) && (__CORTEX_M >= 0x03U) || (defined (__CORTEX_SC) && (__CORTEX_SC >= 300U)))
\r
546 \brief LDR Exclusive (8 bit)
\r
547 \details Executes a exclusive LDR instruction for 8 bit value.
\r
548 \param [in] ptr Pointer to data
\r
549 \return value of type uint8_t at (*ptr)
\r
551 __attribute__((always_inline)) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t *addr)
\r
555 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
\r
556 __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
\r
558 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
\r
559 accepted by assembler. So has to use following less efficient pattern.
\r
561 __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
\r
563 return ((uint8_t) result); /* Add explicit type cast here */
\r
568 \brief LDR Exclusive (16 bit)
\r
569 \details Executes a exclusive LDR instruction for 16 bit values.
\r
570 \param [in] ptr Pointer to data
\r
571 \return value of type uint16_t at (*ptr)
\r
573 __attribute__((always_inline)) __STATIC_INLINE uint16_t __LDREXH(volatile uint16_t *addr)
\r
577 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
\r
578 __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
\r
580 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
\r
581 accepted by assembler. So has to use following less efficient pattern.
\r
583 __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
\r
585 return ((uint16_t) result); /* Add explicit type cast here */
\r
590 \brief LDR Exclusive (32 bit)
\r
591 \details Executes a exclusive LDR instruction for 32 bit values.
\r
592 \param [in] ptr Pointer to data
\r
593 \return value of type uint32_t at (*ptr)
\r
595 __attribute__((always_inline)) __STATIC_INLINE uint32_t __LDREXW(volatile uint32_t *addr)
\r
599 __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
\r
605 \brief STR Exclusive (8 bit)
\r
606 \details Executes a exclusive STR instruction for 8 bit values.
\r
607 \param [in] value Value to store
\r
608 \param [in] ptr Pointer to location
\r
609 \return 0 Function succeeded
\r
610 \return 1 Function failed
\r
612 __attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
\r
616 __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
\r
622 \brief STR Exclusive (16 bit)
\r
623 \details Executes a exclusive STR instruction for 16 bit values.
\r
624 \param [in] value Value to store
\r
625 \param [in] ptr Pointer to location
\r
626 \return 0 Function succeeded
\r
627 \return 1 Function failed
\r
629 __attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
\r
633 __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
\r
639 \brief STR Exclusive (32 bit)
\r
640 \details Executes a exclusive STR instruction for 32 bit values.
\r
641 \param [in] value Value to store
\r
642 \param [in] ptr Pointer to location
\r
643 \return 0 Function succeeded
\r
644 \return 1 Function failed
\r
646 __attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
\r
650 __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
\r
656 \brief Remove the exclusive lock
\r
657 \details Removes the exclusive lock which is created by LDREX.
\r
659 __attribute__((always_inline)) __STATIC_INLINE void __CLREX(void)
\r
661 __ASM volatile ("clrex" ::: "memory");
\r
666 \brief Signed Saturate
\r
667 \details Saturates a signed value.
\r
668 \param [in] value Value to be saturated
\r
669 \param [in] sat Bit position to saturate to (1..32)
\r
670 \return Saturated value
\r
672 #define __SSAT(ARG1,ARG2) \
\r
674 int32_t __RES, __ARG1 = (ARG1); \
\r
675 __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
\r
681 \brief Unsigned Saturate
\r
682 \details Saturates an unsigned value.
\r
683 \param [in] value Value to be saturated
\r
684 \param [in] sat Bit position to saturate to (0..31)
\r
685 \return Saturated value
\r
687 #define __USAT(ARG1,ARG2) \
\r
689 uint32_t __RES, __ARG1 = (ARG1); \
\r
690 __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
\r
696 \brief Rotate Right with Extend (32 bit)
\r
697 \details Moves each bit of a bitstring right by one bit.
\r
698 The carry input is shifted in at the left end of the bitstring.
\r
699 \param [in] value Value to rotate
\r
700 \return Rotated value
\r
702 __attribute__((always_inline)) __STATIC_INLINE uint32_t __RRX(uint32_t value)
\r
706 __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
\r
712 \brief LDRT Unprivileged (8 bit)
\r
713 \details Executes a Unprivileged LDRT instruction for 8 bit value.
\r
714 \param [in] ptr Pointer to data
\r
715 \return value of type uint8_t at (*ptr)
\r
717 __attribute__((always_inline)) __STATIC_INLINE uint8_t __LDRBT(volatile uint8_t *ptr)
\r
721 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
\r
722 __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
\r
724 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
\r
725 accepted by assembler. So has to use following less efficient pattern.
\r
727 __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" );
\r
729 return ((uint8_t) result); /* Add explicit type cast here */
\r
734 \brief LDRT Unprivileged (16 bit)
\r
735 \details Executes a Unprivileged LDRT instruction for 16 bit values.
\r
736 \param [in] ptr Pointer to data
\r
737 \return value of type uint16_t at (*ptr)
\r
739 __attribute__((always_inline)) __STATIC_INLINE uint16_t __LDRHT(volatile uint16_t *ptr)
\r
743 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
\r
744 __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
\r
746 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
\r
747 accepted by assembler. So has to use following less efficient pattern.
\r
749 __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" );
\r
751 return ((uint16_t) result); /* Add explicit type cast here */
\r
756 \brief LDRT Unprivileged (32 bit)
\r
757 \details Executes a Unprivileged LDRT instruction for 32 bit values.
\r
758 \param [in] ptr Pointer to data
\r
759 \return value of type uint32_t at (*ptr)
\r
761 __attribute__((always_inline)) __STATIC_INLINE uint32_t __LDRT(volatile uint32_t *ptr)
\r
765 __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
\r
771 \brief STRT Unprivileged (8 bit)
\r
772 \details Executes a Unprivileged STRT instruction for 8 bit values.
\r
773 \param [in] value Value to store
\r
774 \param [in] ptr Pointer to location
\r
776 __attribute__((always_inline)) __STATIC_INLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
\r
778 __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
\r
783 \brief STRT Unprivileged (16 bit)
\r
784 \details Executes a Unprivileged STRT instruction for 16 bit values.
\r
785 \param [in] value Value to store
\r
786 \param [in] ptr Pointer to location
\r
788 __attribute__((always_inline)) __STATIC_INLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
\r
790 __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
\r
795 \brief STRT Unprivileged (32 bit)
\r
796 \details Executes a Unprivileged STRT instruction for 32 bit values.
\r
797 \param [in] value Value to store
\r
798 \param [in] ptr Pointer to location
\r
800 __attribute__((always_inline)) __STATIC_INLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
\r
802 __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
\r
805 #endif /* (defined (__CORTEX_M) && (__CORTEX_M >= 0x03U) || (defined (__CORTEX_SC) && (__CORTEX_SC >= 300U))) */
\r
807 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
\r
810 /* ################### Compiler specific Intrinsics ########################### */
\r
811 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
\r
812 Access to dedicated SIMD instructions
\r
816 #if (defined (__CORTEX_M) && (__CORTEX_M >= 0x04U)) /* only for Cortex-M4 and above */
\r
818 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SADD8(uint32_t op1, uint32_t op2)
\r
822 __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
826 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
\r
830 __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
834 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2)
\r
838 __ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
842 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UADD8(uint32_t op1, uint32_t op2)
\r
846 __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
850 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2)
\r
854 __ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
858 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2)
\r
862 __ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
867 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2)
\r
871 __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
875 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
\r
879 __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
883 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2)
\r
887 __ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
891 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USUB8(uint32_t op1, uint32_t op2)
\r
895 __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
899 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2)
\r
903 __ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
907 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2)
\r
911 __ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
916 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SADD16(uint32_t op1, uint32_t op2)
\r
920 __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
924 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
\r
928 __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
932 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
\r
936 __ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
940 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UADD16(uint32_t op1, uint32_t op2)
\r
944 __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
948 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2)
\r
952 __ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
956 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2)
\r
960 __ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
964 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2)
\r
968 __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
972 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
\r
976 __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
980 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
\r
984 __ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
988 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USUB16(uint32_t op1, uint32_t op2)
\r
992 __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
996 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2)
\r
1000 __ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1004 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2)
\r
1008 __ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1012 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SASX(uint32_t op1, uint32_t op2)
\r
1016 __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1020 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
\r
1024 __ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1028 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
\r
1032 __ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1036 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UASX(uint32_t op1, uint32_t op2)
\r
1040 __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1044 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQASX(uint32_t op1, uint32_t op2)
\r
1048 __ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1052 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHASX(uint32_t op1, uint32_t op2)
\r
1056 __ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1060 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SSAX(uint32_t op1, uint32_t op2)
\r
1064 __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1068 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
\r
1072 __ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1076 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
\r
1080 __ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1084 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USAX(uint32_t op1, uint32_t op2)
\r
1088 __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1092 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2)
\r
1096 __ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1100 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2)
\r
1104 __ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1108 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USAD8(uint32_t op1, uint32_t op2)
\r
1112 __ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1116 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3)
\r
1120 __ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
\r
1124 #define __SSAT16(ARG1,ARG2) \
\r
1126 int32_t __RES, __ARG1 = (ARG1); \
\r
1127 __ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
\r
1131 #define __USAT16(ARG1,ARG2) \
\r
1133 uint32_t __RES, __ARG1 = (ARG1); \
\r
1134 __ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
\r
1138 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UXTB16(uint32_t op1)
\r
1142 __ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1));
\r
1146 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2)
\r
1150 __ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1154 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SXTB16(uint32_t op1)
\r
1158 __ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
\r
1162 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2)
\r
1166 __ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1170 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
\r
1174 __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1178 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
\r
1182 __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1186 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
\r
1190 __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
\r
1194 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
\r
1198 __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
\r
1202 __attribute__((always_inline)) __STATIC_INLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
\r
1210 #ifndef __ARMEB__ /* Little endian */
\r
1211 __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]) );
\r
1212 #else /* Big endian */
\r
1213 __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]) );
\r
1219 __attribute__((always_inline)) __STATIC_INLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
\r
1227 #ifndef __ARMEB__ /* Little endian */
\r
1228 __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]) );
\r
1229 #else /* Big endian */
\r
1230 __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]) );
\r
1236 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
\r
1240 __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1244 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
\r
1248 __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1252 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3)
\r
1256 __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
\r
1260 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
\r
1264 __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
\r
1268 __attribute__((always_inline)) __STATIC_INLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc)
\r
1276 #ifndef __ARMEB__ /* Little endian */
\r
1277 __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]) );
\r
1278 #else /* Big endian */
\r
1279 __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]) );
\r
1285 __attribute__((always_inline)) __STATIC_INLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc)
\r
1293 #ifndef __ARMEB__ /* Little endian */
\r
1294 __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]) );
\r
1295 #else /* Big endian */
\r
1296 __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]) );
\r
1302 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SEL (uint32_t op1, uint32_t op2)
\r
1306 __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1310 __attribute__((always_inline)) __STATIC_INLINE int32_t __QADD( int32_t op1, int32_t op2)
\r
1314 __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1318 __attribute__((always_inline)) __STATIC_INLINE int32_t __QSUB( int32_t op1, int32_t op2)
\r
1322 __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
\r
1326 #define __PKHBT(ARG1,ARG2,ARG3) \
\r
1328 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
\r
1329 __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
\r
1333 #define __PKHTB(ARG1,ARG2,ARG3) \
\r
1335 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
\r
1337 __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \
\r
1339 __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
\r
1343 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
\r
1347 __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
\r
1351 #endif /* (defined (__CORTEX_M) && (__CORTEX_M >= 0x04U)) */
\r
1352 /*@} end of group CMSIS_SIMD_intrinsics */
\r
1355 #if defined ( __GNUC__ )
\r
1356 #pragma GCC diagnostic pop
\r
1359 #endif /* __CMSIS_GCC_H */
\r