The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
<>
Date:
Mon Jan 16 12:05:23 2017 +0000
Revision:
134:ad3be0349dc5
Parent:
130:d75b3fe1f5cb
Release 134 of the mbed library

Ports for Upcoming Targets


Fixes and Changes

3488: Dev stm i2c v2 unitary functions https://github.com/ARMmbed/mbed-os/pull/3488
3492: Fix #3463 CAN read() return value https://github.com/ARMmbed/mbed-os/pull/3492
3503: [LPC15xx] Ensure that PWM=1 is resolved correctly https://github.com/ARMmbed/mbed-os/pull/3503
3504: [LPC15xx] CAN implementation improvements https://github.com/ARMmbed/mbed-os/pull/3504
3539: NUCLEO_F412ZG - Add support of TRNG peripheral https://github.com/ARMmbed/mbed-os/pull/3539
3540: STM: SPI: Initialize Rx in spi_master_write https://github.com/ARMmbed/mbed-os/pull/3540
3438: K64F: Add support for SERIAL ASYNCH API https://github.com/ARMmbed/mbed-os/pull/3438
3519: MCUXpresso: Fix ENET driver to enable interrupts after interrupt handler is set https://github.com/ARMmbed/mbed-os/pull/3519
3544: STM32L4 deepsleep improvement https://github.com/ARMmbed/mbed-os/pull/3544
3546: NUCLEO-F412ZG - Add CAN peripheral https://github.com/ARMmbed/mbed-os/pull/3546
3551: Fix I2C driver for RZ/A1H https://github.com/ARMmbed/mbed-os/pull/3551
3558: K64F UART Asynch API: Fix synchronization issue https://github.com/ARMmbed/mbed-os/pull/3558
3563: LPC4088 - Fix vector checksum https://github.com/ARMmbed/mbed-os/pull/3563
3567: Dev stm32 F0 v1.7.0 https://github.com/ARMmbed/mbed-os/pull/3567
3577: Fixes linking errors when building with debug profile https://github.com/ARMmbed/mbed-os/pull/3577

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 124:2241e3a39974 1 /**************************************************************************//**
Kojto 124:2241e3a39974 2 * @file core_caFunc.h
Kojto 124:2241e3a39974 3 * @brief CMSIS Cortex-A Core Function Access Header File
Kojto 124:2241e3a39974 4 * @version V3.10
Kojto 124:2241e3a39974 5 * @date 30 Oct 2013
Kojto 124:2241e3a39974 6 *
Kojto 124:2241e3a39974 7 * @note
Kojto 124:2241e3a39974 8 *
Kojto 124:2241e3a39974 9 ******************************************************************************/
Kojto 124:2241e3a39974 10 /* Copyright (c) 2009 - 2013 ARM LIMITED
Kojto 124:2241e3a39974 11
Kojto 124:2241e3a39974 12 All rights reserved.
Kojto 124:2241e3a39974 13 Redistribution and use in source and binary forms, with or without
Kojto 124:2241e3a39974 14 modification, are permitted provided that the following conditions are met:
Kojto 124:2241e3a39974 15 - Redistributions of source code must retain the above copyright
Kojto 124:2241e3a39974 16 notice, this list of conditions and the following disclaimer.
Kojto 124:2241e3a39974 17 - Redistributions in binary form must reproduce the above copyright
Kojto 124:2241e3a39974 18 notice, this list of conditions and the following disclaimer in the
Kojto 124:2241e3a39974 19 documentation and/or other materials provided with the distribution.
Kojto 124:2241e3a39974 20 - Neither the name of ARM nor the names of its contributors may be used
Kojto 124:2241e3a39974 21 to endorse or promote products derived from this software without
Kojto 124:2241e3a39974 22 specific prior written permission.
Kojto 124:2241e3a39974 23 *
Kojto 124:2241e3a39974 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Kojto 124:2241e3a39974 25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Kojto 124:2241e3a39974 26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Kojto 124:2241e3a39974 27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
Kojto 124:2241e3a39974 28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Kojto 124:2241e3a39974 29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Kojto 124:2241e3a39974 30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Kojto 124:2241e3a39974 31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Kojto 124:2241e3a39974 32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Kojto 124:2241e3a39974 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Kojto 124:2241e3a39974 34 POSSIBILITY OF SUCH DAMAGE.
Kojto 124:2241e3a39974 35 ---------------------------------------------------------------------------*/
Kojto 124:2241e3a39974 36
Kojto 124:2241e3a39974 37
Kojto 124:2241e3a39974 38 #ifndef __CORE_CAFUNC_H__
Kojto 124:2241e3a39974 39 #define __CORE_CAFUNC_H__
Kojto 124:2241e3a39974 40
Kojto 124:2241e3a39974 41
Kojto 124:2241e3a39974 42 /* ########################### Core Function Access ########################### */
Kojto 124:2241e3a39974 43 /** \ingroup CMSIS_Core_FunctionInterface
Kojto 124:2241e3a39974 44 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
Kojto 124:2241e3a39974 45 @{
Kojto 124:2241e3a39974 46 */
Kojto 124:2241e3a39974 47
Kojto 124:2241e3a39974 48 #if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
Kojto 124:2241e3a39974 49 /* ARM armcc specific functions */
Kojto 124:2241e3a39974 50
Kojto 124:2241e3a39974 51 #if (__ARMCC_VERSION < 400677)
Kojto 124:2241e3a39974 52 #error "Please use ARM Compiler Toolchain V4.0.677 or later!"
Kojto 124:2241e3a39974 53 #endif
Kojto 124:2241e3a39974 54
Kojto 124:2241e3a39974 55 #define MODE_USR 0x10
Kojto 124:2241e3a39974 56 #define MODE_FIQ 0x11
Kojto 124:2241e3a39974 57 #define MODE_IRQ 0x12
Kojto 124:2241e3a39974 58 #define MODE_SVC 0x13
Kojto 124:2241e3a39974 59 #define MODE_MON 0x16
Kojto 124:2241e3a39974 60 #define MODE_ABT 0x17
Kojto 124:2241e3a39974 61 #define MODE_HYP 0x1A
Kojto 124:2241e3a39974 62 #define MODE_UND 0x1B
Kojto 124:2241e3a39974 63 #define MODE_SYS 0x1F
Kojto 124:2241e3a39974 64
Kojto 124:2241e3a39974 65 /** \brief Get APSR Register
Kojto 124:2241e3a39974 66
Kojto 124:2241e3a39974 67 This function returns the content of the APSR Register.
Kojto 124:2241e3a39974 68
Kojto 124:2241e3a39974 69 \return APSR Register value
Kojto 124:2241e3a39974 70 */
Kojto 124:2241e3a39974 71 __STATIC_INLINE uint32_t __get_APSR(void)
Kojto 124:2241e3a39974 72 {
Kojto 124:2241e3a39974 73 register uint32_t __regAPSR __ASM("apsr");
Kojto 124:2241e3a39974 74 return(__regAPSR);
Kojto 124:2241e3a39974 75 }
Kojto 124:2241e3a39974 76
Kojto 124:2241e3a39974 77
Kojto 124:2241e3a39974 78 /** \brief Get CPSR Register
Kojto 124:2241e3a39974 79
Kojto 124:2241e3a39974 80 This function returns the content of the CPSR Register.
Kojto 124:2241e3a39974 81
Kojto 124:2241e3a39974 82 \return CPSR Register value
Kojto 124:2241e3a39974 83 */
Kojto 124:2241e3a39974 84 __STATIC_INLINE uint32_t __get_CPSR(void)
Kojto 124:2241e3a39974 85 {
Kojto 124:2241e3a39974 86 register uint32_t __regCPSR __ASM("cpsr");
Kojto 124:2241e3a39974 87 return(__regCPSR);
Kojto 124:2241e3a39974 88 }
Kojto 124:2241e3a39974 89
Kojto 124:2241e3a39974 90 /** \brief Set Stack Pointer
Kojto 124:2241e3a39974 91
Kojto 124:2241e3a39974 92 This function assigns the given value to the current stack pointer.
Kojto 124:2241e3a39974 93
Kojto 124:2241e3a39974 94 \param [in] topOfStack Stack Pointer value to set
Kojto 124:2241e3a39974 95 */
Kojto 124:2241e3a39974 96 register uint32_t __regSP __ASM("sp");
Kojto 124:2241e3a39974 97 __STATIC_INLINE void __set_SP(uint32_t topOfStack)
Kojto 124:2241e3a39974 98 {
Kojto 124:2241e3a39974 99 __regSP = topOfStack;
Kojto 124:2241e3a39974 100 }
Kojto 124:2241e3a39974 101
Kojto 124:2241e3a39974 102
Kojto 124:2241e3a39974 103 /** \brief Get link register
Kojto 124:2241e3a39974 104
Kojto 124:2241e3a39974 105 This function returns the value of the link register
Kojto 124:2241e3a39974 106
Kojto 124:2241e3a39974 107 \return Value of link register
Kojto 124:2241e3a39974 108 */
Kojto 124:2241e3a39974 109 register uint32_t __reglr __ASM("lr");
Kojto 124:2241e3a39974 110 __STATIC_INLINE uint32_t __get_LR(void)
Kojto 124:2241e3a39974 111 {
Kojto 124:2241e3a39974 112 return(__reglr);
Kojto 124:2241e3a39974 113 }
Kojto 124:2241e3a39974 114
Kojto 124:2241e3a39974 115 /** \brief Set link register
Kojto 124:2241e3a39974 116
Kojto 124:2241e3a39974 117 This function sets the value of the link register
Kojto 124:2241e3a39974 118
Kojto 124:2241e3a39974 119 \param [in] lr LR value to set
Kojto 124:2241e3a39974 120 */
Kojto 124:2241e3a39974 121 __STATIC_INLINE void __set_LR(uint32_t lr)
Kojto 124:2241e3a39974 122 {
Kojto 124:2241e3a39974 123 __reglr = lr;
Kojto 124:2241e3a39974 124 }
Kojto 124:2241e3a39974 125
Kojto 124:2241e3a39974 126 /** \brief Set Process Stack Pointer
Kojto 124:2241e3a39974 127
Kojto 124:2241e3a39974 128 This function assigns the given value to the USR/SYS Stack Pointer (PSP).
Kojto 124:2241e3a39974 129
Kojto 124:2241e3a39974 130 \param [in] topOfProcStack USR/SYS Stack Pointer value to set
Kojto 124:2241e3a39974 131 */
Kojto 124:2241e3a39974 132 __STATIC_ASM void __set_PSP(uint32_t topOfProcStack)
Kojto 124:2241e3a39974 133 {
Kojto 124:2241e3a39974 134 ARM
Kojto 124:2241e3a39974 135 PRESERVE8
Kojto 124:2241e3a39974 136
Kojto 124:2241e3a39974 137 BIC R0, R0, #7 ;ensure stack is 8-byte aligned
Kojto 124:2241e3a39974 138 MRS R1, CPSR
Kojto 124:2241e3a39974 139 CPS #MODE_SYS ;no effect in USR mode
Kojto 124:2241e3a39974 140 MOV SP, R0
Kojto 124:2241e3a39974 141 MSR CPSR_c, R1 ;no effect in USR mode
Kojto 124:2241e3a39974 142 ISB
Kojto 124:2241e3a39974 143 BX LR
Kojto 124:2241e3a39974 144
Kojto 124:2241e3a39974 145 }
Kojto 124:2241e3a39974 146
Kojto 124:2241e3a39974 147 /** \brief Set User Mode
Kojto 124:2241e3a39974 148
Kojto 124:2241e3a39974 149 This function changes the processor state to User Mode
Kojto 124:2241e3a39974 150 */
Kojto 124:2241e3a39974 151 __STATIC_ASM void __set_CPS_USR(void)
Kojto 124:2241e3a39974 152 {
Kojto 124:2241e3a39974 153 ARM
Kojto 124:2241e3a39974 154
Kojto 124:2241e3a39974 155 CPS #MODE_USR
Kojto 124:2241e3a39974 156 BX LR
Kojto 124:2241e3a39974 157 }
Kojto 124:2241e3a39974 158
Kojto 124:2241e3a39974 159
Kojto 124:2241e3a39974 160 /** \brief Enable FIQ
Kojto 124:2241e3a39974 161
Kojto 124:2241e3a39974 162 This function enables FIQ interrupts by clearing the F-bit in the CPSR.
Kojto 124:2241e3a39974 163 Can only be executed in Privileged modes.
Kojto 124:2241e3a39974 164 */
Kojto 124:2241e3a39974 165 #define __enable_fault_irq __enable_fiq
Kojto 124:2241e3a39974 166
Kojto 124:2241e3a39974 167
Kojto 124:2241e3a39974 168 /** \brief Disable FIQ
Kojto 124:2241e3a39974 169
Kojto 124:2241e3a39974 170 This function disables FIQ interrupts by setting the F-bit in the CPSR.
Kojto 124:2241e3a39974 171 Can only be executed in Privileged modes.
Kojto 124:2241e3a39974 172 */
Kojto 124:2241e3a39974 173 #define __disable_fault_irq __disable_fiq
Kojto 124:2241e3a39974 174
Kojto 124:2241e3a39974 175
Kojto 124:2241e3a39974 176 /** \brief Get FPSCR
Kojto 124:2241e3a39974 177
Kojto 124:2241e3a39974 178 This function returns the current value of the Floating Point Status/Control register.
Kojto 124:2241e3a39974 179
Kojto 124:2241e3a39974 180 \return Floating Point Status/Control register value
Kojto 124:2241e3a39974 181 */
Kojto 124:2241e3a39974 182 __STATIC_INLINE uint32_t __get_FPSCR(void)
Kojto 124:2241e3a39974 183 {
Kojto 124:2241e3a39974 184 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
Kojto 124:2241e3a39974 185 register uint32_t __regfpscr __ASM("fpscr");
Kojto 124:2241e3a39974 186 return(__regfpscr);
Kojto 124:2241e3a39974 187 #else
Kojto 124:2241e3a39974 188 return(0);
Kojto 124:2241e3a39974 189 #endif
Kojto 124:2241e3a39974 190 }
Kojto 124:2241e3a39974 191
Kojto 124:2241e3a39974 192
Kojto 124:2241e3a39974 193 /** \brief Set FPSCR
Kojto 124:2241e3a39974 194
Kojto 124:2241e3a39974 195 This function assigns the given value to the Floating Point Status/Control register.
Kojto 124:2241e3a39974 196
Kojto 124:2241e3a39974 197 \param [in] fpscr Floating Point Status/Control value to set
Kojto 124:2241e3a39974 198 */
Kojto 124:2241e3a39974 199 __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
Kojto 124:2241e3a39974 200 {
Kojto 124:2241e3a39974 201 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
Kojto 124:2241e3a39974 202 register uint32_t __regfpscr __ASM("fpscr");
Kojto 124:2241e3a39974 203 __regfpscr = (fpscr);
Kojto 124:2241e3a39974 204 #endif
Kojto 124:2241e3a39974 205 }
Kojto 124:2241e3a39974 206
Kojto 124:2241e3a39974 207 /** \brief Get FPEXC
Kojto 124:2241e3a39974 208
Kojto 124:2241e3a39974 209 This function returns the current value of the Floating Point Exception Control register.
Kojto 124:2241e3a39974 210
Kojto 124:2241e3a39974 211 \return Floating Point Exception Control register value
Kojto 124:2241e3a39974 212 */
Kojto 124:2241e3a39974 213 __STATIC_INLINE uint32_t __get_FPEXC(void)
Kojto 124:2241e3a39974 214 {
Kojto 124:2241e3a39974 215 #if (__FPU_PRESENT == 1)
Kojto 124:2241e3a39974 216 register uint32_t __regfpexc __ASM("fpexc");
Kojto 124:2241e3a39974 217 return(__regfpexc);
Kojto 124:2241e3a39974 218 #else
Kojto 124:2241e3a39974 219 return(0);
Kojto 124:2241e3a39974 220 #endif
Kojto 124:2241e3a39974 221 }
Kojto 124:2241e3a39974 222
Kojto 124:2241e3a39974 223
Kojto 124:2241e3a39974 224 /** \brief Set FPEXC
Kojto 124:2241e3a39974 225
Kojto 124:2241e3a39974 226 This function assigns the given value to the Floating Point Exception Control register.
Kojto 124:2241e3a39974 227
Kojto 124:2241e3a39974 228 \param [in] fpscr Floating Point Exception Control value to set
Kojto 124:2241e3a39974 229 */
Kojto 124:2241e3a39974 230 __STATIC_INLINE void __set_FPEXC(uint32_t fpexc)
Kojto 124:2241e3a39974 231 {
Kojto 124:2241e3a39974 232 #if (__FPU_PRESENT == 1)
Kojto 124:2241e3a39974 233 register uint32_t __regfpexc __ASM("fpexc");
Kojto 124:2241e3a39974 234 __regfpexc = (fpexc);
Kojto 124:2241e3a39974 235 #endif
Kojto 124:2241e3a39974 236 }
Kojto 124:2241e3a39974 237
Kojto 124:2241e3a39974 238 /** \brief Get CPACR
Kojto 124:2241e3a39974 239
Kojto 124:2241e3a39974 240 This function returns the current value of the Coprocessor Access Control register.
Kojto 124:2241e3a39974 241
Kojto 124:2241e3a39974 242 \return Coprocessor Access Control register value
Kojto 124:2241e3a39974 243 */
Kojto 124:2241e3a39974 244 __STATIC_INLINE uint32_t __get_CPACR(void)
Kojto 124:2241e3a39974 245 {
Kojto 124:2241e3a39974 246 register uint32_t __regCPACR __ASM("cp15:0:c1:c0:2");
Kojto 124:2241e3a39974 247 return __regCPACR;
Kojto 124:2241e3a39974 248 }
Kojto 124:2241e3a39974 249
Kojto 124:2241e3a39974 250 /** \brief Set CPACR
Kojto 124:2241e3a39974 251
Kojto 124:2241e3a39974 252 This function assigns the given value to the Coprocessor Access Control register.
Kojto 124:2241e3a39974 253
Kojto 124:2241e3a39974 254 \param [in] cpacr Coprocessor Acccess Control value to set
Kojto 124:2241e3a39974 255 */
Kojto 124:2241e3a39974 256 __STATIC_INLINE void __set_CPACR(uint32_t cpacr)
Kojto 124:2241e3a39974 257 {
Kojto 124:2241e3a39974 258 register uint32_t __regCPACR __ASM("cp15:0:c1:c0:2");
Kojto 124:2241e3a39974 259 __regCPACR = cpacr;
Kojto 124:2241e3a39974 260 __ISB();
Kojto 124:2241e3a39974 261 }
Kojto 124:2241e3a39974 262
Kojto 124:2241e3a39974 263 /** \brief Get CBAR
Kojto 124:2241e3a39974 264
Kojto 124:2241e3a39974 265 This function returns the value of the Configuration Base Address register.
Kojto 124:2241e3a39974 266
Kojto 124:2241e3a39974 267 \return Configuration Base Address register value
Kojto 124:2241e3a39974 268 */
Kojto 124:2241e3a39974 269 __STATIC_INLINE uint32_t __get_CBAR() {
Kojto 124:2241e3a39974 270 register uint32_t __regCBAR __ASM("cp15:4:c15:c0:0");
Kojto 124:2241e3a39974 271 return(__regCBAR);
Kojto 124:2241e3a39974 272 }
Kojto 124:2241e3a39974 273
Kojto 124:2241e3a39974 274 /** \brief Get TTBR0
Kojto 124:2241e3a39974 275
Kojto 124:2241e3a39974 276 This function returns the value of the Translation Table Base Register 0.
Kojto 124:2241e3a39974 277
Kojto 124:2241e3a39974 278 \return Translation Table Base Register 0 value
Kojto 124:2241e3a39974 279 */
Kojto 124:2241e3a39974 280 __STATIC_INLINE uint32_t __get_TTBR0() {
Kojto 124:2241e3a39974 281 register uint32_t __regTTBR0 __ASM("cp15:0:c2:c0:0");
Kojto 124:2241e3a39974 282 return(__regTTBR0);
Kojto 124:2241e3a39974 283 }
Kojto 124:2241e3a39974 284
Kojto 124:2241e3a39974 285 /** \brief Set TTBR0
Kojto 124:2241e3a39974 286
Kojto 124:2241e3a39974 287 This function assigns the given value to the Translation Table Base Register 0.
Kojto 124:2241e3a39974 288
Kojto 124:2241e3a39974 289 \param [in] ttbr0 Translation Table Base Register 0 value to set
Kojto 124:2241e3a39974 290 */
Kojto 124:2241e3a39974 291 __STATIC_INLINE void __set_TTBR0(uint32_t ttbr0) {
Kojto 124:2241e3a39974 292 register uint32_t __regTTBR0 __ASM("cp15:0:c2:c0:0");
Kojto 124:2241e3a39974 293 __regTTBR0 = ttbr0;
Kojto 124:2241e3a39974 294 __ISB();
Kojto 124:2241e3a39974 295 }
Kojto 124:2241e3a39974 296
Kojto 124:2241e3a39974 297 /** \brief Get DACR
Kojto 124:2241e3a39974 298
Kojto 124:2241e3a39974 299 This function returns the value of the Domain Access Control Register.
Kojto 124:2241e3a39974 300
Kojto 124:2241e3a39974 301 \return Domain Access Control Register value
Kojto 124:2241e3a39974 302 */
Kojto 124:2241e3a39974 303 __STATIC_INLINE uint32_t __get_DACR() {
Kojto 124:2241e3a39974 304 register uint32_t __regDACR __ASM("cp15:0:c3:c0:0");
Kojto 124:2241e3a39974 305 return(__regDACR);
Kojto 124:2241e3a39974 306 }
Kojto 124:2241e3a39974 307
Kojto 124:2241e3a39974 308 /** \brief Set DACR
Kojto 124:2241e3a39974 309
Kojto 124:2241e3a39974 310 This function assigns the given value to the Domain Access Control Register.
Kojto 124:2241e3a39974 311
Kojto 124:2241e3a39974 312 \param [in] dacr Domain Access Control Register value to set
Kojto 124:2241e3a39974 313 */
Kojto 124:2241e3a39974 314 __STATIC_INLINE void __set_DACR(uint32_t dacr) {
Kojto 124:2241e3a39974 315 register uint32_t __regDACR __ASM("cp15:0:c3:c0:0");
Kojto 124:2241e3a39974 316 __regDACR = dacr;
Kojto 124:2241e3a39974 317 __ISB();
Kojto 124:2241e3a39974 318 }
Kojto 124:2241e3a39974 319
Kojto 124:2241e3a39974 320 /******************************** Cache and BTAC enable ****************************************************/
Kojto 124:2241e3a39974 321
Kojto 124:2241e3a39974 322 /** \brief Set SCTLR
Kojto 124:2241e3a39974 323
Kojto 124:2241e3a39974 324 This function assigns the given value to the System Control Register.
Kojto 124:2241e3a39974 325
Kojto 124:2241e3a39974 326 \param [in] sctlr System Control Register value to set
Kojto 124:2241e3a39974 327 */
Kojto 124:2241e3a39974 328 __STATIC_INLINE void __set_SCTLR(uint32_t sctlr)
Kojto 124:2241e3a39974 329 {
Kojto 124:2241e3a39974 330 register uint32_t __regSCTLR __ASM("cp15:0:c1:c0:0");
Kojto 124:2241e3a39974 331 __regSCTLR = sctlr;
Kojto 124:2241e3a39974 332 }
Kojto 124:2241e3a39974 333
Kojto 124:2241e3a39974 334 /** \brief Get SCTLR
Kojto 124:2241e3a39974 335
Kojto 124:2241e3a39974 336 This function returns the value of the System Control Register.
Kojto 124:2241e3a39974 337
Kojto 124:2241e3a39974 338 \return System Control Register value
Kojto 124:2241e3a39974 339 */
Kojto 124:2241e3a39974 340 __STATIC_INLINE uint32_t __get_SCTLR() {
Kojto 124:2241e3a39974 341 register uint32_t __regSCTLR __ASM("cp15:0:c1:c0:0");
Kojto 124:2241e3a39974 342 return(__regSCTLR);
Kojto 124:2241e3a39974 343 }
Kojto 124:2241e3a39974 344
Kojto 124:2241e3a39974 345 /** \brief Enable Caches
Kojto 124:2241e3a39974 346
Kojto 124:2241e3a39974 347 Enable Caches
Kojto 124:2241e3a39974 348 */
Kojto 124:2241e3a39974 349 __STATIC_INLINE void __enable_caches(void) {
Kojto 124:2241e3a39974 350 // Set I bit 12 to enable I Cache
Kojto 124:2241e3a39974 351 // Set C bit 2 to enable D Cache
Kojto 124:2241e3a39974 352 __set_SCTLR( __get_SCTLR() | (1 << 12) | (1 << 2));
Kojto 124:2241e3a39974 353 }
Kojto 124:2241e3a39974 354
Kojto 124:2241e3a39974 355 /** \brief Disable Caches
Kojto 124:2241e3a39974 356
Kojto 124:2241e3a39974 357 Disable Caches
Kojto 124:2241e3a39974 358 */
Kojto 124:2241e3a39974 359 __STATIC_INLINE void __disable_caches(void) {
Kojto 124:2241e3a39974 360 // Clear I bit 12 to disable I Cache
Kojto 124:2241e3a39974 361 // Clear C bit 2 to disable D Cache
Kojto 124:2241e3a39974 362 __set_SCTLR( __get_SCTLR() & ~(1 << 12) & ~(1 << 2));
Kojto 124:2241e3a39974 363 __ISB();
Kojto 124:2241e3a39974 364 }
Kojto 124:2241e3a39974 365
Kojto 124:2241e3a39974 366 /** \brief Enable BTAC
Kojto 124:2241e3a39974 367
Kojto 124:2241e3a39974 368 Enable BTAC
Kojto 124:2241e3a39974 369 */
Kojto 124:2241e3a39974 370 __STATIC_INLINE void __enable_btac(void) {
Kojto 124:2241e3a39974 371 // Set Z bit 11 to enable branch prediction
Kojto 124:2241e3a39974 372 __set_SCTLR( __get_SCTLR() | (1 << 11));
Kojto 124:2241e3a39974 373 __ISB();
Kojto 124:2241e3a39974 374 }
Kojto 124:2241e3a39974 375
Kojto 124:2241e3a39974 376 /** \brief Disable BTAC
Kojto 124:2241e3a39974 377
Kojto 124:2241e3a39974 378 Disable BTAC
Kojto 124:2241e3a39974 379 */
Kojto 124:2241e3a39974 380 __STATIC_INLINE void __disable_btac(void) {
Kojto 124:2241e3a39974 381 // Clear Z bit 11 to disable branch prediction
Kojto 124:2241e3a39974 382 __set_SCTLR( __get_SCTLR() & ~(1 << 11));
Kojto 124:2241e3a39974 383 }
Kojto 124:2241e3a39974 384
Kojto 124:2241e3a39974 385
Kojto 124:2241e3a39974 386 /** \brief Enable MMU
Kojto 124:2241e3a39974 387
Kojto 124:2241e3a39974 388 Enable MMU
Kojto 124:2241e3a39974 389 */
Kojto 124:2241e3a39974 390 __STATIC_INLINE void __enable_mmu(void) {
Kojto 124:2241e3a39974 391 // Set M bit 0 to enable the MMU
Kojto 124:2241e3a39974 392 // Set AFE bit to enable simplified access permissions model
Kojto 124:2241e3a39974 393 // Clear TRE bit to disable TEX remap and A bit to disable strict alignment fault checking
Kojto 124:2241e3a39974 394 __set_SCTLR( (__get_SCTLR() & ~(1 << 28) & ~(1 << 1)) | 1 | (1 << 29));
Kojto 124:2241e3a39974 395 __ISB();
Kojto 124:2241e3a39974 396 }
Kojto 124:2241e3a39974 397
Kojto 124:2241e3a39974 398 /** \brief Disable MMU
Kojto 124:2241e3a39974 399
Kojto 124:2241e3a39974 400 Disable MMU
Kojto 124:2241e3a39974 401 */
Kojto 124:2241e3a39974 402 __STATIC_INLINE void __disable_mmu(void) {
Kojto 124:2241e3a39974 403 // Clear M bit 0 to disable the MMU
Kojto 124:2241e3a39974 404 __set_SCTLR( __get_SCTLR() & ~1);
Kojto 124:2241e3a39974 405 __ISB();
Kojto 124:2241e3a39974 406 }
Kojto 124:2241e3a39974 407
Kojto 124:2241e3a39974 408 /******************************** TLB maintenance operations ************************************************/
Kojto 124:2241e3a39974 409 /** \brief Invalidate the whole tlb
Kojto 124:2241e3a39974 410
Kojto 124:2241e3a39974 411 TLBIALL. Invalidate the whole tlb
Kojto 124:2241e3a39974 412 */
Kojto 124:2241e3a39974 413
Kojto 124:2241e3a39974 414 __STATIC_INLINE void __ca9u_inv_tlb_all(void) {
Kojto 124:2241e3a39974 415 register uint32_t __TLBIALL __ASM("cp15:0:c8:c7:0");
Kojto 124:2241e3a39974 416 __TLBIALL = 0;
Kojto 124:2241e3a39974 417 __DSB();
Kojto 124:2241e3a39974 418 __ISB();
Kojto 124:2241e3a39974 419 }
Kojto 124:2241e3a39974 420
Kojto 124:2241e3a39974 421 /******************************** BTB maintenance operations ************************************************/
Kojto 124:2241e3a39974 422 /** \brief Invalidate entire branch predictor array
Kojto 124:2241e3a39974 423
Kojto 124:2241e3a39974 424 BPIALL. Branch Predictor Invalidate All.
Kojto 124:2241e3a39974 425 */
Kojto 124:2241e3a39974 426
Kojto 124:2241e3a39974 427 __STATIC_INLINE void __v7_inv_btac(void) {
Kojto 124:2241e3a39974 428 register uint32_t __BPIALL __ASM("cp15:0:c7:c5:6");
Kojto 124:2241e3a39974 429 __BPIALL = 0;
Kojto 124:2241e3a39974 430 __DSB(); //ensure completion of the invalidation
Kojto 124:2241e3a39974 431 __ISB(); //ensure instruction fetch path sees new state
Kojto 124:2241e3a39974 432 }
Kojto 124:2241e3a39974 433
Kojto 124:2241e3a39974 434
Kojto 124:2241e3a39974 435 /******************************** L1 cache operations ******************************************************/
Kojto 124:2241e3a39974 436
Kojto 124:2241e3a39974 437 /** \brief Invalidate the whole I$
Kojto 124:2241e3a39974 438
Kojto 124:2241e3a39974 439 ICIALLU. Instruction Cache Invalidate All to PoU
Kojto 124:2241e3a39974 440 */
Kojto 124:2241e3a39974 441 __STATIC_INLINE void __v7_inv_icache_all(void) {
Kojto 124:2241e3a39974 442 register uint32_t __ICIALLU __ASM("cp15:0:c7:c5:0");
Kojto 124:2241e3a39974 443 __ICIALLU = 0;
Kojto 124:2241e3a39974 444 __DSB(); //ensure completion of the invalidation
Kojto 124:2241e3a39974 445 __ISB(); //ensure instruction fetch path sees new I cache state
Kojto 124:2241e3a39974 446 }
Kojto 124:2241e3a39974 447
Kojto 124:2241e3a39974 448 /** \brief Clean D$ by MVA
Kojto 124:2241e3a39974 449
Kojto 124:2241e3a39974 450 DCCMVAC. Data cache clean by MVA to PoC
Kojto 124:2241e3a39974 451 */
Kojto 124:2241e3a39974 452 __STATIC_INLINE void __v7_clean_dcache_mva(void *va) {
Kojto 124:2241e3a39974 453 register uint32_t __DCCMVAC __ASM("cp15:0:c7:c10:1");
Kojto 124:2241e3a39974 454 __DCCMVAC = (uint32_t)va;
Kojto 124:2241e3a39974 455 __DMB(); //ensure the ordering of data cache maintenance operations and their effects
Kojto 124:2241e3a39974 456 }
Kojto 124:2241e3a39974 457
Kojto 124:2241e3a39974 458 /** \brief Invalidate D$ by MVA
Kojto 124:2241e3a39974 459
Kojto 124:2241e3a39974 460 DCIMVAC. Data cache invalidate by MVA to PoC
Kojto 124:2241e3a39974 461 */
Kojto 124:2241e3a39974 462 __STATIC_INLINE void __v7_inv_dcache_mva(void *va) {
Kojto 124:2241e3a39974 463 register uint32_t __DCIMVAC __ASM("cp15:0:c7:c6:1");
Kojto 124:2241e3a39974 464 __DCIMVAC = (uint32_t)va;
Kojto 124:2241e3a39974 465 __DMB(); //ensure the ordering of data cache maintenance operations and their effects
Kojto 124:2241e3a39974 466 }
Kojto 124:2241e3a39974 467
Kojto 124:2241e3a39974 468 /** \brief Clean and Invalidate D$ by MVA
Kojto 124:2241e3a39974 469
Kojto 124:2241e3a39974 470 DCCIMVAC. Data cache clean and invalidate by MVA to PoC
Kojto 124:2241e3a39974 471 */
Kojto 124:2241e3a39974 472 __STATIC_INLINE void __v7_clean_inv_dcache_mva(void *va) {
Kojto 124:2241e3a39974 473 register uint32_t __DCCIMVAC __ASM("cp15:0:c7:c14:1");
Kojto 124:2241e3a39974 474 __DCCIMVAC = (uint32_t)va;
Kojto 124:2241e3a39974 475 __DMB(); //ensure the ordering of data cache maintenance operations and their effects
Kojto 124:2241e3a39974 476 }
Kojto 124:2241e3a39974 477
Kojto 124:2241e3a39974 478 /** \brief Clean and Invalidate the entire data or unified cache
Kojto 124:2241e3a39974 479
Kojto 124:2241e3a39974 480 Generic mechanism for cleaning/invalidating the entire data or unified cache to the point of coherency.
Kojto 124:2241e3a39974 481 */
Kojto 124:2241e3a39974 482 #pragma push
Kojto 124:2241e3a39974 483 #pragma arm
Kojto 124:2241e3a39974 484 __STATIC_ASM void __v7_all_cache(uint32_t op) {
Kojto 124:2241e3a39974 485 ARM
Kojto 124:2241e3a39974 486
Kojto 124:2241e3a39974 487 PUSH {R4-R11}
Kojto 124:2241e3a39974 488
Kojto 124:2241e3a39974 489 MRC p15, 1, R6, c0, c0, 1 // Read CLIDR
Kojto 124:2241e3a39974 490 ANDS R3, R6, #0x07000000 // Extract coherency level
Kojto 124:2241e3a39974 491 MOV R3, R3, LSR #23 // Total cache levels << 1
Kojto 124:2241e3a39974 492 BEQ Finished // If 0, no need to clean
Kojto 124:2241e3a39974 493
Kojto 124:2241e3a39974 494 MOV R10, #0 // R10 holds current cache level << 1
Kojto 124:2241e3a39974 495 Loop1 ADD R2, R10, R10, LSR #1 // R2 holds cache "Set" position
Kojto 124:2241e3a39974 496 MOV R1, R6, LSR R2 // Bottom 3 bits are the Cache-type for this level
Kojto 124:2241e3a39974 497 AND R1, R1, #7 // Isolate those lower 3 bits
Kojto 124:2241e3a39974 498 CMP R1, #2
Kojto 124:2241e3a39974 499 BLT Skip // No cache or only instruction cache at this level
Kojto 124:2241e3a39974 500
Kojto 124:2241e3a39974 501 MCR p15, 2, R10, c0, c0, 0 // Write the Cache Size selection register
Kojto 124:2241e3a39974 502 ISB // ISB to sync the change to the CacheSizeID reg
Kojto 124:2241e3a39974 503 MRC p15, 1, R1, c0, c0, 0 // Reads current Cache Size ID register
Kojto 124:2241e3a39974 504 AND R2, R1, #7 // Extract the line length field
Kojto 124:2241e3a39974 505 ADD R2, R2, #4 // Add 4 for the line length offset (log2 16 bytes)
Kojto 124:2241e3a39974 506 LDR R4, =0x3FF
Kojto 124:2241e3a39974 507 ANDS R4, R4, R1, LSR #3 // R4 is the max number on the way size (right aligned)
Kojto 124:2241e3a39974 508 CLZ R5, R4 // R5 is the bit position of the way size increment
Kojto 124:2241e3a39974 509 LDR R7, =0x7FFF
Kojto 124:2241e3a39974 510 ANDS R7, R7, R1, LSR #13 // R7 is the max number of the index size (right aligned)
Kojto 124:2241e3a39974 511
Kojto 124:2241e3a39974 512 Loop2 MOV R9, R4 // R9 working copy of the max way size (right aligned)
Kojto 124:2241e3a39974 513
Kojto 124:2241e3a39974 514 Loop3 ORR R11, R10, R9, LSL R5 // Factor in the Way number and cache number into R11
Kojto 124:2241e3a39974 515 ORR R11, R11, R7, LSL R2 // Factor in the Set number
Kojto 124:2241e3a39974 516 CMP R0, #0
Kojto 124:2241e3a39974 517 BNE Dccsw
Kojto 124:2241e3a39974 518 MCR p15, 0, R11, c7, c6, 2 // DCISW. Invalidate by Set/Way
Kojto 124:2241e3a39974 519 B cont
Kojto 124:2241e3a39974 520 Dccsw CMP R0, #1
Kojto 124:2241e3a39974 521 BNE Dccisw
Kojto 124:2241e3a39974 522 MCR p15, 0, R11, c7, c10, 2 // DCCSW. Clean by Set/Way
Kojto 124:2241e3a39974 523 B cont
Kojto 124:2241e3a39974 524 Dccisw MCR p15, 0, R11, c7, c14, 2 // DCCISW. Clean and Invalidate by Set/Way
Kojto 124:2241e3a39974 525 cont SUBS R9, R9, #1 // Decrement the Way number
Kojto 124:2241e3a39974 526 BGE Loop3
Kojto 124:2241e3a39974 527 SUBS R7, R7, #1 // Decrement the Set number
Kojto 124:2241e3a39974 528 BGE Loop2
Kojto 124:2241e3a39974 529 Skip ADD R10, R10, #2 // Increment the cache number
Kojto 124:2241e3a39974 530 CMP R3, R10
Kojto 124:2241e3a39974 531 BGT Loop1
Kojto 124:2241e3a39974 532
Kojto 124:2241e3a39974 533 Finished
Kojto 124:2241e3a39974 534 DSB
Kojto 124:2241e3a39974 535 POP {R4-R11}
Kojto 124:2241e3a39974 536 BX lr
Kojto 124:2241e3a39974 537
Kojto 124:2241e3a39974 538 }
Kojto 124:2241e3a39974 539 #pragma pop
Kojto 124:2241e3a39974 540
Kojto 124:2241e3a39974 541
Kojto 124:2241e3a39974 542 /** \brief Invalidate the whole D$
Kojto 124:2241e3a39974 543
Kojto 124:2241e3a39974 544 DCISW. Invalidate by Set/Way
Kojto 124:2241e3a39974 545 */
Kojto 124:2241e3a39974 546
Kojto 124:2241e3a39974 547 __STATIC_INLINE void __v7_inv_dcache_all(void) {
Kojto 124:2241e3a39974 548 __v7_all_cache(0);
Kojto 124:2241e3a39974 549 }
Kojto 124:2241e3a39974 550
Kojto 124:2241e3a39974 551 /** \brief Clean the whole D$
Kojto 124:2241e3a39974 552
Kojto 124:2241e3a39974 553 DCCSW. Clean by Set/Way
Kojto 124:2241e3a39974 554 */
Kojto 124:2241e3a39974 555
Kojto 124:2241e3a39974 556 __STATIC_INLINE void __v7_clean_dcache_all(void) {
Kojto 124:2241e3a39974 557 __v7_all_cache(1);
Kojto 124:2241e3a39974 558 }
Kojto 124:2241e3a39974 559
Kojto 124:2241e3a39974 560 /** \brief Clean and invalidate the whole D$
Kojto 124:2241e3a39974 561
Kojto 124:2241e3a39974 562 DCCISW. Clean and Invalidate by Set/Way
Kojto 124:2241e3a39974 563 */
Kojto 124:2241e3a39974 564
Kojto 124:2241e3a39974 565 __STATIC_INLINE void __v7_clean_inv_dcache_all(void) {
Kojto 124:2241e3a39974 566 __v7_all_cache(2);
Kojto 124:2241e3a39974 567 }
Kojto 124:2241e3a39974 568
Kojto 124:2241e3a39974 569 #include "core_ca_mmu.h"
Kojto 124:2241e3a39974 570
Kojto 124:2241e3a39974 571 #elif (defined (__ICCARM__)) /*---------------- ICC Compiler ---------------------*/
Kojto 124:2241e3a39974 572
Kojto 124:2241e3a39974 573 #define __inline inline
Kojto 124:2241e3a39974 574
Kojto 124:2241e3a39974 575 inline static uint32_t __disable_irq_iar() {
Kojto 124:2241e3a39974 576 int irq_dis = __get_CPSR() & 0x80; // 7bit CPSR.I
Kojto 124:2241e3a39974 577 __disable_irq();
Kojto 124:2241e3a39974 578 return irq_dis;
Kojto 124:2241e3a39974 579 }
Kojto 124:2241e3a39974 580
Kojto 124:2241e3a39974 581 #define MODE_USR 0x10
Kojto 124:2241e3a39974 582 #define MODE_FIQ 0x11
Kojto 124:2241e3a39974 583 #define MODE_IRQ 0x12
Kojto 124:2241e3a39974 584 #define MODE_SVC 0x13
Kojto 124:2241e3a39974 585 #define MODE_MON 0x16
Kojto 124:2241e3a39974 586 #define MODE_ABT 0x17
Kojto 124:2241e3a39974 587 #define MODE_HYP 0x1A
Kojto 124:2241e3a39974 588 #define MODE_UND 0x1B
Kojto 124:2241e3a39974 589 #define MODE_SYS 0x1F
Kojto 124:2241e3a39974 590
Kojto 124:2241e3a39974 591 /** \brief Set Process Stack Pointer
Kojto 124:2241e3a39974 592
Kojto 124:2241e3a39974 593 This function assigns the given value to the USR/SYS Stack Pointer (PSP).
Kojto 124:2241e3a39974 594
Kojto 124:2241e3a39974 595 \param [in] topOfProcStack USR/SYS Stack Pointer value to set
Kojto 124:2241e3a39974 596 */
Kojto 124:2241e3a39974 597 // from rt_CMSIS.c
Kojto 124:2241e3a39974 598 __arm static inline void __set_PSP(uint32_t topOfProcStack) {
Kojto 124:2241e3a39974 599 __asm(
Kojto 124:2241e3a39974 600 " ARM\n"
Kojto 124:2241e3a39974 601 // " PRESERVE8\n"
Kojto 124:2241e3a39974 602
Kojto 124:2241e3a39974 603 " BIC R0, R0, #7 ;ensure stack is 8-byte aligned \n"
Kojto 124:2241e3a39974 604 " MRS R1, CPSR \n"
Kojto 124:2241e3a39974 605 " CPS #0x1F ;no effect in USR mode \n" // MODE_SYS
Kojto 124:2241e3a39974 606 " MOV SP, R0 \n"
Kojto 124:2241e3a39974 607 " MSR CPSR_c, R1 ;no effect in USR mode \n"
Kojto 124:2241e3a39974 608 " ISB \n"
Kojto 124:2241e3a39974 609 " BX LR \n");
Kojto 124:2241e3a39974 610 }
Kojto 124:2241e3a39974 611
Kojto 124:2241e3a39974 612 /** \brief Set User Mode
Kojto 124:2241e3a39974 613
Kojto 124:2241e3a39974 614 This function changes the processor state to User Mode
Kojto 124:2241e3a39974 615 */
Kojto 124:2241e3a39974 616 // from rt_CMSIS.c
Kojto 124:2241e3a39974 617 __arm static inline void __set_CPS_USR(void) {
Kojto 124:2241e3a39974 618 __asm(
Kojto 124:2241e3a39974 619 " ARM \n"
Kojto 124:2241e3a39974 620
Kojto 124:2241e3a39974 621 " CPS #0x10 \n" // MODE_USR
Kojto 124:2241e3a39974 622 " BX LR\n");
Kojto 124:2241e3a39974 623 }
Kojto 124:2241e3a39974 624
Kojto 124:2241e3a39974 625 /** \brief Set TTBR0
Kojto 124:2241e3a39974 626
Kojto 124:2241e3a39974 627 This function assigns the given value to the Translation Table Base Register 0.
Kojto 124:2241e3a39974 628
Kojto 124:2241e3a39974 629 \param [in] ttbr0 Translation Table Base Register 0 value to set
Kojto 124:2241e3a39974 630 */
Kojto 124:2241e3a39974 631 // from mmu_Renesas_RZ_A1.c
Kojto 124:2241e3a39974 632 __STATIC_INLINE void __set_TTBR0(uint32_t ttbr0) {
Kojto 124:2241e3a39974 633 __MCR(15, 0, ttbr0, 2, 0, 0); // reg to cp15
Kojto 124:2241e3a39974 634 __ISB();
Kojto 124:2241e3a39974 635 }
Kojto 124:2241e3a39974 636
Kojto 124:2241e3a39974 637 /** \brief Set DACR
Kojto 124:2241e3a39974 638
Kojto 124:2241e3a39974 639 This function assigns the given value to the Domain Access Control Register.
Kojto 124:2241e3a39974 640
Kojto 124:2241e3a39974 641 \param [in] dacr Domain Access Control Register value to set
Kojto 124:2241e3a39974 642 */
Kojto 124:2241e3a39974 643 // from mmu_Renesas_RZ_A1.c
Kojto 124:2241e3a39974 644 __STATIC_INLINE void __set_DACR(uint32_t dacr) {
Kojto 124:2241e3a39974 645 __MCR(15, 0, dacr, 3, 0, 0); // reg to cp15
Kojto 124:2241e3a39974 646 __ISB();
Kojto 124:2241e3a39974 647 }
Kojto 124:2241e3a39974 648
Kojto 124:2241e3a39974 649
Kojto 124:2241e3a39974 650 /******************************** Cache and BTAC enable ****************************************************/
Kojto 124:2241e3a39974 651 /** \brief Set SCTLR
Kojto 124:2241e3a39974 652
Kojto 124:2241e3a39974 653 This function assigns the given value to the System Control Register.
Kojto 124:2241e3a39974 654
Kojto 124:2241e3a39974 655 \param [in] sctlr System Control Register value to set
Kojto 124:2241e3a39974 656 */
Kojto 124:2241e3a39974 657 // from __enable_mmu()
Kojto 124:2241e3a39974 658 __STATIC_INLINE void __set_SCTLR(uint32_t sctlr) {
Kojto 124:2241e3a39974 659 __MCR(15, 0, sctlr, 1, 0, 0); // reg to cp15
Kojto 124:2241e3a39974 660 }
Kojto 124:2241e3a39974 661
Kojto 124:2241e3a39974 662 /** \brief Get SCTLR
Kojto 124:2241e3a39974 663
Kojto 124:2241e3a39974 664 This function returns the value of the System Control Register.
Kojto 124:2241e3a39974 665
Kojto 124:2241e3a39974 666 \return System Control Register value
Kojto 124:2241e3a39974 667 */
Kojto 124:2241e3a39974 668 // from __enable_mmu()
Kojto 124:2241e3a39974 669 __STATIC_INLINE uint32_t __get_SCTLR() {
Kojto 124:2241e3a39974 670 uint32_t __regSCTLR = __MRC(15, 0, 1, 0, 0);
Kojto 124:2241e3a39974 671 return __regSCTLR;
Kojto 124:2241e3a39974 672 }
Kojto 124:2241e3a39974 673
Kojto 124:2241e3a39974 674 /** \brief Enable Caches
Kojto 124:2241e3a39974 675
Kojto 124:2241e3a39974 676 Enable Caches
Kojto 124:2241e3a39974 677 */
Kojto 124:2241e3a39974 678 // from system_Renesas_RZ_A1.c
Kojto 124:2241e3a39974 679 __STATIC_INLINE void __enable_caches(void) {
Kojto 124:2241e3a39974 680 __set_SCTLR( __get_SCTLR() | (1 << 12) | (1 << 2));
Kojto 124:2241e3a39974 681 }
Kojto 124:2241e3a39974 682
Kojto 124:2241e3a39974 683 /** \brief Enable BTAC
Kojto 124:2241e3a39974 684
Kojto 124:2241e3a39974 685 Enable BTAC
Kojto 124:2241e3a39974 686 */
Kojto 124:2241e3a39974 687 // from system_Renesas_RZ_A1.c
Kojto 124:2241e3a39974 688 __STATIC_INLINE void __enable_btac(void) {
Kojto 124:2241e3a39974 689 __set_SCTLR( __get_SCTLR() | (1 << 11));
Kojto 124:2241e3a39974 690 __ISB();
Kojto 124:2241e3a39974 691 }
Kojto 124:2241e3a39974 692
Kojto 124:2241e3a39974 693 /** \brief Enable MMU
Kojto 124:2241e3a39974 694
Kojto 124:2241e3a39974 695 Enable MMU
Kojto 124:2241e3a39974 696 */
Kojto 124:2241e3a39974 697 // from system_Renesas_RZ_A1.c
Kojto 124:2241e3a39974 698 __STATIC_INLINE void __enable_mmu(void) {
Kojto 124:2241e3a39974 699 // Set M bit 0 to enable the MMU
Kojto 124:2241e3a39974 700 // Set AFE bit to enable simplified access permissions model
Kojto 124:2241e3a39974 701 // Clear TRE bit to disable TEX remap and A bit to disable strict alignment fault checking
Kojto 124:2241e3a39974 702 __set_SCTLR( (__get_SCTLR() & ~(1 << 28) & ~(1 << 1)) | 1 | (1 << 29));
Kojto 124:2241e3a39974 703 __ISB();
Kojto 124:2241e3a39974 704 }
Kojto 124:2241e3a39974 705
Kojto 124:2241e3a39974 706 /******************************** TLB maintenance operations ************************************************/
Kojto 124:2241e3a39974 707 /** \brief Invalidate the whole tlb
Kojto 124:2241e3a39974 708
Kojto 124:2241e3a39974 709 TLBIALL. Invalidate the whole tlb
Kojto 124:2241e3a39974 710 */
Kojto 124:2241e3a39974 711 // from system_Renesas_RZ_A1.c
Kojto 124:2241e3a39974 712 __STATIC_INLINE void __ca9u_inv_tlb_all(void) {
Kojto 124:2241e3a39974 713 uint32_t val = 0;
Kojto 124:2241e3a39974 714 __MCR(15, 0, val, 8, 7, 0); // reg to cp15
Kojto 124:2241e3a39974 715 __MCR(15, 0, val, 8, 6, 0); // reg to cp15
Kojto 124:2241e3a39974 716 __MCR(15, 0, val, 8, 5, 0); // reg to cp15
Kojto 124:2241e3a39974 717 __DSB();
Kojto 124:2241e3a39974 718 __ISB();
Kojto 124:2241e3a39974 719 }
Kojto 124:2241e3a39974 720
Kojto 124:2241e3a39974 721 /******************************** BTB maintenance operations ************************************************/
Kojto 124:2241e3a39974 722 /** \brief Invalidate entire branch predictor array
Kojto 124:2241e3a39974 723
Kojto 124:2241e3a39974 724 BPIALL. Branch Predictor Invalidate All.
Kojto 124:2241e3a39974 725 */
Kojto 124:2241e3a39974 726 // from system_Renesas_RZ_A1.c
Kojto 124:2241e3a39974 727 __STATIC_INLINE void __v7_inv_btac(void) {
Kojto 124:2241e3a39974 728 uint32_t val = 0;
Kojto 124:2241e3a39974 729 __MCR(15, 0, val, 7, 5, 6); // reg to cp15
Kojto 124:2241e3a39974 730 __DSB(); //ensure completion of the invalidation
Kojto 124:2241e3a39974 731 __ISB(); //ensure instruction fetch path sees new state
Kojto 124:2241e3a39974 732 }
Kojto 124:2241e3a39974 733
Kojto 124:2241e3a39974 734
Kojto 124:2241e3a39974 735 /******************************** L1 cache operations ******************************************************/
Kojto 124:2241e3a39974 736
Kojto 124:2241e3a39974 737 /** \brief Invalidate the whole I$
Kojto 124:2241e3a39974 738
Kojto 124:2241e3a39974 739 ICIALLU. Instruction Cache Invalidate All to PoU
Kojto 124:2241e3a39974 740 */
Kojto 124:2241e3a39974 741 // from system_Renesas_RZ_A1.c
Kojto 124:2241e3a39974 742 __STATIC_INLINE void __v7_inv_icache_all(void) {
Kojto 124:2241e3a39974 743 uint32_t val = 0;
Kojto 124:2241e3a39974 744 __MCR(15, 0, val, 7, 5, 0); // reg to cp15
Kojto 124:2241e3a39974 745 __DSB(); //ensure completion of the invalidation
Kojto 124:2241e3a39974 746 __ISB(); //ensure instruction fetch path sees new I cache state
Kojto 124:2241e3a39974 747 }
Kojto 124:2241e3a39974 748
Kojto 124:2241e3a39974 749 // from __v7_inv_dcache_all()
Kojto 124:2241e3a39974 750 __arm static inline void __v7_all_cache(uint32_t op) {
Kojto 124:2241e3a39974 751 __asm(
Kojto 124:2241e3a39974 752 " ARM \n"
Kojto 124:2241e3a39974 753
Kojto 124:2241e3a39974 754 " PUSH {R4-R11} \n"
Kojto 124:2241e3a39974 755
Kojto 124:2241e3a39974 756 " MRC p15, 1, R6, c0, c0, 1\n" // Read CLIDR
Kojto 124:2241e3a39974 757 " ANDS R3, R6, #0x07000000\n" // Extract coherency level
Kojto 124:2241e3a39974 758 " MOV R3, R3, LSR #23\n" // Total cache levels << 1
Kojto 124:2241e3a39974 759 " BEQ Finished\n" // If 0, no need to clean
Kojto 124:2241e3a39974 760
Kojto 124:2241e3a39974 761 " MOV R10, #0\n" // R10 holds current cache level << 1
Kojto 124:2241e3a39974 762 "Loop1: ADD R2, R10, R10, LSR #1\n" // R2 holds cache "Set" position
Kojto 124:2241e3a39974 763 " MOV R1, R6, LSR R2 \n" // Bottom 3 bits are the Cache-type for this level
Kojto 124:2241e3a39974 764 " AND R1, R1, #7 \n" // Isolate those lower 3 bits
Kojto 124:2241e3a39974 765 " CMP R1, #2 \n"
Kojto 124:2241e3a39974 766 " BLT Skip \n" // No cache or only instruction cache at this level
Kojto 124:2241e3a39974 767
Kojto 124:2241e3a39974 768 " MCR p15, 2, R10, c0, c0, 0 \n" // Write the Cache Size selection register
Kojto 124:2241e3a39974 769 " ISB \n" // ISB to sync the change to the CacheSizeID reg
Kojto 124:2241e3a39974 770 " MRC p15, 1, R1, c0, c0, 0 \n" // Reads current Cache Size ID register
Kojto 124:2241e3a39974 771 " AND R2, R1, #7 \n" // Extract the line length field
Kojto 124:2241e3a39974 772 " ADD R2, R2, #4 \n" // Add 4 for the line length offset (log2 16 bytes)
Kojto 124:2241e3a39974 773 " movw R4, #0x3FF \n"
Kojto 124:2241e3a39974 774 " ANDS R4, R4, R1, LSR #3 \n" // R4 is the max number on the way size (right aligned)
Kojto 124:2241e3a39974 775 " CLZ R5, R4 \n" // R5 is the bit position of the way size increment
Kojto 124:2241e3a39974 776 " movw R7, #0x7FFF \n"
Kojto 124:2241e3a39974 777 " ANDS R7, R7, R1, LSR #13 \n" // R7 is the max number of the index size (right aligned)
Kojto 124:2241e3a39974 778
Kojto 124:2241e3a39974 779 "Loop2: MOV R9, R4 \n" // R9 working copy of the max way size (right aligned)
Kojto 124:2241e3a39974 780
Kojto 124:2241e3a39974 781 "Loop3: ORR R11, R10, R9, LSL R5 \n" // Factor in the Way number and cache number into R11
Kojto 124:2241e3a39974 782 " ORR R11, R11, R7, LSL R2 \n" // Factor in the Set number
Kojto 124:2241e3a39974 783 " CMP R0, #0 \n"
Kojto 124:2241e3a39974 784 " BNE Dccsw \n"
Kojto 124:2241e3a39974 785 " MCR p15, 0, R11, c7, c6, 2 \n" // DCISW. Invalidate by Set/Way
Kojto 124:2241e3a39974 786 " B cont \n"
Kojto 124:2241e3a39974 787 "Dccsw: CMP R0, #1 \n"
Kojto 124:2241e3a39974 788 " BNE Dccisw \n"
Kojto 124:2241e3a39974 789 " MCR p15, 0, R11, c7, c10, 2 \n" // DCCSW. Clean by Set/Way
Kojto 124:2241e3a39974 790 " B cont \n"
Kojto 124:2241e3a39974 791 "Dccisw: MCR p15, 0, R11, c7, c14, 2 \n" // DCCISW, Clean and Invalidate by Set/Way
Kojto 124:2241e3a39974 792 "cont: SUBS R9, R9, #1 \n" // Decrement the Way number
Kojto 124:2241e3a39974 793 " BGE Loop3 \n"
Kojto 124:2241e3a39974 794 " SUBS R7, R7, #1 \n" // Decrement the Set number
Kojto 124:2241e3a39974 795 " BGE Loop2 \n"
Kojto 124:2241e3a39974 796 "Skip: ADD R10, R10, #2 \n" // increment the cache number
Kojto 124:2241e3a39974 797 " CMP R3, R10 \n"
Kojto 124:2241e3a39974 798 " BGT Loop1 \n"
Kojto 124:2241e3a39974 799
Kojto 124:2241e3a39974 800 "Finished: \n"
Kojto 124:2241e3a39974 801 " DSB \n"
Kojto 124:2241e3a39974 802 " POP {R4-R11} \n"
Kojto 124:2241e3a39974 803 " BX lr \n" );
Kojto 124:2241e3a39974 804 }
Kojto 124:2241e3a39974 805
Kojto 124:2241e3a39974 806 /** \brief Invalidate the whole D$
Kojto 124:2241e3a39974 807
Kojto 124:2241e3a39974 808 DCISW. Invalidate by Set/Way
Kojto 124:2241e3a39974 809 */
Kojto 124:2241e3a39974 810 // from system_Renesas_RZ_A1.c
Kojto 124:2241e3a39974 811 __STATIC_INLINE void __v7_inv_dcache_all(void) {
Kojto 124:2241e3a39974 812 __v7_all_cache(0);
Kojto 124:2241e3a39974 813 }
<> 130:d75b3fe1f5cb 814 /** \brief Clean the whole D$
<> 130:d75b3fe1f5cb 815
<> 130:d75b3fe1f5cb 816 DCCSW. Clean by Set/Way
<> 130:d75b3fe1f5cb 817 */
<> 130:d75b3fe1f5cb 818
<> 130:d75b3fe1f5cb 819 __STATIC_INLINE void __v7_clean_dcache_all(void) {
<> 130:d75b3fe1f5cb 820 __v7_all_cache(1);
<> 130:d75b3fe1f5cb 821 }
<> 130:d75b3fe1f5cb 822
<> 130:d75b3fe1f5cb 823 /** \brief Clean and invalidate the whole D$
<> 130:d75b3fe1f5cb 824
<> 130:d75b3fe1f5cb 825 DCCISW. Clean and Invalidate by Set/Way
<> 130:d75b3fe1f5cb 826 */
<> 130:d75b3fe1f5cb 827
<> 130:d75b3fe1f5cb 828 __STATIC_INLINE void __v7_clean_inv_dcache_all(void) {
<> 130:d75b3fe1f5cb 829 __v7_all_cache(2);
<> 130:d75b3fe1f5cb 830 }
Kojto 124:2241e3a39974 831 /** \brief Clean and Invalidate D$ by MVA
Kojto 124:2241e3a39974 832
Kojto 124:2241e3a39974 833 DCCIMVAC. Data cache clean and invalidate by MVA to PoC
Kojto 124:2241e3a39974 834 */
Kojto 124:2241e3a39974 835 __STATIC_INLINE void __v7_clean_inv_dcache_mva(void *va) {
Kojto 124:2241e3a39974 836 __MCR(15, 0, (uint32_t)va, 7, 14, 1);
Kojto 124:2241e3a39974 837 __DMB();
Kojto 124:2241e3a39974 838 }
Kojto 124:2241e3a39974 839
Kojto 124:2241e3a39974 840 #include "core_ca_mmu.h"
Kojto 124:2241e3a39974 841
Kojto 124:2241e3a39974 842 #elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/
Kojto 124:2241e3a39974 843 /* GNU gcc specific functions */
Kojto 124:2241e3a39974 844
Kojto 124:2241e3a39974 845 #define MODE_USR 0x10
Kojto 124:2241e3a39974 846 #define MODE_FIQ 0x11
Kojto 124:2241e3a39974 847 #define MODE_IRQ 0x12
Kojto 124:2241e3a39974 848 #define MODE_SVC 0x13
Kojto 124:2241e3a39974 849 #define MODE_MON 0x16
Kojto 124:2241e3a39974 850 #define MODE_ABT 0x17
Kojto 124:2241e3a39974 851 #define MODE_HYP 0x1A
Kojto 124:2241e3a39974 852 #define MODE_UND 0x1B
Kojto 124:2241e3a39974 853 #define MODE_SYS 0x1F
Kojto 124:2241e3a39974 854
Kojto 124:2241e3a39974 855
Kojto 124:2241e3a39974 856 __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void)
Kojto 124:2241e3a39974 857 {
Kojto 124:2241e3a39974 858 __ASM volatile ("cpsie i");
Kojto 124:2241e3a39974 859 }
Kojto 124:2241e3a39974 860
Kojto 124:2241e3a39974 861 /** \brief Disable IRQ Interrupts
Kojto 124:2241e3a39974 862
Kojto 124:2241e3a39974 863 This function disables IRQ interrupts by setting the I-bit in the CPSR.
Kojto 124:2241e3a39974 864 Can only be executed in Privileged modes.
Kojto 124:2241e3a39974 865 */
Kojto 124:2241e3a39974 866 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __disable_irq(void)
Kojto 124:2241e3a39974 867 {
Kojto 124:2241e3a39974 868 uint32_t result;
Kojto 124:2241e3a39974 869
Kojto 124:2241e3a39974 870 __ASM volatile ("mrs %0, cpsr" : "=r" (result));
Kojto 124:2241e3a39974 871 __ASM volatile ("cpsid i");
Kojto 124:2241e3a39974 872 return(result & 0x80);
Kojto 124:2241e3a39974 873 }
Kojto 124:2241e3a39974 874
Kojto 124:2241e3a39974 875
Kojto 124:2241e3a39974 876 /** \brief Get APSR Register
Kojto 124:2241e3a39974 877
Kojto 124:2241e3a39974 878 This function returns the content of the APSR Register.
Kojto 124:2241e3a39974 879
Kojto 124:2241e3a39974 880 \return APSR Register value
Kojto 124:2241e3a39974 881 */
Kojto 124:2241e3a39974 882 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(void)
Kojto 124:2241e3a39974 883 {
Kojto 124:2241e3a39974 884 #if 1
Kojto 124:2241e3a39974 885 register uint32_t __regAPSR;
Kojto 124:2241e3a39974 886 __ASM volatile ("mrs %0, apsr" : "=r" (__regAPSR) );
Kojto 124:2241e3a39974 887 #else
Kojto 124:2241e3a39974 888 register uint32_t __regAPSR __ASM("apsr");
Kojto 124:2241e3a39974 889 #endif
Kojto 124:2241e3a39974 890 return(__regAPSR);
Kojto 124:2241e3a39974 891 }
Kojto 124:2241e3a39974 892
Kojto 124:2241e3a39974 893
Kojto 124:2241e3a39974 894 /** \brief Get CPSR Register
Kojto 124:2241e3a39974 895
Kojto 124:2241e3a39974 896 This function returns the content of the CPSR Register.
Kojto 124:2241e3a39974 897
Kojto 124:2241e3a39974 898 \return CPSR Register value
Kojto 124:2241e3a39974 899 */
Kojto 124:2241e3a39974 900 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CPSR(void)
Kojto 124:2241e3a39974 901 {
Kojto 124:2241e3a39974 902 #if 1
Kojto 124:2241e3a39974 903 register uint32_t __regCPSR;
Kojto 124:2241e3a39974 904 __ASM volatile ("mrs %0, cpsr" : "=r" (__regCPSR));
Kojto 124:2241e3a39974 905 #else
Kojto 124:2241e3a39974 906 register uint32_t __regCPSR __ASM("cpsr");
Kojto 124:2241e3a39974 907 #endif
Kojto 124:2241e3a39974 908 return(__regCPSR);
Kojto 124:2241e3a39974 909 }
Kojto 124:2241e3a39974 910
Kojto 124:2241e3a39974 911 #if 0
Kojto 124:2241e3a39974 912 /** \brief Set Stack Pointer
Kojto 124:2241e3a39974 913
Kojto 124:2241e3a39974 914 This function assigns the given value to the current stack pointer.
Kojto 124:2241e3a39974 915
Kojto 124:2241e3a39974 916 \param [in] topOfStack Stack Pointer value to set
Kojto 124:2241e3a39974 917 */
Kojto 124:2241e3a39974 918 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_SP(uint32_t topOfStack)
Kojto 124:2241e3a39974 919 {
Kojto 124:2241e3a39974 920 register uint32_t __regSP __ASM("sp");
Kojto 124:2241e3a39974 921 __regSP = topOfStack;
Kojto 124:2241e3a39974 922 }
Kojto 124:2241e3a39974 923 #endif
Kojto 124:2241e3a39974 924
Kojto 124:2241e3a39974 925 /** \brief Get link register
Kojto 124:2241e3a39974 926
Kojto 124:2241e3a39974 927 This function returns the value of the link register
Kojto 124:2241e3a39974 928
Kojto 124:2241e3a39974 929 \return Value of link register
Kojto 124:2241e3a39974 930 */
Kojto 124:2241e3a39974 931 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_LR(void)
Kojto 124:2241e3a39974 932 {
Kojto 124:2241e3a39974 933 register uint32_t __reglr __ASM("lr");
Kojto 124:2241e3a39974 934 return(__reglr);
Kojto 124:2241e3a39974 935 }
Kojto 124:2241e3a39974 936
Kojto 124:2241e3a39974 937 #if 0
Kojto 124:2241e3a39974 938 /** \brief Set link register
Kojto 124:2241e3a39974 939
Kojto 124:2241e3a39974 940 This function sets the value of the link register
Kojto 124:2241e3a39974 941
Kojto 124:2241e3a39974 942 \param [in] lr LR value to set
Kojto 124:2241e3a39974 943 */
Kojto 124:2241e3a39974 944 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_LR(uint32_t lr)
Kojto 124:2241e3a39974 945 {
Kojto 124:2241e3a39974 946 register uint32_t __reglr __ASM("lr");
Kojto 124:2241e3a39974 947 __reglr = lr;
Kojto 124:2241e3a39974 948 }
Kojto 124:2241e3a39974 949 #endif
Kojto 124:2241e3a39974 950
Kojto 124:2241e3a39974 951 /** \brief Set Process Stack Pointer
Kojto 124:2241e3a39974 952
Kojto 124:2241e3a39974 953 This function assigns the given value to the USR/SYS Stack Pointer (PSP).
Kojto 124:2241e3a39974 954
Kojto 124:2241e3a39974 955 \param [in] topOfProcStack USR/SYS Stack Pointer value to set
Kojto 124:2241e3a39974 956 */
Kojto 124:2241e3a39974 957 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
Kojto 124:2241e3a39974 958 {
Kojto 124:2241e3a39974 959 __asm__ volatile (
Kojto 124:2241e3a39974 960 ".ARM;"
Kojto 124:2241e3a39974 961 ".eabi_attribute Tag_ABI_align8_preserved,1;"
Kojto 124:2241e3a39974 962
Kojto 124:2241e3a39974 963 "BIC R0, R0, #7;" /* ;ensure stack is 8-byte aligned */
Kojto 124:2241e3a39974 964 "MRS R1, CPSR;"
Kojto 124:2241e3a39974 965 "CPS %0;" /* ;no effect in USR mode */
Kojto 124:2241e3a39974 966 "MOV SP, R0;"
Kojto 124:2241e3a39974 967 "MSR CPSR_c, R1;" /* ;no effect in USR mode */
Kojto 124:2241e3a39974 968 "ISB;"
Kojto 124:2241e3a39974 969 //"BX LR;"
Kojto 124:2241e3a39974 970 :
Kojto 124:2241e3a39974 971 : "i"(MODE_SYS)
Kojto 124:2241e3a39974 972 : "r0", "r1");
Kojto 124:2241e3a39974 973 return;
Kojto 124:2241e3a39974 974 }
Kojto 124:2241e3a39974 975
Kojto 124:2241e3a39974 976 /** \brief Set User Mode
Kojto 124:2241e3a39974 977
Kojto 124:2241e3a39974 978 This function changes the processor state to User Mode
Kojto 124:2241e3a39974 979 */
Kojto 124:2241e3a39974 980 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CPS_USR(void)
Kojto 124:2241e3a39974 981 {
Kojto 124:2241e3a39974 982 __asm__ volatile (
Kojto 124:2241e3a39974 983 ".ARM;"
Kojto 124:2241e3a39974 984
Kojto 124:2241e3a39974 985 "CPS %0;"
Kojto 124:2241e3a39974 986 //"BX LR;"
Kojto 124:2241e3a39974 987 :
Kojto 124:2241e3a39974 988 : "i"(MODE_USR)
Kojto 124:2241e3a39974 989 : );
Kojto 124:2241e3a39974 990 return;
Kojto 124:2241e3a39974 991 }
Kojto 124:2241e3a39974 992
Kojto 124:2241e3a39974 993
Kojto 124:2241e3a39974 994 /** \brief Enable FIQ
Kojto 124:2241e3a39974 995
Kojto 124:2241e3a39974 996 This function enables FIQ interrupts by clearing the F-bit in the CPSR.
Kojto 124:2241e3a39974 997 Can only be executed in Privileged modes.
Kojto 124:2241e3a39974 998 */
Kojto 124:2241e3a39974 999 #define __enable_fault_irq() __asm__ volatile ("cpsie f")
Kojto 124:2241e3a39974 1000
Kojto 124:2241e3a39974 1001
Kojto 124:2241e3a39974 1002 /** \brief Disable FIQ
Kojto 124:2241e3a39974 1003
Kojto 124:2241e3a39974 1004 This function disables FIQ interrupts by setting the F-bit in the CPSR.
Kojto 124:2241e3a39974 1005 Can only be executed in Privileged modes.
Kojto 124:2241e3a39974 1006 */
Kojto 124:2241e3a39974 1007 #define __disable_fault_irq() __asm__ volatile ("cpsid f")
Kojto 124:2241e3a39974 1008
Kojto 124:2241e3a39974 1009
Kojto 124:2241e3a39974 1010 /** \brief Get FPSCR
Kojto 124:2241e3a39974 1011
Kojto 124:2241e3a39974 1012 This function returns the current value of the Floating Point Status/Control register.
Kojto 124:2241e3a39974 1013
Kojto 124:2241e3a39974 1014 \return Floating Point Status/Control register value
Kojto 124:2241e3a39974 1015 */
Kojto 124:2241e3a39974 1016 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(void)
Kojto 124:2241e3a39974 1017 {
Kojto 124:2241e3a39974 1018 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
Kojto 124:2241e3a39974 1019 #if 1
Kojto 124:2241e3a39974 1020 uint32_t result;
Kojto 124:2241e3a39974 1021
Kojto 124:2241e3a39974 1022 __ASM volatile ("vmrs %0, fpscr" : "=r" (result) );
Kojto 124:2241e3a39974 1023 return (result);
Kojto 124:2241e3a39974 1024 #else
Kojto 124:2241e3a39974 1025 register uint32_t __regfpscr __ASM("fpscr");
Kojto 124:2241e3a39974 1026 return(__regfpscr);
Kojto 124:2241e3a39974 1027 #endif
Kojto 124:2241e3a39974 1028 #else
Kojto 124:2241e3a39974 1029 return(0);
Kojto 124:2241e3a39974 1030 #endif
Kojto 124:2241e3a39974 1031 }
Kojto 124:2241e3a39974 1032
Kojto 124:2241e3a39974 1033
Kojto 124:2241e3a39974 1034 /** \brief Set FPSCR
Kojto 124:2241e3a39974 1035
Kojto 124:2241e3a39974 1036 This function assigns the given value to the Floating Point Status/Control register.
Kojto 124:2241e3a39974 1037
Kojto 124:2241e3a39974 1038 \param [in] fpscr Floating Point Status/Control value to set
Kojto 124:2241e3a39974 1039 */
Kojto 124:2241e3a39974 1040 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
Kojto 124:2241e3a39974 1041 {
Kojto 124:2241e3a39974 1042 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
Kojto 124:2241e3a39974 1043 #if 1
Kojto 124:2241e3a39974 1044 __ASM volatile ("vmsr fpscr, %0" : : "r" (fpscr) );
Kojto 124:2241e3a39974 1045 #else
Kojto 124:2241e3a39974 1046 register uint32_t __regfpscr __ASM("fpscr");
Kojto 124:2241e3a39974 1047 __regfpscr = (fpscr);
Kojto 124:2241e3a39974 1048 #endif
Kojto 124:2241e3a39974 1049 #endif
Kojto 124:2241e3a39974 1050 }
Kojto 124:2241e3a39974 1051
Kojto 124:2241e3a39974 1052 /** \brief Get FPEXC
Kojto 124:2241e3a39974 1053
Kojto 124:2241e3a39974 1054 This function returns the current value of the Floating Point Exception Control register.
Kojto 124:2241e3a39974 1055
Kojto 124:2241e3a39974 1056 \return Floating Point Exception Control register value
Kojto 124:2241e3a39974 1057 */
Kojto 124:2241e3a39974 1058 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPEXC(void)
Kojto 124:2241e3a39974 1059 {
Kojto 124:2241e3a39974 1060 #if (__FPU_PRESENT == 1)
Kojto 124:2241e3a39974 1061 #if 1
Kojto 124:2241e3a39974 1062 uint32_t result;
Kojto 124:2241e3a39974 1063
Kojto 124:2241e3a39974 1064 __ASM volatile ("vmrs %0, fpexc" : "=r" (result));
Kojto 124:2241e3a39974 1065 return (result);
Kojto 124:2241e3a39974 1066 #else
Kojto 124:2241e3a39974 1067 register uint32_t __regfpexc __ASM("fpexc");
Kojto 124:2241e3a39974 1068 return(__regfpexc);
Kojto 124:2241e3a39974 1069 #endif
Kojto 124:2241e3a39974 1070 #else
Kojto 124:2241e3a39974 1071 return(0);
Kojto 124:2241e3a39974 1072 #endif
Kojto 124:2241e3a39974 1073 }
Kojto 124:2241e3a39974 1074
Kojto 124:2241e3a39974 1075
Kojto 124:2241e3a39974 1076 /** \brief Set FPEXC
Kojto 124:2241e3a39974 1077
Kojto 124:2241e3a39974 1078 This function assigns the given value to the Floating Point Exception Control register.
Kojto 124:2241e3a39974 1079
Kojto 124:2241e3a39974 1080 \param [in] fpscr Floating Point Exception Control value to set
Kojto 124:2241e3a39974 1081 */
Kojto 124:2241e3a39974 1082 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPEXC(uint32_t fpexc)
Kojto 124:2241e3a39974 1083 {
Kojto 124:2241e3a39974 1084 #if (__FPU_PRESENT == 1)
Kojto 124:2241e3a39974 1085 #if 1
Kojto 124:2241e3a39974 1086 __ASM volatile ("vmsr fpexc, %0" : : "r" (fpexc));
Kojto 124:2241e3a39974 1087 #else
Kojto 124:2241e3a39974 1088 register uint32_t __regfpexc __ASM("fpexc");
Kojto 124:2241e3a39974 1089 __regfpexc = (fpexc);
Kojto 124:2241e3a39974 1090 #endif
Kojto 124:2241e3a39974 1091 #endif
Kojto 124:2241e3a39974 1092 }
Kojto 124:2241e3a39974 1093
Kojto 124:2241e3a39974 1094 /** \brief Get CPACR
Kojto 124:2241e3a39974 1095
Kojto 124:2241e3a39974 1096 This function returns the current value of the Coprocessor Access Control register.
Kojto 124:2241e3a39974 1097
Kojto 124:2241e3a39974 1098 \return Coprocessor Access Control register value
Kojto 124:2241e3a39974 1099 */
Kojto 124:2241e3a39974 1100 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CPACR(void)
Kojto 124:2241e3a39974 1101 {
Kojto 124:2241e3a39974 1102 #if 1
Kojto 124:2241e3a39974 1103 register uint32_t __regCPACR;
Kojto 124:2241e3a39974 1104 __ASM volatile ("mrc p15, 0, %0, c1, c0, 2" : "=r" (__regCPACR));
Kojto 124:2241e3a39974 1105 #else
Kojto 124:2241e3a39974 1106 register uint32_t __regCPACR __ASM("cp15:0:c1:c0:2");
Kojto 124:2241e3a39974 1107 #endif
Kojto 124:2241e3a39974 1108 return __regCPACR;
Kojto 124:2241e3a39974 1109 }
Kojto 124:2241e3a39974 1110
Kojto 124:2241e3a39974 1111 /** \brief Set CPACR
Kojto 124:2241e3a39974 1112
Kojto 124:2241e3a39974 1113 This function assigns the given value to the Coprocessor Access Control register.
Kojto 124:2241e3a39974 1114
Kojto 124:2241e3a39974 1115 \param [in] cpacr Coprocessor Acccess Control value to set
Kojto 124:2241e3a39974 1116 */
Kojto 124:2241e3a39974 1117 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CPACR(uint32_t cpacr)
Kojto 124:2241e3a39974 1118 {
Kojto 124:2241e3a39974 1119 #if 1
Kojto 124:2241e3a39974 1120 __ASM volatile ("mcr p15, 0, %0, c1, c0, 2" : : "r" (cpacr));
Kojto 124:2241e3a39974 1121 #else
Kojto 124:2241e3a39974 1122 register uint32_t __regCPACR __ASM("cp15:0:c1:c0:2");
Kojto 124:2241e3a39974 1123 __regCPACR = cpacr;
Kojto 124:2241e3a39974 1124 #endif
Kojto 124:2241e3a39974 1125 __ISB();
Kojto 124:2241e3a39974 1126 }
Kojto 124:2241e3a39974 1127
Kojto 124:2241e3a39974 1128 /** \brief Get CBAR
Kojto 124:2241e3a39974 1129
Kojto 124:2241e3a39974 1130 This function returns the value of the Configuration Base Address register.
Kojto 124:2241e3a39974 1131
Kojto 124:2241e3a39974 1132 \return Configuration Base Address register value
Kojto 124:2241e3a39974 1133 */
Kojto 124:2241e3a39974 1134 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CBAR() {
Kojto 124:2241e3a39974 1135 #if 1
Kojto 124:2241e3a39974 1136 register uint32_t __regCBAR;
Kojto 124:2241e3a39974 1137 __ASM volatile ("mrc p15, 4, %0, c15, c0, 0" : "=r" (__regCBAR));
Kojto 124:2241e3a39974 1138 #else
Kojto 124:2241e3a39974 1139 register uint32_t __regCBAR __ASM("cp15:4:c15:c0:0");
Kojto 124:2241e3a39974 1140 #endif
Kojto 124:2241e3a39974 1141 return(__regCBAR);
Kojto 124:2241e3a39974 1142 }
Kojto 124:2241e3a39974 1143
Kojto 124:2241e3a39974 1144 /** \brief Get TTBR0
Kojto 124:2241e3a39974 1145
Kojto 124:2241e3a39974 1146 This function returns the value of the Translation Table Base Register 0.
Kojto 124:2241e3a39974 1147
Kojto 124:2241e3a39974 1148 \return Translation Table Base Register 0 value
Kojto 124:2241e3a39974 1149 */
Kojto 124:2241e3a39974 1150 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_TTBR0() {
Kojto 124:2241e3a39974 1151 #if 1
Kojto 124:2241e3a39974 1152 register uint32_t __regTTBR0;
Kojto 124:2241e3a39974 1153 __ASM volatile ("mrc p15, 0, %0, c2, c0, 0" : "=r" (__regTTBR0));
Kojto 124:2241e3a39974 1154 #else
Kojto 124:2241e3a39974 1155 register uint32_t __regTTBR0 __ASM("cp15:0:c2:c0:0");
Kojto 124:2241e3a39974 1156 #endif
Kojto 124:2241e3a39974 1157 return(__regTTBR0);
Kojto 124:2241e3a39974 1158 }
Kojto 124:2241e3a39974 1159
Kojto 124:2241e3a39974 1160 /** \brief Set TTBR0
Kojto 124:2241e3a39974 1161
Kojto 124:2241e3a39974 1162 This function assigns the given value to the Translation Table Base Register 0.
Kojto 124:2241e3a39974 1163
Kojto 124:2241e3a39974 1164 \param [in] ttbr0 Translation Table Base Register 0 value to set
Kojto 124:2241e3a39974 1165 */
Kojto 124:2241e3a39974 1166 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_TTBR0(uint32_t ttbr0) {
Kojto 124:2241e3a39974 1167 #if 1
Kojto 124:2241e3a39974 1168 __ASM volatile ("mcr p15, 0, %0, c2, c0, 0" : : "r" (ttbr0));
Kojto 124:2241e3a39974 1169 #else
Kojto 124:2241e3a39974 1170 register uint32_t __regTTBR0 __ASM("cp15:0:c2:c0:0");
Kojto 124:2241e3a39974 1171 __regTTBR0 = ttbr0;
Kojto 124:2241e3a39974 1172 #endif
Kojto 124:2241e3a39974 1173 __ISB();
Kojto 124:2241e3a39974 1174 }
Kojto 124:2241e3a39974 1175
Kojto 124:2241e3a39974 1176 /** \brief Get DACR
Kojto 124:2241e3a39974 1177
Kojto 124:2241e3a39974 1178 This function returns the value of the Domain Access Control Register.
Kojto 124:2241e3a39974 1179
Kojto 124:2241e3a39974 1180 \return Domain Access Control Register value
Kojto 124:2241e3a39974 1181 */
Kojto 124:2241e3a39974 1182 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_DACR() {
Kojto 124:2241e3a39974 1183 #if 1
Kojto 124:2241e3a39974 1184 register uint32_t __regDACR;
Kojto 124:2241e3a39974 1185 __ASM volatile ("mrc p15, 0, %0, c3, c0, 0" : "=r" (__regDACR));
Kojto 124:2241e3a39974 1186 #else
Kojto 124:2241e3a39974 1187 register uint32_t __regDACR __ASM("cp15:0:c3:c0:0");
Kojto 124:2241e3a39974 1188 #endif
Kojto 124:2241e3a39974 1189 return(__regDACR);
Kojto 124:2241e3a39974 1190 }
Kojto 124:2241e3a39974 1191
Kojto 124:2241e3a39974 1192 /** \brief Set DACR
Kojto 124:2241e3a39974 1193
Kojto 124:2241e3a39974 1194 This function assigns the given value to the Domain Access Control Register.
Kojto 124:2241e3a39974 1195
Kojto 124:2241e3a39974 1196 \param [in] dacr Domain Access Control Register value to set
Kojto 124:2241e3a39974 1197 */
Kojto 124:2241e3a39974 1198 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_DACR(uint32_t dacr) {
Kojto 124:2241e3a39974 1199 #if 1
Kojto 124:2241e3a39974 1200 __ASM volatile ("mcr p15, 0, %0, c3, c0, 0" : : "r" (dacr));
Kojto 124:2241e3a39974 1201 #else
Kojto 124:2241e3a39974 1202 register uint32_t __regDACR __ASM("cp15:0:c3:c0:0");
Kojto 124:2241e3a39974 1203 __regDACR = dacr;
Kojto 124:2241e3a39974 1204 #endif
Kojto 124:2241e3a39974 1205 __ISB();
Kojto 124:2241e3a39974 1206 }
Kojto 124:2241e3a39974 1207
Kojto 124:2241e3a39974 1208 /******************************** Cache and BTAC enable ****************************************************/
Kojto 124:2241e3a39974 1209
Kojto 124:2241e3a39974 1210 /** \brief Set SCTLR
Kojto 124:2241e3a39974 1211
Kojto 124:2241e3a39974 1212 This function assigns the given value to the System Control Register.
Kojto 124:2241e3a39974 1213
Kojto 124:2241e3a39974 1214 \param [in] sctlr System Control Register value to set
Kojto 124:2241e3a39974 1215 */
Kojto 124:2241e3a39974 1216 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_SCTLR(uint32_t sctlr)
Kojto 124:2241e3a39974 1217 {
Kojto 124:2241e3a39974 1218 #if 1
Kojto 124:2241e3a39974 1219 __ASM volatile ("mcr p15, 0, %0, c1, c0, 0" : : "r" (sctlr));
Kojto 124:2241e3a39974 1220 #else
Kojto 124:2241e3a39974 1221 register uint32_t __regSCTLR __ASM("cp15:0:c1:c0:0");
Kojto 124:2241e3a39974 1222 __regSCTLR = sctlr;
Kojto 124:2241e3a39974 1223 #endif
Kojto 124:2241e3a39974 1224 }
Kojto 124:2241e3a39974 1225
Kojto 124:2241e3a39974 1226 /** \brief Get SCTLR
Kojto 124:2241e3a39974 1227
Kojto 124:2241e3a39974 1228 This function returns the value of the System Control Register.
Kojto 124:2241e3a39974 1229
Kojto 124:2241e3a39974 1230 \return System Control Register value
Kojto 124:2241e3a39974 1231 */
Kojto 124:2241e3a39974 1232 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_SCTLR() {
Kojto 124:2241e3a39974 1233 #if 1
Kojto 124:2241e3a39974 1234 register uint32_t __regSCTLR;
Kojto 124:2241e3a39974 1235 __ASM volatile ("mrc p15, 0, %0, c1, c0, 0" : "=r" (__regSCTLR));
Kojto 124:2241e3a39974 1236 #else
Kojto 124:2241e3a39974 1237 register uint32_t __regSCTLR __ASM("cp15:0:c1:c0:0");
Kojto 124:2241e3a39974 1238 #endif
Kojto 124:2241e3a39974 1239 return(__regSCTLR);
Kojto 124:2241e3a39974 1240 }
Kojto 124:2241e3a39974 1241
Kojto 124:2241e3a39974 1242 /** \brief Enable Caches
Kojto 124:2241e3a39974 1243
Kojto 124:2241e3a39974 1244 Enable Caches
Kojto 124:2241e3a39974 1245 */
Kojto 124:2241e3a39974 1246 __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_caches(void) {
Kojto 124:2241e3a39974 1247 // Set I bit 12 to enable I Cache
Kojto 124:2241e3a39974 1248 // Set C bit 2 to enable D Cache
Kojto 124:2241e3a39974 1249 __set_SCTLR( __get_SCTLR() | (1 << 12) | (1 << 2));
Kojto 124:2241e3a39974 1250 }
Kojto 124:2241e3a39974 1251
Kojto 124:2241e3a39974 1252 /** \brief Disable Caches
Kojto 124:2241e3a39974 1253
Kojto 124:2241e3a39974 1254 Disable Caches
Kojto 124:2241e3a39974 1255 */
Kojto 124:2241e3a39974 1256 __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_caches(void) {
Kojto 124:2241e3a39974 1257 // Clear I bit 12 to disable I Cache
Kojto 124:2241e3a39974 1258 // Clear C bit 2 to disable D Cache
Kojto 124:2241e3a39974 1259 __set_SCTLR( __get_SCTLR() & ~(1 << 12) & ~(1 << 2));
Kojto 124:2241e3a39974 1260 __ISB();
Kojto 124:2241e3a39974 1261 }
Kojto 124:2241e3a39974 1262
Kojto 124:2241e3a39974 1263 /** \brief Enable BTAC
Kojto 124:2241e3a39974 1264
Kojto 124:2241e3a39974 1265 Enable BTAC
Kojto 124:2241e3a39974 1266 */
Kojto 124:2241e3a39974 1267 __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_btac(void) {
Kojto 124:2241e3a39974 1268 // Set Z bit 11 to enable branch prediction
Kojto 124:2241e3a39974 1269 __set_SCTLR( __get_SCTLR() | (1 << 11));
Kojto 124:2241e3a39974 1270 __ISB();
Kojto 124:2241e3a39974 1271 }
Kojto 124:2241e3a39974 1272
Kojto 124:2241e3a39974 1273 /** \brief Disable BTAC
Kojto 124:2241e3a39974 1274
Kojto 124:2241e3a39974 1275 Disable BTAC
Kojto 124:2241e3a39974 1276 */
Kojto 124:2241e3a39974 1277 __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_btac(void) {
Kojto 124:2241e3a39974 1278 // Clear Z bit 11 to disable branch prediction
Kojto 124:2241e3a39974 1279 __set_SCTLR( __get_SCTLR() & ~(1 << 11));
Kojto 124:2241e3a39974 1280 }
Kojto 124:2241e3a39974 1281
Kojto 124:2241e3a39974 1282
Kojto 124:2241e3a39974 1283 /** \brief Enable MMU
Kojto 124:2241e3a39974 1284
Kojto 124:2241e3a39974 1285 Enable MMU
Kojto 124:2241e3a39974 1286 */
Kojto 124:2241e3a39974 1287 __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_mmu(void) {
Kojto 124:2241e3a39974 1288 // Set M bit 0 to enable the MMU
Kojto 124:2241e3a39974 1289 // Set AFE bit to enable simplified access permissions model
Kojto 124:2241e3a39974 1290 // Clear TRE bit to disable TEX remap and A bit to disable strict alignment fault checking
Kojto 124:2241e3a39974 1291 __set_SCTLR( (__get_SCTLR() & ~(1 << 28) & ~(1 << 1)) | 1 | (1 << 29));
Kojto 124:2241e3a39974 1292 __ISB();
Kojto 124:2241e3a39974 1293 }
Kojto 124:2241e3a39974 1294
Kojto 124:2241e3a39974 1295 /** \brief Disable MMU
Kojto 124:2241e3a39974 1296
Kojto 124:2241e3a39974 1297 Disable MMU
Kojto 124:2241e3a39974 1298 */
Kojto 124:2241e3a39974 1299 __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_mmu(void) {
Kojto 124:2241e3a39974 1300 // Clear M bit 0 to disable the MMU
Kojto 124:2241e3a39974 1301 __set_SCTLR( __get_SCTLR() & ~1);
Kojto 124:2241e3a39974 1302 __ISB();
Kojto 124:2241e3a39974 1303 }
Kojto 124:2241e3a39974 1304
Kojto 124:2241e3a39974 1305 /******************************** TLB maintenance operations ************************************************/
Kojto 124:2241e3a39974 1306 /** \brief Invalidate the whole tlb
Kojto 124:2241e3a39974 1307
Kojto 124:2241e3a39974 1308 TLBIALL. Invalidate the whole tlb
Kojto 124:2241e3a39974 1309 */
Kojto 124:2241e3a39974 1310
Kojto 124:2241e3a39974 1311 __attribute__( ( always_inline ) ) __STATIC_INLINE void __ca9u_inv_tlb_all(void) {
Kojto 124:2241e3a39974 1312 #if 1
Kojto 124:2241e3a39974 1313 __ASM volatile ("mcr p15, 0, %0, c8, c7, 0" : : "r" (0));
Kojto 124:2241e3a39974 1314 #else
Kojto 124:2241e3a39974 1315 register uint32_t __TLBIALL __ASM("cp15:0:c8:c7:0");
Kojto 124:2241e3a39974 1316 __TLBIALL = 0;
Kojto 124:2241e3a39974 1317 #endif
Kojto 124:2241e3a39974 1318 __DSB();
Kojto 124:2241e3a39974 1319 __ISB();
Kojto 124:2241e3a39974 1320 }
Kojto 124:2241e3a39974 1321
Kojto 124:2241e3a39974 1322 /******************************** BTB maintenance operations ************************************************/
Kojto 124:2241e3a39974 1323 /** \brief Invalidate entire branch predictor array
Kojto 124:2241e3a39974 1324
Kojto 124:2241e3a39974 1325 BPIALL. Branch Predictor Invalidate All.
Kojto 124:2241e3a39974 1326 */
Kojto 124:2241e3a39974 1327
Kojto 124:2241e3a39974 1328 __attribute__( ( always_inline ) ) __STATIC_INLINE void __v7_inv_btac(void) {
Kojto 124:2241e3a39974 1329 #if 1
Kojto 124:2241e3a39974 1330 __ASM volatile ("mcr p15, 0, %0, c7, c5, 6" : : "r" (0));
Kojto 124:2241e3a39974 1331 #else
Kojto 124:2241e3a39974 1332 register uint32_t __BPIALL __ASM("cp15:0:c7:c5:6");
Kojto 124:2241e3a39974 1333 __BPIALL = 0;
Kojto 124:2241e3a39974 1334 #endif
Kojto 124:2241e3a39974 1335 __DSB(); //ensure completion of the invalidation
Kojto 124:2241e3a39974 1336 __ISB(); //ensure instruction fetch path sees new state
Kojto 124:2241e3a39974 1337 }
Kojto 124:2241e3a39974 1338
Kojto 124:2241e3a39974 1339
Kojto 124:2241e3a39974 1340 /******************************** L1 cache operations ******************************************************/
Kojto 124:2241e3a39974 1341
Kojto 124:2241e3a39974 1342 /** \brief Invalidate the whole I$
Kojto 124:2241e3a39974 1343
Kojto 124:2241e3a39974 1344 ICIALLU. Instruction Cache Invalidate All to PoU
Kojto 124:2241e3a39974 1345 */
Kojto 124:2241e3a39974 1346 __attribute__( ( always_inline ) ) __STATIC_INLINE void __v7_inv_icache_all(void) {
Kojto 124:2241e3a39974 1347 #if 1
Kojto 124:2241e3a39974 1348 __ASM volatile ("mcr p15, 0, %0, c7, c5, 0" : : "r" (0));
Kojto 124:2241e3a39974 1349 #else
Kojto 124:2241e3a39974 1350 register uint32_t __ICIALLU __ASM("cp15:0:c7:c5:0");
Kojto 124:2241e3a39974 1351 __ICIALLU = 0;
Kojto 124:2241e3a39974 1352 #endif
Kojto 124:2241e3a39974 1353 __DSB(); //ensure completion of the invalidation
Kojto 124:2241e3a39974 1354 __ISB(); //ensure instruction fetch path sees new I cache state
Kojto 124:2241e3a39974 1355 }
Kojto 124:2241e3a39974 1356
Kojto 124:2241e3a39974 1357 /** \brief Clean D$ by MVA
Kojto 124:2241e3a39974 1358
Kojto 124:2241e3a39974 1359 DCCMVAC. Data cache clean by MVA to PoC
Kojto 124:2241e3a39974 1360 */
Kojto 124:2241e3a39974 1361 __attribute__( ( always_inline ) ) __STATIC_INLINE void __v7_clean_dcache_mva(void *va) {
Kojto 124:2241e3a39974 1362 #if 1
Kojto 124:2241e3a39974 1363 __ASM volatile ("mcr p15, 0, %0, c7, c10, 1" : : "r" ((uint32_t)va));
Kojto 124:2241e3a39974 1364 #else
Kojto 124:2241e3a39974 1365 register uint32_t __DCCMVAC __ASM("cp15:0:c7:c10:1");
Kojto 124:2241e3a39974 1366 __DCCMVAC = (uint32_t)va;
Kojto 124:2241e3a39974 1367 #endif
Kojto 124:2241e3a39974 1368 __DMB(); //ensure the ordering of data cache maintenance operations and their effects
Kojto 124:2241e3a39974 1369 }
Kojto 124:2241e3a39974 1370
Kojto 124:2241e3a39974 1371 /** \brief Invalidate D$ by MVA
Kojto 124:2241e3a39974 1372
Kojto 124:2241e3a39974 1373 DCIMVAC. Data cache invalidate by MVA to PoC
Kojto 124:2241e3a39974 1374 */
Kojto 124:2241e3a39974 1375 __attribute__( ( always_inline ) ) __STATIC_INLINE void __v7_inv_dcache_mva(void *va) {
Kojto 124:2241e3a39974 1376 #if 1
Kojto 124:2241e3a39974 1377 __ASM volatile ("mcr p15, 0, %0, c7, c6, 1" : : "r" ((uint32_t)va));
Kojto 124:2241e3a39974 1378 #else
Kojto 124:2241e3a39974 1379 register uint32_t __DCIMVAC __ASM("cp15:0:c7:c6:1");
Kojto 124:2241e3a39974 1380 __DCIMVAC = (uint32_t)va;
Kojto 124:2241e3a39974 1381 #endif
Kojto 124:2241e3a39974 1382 __DMB(); //ensure the ordering of data cache maintenance operations and their effects
Kojto 124:2241e3a39974 1383 }
Kojto 124:2241e3a39974 1384
Kojto 124:2241e3a39974 1385 /** \brief Clean and Invalidate D$ by MVA
Kojto 124:2241e3a39974 1386
Kojto 124:2241e3a39974 1387 DCCIMVAC. Data cache clean and invalidate by MVA to PoC
Kojto 124:2241e3a39974 1388 */
Kojto 124:2241e3a39974 1389 __attribute__( ( always_inline ) ) __STATIC_INLINE void __v7_clean_inv_dcache_mva(void *va) {
Kojto 124:2241e3a39974 1390 #if 1
Kojto 124:2241e3a39974 1391 __ASM volatile ("mcr p15, 0, %0, c7, c14, 1" : : "r" ((uint32_t)va));
Kojto 124:2241e3a39974 1392 #else
Kojto 124:2241e3a39974 1393 register uint32_t __DCCIMVAC __ASM("cp15:0:c7:c14:1");
Kojto 124:2241e3a39974 1394 __DCCIMVAC = (uint32_t)va;
Kojto 124:2241e3a39974 1395 #endif
Kojto 124:2241e3a39974 1396 __DMB(); //ensure the ordering of data cache maintenance operations and their effects
Kojto 124:2241e3a39974 1397 }
Kojto 124:2241e3a39974 1398
Kojto 124:2241e3a39974 1399 /** \brief Clean and Invalidate the entire data or unified cache
Kojto 124:2241e3a39974 1400
Kojto 124:2241e3a39974 1401 Generic mechanism for cleaning/invalidating the entire data or unified cache to the point of coherency.
Kojto 124:2241e3a39974 1402 */
Kojto 124:2241e3a39974 1403 extern void __v7_all_cache(uint32_t op);
Kojto 124:2241e3a39974 1404
Kojto 124:2241e3a39974 1405
Kojto 124:2241e3a39974 1406 /** \brief Invalidate the whole D$
Kojto 124:2241e3a39974 1407
Kojto 124:2241e3a39974 1408 DCISW. Invalidate by Set/Way
Kojto 124:2241e3a39974 1409 */
Kojto 124:2241e3a39974 1410
Kojto 124:2241e3a39974 1411 __attribute__( ( always_inline ) ) __STATIC_INLINE void __v7_inv_dcache_all(void) {
Kojto 124:2241e3a39974 1412 __v7_all_cache(0);
Kojto 124:2241e3a39974 1413 }
Kojto 124:2241e3a39974 1414
Kojto 124:2241e3a39974 1415 /** \brief Clean the whole D$
Kojto 124:2241e3a39974 1416
Kojto 124:2241e3a39974 1417 DCCSW. Clean by Set/Way
Kojto 124:2241e3a39974 1418 */
Kojto 124:2241e3a39974 1419
Kojto 124:2241e3a39974 1420 __attribute__( ( always_inline ) ) __STATIC_INLINE void __v7_clean_dcache_all(void) {
Kojto 124:2241e3a39974 1421 __v7_all_cache(1);
Kojto 124:2241e3a39974 1422 }
Kojto 124:2241e3a39974 1423
Kojto 124:2241e3a39974 1424 /** \brief Clean and invalidate the whole D$
Kojto 124:2241e3a39974 1425
Kojto 124:2241e3a39974 1426 DCCISW. Clean and Invalidate by Set/Way
Kojto 124:2241e3a39974 1427 */
Kojto 124:2241e3a39974 1428
Kojto 124:2241e3a39974 1429 __attribute__( ( always_inline ) ) __STATIC_INLINE void __v7_clean_inv_dcache_all(void) {
Kojto 124:2241e3a39974 1430 __v7_all_cache(2);
Kojto 124:2241e3a39974 1431 }
Kojto 124:2241e3a39974 1432
Kojto 124:2241e3a39974 1433 #include "core_ca_mmu.h"
Kojto 124:2241e3a39974 1434
Kojto 124:2241e3a39974 1435 #elif (defined (__TASKING__)) /*--------------- TASKING Compiler -----------------*/
Kojto 124:2241e3a39974 1436
Kojto 124:2241e3a39974 1437 #error TASKING Compiler support not implemented for Cortex-A
Kojto 124:2241e3a39974 1438
Kojto 124:2241e3a39974 1439 #endif
Kojto 124:2241e3a39974 1440
Kojto 124:2241e3a39974 1441 /*@} end of CMSIS_Core_RegAccFunctions */
Kojto 124:2241e3a39974 1442
Kojto 124:2241e3a39974 1443
Kojto 124:2241e3a39974 1444 #endif /* __CORE_CAFUNC_H__ */