1 /**************************************************************************//**
3 * @brief CMSIS compiler specific macros, functions, instructions
6 ******************************************************************************/
8 * Copyright (c) 2009-2017 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 */
44 #define __INLINE inline
46 #ifndef __STATIC_INLINE
47 #define __STATIC_INLINE static inline
50 #define __NO_RETURN __attribute__((noreturn))
53 #define __USED __attribute__((used))
56 #define __WEAK __attribute__((weak))
59 #define __PACKED __attribute__((packed, aligned(1)))
61 #ifndef __PACKED_STRUCT
62 #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
64 #ifndef __UNALIGNED_UINT16_WRITE
65 #pragma GCC diagnostic push
66 #pragma GCC diagnostic ignored "-Wpacked"
67 /*lint -esym(9058, T_UINT16_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_WRITE */
68 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
69 #pragma GCC diagnostic pop
70 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
72 #ifndef __UNALIGNED_UINT16_READ
73 #pragma GCC diagnostic push
74 #pragma GCC diagnostic ignored "-Wpacked"
75 /*lint -esym(9058, T_UINT16_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_READ */
76 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
77 #pragma GCC diagnostic pop
78 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
80 #ifndef __UNALIGNED_UINT32_WRITE
81 #pragma GCC diagnostic push
82 #pragma GCC diagnostic ignored "-Wpacked"
83 /*lint -esym(9058, T_UINT32_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_WRITE */
84 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
85 #pragma GCC diagnostic pop
86 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
88 #ifndef __UNALIGNED_UINT32_READ
89 #pragma GCC diagnostic push
90 #pragma GCC diagnostic ignored "-Wpacked"
91 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
92 #pragma GCC diagnostic pop
93 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
96 #define __ALIGNED(x) __attribute__((aligned(x)))
100 /* ########################### Core Function Access ########################### */
104 \details Returns the current value of the Floating Point Status/Control register.
105 \return Floating Point Status/Control register value
107 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_FPSCR(void)
109 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
110 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
111 #if __has_builtin(__builtin_arm_get_fpscr) || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
112 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
113 return __builtin_arm_get_fpscr();
117 __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
128 \details Assigns the given value to the Floating Point Status/Control register.
129 \param [in] fpscr Floating Point Status/Control value to set
131 __attribute__((always_inline)) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
133 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
134 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
135 #if __has_builtin(__builtin_arm_set_fpscr) || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
136 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
137 __builtin_arm_set_fpscr(fpscr);
139 __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory");
146 /* ########################## Core Instruction Access ######################### */
150 #define __NOP __builtin_arm_nop
153 \brief Wait For Interrupt
155 #define __WFI __builtin_arm_wfi
158 \brief Wait For Event
160 #define __WFE __builtin_arm_wfe
165 #define __SEV __builtin_arm_sev
168 \brief Instruction Synchronization Barrier
169 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
170 so that all instructions following the ISB are fetched from cache or memory,
171 after the instruction has been completed.
173 __attribute__((always_inline)) __STATIC_INLINE void __ISB(void)
175 __ASM volatile ("isb 0xF":::"memory");
180 \brief Data Synchronization Barrier
181 \details Acts as a special kind of Data Memory Barrier.
182 It completes when all explicit memory accesses before this instruction complete.
184 __attribute__((always_inline)) __STATIC_INLINE void __DSB(void)
186 __ASM volatile ("dsb 0xF":::"memory");
190 \brief Data Memory Barrier
191 \details Ensures the apparent order of the explicit memory operations before
192 and after the instruction, without ensuring their completion.
194 __attribute__((always_inline)) __STATIC_INLINE void __DMB(void)
196 __ASM volatile ("dmb 0xF":::"memory");
200 \brief Reverse byte order (32 bit)
201 \details Reverses the byte order in integer value.
202 \param [in] value Value to reverse
203 \return Reversed value
205 __attribute__((always_inline)) __STATIC_INLINE uint32_t __REV(uint32_t value)
207 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
208 return __builtin_bswap32(value);
212 __ASM volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
218 \brief Reverse byte order (16 bit)
219 \param [in] value Value to reverse
220 \return Reversed value
222 #ifndef __NO_EMBEDDED_ASM
223 __attribute__((section(".rev16_text"))) __STATIC_INLINE uint32_t __REV16(uint32_t value)
226 __ASM volatile("rev16 %0, %1" : "=r" (result) : "r" (value));
232 \brief Reverse byte order in signed short value
233 \details Reverses the byte order in a signed short value with sign extension to integer.
234 \param [in] value Value to reverse
235 \return Reversed value
237 __attribute__((always_inline)) __STATIC_INLINE int32_t __REVSH(int32_t value)
239 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
240 return (short)__builtin_bswap16(value);
244 __ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
250 \brief Rotate Right in unsigned value (32 bit)
251 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
252 \param [in] op1 Value to rotate
253 \param [in] op2 Number of Bits to rotate
254 \return Rotated value
256 __attribute__((always_inline)) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
258 return (op1 >> op2) | (op1 << (32U - op2));
263 \param [in] value is ignored by the processor.
264 If required, a debugger can use it to store additional information about the breakpoint.
266 #define __BKPT(value) __ASM volatile ("bkpt "#value)
269 \brief Reverse bit order of value
270 \details Reverses the bit order of the given value.
271 \param [in] value Value to reverse
272 \return Reversed value
274 __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
278 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
279 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
280 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
281 __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
283 int32_t s = (4 /*sizeof(v)*/ * 8) - 1; /* extra shift needed at end */
285 result = value; /* r will be reversed bits of v; first get LSB of v */
286 for (value >>= 1U; value; value >>= 1U)
289 result |= value & 1U;
292 result <<= s; /* shift when v's highest bits are zero */
298 \brief Count leading zeros
299 \param [in] value Value to count the leading zeros
300 \return number of leading zeros in value
302 #define __CLZ __builtin_clz
305 \brief LDR Exclusive (8 bit)
306 \details Executes a exclusive LDR instruction for 8 bit value.
307 \param [in] ptr Pointer to data
308 \return value of type uint8_t at (*ptr)
310 __attribute__((always_inline)) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t *addr)
314 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
315 __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
317 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
318 accepted by assembler. So has to use following less efficient pattern.
320 __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
322 return ((uint8_t) result); /* Add explicit type cast here */
327 \brief LDR Exclusive (16 bit)
328 \details Executes a exclusive LDR instruction for 16 bit values.
329 \param [in] ptr Pointer to data
330 \return value of type uint16_t at (*ptr)
332 __attribute__((always_inline)) __STATIC_INLINE uint16_t __LDREXH(volatile uint16_t *addr)
336 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
337 __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
339 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
340 accepted by assembler. So has to use following less efficient pattern.
342 __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
344 return ((uint16_t) result); /* Add explicit type cast here */
349 \brief LDR Exclusive (32 bit)
350 \details Executes a exclusive LDR instruction for 32 bit values.
351 \param [in] ptr Pointer to data
352 \return value of type uint32_t at (*ptr)
354 __attribute__((always_inline)) __STATIC_INLINE uint32_t __LDREXW(volatile uint32_t *addr)
358 __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
364 \brief STR Exclusive (8 bit)
365 \details Executes a exclusive STR instruction for 8 bit values.
366 \param [in] value Value to store
367 \param [in] ptr Pointer to location
368 \return 0 Function succeeded
369 \return 1 Function failed
371 __attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
375 __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
381 \brief STR Exclusive (16 bit)
382 \details Executes a exclusive STR instruction for 16 bit values.
383 \param [in] value Value to store
384 \param [in] ptr Pointer to location
385 \return 0 Function succeeded
386 \return 1 Function failed
388 __attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
392 __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
398 \brief STR Exclusive (32 bit)
399 \details Executes a exclusive STR instruction for 32 bit values.
400 \param [in] value Value to store
401 \param [in] ptr Pointer to location
402 \return 0 Function succeeded
403 \return 1 Function failed
405 __attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
409 __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
415 \brief Remove the exclusive lock
416 \details Removes the exclusive lock which is created by LDREX.
418 __attribute__((always_inline)) __STATIC_INLINE void __CLREX(void)
420 __ASM volatile ("clrex" ::: "memory");
423 /** \brief Get CPSR Register
424 \return CPSR Register value
426 __STATIC_INLINE uint32_t __get_CPSR(void)
429 __ASM volatile("MRS %0, cpsr" : "=r" (result) );
433 /** \brief Set CPSR Register
434 \param [in] cpsr CPSR value to set
436 __STATIC_INLINE void __set_CPSR(uint32_t cpsr)
438 __ASM volatile ("MSR cpsr, %0" : : "r" (cpsr) : "memory");
442 \return Processor Mode
444 __STATIC_INLINE uint32_t __get_mode(void) {
445 return (__get_CPSR() & 0x1FU);
449 \param [in] mode Mode value to set
451 __STATIC_INLINE void __set_mode(uint32_t mode) {
452 __ASM volatile("MSR cpsr_c, %0" : : "r" (mode) : "memory");
455 /** \brief Set Stack Pointer
456 \param [in] stack Stack Pointer value to set
458 __STATIC_INLINE void __set_SP(uint32_t stack)
460 __ASM volatile("MOV sp, %0" : : "r" (stack) : "memory");
463 /** \brief Set USR/SYS Stack Pointer
464 \param [in] topOfProcStack USR/SYS Stack Pointer value to set
466 __STATIC_INLINE void __set_SP_usr(uint32_t topOfProcStack)
470 "BIC r0, r0, #7 \n" // ensure stack is 8-byte aligned
472 "CPS #0x1F \n" // no effect in USR mode
474 "MSR cpsr_c, r1 \n" // no effect in USR mode
480 \return Floating Point Exception Control register value
482 __STATIC_INLINE uint32_t __get_FPEXC(void)
484 #if (__FPU_PRESENT == 1)
486 __ASM volatile("MRS %0, fpexc" : "=r" (result) );
494 \param [in] fpexc Floating Point Exception Control value to set
496 __STATIC_INLINE void __set_FPEXC(uint32_t fpexc)
498 #if (__FPU_PRESENT == 1)
499 __ASM volatile ("MSR fpexc, %0" : : "r" (fpexc) : "memory");
504 \return Auxiliary Control register value
506 __STATIC_INLINE uint32_t __get_ACTLR(void)
509 __ASM volatile("MRS %0, actlr" : "=r" (result) );
514 \param [in] actlr Auxiliary Control value to set
516 __STATIC_INLINE void __set_ACTLR(uint32_t actlr)
518 __ASM volatile ("MSR fpexc, %0" : : "r" (actlr) : "memory");
521 \return Coprocessor Access Control register value
523 __STATIC_INLINE uint32_t __get_CPACR(void)
526 __ASM volatile("MRC p15, 0, %0, c1, c0, 2" : "=r"(result));
531 \param [in] cpacr Coprocessor Access Control value to set
533 __STATIC_INLINE void __set_CPACR(uint32_t cpacr)
535 __ASM volatile("MCR p15, 0, %0, c1, c0, 2" : : "r"(cpacr) : "memory");
539 \return Configuration Base Address register value
541 __STATIC_INLINE uint32_t __get_CBAR() {
543 __ASM volatile("MRC p15, 4, %0, c15, c0, 0" : "=r"(result));
549 This function returns the value of the Translation Table Base Register 0.
551 \return Translation Table Base Register 0 value
553 __STATIC_INLINE uint32_t __get_TTBR0() {
555 __ASM volatile("MRC p15, 0, %0, c2, c0, 0" : "=r"(result));
561 This function assigns the given value to the Translation Table Base Register 0.
563 \param [in] ttbr0 Translation Table Base Register 0 value to set
565 __STATIC_INLINE void __set_TTBR0(uint32_t ttbr0) {
566 __ASM volatile("MCR p15, 0, %0, c2, c0, 0" : : "r"(ttbr0) : "memory");
571 This function returns the value of the Domain Access Control Register.
573 \return Domain Access Control Register value
575 __STATIC_INLINE uint32_t __get_DACR() {
577 __ASM volatile("MRC p15, 0, %0, c3, c0, 0" : "=r"(result));
583 This function assigns the given value to the Domain Access Control Register.
585 \param [in] dacr Domain Access Control Register value to set
587 __STATIC_INLINE void __set_DACR(uint32_t dacr) {
588 __ASM volatile("MCR p15, 0, %0, c3, c0, 0" : : "r"(dacr) : "memory");
593 This function assigns the given value to the System Control Register.
595 \param [in] sctlr System Control Register value to set
597 __STATIC_INLINE void __set_SCTLR(uint32_t sctlr)
599 __ASM volatile("MCR p15, 0, %0, c1, c0, 0" : : "r"(sctlr) : "memory");
603 \return System Control Register value
605 __STATIC_INLINE uint32_t __get_SCTLR() {
607 __ASM volatile("MRC p15, 0, %0, c1, c0, 0" : "=r"(result));
612 \param [in] actrl Auxiliary Control Register value to set
614 __STATIC_INLINE void __set_ACTRL(uint32_t actrl)
616 __ASM volatile("MCR p15, 0, %0, c1, c0, 1" : : "r"(actrl) : "memory");
620 \return Auxiliary Control Register value
622 __STATIC_INLINE uint32_t __get_ACTRL(void)
625 __ASM volatile("MRC p15, 0, %0, c1, c0, 1" : "=r"(result));
631 This function returns the value of the Multiprocessor Affinity Register.
633 \return Multiprocessor Affinity Register value
635 __STATIC_INLINE uint32_t __get_MPIDR(void)
638 __ASM volatile("MRC p15, 0, %0, c0, c0, 5" : "=r"(result));
644 This function returns the value of the Vector Base Address Register.
646 \return Vector Base Address Register
648 __STATIC_INLINE uint32_t __get_VBAR(void)
651 __ASM volatile("MRC p15, 0, %0, c12, c0, 0" : "=r"(result));
657 This function assigns the given value to the Vector Base Address Register.
659 \param [in] vbar Vector Base Address Register value to set
661 __STATIC_INLINE void __set_VBAR(uint32_t vbar)
663 __ASM volatile("MCR p15, 0, %0, c12, c0, 1" : : "r"(vbar) : "memory");
666 /** \brief Set CNTFRQ
668 This function assigns the given value to PL1 Physical Timer Counter Frequency Register (CNTFRQ).
670 \param [in] value CNTFRQ Register value to set
672 __STATIC_INLINE void __set_CNTFRQ(uint32_t value) {
673 __ASM volatile("MCR p15, 0, %0, c14, c0, 0" : : "r"(value) : "memory");
676 /** \brief Set CNTP_TVAL
678 This function assigns the given value to PL1 Physical Timer Value Register (CNTP_TVAL).
680 \param [in] value CNTP_TVAL Register value to set
682 __STATIC_INLINE void __set_CNTP_TVAL(uint32_t value) {
683 __ASM volatile("MCR p15, 0, %0, c14, c2, 0" : : "r"(value) : "memory");
686 /** \brief Get CNTP_TVAL
688 This function returns the value of the PL1 Physical Timer Value Register (CNTP_TVAL).
690 \return CNTP_TVAL Register value
692 __STATIC_INLINE uint32_t __get_CNTP_TVAL() {
694 __ASM volatile("MRC p15, 0, %0, c14, c2, 0" : "=r"(result));
698 /** \brief Set CNTP_CTL
700 This function assigns the given value to PL1 Physical Timer Control Register (CNTP_CTL).
702 \param [in] value CNTP_CTL Register value to set
704 __STATIC_INLINE void __set_CNTP_CTL(uint32_t value) {
705 __ASM volatile("MCR p15, 0, %0, c14, c2, 1" : : "r"(value) : "memory");
708 /** \brief Get CNTP_CTL register
709 \return CNTP_CTL Register value
711 __STATIC_INLINE uint32_t __get_CNTP_CTL() {
713 __ASM volatile("MRC p15, 0, %0, c14, c2, 1" : "=r"(result));
717 /** \brief Set TLBIALL
721 __STATIC_INLINE void __set_TLBIALL(uint32_t value) {
722 __ASM volatile("MCR p15, 0, %0, c8, c7, 0" : : "r"(value) : "memory");
725 /** \brief Set BPIALL.
727 Branch Predictor Invalidate All
729 __STATIC_INLINE void __set_BPIALL(uint32_t value) {
730 __ASM volatile("MCR p15, 0, %0, c7, c5, 6" : : "r"(value) : "memory");
733 /** \brief Set ICIALLU
735 Instruction Cache Invalidate All
737 __STATIC_INLINE void __set_ICIALLU(uint32_t value) {
738 __ASM volatile("MCR p15, 0, %0, c7, c5, 0" : : "r"(value) : "memory");
741 /** \brief Set DCCMVAC
745 __STATIC_INLINE void __set_DCCMVAC(uint32_t value) {
746 __ASM volatile("MCR p15, 0, %0, c7, c10, 1" : : "r"(value) : "memory");
749 /** \brief Set DCIMVAC
751 Data cache invalidate
753 __STATIC_INLINE void __set_DCIMVAC(uint32_t value) {
754 __ASM volatile("MCR p15, 0, %0, c7, c6, 1" : : "r"(value) : "memory");
757 /** \brief Set DCCIMVAC
759 Data cache clean and invalidate
761 __STATIC_INLINE void __set_DCCIMVAC(uint32_t value) {
762 __ASM volatile("MCR p15, 0, %0, c7, c14, 1" : : "r"(value) : "memory");
766 /** \brief Set CCSIDR
768 __STATIC_INLINE void __set_CCSIDR(uint32_t value) {
769 __ASM volatile("MCR p15, 2, %0, c0, c0, 0" : : "r"(value) : "memory");
772 /** \brief Get CCSIDR
773 \return CCSIDR Register value
775 __STATIC_INLINE uint32_t __get_CCSIDR() {
777 __ASM volatile("MRC p15, 1, %0, c0, c0, 0" : "=r"(result));
782 \return CLIDR Register value
784 __STATIC_INLINE uint32_t __get_CLIDR() {
786 __ASM volatile("MRC p15, 1, %0, c0, c0, 1" : "=r"(result));
790 __STATIC_INLINE int32_t log2_up(uint32_t n)
798 /* if n not power of 2 -> round up*/
799 if ( n & (n - 1) ) log++;
803 __STATIC_INLINE void __L1C_MaintainDCacheSetWay(uint32_t level, uint32_t maint)
805 register volatile uint32_t Dummy;
806 register volatile uint32_t ccsidr;
810 uint32_t log2_linesize;
811 uint32_t log2_num_ways;
814 /* set csselr, select ccsidr register */
816 /* get current ccsidr register */
817 ccsidr = __get_CCSIDR();
818 num_sets = ((ccsidr & 0x0FFFE000) >> 13) + 1;
819 num_ways = ((ccsidr & 0x00001FF8) >> 3) + 1;
820 log2_linesize = (ccsidr & 0x00000007) + 2 + 2;
821 log2_num_ways = log2_up(num_ways);
822 shift_way = 32 - log2_num_ways;
823 for(int way = num_ways-1; way >= 0; way--) {
824 for(int set = num_sets-1; set >= 0; set--) {
825 Dummy = (level << 1) | (set << log2_linesize) | (way << shift_way);
829 __ASM volatile("MCR p15, 0, %0, c7, c6, 2" : : "r"(Dummy) : "memory"); // DCISW. Invalidate by Set/Way
833 __ASM volatile("MCR p15, 0, %0, c7, c10, 2" : : "r"(Dummy) : "memory"); // DCCSW. Clean by Set/Way
837 __ASM volatile("MCR p15, 0, %0, c7, c14, 2" : : "r"(Dummy) : "memory"); // DCCISW. Clean and Invalidate by Set/Way
846 /** \brief Clean and Invalidate the entire data or unified cache
848 Generic mechanism for cleaning/invalidating the entire data or unified cache to the point of coherency
850 __STATIC_INLINE void __L1C_CleanInvalidateCache(uint32_t op) {
851 register volatile uint32_t clidr;
853 clidr = __get_CLIDR();
854 for(uint32_t i = 0; i<7; i++)
856 cache_type = (clidr >> i*3) & 0x7UL;
857 if ((cache_type >= 2) && (cache_type <= 4))
859 __L1C_MaintainDCacheSetWay(i, op);
865 /** \brief Enable Floating Point Unit
867 Critical section, called from undef handler, so systick is disabled
869 __STATIC_INLINE void __FPU_Enable(void) {
871 //Permit access to VFP/NEON, registers by modifying CPACR
872 " MRC p15,0,R1,c1,c0,2 \n"
873 " ORR R1,R1,#0x00F00000 \n"
874 " MCR p15,0,R1,c1,c0,2 \n"
876 //Ensure that subsequent instructions occur in the context of VFP/NEON access permitted
881 " ORR R1,R1,#0x40000000 \n"
884 //Initialise VFP/NEON registers to 0
887 #if TARGET_FEATURE_EXTENSION_REGISTER_COUNT >= 16
888 //Initialise D16 registers to 0
907 #if TARGET_FEATURE_EXTENSION_REGISTER_COUNT == 32
908 //Initialise D32 registers to 0
928 // Initialise FPSCR to a known state
929 // Mask off all bits that do not have to be preserved. Non-preserved bits can/should be zero.
930 __set_FPSCR(__get_FPSCR() & 0x00086060u);
933 #pragma GCC diagnostic pop
935 #endif /* __CMSIS_GCC_H */