1 /**************************************************************************//**
3 * @brief CMSIS compiler specific macros, functions, instructions
5 * @date 17. December 2019
6 ******************************************************************************/
8 * Copyright (c) 2009-2019 Arm Limited. All rights reserved.
10 * SPDX-License-Identifier: Apache-2.0
12 * Licensed under the Apache License, Version 2.0 (the License); you may
13 * not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
16 * www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
28 /* ignore some GCC warnings */
29 #pragma GCC diagnostic push
30 #pragma GCC diagnostic ignored "-Wsign-conversion"
31 #pragma GCC diagnostic ignored "-Wconversion"
32 #pragma GCC diagnostic ignored "-Wunused-parameter"
34 /* Fallback for __has_builtin */
36 #define __has_builtin(x) (0)
39 /* CMSIS compiler specific defines */
45 #define __INLINE inline
48 #define __FORCEINLINE __attribute__((always_inline))
50 #ifndef __STATIC_INLINE
51 #define __STATIC_INLINE static inline
53 #ifndef __STATIC_FORCEINLINE
54 #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline
57 #define __NO_RETURN __attribute__((__noreturn__))
59 #ifndef CMSIS_DEPRECATED
60 #define CMSIS_DEPRECATED __attribute__((deprecated))
63 #define __USED __attribute__((used))
66 #define __WEAK __attribute__((weak))
69 #define __PACKED __attribute__((packed, aligned(1)))
71 #ifndef __PACKED_STRUCT
72 #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
74 #ifndef __UNALIGNED_UINT16_WRITE
75 #pragma GCC diagnostic push
76 #pragma GCC diagnostic ignored "-Wpacked"
77 /*lint -esym(9058, T_UINT16_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_WRITE */
78 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
79 #pragma GCC diagnostic pop
80 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
82 #ifndef __UNALIGNED_UINT16_READ
83 #pragma GCC diagnostic push
84 #pragma GCC diagnostic ignored "-Wpacked"
85 /*lint -esym(9058, T_UINT16_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_READ */
86 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
87 #pragma GCC diagnostic pop
88 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
90 #ifndef __UNALIGNED_UINT32_WRITE
91 #pragma GCC diagnostic push
92 #pragma GCC diagnostic ignored "-Wpacked"
93 /*lint -esym(9058, T_UINT32_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_WRITE */
94 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
95 #pragma GCC diagnostic pop
96 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
98 #ifndef __UNALIGNED_UINT32_READ
99 #pragma GCC diagnostic push
100 #pragma GCC diagnostic ignored "-Wpacked"
101 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
102 #pragma GCC diagnostic pop
103 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
106 #define __ALIGNED(x) __attribute__((aligned(x)))
108 #ifndef __COMPILER_BARRIER
109 #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
113 __STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
117 __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
122 __STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
126 __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
131 __STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
135 __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
139 __STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
143 __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
147 __STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2)
151 __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
155 __STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
159 __ASM ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
163 __STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
167 __ASM ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
171 __STATIC_FORCEINLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
179 #ifndef __ARMEB__ /* Little endian */
180 __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]) );
181 #else /* Big endian */
182 __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]) );
188 __STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2)
192 __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
196 __STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1)
200 __ASM ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
205 __STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
209 __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
215 #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
216 ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
218 #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
219 ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
221 __STATIC_FORCEINLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
225 __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
229 __STATIC_FORCEINLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
233 __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
237 __STATIC_FORCEINLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
241 __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
245 __STATIC_FORCEINLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
253 #ifndef __ARMEB__ /* Little endian */
254 __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]) );
255 #else /* Big endian */
256 __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]) );
262 __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
266 __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
270 __STATIC_FORCEINLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
274 __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
278 __STATIC_FORCEINLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
282 __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
286 __STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
290 __ASM ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
294 __STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
298 __ASM ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
302 __STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
306 __ASM ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
310 __STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
314 __ASM ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
318 __STATIC_FORCEINLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
322 __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
327 /* ########################## Core Instruction Access ######################### */
331 #define __NOP() __ASM volatile ("nop")
334 \brief Wait For Interrupt
336 #define __WFI() __ASM volatile ("wfi":::"memory")
339 \brief Wait For Event
341 #define __WFE() __ASM volatile ("wfe":::"memory")
346 #define __SEV() __ASM volatile ("sev")
349 \brief Instruction Synchronization Barrier
350 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
351 so that all instructions following the ISB are fetched from cache or memory,
352 after the instruction has been completed.
354 __STATIC_FORCEINLINE void __ISB(void)
356 __ASM volatile ("isb 0xF":::"memory");
361 \brief Data Synchronization Barrier
362 \details Acts as a special kind of Data Memory Barrier.
363 It completes when all explicit memory accesses before this instruction complete.
365 __STATIC_FORCEINLINE void __DSB(void)
367 __ASM volatile ("dsb 0xF":::"memory");
371 \brief Data Memory Barrier
372 \details Ensures the apparent order of the explicit memory operations before
373 and after the instruction, without ensuring their completion.
375 __STATIC_FORCEINLINE void __DMB(void)
377 __ASM volatile ("dmb 0xF":::"memory");
381 \brief Reverse byte order (32 bit)
382 \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
383 \param [in] value Value to reverse
384 \return Reversed value
386 __STATIC_FORCEINLINE uint32_t __REV(uint32_t value)
388 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
389 return __builtin_bswap32(value);
393 __ASM ("rev %0, %1" : "=r" (result) : "r" (value) );
399 \brief Reverse byte order (16 bit)
400 \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
401 \param [in] value Value to reverse
402 \return Reversed value
404 __STATIC_FORCEINLINE uint32_t __REV16(uint32_t value)
407 __ASM ("rev16 %0, %1" : "=r" (result) : "r" (value));
412 \brief Reverse byte order (16 bit)
413 \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
414 \param [in] value Value to reverse
415 \return Reversed value
417 __STATIC_FORCEINLINE int16_t __REVSH(int16_t value)
419 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
420 return (int16_t)__builtin_bswap16(value);
424 __ASM ("revsh %0, %1" : "=r" (result) : "r" (value) );
430 \brief Rotate Right in unsigned value (32 bit)
431 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
432 \param [in] op1 Value to rotate
433 \param [in] op2 Number of Bits to rotate
434 \return Rotated value
436 __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
442 return (op1 >> op2) | (op1 << (32U - op2));
448 \param [in] value is ignored by the processor.
449 If required, a debugger can use it to store additional information about the breakpoint.
451 #define __BKPT(value) __ASM volatile ("bkpt "#value)
454 \brief Reverse bit order of value
455 \details Reverses the bit order of the given value.
456 \param [in] value Value to reverse
457 \return Reversed value
459 __STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value)
463 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
464 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
465 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
466 __ASM ("rbit %0, %1" : "=r" (result) : "r" (value) );
468 int32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */
470 result = value; /* r will be reversed bits of v; first get LSB of v */
471 for (value >>= 1U; value; value >>= 1U)
474 result |= value & 1U;
477 result <<= s; /* shift when v's highest bits are zero */
483 \brief Count leading zeros
484 \param [in] value Value to count the leading zeros
485 \return number of leading zeros in value
487 __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value)
489 /* Even though __builtin_clz produces a CLZ instruction on ARM, formally
490 __builtin_clz(0) is undefined behaviour, so handle this case specially.
491 This guarantees ARM-compatible results if happening to compile on a non-ARM
492 target, and ensures the compiler doesn't decide to activate any
493 optimisations using the logic "value was passed to __builtin_clz, so it
495 ARM GCC 7.3 and possibly earlier will optimise this test away, leaving a
496 single CLZ instruction.
502 return __builtin_clz(value);
506 \brief LDR Exclusive (8 bit)
507 \details Executes a exclusive LDR instruction for 8 bit value.
508 \param [in] ptr Pointer to data
509 \return value of type uint8_t at (*ptr)
511 __STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr)
515 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
516 __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
518 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
519 accepted by assembler. So has to use following less efficient pattern.
521 __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
523 return ((uint8_t) result); /* Add explicit type cast here */
528 \brief LDR Exclusive (16 bit)
529 \details Executes a exclusive LDR instruction for 16 bit values.
530 \param [in] ptr Pointer to data
531 \return value of type uint16_t at (*ptr)
533 __STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr)
537 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
538 __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
540 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
541 accepted by assembler. So has to use following less efficient pattern.
543 __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
545 return ((uint16_t) result); /* Add explicit type cast here */
550 \brief LDR Exclusive (32 bit)
551 \details Executes a exclusive LDR instruction for 32 bit values.
552 \param [in] ptr Pointer to data
553 \return value of type uint32_t at (*ptr)
555 __STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr)
559 __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
565 \brief STR Exclusive (8 bit)
566 \details Executes a exclusive STR instruction for 8 bit values.
567 \param [in] value Value to store
568 \param [in] ptr Pointer to location
569 \return 0 Function succeeded
570 \return 1 Function failed
572 __STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
576 __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
582 \brief STR Exclusive (16 bit)
583 \details Executes a exclusive STR instruction for 16 bit values.
584 \param [in] value Value to store
585 \param [in] ptr Pointer to location
586 \return 0 Function succeeded
587 \return 1 Function failed
589 __STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
593 __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
599 \brief STR Exclusive (32 bit)
600 \details Executes a exclusive STR instruction for 32 bit values.
601 \param [in] value Value to store
602 \param [in] ptr Pointer to location
603 \return 0 Function succeeded
604 \return 1 Function failed
606 __STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
610 __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
616 \brief Remove the exclusive lock
617 \details Removes the exclusive lock which is created by LDREX.
619 __STATIC_FORCEINLINE void __CLREX(void)
621 __ASM volatile ("clrex" ::: "memory");
625 \brief Signed Saturate
626 \details Saturates a signed value.
627 \param [in] value Value to be saturated
628 \param [in] sat Bit position to saturate to (1..32)
629 \return Saturated value
631 #define __SSAT(ARG1, ARG2) \
634 int32_t __RES, __ARG1 = (ARG1); \
635 __ASM volatile ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
641 \brief Unsigned Saturate
642 \details Saturates an unsigned value.
643 \param [in] value Value to be saturated
644 \param [in] sat Bit position to saturate to (0..31)
645 \return Saturated value
647 #define __USAT(ARG1, ARG2) \
650 uint32_t __RES, __ARG1 = (ARG1); \
651 __ASM volatile ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
655 /* ########################### Core Function Access ########################### */
658 \brief Enable IRQ Interrupts
659 \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
660 Can only be executed in Privileged modes.
662 __STATIC_FORCEINLINE void __enable_irq(void)
664 __ASM volatile ("cpsie i" : : : "memory");
668 \brief Disable IRQ Interrupts
669 \details Disables IRQ interrupts by setting the I-bit in the CPSR.
670 Can only be executed in Privileged modes.
672 __STATIC_FORCEINLINE void __disable_irq(void)
674 __ASM volatile ("cpsid i" : : : "memory");
679 \details Returns the current value of the Floating Point Status/Control register.
680 \return Floating Point Status/Control register value
682 __STATIC_FORCEINLINE uint32_t __get_FPSCR(void)
684 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
685 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
686 #if __has_builtin(__builtin_arm_get_fpscr)
687 // Re-enable using built-in when GCC has been fixed
688 // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
689 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
690 return __builtin_arm_get_fpscr();
694 __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
704 \details Assigns the given value to the Floating Point Status/Control register.
705 \param [in] fpscr Floating Point Status/Control value to set
707 __STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr)
709 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
710 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
711 #if __has_builtin(__builtin_arm_set_fpscr)
712 // Re-enable using built-in when GCC has been fixed
713 // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
714 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
715 __builtin_arm_set_fpscr(fpscr);
717 __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory");
724 /** \brief Get CPSR Register
725 \return CPSR Register value
727 __STATIC_FORCEINLINE uint32_t __get_CPSR(void)
730 __ASM volatile("MRS %0, cpsr" : "=r" (result) );
734 /** \brief Set CPSR Register
735 \param [in] cpsr CPSR value to set
737 __STATIC_FORCEINLINE void __set_CPSR(uint32_t cpsr)
739 __ASM volatile ("MSR cpsr, %0" : : "r" (cpsr) : "cc", "memory");
743 \return Processor Mode
745 __STATIC_FORCEINLINE uint32_t __get_mode(void)
747 return (__get_CPSR() & 0x1FU);
751 \param [in] mode Mode value to set
753 __STATIC_FORCEINLINE void __set_mode(uint32_t mode)
755 __ASM volatile("MSR cpsr_c, %0" : : "r" (mode) : "memory");
758 /** \brief Get Stack Pointer
759 \return Stack Pointer value
761 __STATIC_FORCEINLINE uint32_t __get_SP(void)
764 __ASM volatile("MOV %0, sp" : "=r" (result) : : "memory");
768 /** \brief Set Stack Pointer
769 \param [in] stack Stack Pointer value to set
771 __STATIC_FORCEINLINE void __set_SP(uint32_t stack)
773 __ASM volatile("MOV sp, %0" : : "r" (stack) : "memory");
776 /** \brief Get USR/SYS Stack Pointer
777 \return USR/SYS Stack Pointer value
779 __STATIC_FORCEINLINE uint32_t __get_SP_usr(void)
781 uint32_t cpsr = __get_CPSR();
785 "MOV %0, sp " : "=r"(result) : : "memory"
792 /** \brief Set USR/SYS Stack Pointer
793 \param [in] topOfProcStack USR/SYS Stack Pointer value to set
795 __STATIC_FORCEINLINE void __set_SP_usr(uint32_t topOfProcStack)
797 uint32_t cpsr = __get_CPSR();
800 "MOV sp, %0 " : : "r" (topOfProcStack) : "memory"
807 \return Floating Point Exception Control register value
809 __STATIC_FORCEINLINE uint32_t __get_FPEXC(void)
811 #if (__FPU_PRESENT == 1)
813 __ASM volatile("VMRS %0, fpexc" : "=r" (result) );
821 \param [in] fpexc Floating Point Exception Control value to set
823 __STATIC_FORCEINLINE void __set_FPEXC(uint32_t fpexc)
825 #if (__FPU_PRESENT == 1)
826 __ASM volatile ("VMSR fpexc, %0" : : "r" (fpexc) : "memory");
831 * Include common core functions to access Coprocessor 15 registers
834 #define __get_CP(cp, op1, Rt, CRn, CRm, op2) __ASM volatile("MRC p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : "=r" (Rt) : : "memory" )
835 #define __set_CP(cp, op1, Rt, CRn, CRm, op2) __ASM volatile("MCR p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : : "r" (Rt) : "memory" )
836 #define __get_CP64(cp, op1, Rt, CRm) __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : "=r" (Rt) : : "memory" )
837 #define __set_CP64(cp, op1, Rt, CRm) __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : : "r" (Rt) : "memory" )
839 #include "cmsis_cp15.h"
841 /** \brief Enable Floating Point Unit
843 Critical section, called from undef handler, so systick is disabled
845 __STATIC_INLINE void __FPU_Enable(void)
848 //Permit access to VFP/NEON, registers by modifying CPACR
849 " MRC p15,0,R1,c1,c0,2 \n"
850 " ORR R1,R1,#0x00F00000 \n"
851 " MCR p15,0,R1,c1,c0,2 \n"
853 //Ensure that subsequent instructions occur in the context of VFP/NEON access permitted
858 " ORR R1,R1,#0x40000000 \n"
861 //Initialise VFP/NEON registers to 0
864 //Initialise D16 registers to 0
882 #if (defined(__ARM_NEON) && (__ARM_NEON == 1))
883 //Initialise D32 registers to 0
902 //Initialise FPSCR to a known state
904 " LDR R2,=0x00086060 \n" //Mask off all bits that do not have to be preserved. Non-preserved bits can/should be zero.
907 : : : "cc", "r1", "r2"
911 #pragma GCC diagnostic pop
913 #endif /* __CMSIS_GCC_H */