1 /**************************************************************************//**
3 * @brief CMSIS Cortex-M Core Function/Instruction Header File
5 * @date 13. September 2016
6 ******************************************************************************/
8 * Copyright (c) 2009-2016 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 * http://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.
25 #ifndef __CMSIS_ARMCC_H
26 #define __CMSIS_ARMCC_H
29 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677)
30 #error "Please use ARM Compiler Toolchain V4.0.677 or later!"
33 /* CMSIS compiler specific defines */
38 #define __INLINE __inline
40 #ifndef __STATIC_INLINE
41 #define __STATIC_INLINE static __inline
44 #define __NO_RETURN __declspec(noreturn)
47 #define __USED __attribute__((used))
50 #define __WEAK __attribute__((weak))
52 #ifndef __UNALIGNED_UINT32
53 #define __UNALIGNED_UINT32(x) (*((__packed uint32_t *)(x)))
56 #define __ALIGNED(x) __attribute__((aligned(x)))
59 #define __PACKED __attribute__((packed))
63 /* ########################### Core Function Access ########################### */
64 /** \ingroup CMSIS_Core_FunctionInterface
65 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
70 \brief Enable IRQ Interrupts
71 \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
72 Can only be executed in Privileged modes.
74 /* intrinsic void __enable_irq(); */
78 \brief Disable IRQ Interrupts
79 \details Disables IRQ interrupts by setting the I-bit in the CPSR.
80 Can only be executed in Privileged modes.
82 /* intrinsic void __disable_irq(); */
85 \brief Get Control Register
86 \details Returns the content of the Control Register.
87 \return Control Register value
89 __STATIC_INLINE uint32_t __get_CONTROL(void)
91 register uint32_t __regControl __ASM("control");
97 \brief Set Control Register
98 \details Writes the given value to the Control Register.
99 \param [in] control Control Register value to set
101 __STATIC_INLINE void __set_CONTROL(uint32_t control)
103 register uint32_t __regControl __ASM("control");
104 __regControl = control;
109 \brief Get IPSR Register
110 \details Returns the content of the IPSR Register.
111 \return IPSR Register value
113 __STATIC_INLINE uint32_t __get_IPSR(void)
115 register uint32_t __regIPSR __ASM("ipsr");
121 \brief Get APSR Register
122 \details Returns the content of the APSR Register.
123 \return APSR Register value
125 __STATIC_INLINE uint32_t __get_APSR(void)
127 register uint32_t __regAPSR __ASM("apsr");
133 \brief Get xPSR Register
134 \details Returns the content of the xPSR Register.
135 \return xPSR Register value
137 __STATIC_INLINE uint32_t __get_xPSR(void)
139 register uint32_t __regXPSR __ASM("xpsr");
145 \brief Get Process Stack Pointer
146 \details Returns the current value of the Process Stack Pointer (PSP).
147 \return PSP Register value
149 __STATIC_INLINE uint32_t __get_PSP(void)
151 register uint32_t __regProcessStackPointer __ASM("psp");
152 return(__regProcessStackPointer);
157 \brief Set Process Stack Pointer
158 \details Assigns the given value to the Process Stack Pointer (PSP).
159 \param [in] topOfProcStack Process Stack Pointer value to set
161 __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
163 register uint32_t __regProcessStackPointer __ASM("psp");
164 __regProcessStackPointer = topOfProcStack;
169 \brief Get Main Stack Pointer
170 \details Returns the current value of the Main Stack Pointer (MSP).
171 \return MSP Register value
173 __STATIC_INLINE uint32_t __get_MSP(void)
175 register uint32_t __regMainStackPointer __ASM("msp");
176 return(__regMainStackPointer);
181 \brief Set Main Stack Pointer
182 \details Assigns the given value to the Main Stack Pointer (MSP).
183 \param [in] topOfMainStack Main Stack Pointer value to set
185 __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
187 register uint32_t __regMainStackPointer __ASM("msp");
188 __regMainStackPointer = topOfMainStack;
193 \brief Get Priority Mask
194 \details Returns the current state of the priority mask bit from the Priority Mask Register.
195 \return Priority Mask value
197 __STATIC_INLINE uint32_t __get_PRIMASK(void)
199 register uint32_t __regPriMask __ASM("primask");
200 return(__regPriMask);
205 \brief Set Priority Mask
206 \details Assigns the given value to the Priority Mask Register.
207 \param [in] priMask Priority Mask
209 __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
211 register uint32_t __regPriMask __ASM("primask");
212 __regPriMask = (priMask);
216 #if ((defined (__TARGET_ARCH_7_M ) && (__TARGET_ARCH_7_M == 1)) || \
217 (defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1)) )
221 \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
222 Can only be executed in Privileged modes.
224 #define __enable_fault_irq __enable_fiq
229 \details Disables FIQ interrupts by setting the F-bit in the CPSR.
230 Can only be executed in Privileged modes.
232 #define __disable_fault_irq __disable_fiq
236 \brief Get Base Priority
237 \details Returns the current value of the Base Priority register.
238 \return Base Priority register value
240 __STATIC_INLINE uint32_t __get_BASEPRI(void)
242 register uint32_t __regBasePri __ASM("basepri");
243 return(__regBasePri);
248 \brief Set Base Priority
249 \details Assigns the given value to the Base Priority register.
250 \param [in] basePri Base Priority value to set
252 __STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
254 register uint32_t __regBasePri __ASM("basepri");
255 __regBasePri = (basePri & 0xFFU);
260 \brief Set Base Priority with condition
261 \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
262 or the new value increases the BASEPRI priority level.
263 \param [in] basePri Base Priority value to set
265 __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri)
267 register uint32_t __regBasePriMax __ASM("basepri_max");
268 __regBasePriMax = (basePri & 0xFFU);
273 \brief Get Fault Mask
274 \details Returns the current value of the Fault Mask register.
275 \return Fault Mask register value
277 __STATIC_INLINE uint32_t __get_FAULTMASK(void)
279 register uint32_t __regFaultMask __ASM("faultmask");
280 return(__regFaultMask);
285 \brief Set Fault Mask
286 \details Assigns the given value to the Fault Mask register.
287 \param [in] faultMask Fault Mask value to set
289 __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
291 register uint32_t __regFaultMask __ASM("faultmask");
292 __regFaultMask = (faultMask & (uint32_t)1U);
295 #endif /* ((defined (__TARGET_ARCH_7_M ) && (__TARGET_ARCH_7_M == 1)) || \
296 (defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1)) ) */
299 #if ((defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1)) )
303 \details Returns the current value of the Floating Point Status/Control register.
304 \return Floating Point Status/Control register value
306 __STATIC_INLINE uint32_t __get_FPSCR(void)
308 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
309 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
310 register uint32_t __regfpscr __ASM("fpscr");
320 \details Assigns the given value to the Floating Point Status/Control register.
321 \param [in] fpscr Floating Point Status/Control value to set
323 __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
325 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
326 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
327 register uint32_t __regfpscr __ASM("fpscr");
328 __regfpscr = (fpscr);
332 #endif /* ((defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1)) ) */
336 /*@} end of CMSIS_Core_RegAccFunctions */
339 /* ########################## Core Instruction Access ######################### */
340 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
341 Access to dedicated instructions
347 \details No Operation does nothing. This instruction can be used for code alignment purposes.
353 \brief Wait For Interrupt
354 \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
360 \brief Wait For Event
361 \details Wait For Event is a hint instruction that permits the processor to enter
362 a low-power state until one of a number of events occurs.
369 \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
375 \brief Instruction Synchronization Barrier
376 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
377 so that all instructions following the ISB are fetched from cache or memory,
378 after the instruction has been completed.
380 #define __ISB() do {\
381 __schedule_barrier();\
383 __schedule_barrier();\
387 \brief Data Synchronization Barrier
388 \details Acts as a special kind of Data Memory Barrier.
389 It completes when all explicit memory accesses before this instruction complete.
391 #define __DSB() do {\
392 __schedule_barrier();\
394 __schedule_barrier();\
398 \brief Data Memory Barrier
399 \details Ensures the apparent order of the explicit memory operations before
400 and after the instruction, without ensuring their completion.
402 #define __DMB() do {\
403 __schedule_barrier();\
405 __schedule_barrier();\
409 \brief Reverse byte order (32 bit)
410 \details Reverses the byte order in integer value.
411 \param [in] value Value to reverse
412 \return Reversed value
418 \brief Reverse byte order (16 bit)
419 \details Reverses the byte order in two unsigned short values.
420 \param [in] value Value to reverse
421 \return Reversed value
423 #ifndef __NO_EMBEDDED_ASM
424 __attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
433 \brief Reverse byte order in signed short value
434 \details Reverses the byte order in a signed short value with sign extension to integer.
435 \param [in] value Value to reverse
436 \return Reversed value
438 #ifndef __NO_EMBEDDED_ASM
439 __attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value)
448 \brief Rotate Right in unsigned value (32 bit)
449 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
450 \param [in] op1 Value to rotate
451 \param [in] op2 Number of Bits to rotate
452 \return Rotated value
459 \details Causes the processor to enter Debug state.
460 Debug tools can use this to investigate system state when the instruction at a particular address is reached.
461 \param [in] value is ignored by the processor.
462 If required, a debugger can use it to store additional information about the breakpoint.
464 #define __BKPT(value) __breakpoint(value)
468 \brief Reverse bit order of value
469 \details Reverses the bit order of the given value.
470 \param [in] value Value to reverse
471 \return Reversed value
473 #if ((defined (__TARGET_ARCH_7_M ) && (__TARGET_ARCH_7_M == 1)) || \
474 (defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1)) )
475 #define __RBIT __rbit
477 __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
480 int32_t s = (4 /*sizeof(v)*/ * 8) - 1; /* extra shift needed at end */
482 result = value; /* r will be reversed bits of v; first get LSB of v */
483 for (value >>= 1U; value; value >>= 1U)
486 result |= value & 1U;
489 result <<= s; /* shift when v's highest bits are zero */
496 \brief Count leading zeros
497 \details Counts the number of leading zeros of a data value.
498 \param [in] value Value to count the leading zeros
499 \return number of leading zeros in value
504 #if ((defined (__TARGET_ARCH_7_M ) && (__TARGET_ARCH_7_M == 1)) || \
505 (defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1)) )
508 \brief LDR Exclusive (8 bit)
509 \details Executes a exclusive LDR instruction for 8 bit value.
510 \param [in] ptr Pointer to data
511 \return value of type uint8_t at (*ptr)
513 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
514 #define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
516 #define __LDREXB(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr)) _Pragma("pop")
521 \brief LDR Exclusive (16 bit)
522 \details Executes a exclusive LDR instruction for 16 bit values.
523 \param [in] ptr Pointer to data
524 \return value of type uint16_t at (*ptr)
526 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
527 #define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
529 #define __LDREXH(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr)) _Pragma("pop")
534 \brief LDR Exclusive (32 bit)
535 \details Executes a exclusive LDR instruction for 32 bit values.
536 \param [in] ptr Pointer to data
537 \return value of type uint32_t at (*ptr)
539 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
540 #define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
542 #define __LDREXW(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr)) _Pragma("pop")
547 \brief STR Exclusive (8 bit)
548 \details Executes a exclusive STR instruction for 8 bit values.
549 \param [in] value Value to store
550 \param [in] ptr Pointer to location
551 \return 0 Function succeeded
552 \return 1 Function failed
554 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
555 #define __STREXB(value, ptr) __strex(value, ptr)
557 #define __STREXB(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
562 \brief STR Exclusive (16 bit)
563 \details Executes a exclusive STR instruction for 16 bit values.
564 \param [in] value Value to store
565 \param [in] ptr Pointer to location
566 \return 0 Function succeeded
567 \return 1 Function failed
569 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
570 #define __STREXH(value, ptr) __strex(value, ptr)
572 #define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
577 \brief STR Exclusive (32 bit)
578 \details Executes a exclusive STR instruction for 32 bit values.
579 \param [in] value Value to store
580 \param [in] ptr Pointer to location
581 \return 0 Function succeeded
582 \return 1 Function failed
584 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
585 #define __STREXW(value, ptr) __strex(value, ptr)
587 #define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
592 \brief Remove the exclusive lock
593 \details Removes the exclusive lock which is created by LDREX.
595 #define __CLREX __clrex
599 \brief Signed Saturate
600 \details Saturates a signed value.
601 \param [in] value Value to be saturated
602 \param [in] sat Bit position to saturate to (1..32)
603 \return Saturated value
605 #define __SSAT __ssat
609 \brief Unsigned Saturate
610 \details Saturates an unsigned value.
611 \param [in] value Value to be saturated
612 \param [in] sat Bit position to saturate to (0..31)
613 \return Saturated value
615 #define __USAT __usat
619 \brief Rotate Right with Extend (32 bit)
620 \details Moves each bit of a bitstring right by one bit.
621 The carry input is shifted in at the left end of the bitstring.
622 \param [in] value Value to rotate
623 \return Rotated value
625 #ifndef __NO_EMBEDDED_ASM
626 __attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value)
635 \brief LDRT Unprivileged (8 bit)
636 \details Executes a Unprivileged LDRT instruction for 8 bit value.
637 \param [in] ptr Pointer to data
638 \return value of type uint8_t at (*ptr)
640 #define __LDRBT(ptr) ((uint8_t ) __ldrt(ptr))
644 \brief LDRT Unprivileged (16 bit)
645 \details Executes a Unprivileged LDRT instruction for 16 bit values.
646 \param [in] ptr Pointer to data
647 \return value of type uint16_t at (*ptr)
649 #define __LDRHT(ptr) ((uint16_t) __ldrt(ptr))
653 \brief LDRT Unprivileged (32 bit)
654 \details Executes a Unprivileged LDRT instruction for 32 bit values.
655 \param [in] ptr Pointer to data
656 \return value of type uint32_t at (*ptr)
658 #define __LDRT(ptr) ((uint32_t ) __ldrt(ptr))
662 \brief STRT Unprivileged (8 bit)
663 \details Executes a Unprivileged STRT instruction for 8 bit values.
664 \param [in] value Value to store
665 \param [in] ptr Pointer to location
667 #define __STRBT(value, ptr) __strt(value, ptr)
671 \brief STRT Unprivileged (16 bit)
672 \details Executes a Unprivileged STRT instruction for 16 bit values.
673 \param [in] value Value to store
674 \param [in] ptr Pointer to location
676 #define __STRHT(value, ptr) __strt(value, ptr)
680 \brief STRT Unprivileged (32 bit)
681 \details Executes a Unprivileged STRT instruction for 32 bit values.
682 \param [in] value Value to store
683 \param [in] ptr Pointer to location
685 #define __STRT(value, ptr) __strt(value, ptr)
687 #endif /* ((defined (__TARGET_ARCH_7_M ) && (__TARGET_ARCH_7_M == 1)) || \
688 (defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1)) ) */
690 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
693 /* ################### Compiler specific Intrinsics ########################### */
694 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
695 Access to dedicated SIMD instructions
699 #if ((defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1)) )
701 #define __SADD8 __sadd8
702 #define __QADD8 __qadd8
703 #define __SHADD8 __shadd8
704 #define __UADD8 __uadd8
705 #define __UQADD8 __uqadd8
706 #define __UHADD8 __uhadd8
707 #define __SSUB8 __ssub8
708 #define __QSUB8 __qsub8
709 #define __SHSUB8 __shsub8
710 #define __USUB8 __usub8
711 #define __UQSUB8 __uqsub8
712 #define __UHSUB8 __uhsub8
713 #define __SADD16 __sadd16
714 #define __QADD16 __qadd16
715 #define __SHADD16 __shadd16
716 #define __UADD16 __uadd16
717 #define __UQADD16 __uqadd16
718 #define __UHADD16 __uhadd16
719 #define __SSUB16 __ssub16
720 #define __QSUB16 __qsub16
721 #define __SHSUB16 __shsub16
722 #define __USUB16 __usub16
723 #define __UQSUB16 __uqsub16
724 #define __UHSUB16 __uhsub16
725 #define __SASX __sasx
726 #define __QASX __qasx
727 #define __SHASX __shasx
728 #define __UASX __uasx
729 #define __UQASX __uqasx
730 #define __UHASX __uhasx
731 #define __SSAX __ssax
732 #define __QSAX __qsax
733 #define __SHSAX __shsax
734 #define __USAX __usax
735 #define __UQSAX __uqsax
736 #define __UHSAX __uhsax
737 #define __USAD8 __usad8
738 #define __USADA8 __usada8
739 #define __SSAT16 __ssat16
740 #define __USAT16 __usat16
741 #define __UXTB16 __uxtb16
742 #define __UXTAB16 __uxtab16
743 #define __SXTB16 __sxtb16
744 #define __SXTAB16 __sxtab16
745 #define __SMUAD __smuad
746 #define __SMUADX __smuadx
747 #define __SMLAD __smlad
748 #define __SMLADX __smladx
749 #define __SMLALD __smlald
750 #define __SMLALDX __smlaldx
751 #define __SMUSD __smusd
752 #define __SMUSDX __smusdx
753 #define __SMLSD __smlsd
754 #define __SMLSDX __smlsdx
755 #define __SMLSLD __smlsld
756 #define __SMLSLDX __smlsldx
758 #define __QADD __qadd
759 #define __QSUB __qsub
761 #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
762 ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
764 #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
765 ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
767 #define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \
768 ((int64_t)(ARG3) << 32U) ) >> 32U))
770 #endif /* ((defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1)) ) */
771 /*@} end of group CMSIS_SIMD_intrinsics */
774 #endif /* __CMSIS_ARMCC_H */