1 /**************************************************************************//**
3 * @brief CMSIS Cortex-M Core Function/Instruction Header File
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!"
34 /* ########################### Core Function Access ########################### */
35 /** \ingroup CMSIS_Core_FunctionInterface
36 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
40 /* intrinsic void __enable_irq(); */
41 /* intrinsic void __disable_irq(); */
44 \brief Get Control Register
45 \details Returns the content of the Control Register.
46 \return Control Register value
48 __STATIC_INLINE uint32_t __get_CONTROL(void)
50 register uint32_t __regControl __ASM("control");
56 \brief Set Control Register
57 \details Writes the given value to the Control Register.
58 \param [in] control Control Register value to set
60 __STATIC_INLINE void __set_CONTROL(uint32_t control)
62 register uint32_t __regControl __ASM("control");
63 __regControl = control;
68 \brief Get IPSR Register
69 \details Returns the content of the IPSR Register.
70 \return IPSR Register value
72 __STATIC_INLINE uint32_t __get_IPSR(void)
74 register uint32_t __regIPSR __ASM("ipsr");
80 \brief Get APSR Register
81 \details Returns the content of the APSR Register.
82 \return APSR Register value
84 __STATIC_INLINE uint32_t __get_APSR(void)
86 register uint32_t __regAPSR __ASM("apsr");
92 \brief Get xPSR Register
93 \details Returns the content of the xPSR Register.
94 \return xPSR Register value
96 __STATIC_INLINE uint32_t __get_xPSR(void)
98 register uint32_t __regXPSR __ASM("xpsr");
104 \brief Get Process Stack Pointer
105 \details Returns the current value of the Process Stack Pointer (PSP).
106 \return PSP Register value
108 __STATIC_INLINE uint32_t __get_PSP(void)
110 register uint32_t __regProcessStackPointer __ASM("psp");
111 return(__regProcessStackPointer);
116 \brief Set Process Stack Pointer
117 \details Assigns the given value to the Process Stack Pointer (PSP).
118 \param [in] topOfProcStack Process Stack Pointer value to set
120 __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
122 register uint32_t __regProcessStackPointer __ASM("psp");
123 __regProcessStackPointer = topOfProcStack;
128 \brief Get Main Stack Pointer
129 \details Returns the current value of the Main Stack Pointer (MSP).
130 \return MSP Register value
132 __STATIC_INLINE uint32_t __get_MSP(void)
134 register uint32_t __regMainStackPointer __ASM("msp");
135 return(__regMainStackPointer);
140 \brief Set Main Stack Pointer
141 \details Assigns the given value to the Main Stack Pointer (MSP).
142 \param [in] topOfMainStack Main Stack Pointer value to set
144 __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
146 register uint32_t __regMainStackPointer __ASM("msp");
147 __regMainStackPointer = topOfMainStack;
152 \brief Get Priority Mask
153 \details Returns the current state of the priority mask bit from the Priority Mask Register.
154 \return Priority Mask value
156 __STATIC_INLINE uint32_t __get_PRIMASK(void)
158 register uint32_t __regPriMask __ASM("primask");
159 return(__regPriMask);
164 \brief Set Priority Mask
165 \details Assigns the given value to the Priority Mask Register.
166 \param [in] priMask Priority Mask
168 __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
170 register uint32_t __regPriMask __ASM("primask");
171 __regPriMask = (priMask);
175 #if ((defined (__CORTEX_M ) && (__CORTEX_M >= 3U)) || \
176 (defined (__CORTEX_SC) && (__CORTEX_SC >= 300U)) )
180 \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
181 Can only be executed in Privileged modes.
183 #define __enable_fault_irq __enable_fiq
188 \details Disables FIQ interrupts by setting the F-bit in the CPSR.
189 Can only be executed in Privileged modes.
191 #define __disable_fault_irq __disable_fiq
195 \brief Get Base Priority
196 \details Returns the current value of the Base Priority register.
197 \return Base Priority register value
199 __STATIC_INLINE uint32_t __get_BASEPRI(void)
201 register uint32_t __regBasePri __ASM("basepri");
202 return(__regBasePri);
207 \brief Set Base Priority
208 \details Assigns the given value to the Base Priority register.
209 \param [in] basePri Base Priority value to set
211 __STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
213 register uint32_t __regBasePri __ASM("basepri");
214 __regBasePri = (basePri & 0xFFU);
219 \brief Set Base Priority with condition
220 \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
221 or the new value increases the BASEPRI priority level.
222 \param [in] basePri Base Priority value to set
224 __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri)
226 register uint32_t __regBasePriMax __ASM("basepri_max");
227 __regBasePriMax = (basePri & 0xFFU);
232 \brief Get Fault Mask
233 \details Returns the current value of the Fault Mask register.
234 \return Fault Mask register value
236 __STATIC_INLINE uint32_t __get_FAULTMASK(void)
238 register uint32_t __regFaultMask __ASM("faultmask");
239 return(__regFaultMask);
244 \brief Set Fault Mask
245 \details Assigns the given value to the Fault Mask register.
246 \param [in] faultMask Fault Mask value to set
248 __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
250 register uint32_t __regFaultMask __ASM("faultmask");
251 __regFaultMask = (faultMask & (uint32_t)1);
254 #endif /* ((defined (__CORTEX_M ) && (__CORTEX_M >= 3U)) || \
255 (defined (__CORTEX_SC) && (__CORTEX_SC >= 300U)) ) */
258 #if (defined (__CORTEX_M) && (__CORTEX_M >= 4U))
262 \details Returns the current value of the Floating Point Status/Control register.
263 \return Floating Point Status/Control register value
265 __STATIC_INLINE uint32_t __get_FPSCR(void)
267 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
268 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
269 register uint32_t __regfpscr __ASM("fpscr");
279 \details Assigns the given value to the Floating Point Status/Control register.
280 \param [in] fpscr Floating Point Status/Control value to set
282 __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
284 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
285 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
286 register uint32_t __regfpscr __ASM("fpscr");
287 __regfpscr = (fpscr);
291 #endif /* (defined (__CORTEX_M) && (__CORTEX_M >= 4U)) */
295 /*@} end of CMSIS_Core_RegAccFunctions */
298 /* ########################## Core Instruction Access ######################### */
299 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
300 Access to dedicated instructions
306 \details No Operation does nothing. This instruction can be used for code alignment purposes.
312 \brief Wait For Interrupt
313 \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
319 \brief Wait For Event
320 \details Wait For Event is a hint instruction that permits the processor to enter
321 a low-power state until one of a number of events occurs.
328 \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
334 \brief Instruction Synchronization Barrier
335 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
336 so that all instructions following the ISB are fetched from cache or memory,
337 after the instruction has been completed.
339 #define __ISB() do {\
340 __schedule_barrier();\
342 __schedule_barrier();\
346 \brief Data Synchronization Barrier
347 \details Acts as a special kind of Data Memory Barrier.
348 It completes when all explicit memory accesses before this instruction complete.
350 #define __DSB() do {\
351 __schedule_barrier();\
353 __schedule_barrier();\
357 \brief Data Memory Barrier
358 \details Ensures the apparent order of the explicit memory operations before
359 and after the instruction, without ensuring their completion.
361 #define __DMB() do {\
362 __schedule_barrier();\
364 __schedule_barrier();\
368 \brief Reverse byte order (32 bit)
369 \details Reverses the byte order in integer value.
370 \param [in] value Value to reverse
371 \return Reversed value
377 \brief Reverse byte order (16 bit)
378 \details Reverses the byte order in two unsigned short values.
379 \param [in] value Value to reverse
380 \return Reversed value
382 #ifndef __NO_EMBEDDED_ASM
383 __attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
391 \brief Reverse byte order in signed short value
392 \details Reverses the byte order in a signed short value with sign extension to integer.
393 \param [in] value Value to reverse
394 \return Reversed value
396 #ifndef __NO_EMBEDDED_ASM
397 __attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value)
406 \brief Rotate Right in unsigned value (32 bit)
407 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
408 \param [in] value Value to rotate
409 \param [in] value Number of Bits to rotate
410 \return Rotated value
417 \details Causes the processor to enter Debug state.
418 Debug tools can use this to investigate system state when the instruction at a particular address is reached.
419 \param [in] value is ignored by the processor.
420 If required, a debugger can use it to store additional information about the breakpoint.
422 #define __BKPT(value) __breakpoint(value)
426 \brief Reverse bit order of value
427 \details Reverses the bit order of the given value.
428 \param [in] value Value to reverse
429 \return Reversed value
431 #if ((defined (__CORTEX_M ) && (__CORTEX_M >= 3U)) || \
432 (defined (__CORTEX_SC) && (__CORTEX_SC >= 300U)) )
433 #define __RBIT __rbit
435 __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
438 int32_t s = 4 /*sizeof(v)*/ * 8 - 1; /* extra shift needed at end */
440 result = value; /* r will be reversed bits of v; first get LSB of v */
441 for (value >>= 1U; value; value >>= 1U)
444 result |= value & 1U;
447 result <<= s; /* shift when v's highest bits are zero */
454 \brief Count leading zeros
455 \details Counts the number of leading zeros of a data value.
456 \param [in] value Value to count the leading zeros
457 \return number of leading zeros in value
462 #if ((defined (__CORTEX_M ) && (__CORTEX_M >= 3U)) || \
463 (defined (__CORTEX_SC) && (__CORTEX_SC >= 300U)) )
466 \brief LDR Exclusive (8 bit)
467 \details Executes a exclusive LDR instruction for 8 bit value.
468 \param [in] ptr Pointer to data
469 \return value of type uint8_t at (*ptr)
471 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
472 #define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
474 #define __LDREXB(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr)) _Pragma("pop")
479 \brief LDR Exclusive (16 bit)
480 \details Executes a exclusive LDR instruction for 16 bit values.
481 \param [in] ptr Pointer to data
482 \return value of type uint16_t at (*ptr)
484 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
485 #define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
487 #define __LDREXH(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr)) _Pragma("pop")
492 \brief LDR Exclusive (32 bit)
493 \details Executes a exclusive LDR instruction for 32 bit values.
494 \param [in] ptr Pointer to data
495 \return value of type uint32_t at (*ptr)
497 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
498 #define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
500 #define __LDREXW(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr)) _Pragma("pop")
505 \brief STR Exclusive (8 bit)
506 \details Executes a exclusive STR instruction for 8 bit values.
507 \param [in] value Value to store
508 \param [in] ptr Pointer to location
509 \return 0 Function succeeded
510 \return 1 Function failed
512 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
513 #define __STREXB(value, ptr) __strex(value, ptr)
515 #define __STREXB(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
520 \brief STR Exclusive (16 bit)
521 \details Executes a exclusive STR instruction for 16 bit values.
522 \param [in] value Value to store
523 \param [in] ptr Pointer to location
524 \return 0 Function succeeded
525 \return 1 Function failed
527 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
528 #define __STREXH(value, ptr) __strex(value, ptr)
530 #define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
535 \brief STR Exclusive (32 bit)
536 \details Executes a exclusive STR instruction for 32 bit values.
537 \param [in] value Value to store
538 \param [in] ptr Pointer to location
539 \return 0 Function succeeded
540 \return 1 Function failed
542 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
543 #define __STREXW(value, ptr) __strex(value, ptr)
545 #define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
550 \brief Remove the exclusive lock
551 \details Removes the exclusive lock which is created by LDREX.
553 #define __CLREX __clrex
557 \brief Signed Saturate
558 \details Saturates a signed value.
559 \param [in] value Value to be saturated
560 \param [in] sat Bit position to saturate to (1..32)
561 \return Saturated value
563 #define __SSAT __ssat
567 \brief Unsigned Saturate
568 \details Saturates an unsigned value.
569 \param [in] value Value to be saturated
570 \param [in] sat Bit position to saturate to (0..31)
571 \return Saturated value
573 #define __USAT __usat
577 \brief Rotate Right with Extend (32 bit)
578 \details Moves each bit of a bitstring right by one bit.
579 The carry input is shifted in at the left end of the bitstring.
580 \param [in] value Value to rotate
581 \return Rotated value
583 #ifndef __NO_EMBEDDED_ASM
584 __attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value)
593 \brief LDRT Unprivileged (8 bit)
594 \details Executes a Unprivileged LDRT instruction for 8 bit value.
595 \param [in] ptr Pointer to data
596 \return value of type uint8_t at (*ptr)
598 #define __LDRBT(ptr) ((uint8_t ) __ldrt(ptr))
602 \brief LDRT Unprivileged (16 bit)
603 \details Executes a Unprivileged LDRT instruction for 16 bit values.
604 \param [in] ptr Pointer to data
605 \return value of type uint16_t at (*ptr)
607 #define __LDRHT(ptr) ((uint16_t) __ldrt(ptr))
611 \brief LDRT Unprivileged (32 bit)
612 \details Executes a Unprivileged LDRT instruction for 32 bit values.
613 \param [in] ptr Pointer to data
614 \return value of type uint32_t at (*ptr)
616 #define __LDRT(ptr) ((uint32_t ) __ldrt(ptr))
620 \brief STRT Unprivileged (8 bit)
621 \details Executes a Unprivileged STRT instruction for 8 bit values.
622 \param [in] value Value to store
623 \param [in] ptr Pointer to location
625 #define __STRBT(value, ptr) __strt(value, ptr)
629 \brief STRT Unprivileged (16 bit)
630 \details Executes a Unprivileged STRT instruction for 16 bit values.
631 \param [in] value Value to store
632 \param [in] ptr Pointer to location
634 #define __STRHT(value, ptr) __strt(value, ptr)
638 \brief STRT Unprivileged (32 bit)
639 \details Executes a Unprivileged STRT instruction for 32 bit values.
640 \param [in] value Value to store
641 \param [in] ptr Pointer to location
643 #define __STRT(value, ptr) __strt(value, ptr)
645 #endif /* ((defined (__CORTEX_M ) && (__CORTEX_M >= 3U)) || \
646 (defined (__CORTEX_SC) && (__CORTEX_SC >= 300U)) ) */
648 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
651 /* ################### Compiler specific Intrinsics ########################### */
652 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
653 Access to dedicated SIMD instructions
657 #if (defined (__CORTEX_M) && (__CORTEX_M >= 4U))
660 #define __SADD8 __sadd8
661 #define __QADD8 __qadd8
662 #define __SHADD8 __shadd8
663 #define __UADD8 __uadd8
664 #define __UQADD8 __uqadd8
665 #define __UHADD8 __uhadd8
666 #define __SSUB8 __ssub8
667 #define __QSUB8 __qsub8
668 #define __SHSUB8 __shsub8
669 #define __USUB8 __usub8
670 #define __UQSUB8 __uqsub8
671 #define __UHSUB8 __uhsub8
672 #define __SADD16 __sadd16
673 #define __QADD16 __qadd16
674 #define __SHADD16 __shadd16
675 #define __UADD16 __uadd16
676 #define __UQADD16 __uqadd16
677 #define __UHADD16 __uhadd16
678 #define __SSUB16 __ssub16
679 #define __QSUB16 __qsub16
680 #define __SHSUB16 __shsub16
681 #define __USUB16 __usub16
682 #define __UQSUB16 __uqsub16
683 #define __UHSUB16 __uhsub16
684 #define __SASX __sasx
685 #define __QASX __qasx
686 #define __SHASX __shasx
687 #define __UASX __uasx
688 #define __UQASX __uqasx
689 #define __UHASX __uhasx
690 #define __SSAX __ssax
691 #define __QSAX __qsax
692 #define __SHSAX __shsax
693 #define __USAX __usax
694 #define __UQSAX __uqsax
695 #define __UHSAX __uhsax
696 #define __USAD8 __usad8
697 #define __USADA8 __usada8
698 #define __SSAT16 __ssat16
699 #define __USAT16 __usat16
700 #define __UXTB16 __uxtb16
701 #define __UXTAB16 __uxtab16
702 #define __SXTB16 __sxtb16
703 #define __SXTAB16 __sxtab16
704 #define __SMUAD __smuad
705 #define __SMUADX __smuadx
706 #define __SMLAD __smlad
707 #define __SMLADX __smladx
708 #define __SMLALD __smlald
709 #define __SMLALDX __smlaldx
710 #define __SMUSD __smusd
711 #define __SMUSDX __smusdx
712 #define __SMLSD __smlsd
713 #define __SMLSDX __smlsdx
714 #define __SMLSLD __smlsld
715 #define __SMLSLDX __smlsldx
717 #define __QADD __qadd
718 #define __QSUB __qsub
720 #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
721 ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
723 #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
724 ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
726 #define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \
727 ((int64_t)(ARG3) << 32U) ) >> 32U))
729 #endif /* (defined (__CORTEX_M) && (__CORTEX_M >= 4U)) */
730 /*@} end of group CMSIS_SIMD_intrinsics */
733 #endif /* __CMSIS_ARMCC_H */