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:
Kojto
Date:
Fri Aug 19 10:17:11 2016 +0100
Revision:
124:2241e3a39974
Child:
130:d75b3fe1f5cb
Release 124 of the mbed library

Changes:

- new targets - KL27Z, K66F
- deprecate macro - add since argument
- override new and delete operators to trap errors
- Maxim - i2c and dac bugfixes
- STM - STM32F4 - serial flow enablement, enable async serial
- pwm and analog definition clean-up
- Nordic - NRF51 - fix for overflow in the ticket

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 }
Kojto 124:2241e3a39974 814 /** \brief Clean and Invalidate D$ by MVA
Kojto 124:2241e3a39974 815
Kojto 124:2241e3a39974 816 DCCIMVAC. Data cache clean and invalidate by MVA to PoC
Kojto 124:2241e3a39974 817 */
Kojto 124:2241e3a39974 818 __STATIC_INLINE void __v7_clean_inv_dcache_mva(void *va) {
Kojto 124:2241e3a39974 819 __MCR(15, 0, (uint32_t)va, 7, 14, 1);
Kojto 124:2241e3a39974 820 __DMB();
Kojto 124:2241e3a39974 821 }
Kojto 124:2241e3a39974 822
Kojto 124:2241e3a39974 823 #include "core_ca_mmu.h"
Kojto 124:2241e3a39974 824
Kojto 124:2241e3a39974 825 #elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/
Kojto 124:2241e3a39974 826 /* GNU gcc specific functions */
Kojto 124:2241e3a39974 827
Kojto 124:2241e3a39974 828 #define MODE_USR 0x10
Kojto 124:2241e3a39974 829 #define MODE_FIQ 0x11
Kojto 124:2241e3a39974 830 #define MODE_IRQ 0x12
Kojto 124:2241e3a39974 831 #define MODE_SVC 0x13
Kojto 124:2241e3a39974 832 #define MODE_MON 0x16
Kojto 124:2241e3a39974 833 #define MODE_ABT 0x17
Kojto 124:2241e3a39974 834 #define MODE_HYP 0x1A
Kojto 124:2241e3a39974 835 #define MODE_UND 0x1B
Kojto 124:2241e3a39974 836 #define MODE_SYS 0x1F
Kojto 124:2241e3a39974 837
Kojto 124:2241e3a39974 838
Kojto 124:2241e3a39974 839 __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void)
Kojto 124:2241e3a39974 840 {
Kojto 124:2241e3a39974 841 __ASM volatile ("cpsie i");
Kojto 124:2241e3a39974 842 }
Kojto 124:2241e3a39974 843
Kojto 124:2241e3a39974 844 /** \brief Disable IRQ Interrupts
Kojto 124:2241e3a39974 845
Kojto 124:2241e3a39974 846 This function disables IRQ interrupts by setting the I-bit in the CPSR.
Kojto 124:2241e3a39974 847 Can only be executed in Privileged modes.
Kojto 124:2241e3a39974 848 */
Kojto 124:2241e3a39974 849 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __disable_irq(void)
Kojto 124:2241e3a39974 850 {
Kojto 124:2241e3a39974 851 uint32_t result;
Kojto 124:2241e3a39974 852
Kojto 124:2241e3a39974 853 __ASM volatile ("mrs %0, cpsr" : "=r" (result));
Kojto 124:2241e3a39974 854 __ASM volatile ("cpsid i");
Kojto 124:2241e3a39974 855 return(result & 0x80);
Kojto 124:2241e3a39974 856 }
Kojto 124:2241e3a39974 857
Kojto 124:2241e3a39974 858
Kojto 124:2241e3a39974 859 /** \brief Get APSR Register
Kojto 124:2241e3a39974 860
Kojto 124:2241e3a39974 861 This function returns the content of the APSR Register.
Kojto 124:2241e3a39974 862
Kojto 124:2241e3a39974 863 \return APSR Register value
Kojto 124:2241e3a39974 864 */
Kojto 124:2241e3a39974 865 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(void)
Kojto 124:2241e3a39974 866 {
Kojto 124:2241e3a39974 867 #if 1
Kojto 124:2241e3a39974 868 register uint32_t __regAPSR;
Kojto 124:2241e3a39974 869 __ASM volatile ("mrs %0, apsr" : "=r" (__regAPSR) );
Kojto 124:2241e3a39974 870 #else
Kojto 124:2241e3a39974 871 register uint32_t __regAPSR __ASM("apsr");
Kojto 124:2241e3a39974 872 #endif
Kojto 124:2241e3a39974 873 return(__regAPSR);
Kojto 124:2241e3a39974 874 }
Kojto 124:2241e3a39974 875
Kojto 124:2241e3a39974 876
Kojto 124:2241e3a39974 877 /** \brief Get CPSR Register
Kojto 124:2241e3a39974 878
Kojto 124:2241e3a39974 879 This function returns the content of the CPSR Register.
Kojto 124:2241e3a39974 880
Kojto 124:2241e3a39974 881 \return CPSR Register value
Kojto 124:2241e3a39974 882 */
Kojto 124:2241e3a39974 883 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CPSR(void)
Kojto 124:2241e3a39974 884 {
Kojto 124:2241e3a39974 885 #if 1
Kojto 124:2241e3a39974 886 register uint32_t __regCPSR;
Kojto 124:2241e3a39974 887 __ASM volatile ("mrs %0, cpsr" : "=r" (__regCPSR));
Kojto 124:2241e3a39974 888 #else
Kojto 124:2241e3a39974 889 register uint32_t __regCPSR __ASM("cpsr");
Kojto 124:2241e3a39974 890 #endif
Kojto 124:2241e3a39974 891 return(__regCPSR);
Kojto 124:2241e3a39974 892 }
Kojto 124:2241e3a39974 893
Kojto 124:2241e3a39974 894 #if 0
Kojto 124:2241e3a39974 895 /** \brief Set Stack Pointer
Kojto 124:2241e3a39974 896
Kojto 124:2241e3a39974 897 This function assigns the given value to the current stack pointer.
Kojto 124:2241e3a39974 898
Kojto 124:2241e3a39974 899 \param [in] topOfStack Stack Pointer value to set
Kojto 124:2241e3a39974 900 */
Kojto 124:2241e3a39974 901 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_SP(uint32_t topOfStack)
Kojto 124:2241e3a39974 902 {
Kojto 124:2241e3a39974 903 register uint32_t __regSP __ASM("sp");
Kojto 124:2241e3a39974 904 __regSP = topOfStack;
Kojto 124:2241e3a39974 905 }
Kojto 124:2241e3a39974 906 #endif
Kojto 124:2241e3a39974 907
Kojto 124:2241e3a39974 908 /** \brief Get link register
Kojto 124:2241e3a39974 909
Kojto 124:2241e3a39974 910 This function returns the value of the link register
Kojto 124:2241e3a39974 911
Kojto 124:2241e3a39974 912 \return Value of link register
Kojto 124:2241e3a39974 913 */
Kojto 124:2241e3a39974 914 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_LR(void)
Kojto 124:2241e3a39974 915 {
Kojto 124:2241e3a39974 916 register uint32_t __reglr __ASM("lr");
Kojto 124:2241e3a39974 917 return(__reglr);
Kojto 124:2241e3a39974 918 }
Kojto 124:2241e3a39974 919
Kojto 124:2241e3a39974 920 #if 0
Kojto 124:2241e3a39974 921 /** \brief Set link register
Kojto 124:2241e3a39974 922
Kojto 124:2241e3a39974 923 This function sets the value of the link register
Kojto 124:2241e3a39974 924
Kojto 124:2241e3a39974 925 \param [in] lr LR value to set
Kojto 124:2241e3a39974 926 */
Kojto 124:2241e3a39974 927 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_LR(uint32_t lr)
Kojto 124:2241e3a39974 928 {
Kojto 124:2241e3a39974 929 register uint32_t __reglr __ASM("lr");
Kojto 124:2241e3a39974 930 __reglr = lr;
Kojto 124:2241e3a39974 931 }
Kojto 124:2241e3a39974 932 #endif
Kojto 124:2241e3a39974 933
Kojto 124:2241e3a39974 934 /** \brief Set Process Stack Pointer
Kojto 124:2241e3a39974 935
Kojto 124:2241e3a39974 936 This function assigns the given value to the USR/SYS Stack Pointer (PSP).
Kojto 124:2241e3a39974 937
Kojto 124:2241e3a39974 938 \param [in] topOfProcStack USR/SYS Stack Pointer value to set
Kojto 124:2241e3a39974 939 */
Kojto 124:2241e3a39974 940 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
Kojto 124:2241e3a39974 941 {
Kojto 124:2241e3a39974 942 __asm__ volatile (
Kojto 124:2241e3a39974 943 ".ARM;"
Kojto 124:2241e3a39974 944 ".eabi_attribute Tag_ABI_align8_preserved,1;"
Kojto 124:2241e3a39974 945
Kojto 124:2241e3a39974 946 "BIC R0, R0, #7;" /* ;ensure stack is 8-byte aligned */
Kojto 124:2241e3a39974 947 "MRS R1, CPSR;"
Kojto 124:2241e3a39974 948 "CPS %0;" /* ;no effect in USR mode */
Kojto 124:2241e3a39974 949 "MOV SP, R0;"
Kojto 124:2241e3a39974 950 "MSR CPSR_c, R1;" /* ;no effect in USR mode */
Kojto 124:2241e3a39974 951 "ISB;"
Kojto 124:2241e3a39974 952 //"BX LR;"
Kojto 124:2241e3a39974 953 :
Kojto 124:2241e3a39974 954 : "i"(MODE_SYS)
Kojto 124:2241e3a39974 955 : "r0", "r1");
Kojto 124:2241e3a39974 956 return;
Kojto 124:2241e3a39974 957 }
Kojto 124:2241e3a39974 958
Kojto 124:2241e3a39974 959 /** \brief Set User Mode
Kojto 124:2241e3a39974 960
Kojto 124:2241e3a39974 961 This function changes the processor state to User Mode
Kojto 124:2241e3a39974 962 */
Kojto 124:2241e3a39974 963 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CPS_USR(void)
Kojto 124:2241e3a39974 964 {
Kojto 124:2241e3a39974 965 __asm__ volatile (
Kojto 124:2241e3a39974 966 ".ARM;"
Kojto 124:2241e3a39974 967
Kojto 124:2241e3a39974 968 "CPS %0;"
Kojto 124:2241e3a39974 969 //"BX LR;"
Kojto 124:2241e3a39974 970 :
Kojto 124:2241e3a39974 971 : "i"(MODE_USR)
Kojto 124:2241e3a39974 972 : );
Kojto 124:2241e3a39974 973 return;
Kojto 124:2241e3a39974 974 }
Kojto 124:2241e3a39974 975
Kojto 124:2241e3a39974 976
Kojto 124:2241e3a39974 977 /** \brief Enable FIQ
Kojto 124:2241e3a39974 978
Kojto 124:2241e3a39974 979 This function enables FIQ interrupts by clearing the F-bit in the CPSR.
Kojto 124:2241e3a39974 980 Can only be executed in Privileged modes.
Kojto 124:2241e3a39974 981 */
Kojto 124:2241e3a39974 982 #define __enable_fault_irq() __asm__ volatile ("cpsie f")
Kojto 124:2241e3a39974 983
Kojto 124:2241e3a39974 984
Kojto 124:2241e3a39974 985 /** \brief Disable FIQ
Kojto 124:2241e3a39974 986
Kojto 124:2241e3a39974 987 This function disables FIQ interrupts by setting the F-bit in the CPSR.
Kojto 124:2241e3a39974 988 Can only be executed in Privileged modes.
Kojto 124:2241e3a39974 989 */
Kojto 124:2241e3a39974 990 #define __disable_fault_irq() __asm__ volatile ("cpsid f")
Kojto 124:2241e3a39974 991
Kojto 124:2241e3a39974 992
Kojto 124:2241e3a39974 993 /** \brief Get FPSCR
Kojto 124:2241e3a39974 994
Kojto 124:2241e3a39974 995 This function returns the current value of the Floating Point Status/Control register.
Kojto 124:2241e3a39974 996
Kojto 124:2241e3a39974 997 \return Floating Point Status/Control register value
Kojto 124:2241e3a39974 998 */
Kojto 124:2241e3a39974 999 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(void)
Kojto 124:2241e3a39974 1000 {
Kojto 124:2241e3a39974 1001 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
Kojto 124:2241e3a39974 1002 #if 1
Kojto 124:2241e3a39974 1003 uint32_t result;
Kojto 124:2241e3a39974 1004
Kojto 124:2241e3a39974 1005 __ASM volatile ("vmrs %0, fpscr" : "=r" (result) );
Kojto 124:2241e3a39974 1006 return (result);
Kojto 124:2241e3a39974 1007 #else
Kojto 124:2241e3a39974 1008 register uint32_t __regfpscr __ASM("fpscr");
Kojto 124:2241e3a39974 1009 return(__regfpscr);
Kojto 124:2241e3a39974 1010 #endif
Kojto 124:2241e3a39974 1011 #else
Kojto 124:2241e3a39974 1012 return(0);
Kojto 124:2241e3a39974 1013 #endif
Kojto 124:2241e3a39974 1014 }
Kojto 124:2241e3a39974 1015
Kojto 124:2241e3a39974 1016
Kojto 124:2241e3a39974 1017 /** \brief Set FPSCR
Kojto 124:2241e3a39974 1018
Kojto 124:2241e3a39974 1019 This function assigns the given value to the Floating Point Status/Control register.
Kojto 124:2241e3a39974 1020
Kojto 124:2241e3a39974 1021 \param [in] fpscr Floating Point Status/Control value to set
Kojto 124:2241e3a39974 1022 */
Kojto 124:2241e3a39974 1023 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
Kojto 124:2241e3a39974 1024 {
Kojto 124:2241e3a39974 1025 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
Kojto 124:2241e3a39974 1026 #if 1
Kojto 124:2241e3a39974 1027 __ASM volatile ("vmsr fpscr, %0" : : "r" (fpscr) );
Kojto 124:2241e3a39974 1028 #else
Kojto 124:2241e3a39974 1029 register uint32_t __regfpscr __ASM("fpscr");
Kojto 124:2241e3a39974 1030 __regfpscr = (fpscr);
Kojto 124:2241e3a39974 1031 #endif
Kojto 124:2241e3a39974 1032 #endif
Kojto 124:2241e3a39974 1033 }
Kojto 124:2241e3a39974 1034
Kojto 124:2241e3a39974 1035 /** \brief Get FPEXC
Kojto 124:2241e3a39974 1036
Kojto 124:2241e3a39974 1037 This function returns the current value of the Floating Point Exception Control register.
Kojto 124:2241e3a39974 1038
Kojto 124:2241e3a39974 1039 \return Floating Point Exception Control register value
Kojto 124:2241e3a39974 1040 */
Kojto 124:2241e3a39974 1041 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPEXC(void)
Kojto 124:2241e3a39974 1042 {
Kojto 124:2241e3a39974 1043 #if (__FPU_PRESENT == 1)
Kojto 124:2241e3a39974 1044 #if 1
Kojto 124:2241e3a39974 1045 uint32_t result;
Kojto 124:2241e3a39974 1046
Kojto 124:2241e3a39974 1047 __ASM volatile ("vmrs %0, fpexc" : "=r" (result));
Kojto 124:2241e3a39974 1048 return (result);
Kojto 124:2241e3a39974 1049 #else
Kojto 124:2241e3a39974 1050 register uint32_t __regfpexc __ASM("fpexc");
Kojto 124:2241e3a39974 1051 return(__regfpexc);
Kojto 124:2241e3a39974 1052 #endif
Kojto 124:2241e3a39974 1053 #else
Kojto 124:2241e3a39974 1054 return(0);
Kojto 124:2241e3a39974 1055 #endif
Kojto 124:2241e3a39974 1056 }
Kojto 124:2241e3a39974 1057
Kojto 124:2241e3a39974 1058
Kojto 124:2241e3a39974 1059 /** \brief Set FPEXC
Kojto 124:2241e3a39974 1060
Kojto 124:2241e3a39974 1061 This function assigns the given value to the Floating Point Exception Control register.
Kojto 124:2241e3a39974 1062
Kojto 124:2241e3a39974 1063 \param [in] fpscr Floating Point Exception Control value to set
Kojto 124:2241e3a39974 1064 */
Kojto 124:2241e3a39974 1065 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPEXC(uint32_t fpexc)
Kojto 124:2241e3a39974 1066 {
Kojto 124:2241e3a39974 1067 #if (__FPU_PRESENT == 1)
Kojto 124:2241e3a39974 1068 #if 1
Kojto 124:2241e3a39974 1069 __ASM volatile ("vmsr fpexc, %0" : : "r" (fpexc));
Kojto 124:2241e3a39974 1070 #else
Kojto 124:2241e3a39974 1071 register uint32_t __regfpexc __ASM("fpexc");
Kojto 124:2241e3a39974 1072 __regfpexc = (fpexc);
Kojto 124:2241e3a39974 1073 #endif
Kojto 124:2241e3a39974 1074 #endif
Kojto 124:2241e3a39974 1075 }
Kojto 124:2241e3a39974 1076
Kojto 124:2241e3a39974 1077 /** \brief Get CPACR
Kojto 124:2241e3a39974 1078
Kojto 124:2241e3a39974 1079 This function returns the current value of the Coprocessor Access Control register.
Kojto 124:2241e3a39974 1080
Kojto 124:2241e3a39974 1081 \return Coprocessor Access Control register value
Kojto 124:2241e3a39974 1082 */
Kojto 124:2241e3a39974 1083 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CPACR(void)
Kojto 124:2241e3a39974 1084 {
Kojto 124:2241e3a39974 1085 #if 1
Kojto 124:2241e3a39974 1086 register uint32_t __regCPACR;
Kojto 124:2241e3a39974 1087 __ASM volatile ("mrc p15, 0, %0, c1, c0, 2" : "=r" (__regCPACR));
Kojto 124:2241e3a39974 1088 #else
Kojto 124:2241e3a39974 1089 register uint32_t __regCPACR __ASM("cp15:0:c1:c0:2");
Kojto 124:2241e3a39974 1090 #endif
Kojto 124:2241e3a39974 1091 return __regCPACR;
Kojto 124:2241e3a39974 1092 }
Kojto 124:2241e3a39974 1093
Kojto 124:2241e3a39974 1094 /** \brief Set CPACR
Kojto 124:2241e3a39974 1095
Kojto 124:2241e3a39974 1096 This function assigns the given value to the Coprocessor Access Control register.
Kojto 124:2241e3a39974 1097
Kojto 124:2241e3a39974 1098 \param [in] cpacr Coprocessor Acccess Control value to set
Kojto 124:2241e3a39974 1099 */
Kojto 124:2241e3a39974 1100 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CPACR(uint32_t cpacr)
Kojto 124:2241e3a39974 1101 {
Kojto 124:2241e3a39974 1102 #if 1
Kojto 124:2241e3a39974 1103 __ASM volatile ("mcr p15, 0, %0, c1, c0, 2" : : "r" (cpacr));
Kojto 124:2241e3a39974 1104 #else
Kojto 124:2241e3a39974 1105 register uint32_t __regCPACR __ASM("cp15:0:c1:c0:2");
Kojto 124:2241e3a39974 1106 __regCPACR = cpacr;
Kojto 124:2241e3a39974 1107 #endif
Kojto 124:2241e3a39974 1108 __ISB();
Kojto 124:2241e3a39974 1109 }
Kojto 124:2241e3a39974 1110
Kojto 124:2241e3a39974 1111 /** \brief Get CBAR
Kojto 124:2241e3a39974 1112
Kojto 124:2241e3a39974 1113 This function returns the value of the Configuration Base Address register.
Kojto 124:2241e3a39974 1114
Kojto 124:2241e3a39974 1115 \return Configuration Base Address register value
Kojto 124:2241e3a39974 1116 */
Kojto 124:2241e3a39974 1117 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CBAR() {
Kojto 124:2241e3a39974 1118 #if 1
Kojto 124:2241e3a39974 1119 register uint32_t __regCBAR;
Kojto 124:2241e3a39974 1120 __ASM volatile ("mrc p15, 4, %0, c15, c0, 0" : "=r" (__regCBAR));
Kojto 124:2241e3a39974 1121 #else
Kojto 124:2241e3a39974 1122 register uint32_t __regCBAR __ASM("cp15:4:c15:c0:0");
Kojto 124:2241e3a39974 1123 #endif
Kojto 124:2241e3a39974 1124 return(__regCBAR);
Kojto 124:2241e3a39974 1125 }
Kojto 124:2241e3a39974 1126
Kojto 124:2241e3a39974 1127 /** \brief Get TTBR0
Kojto 124:2241e3a39974 1128
Kojto 124:2241e3a39974 1129 This function returns the value of the Translation Table Base Register 0.
Kojto 124:2241e3a39974 1130
Kojto 124:2241e3a39974 1131 \return Translation Table Base Register 0 value
Kojto 124:2241e3a39974 1132 */
Kojto 124:2241e3a39974 1133 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_TTBR0() {
Kojto 124:2241e3a39974 1134 #if 1
Kojto 124:2241e3a39974 1135 register uint32_t __regTTBR0;
Kojto 124:2241e3a39974 1136 __ASM volatile ("mrc p15, 0, %0, c2, c0, 0" : "=r" (__regTTBR0));
Kojto 124:2241e3a39974 1137 #else
Kojto 124:2241e3a39974 1138 register uint32_t __regTTBR0 __ASM("cp15:0:c2:c0:0");
Kojto 124:2241e3a39974 1139 #endif
Kojto 124:2241e3a39974 1140 return(__regTTBR0);
Kojto 124:2241e3a39974 1141 }
Kojto 124:2241e3a39974 1142
Kojto 124:2241e3a39974 1143 /** \brief Set TTBR0
Kojto 124:2241e3a39974 1144
Kojto 124:2241e3a39974 1145 This function assigns the given value to the Translation Table Base Register 0.
Kojto 124:2241e3a39974 1146
Kojto 124:2241e3a39974 1147 \param [in] ttbr0 Translation Table Base Register 0 value to set
Kojto 124:2241e3a39974 1148 */
Kojto 124:2241e3a39974 1149 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_TTBR0(uint32_t ttbr0) {
Kojto 124:2241e3a39974 1150 #if 1
Kojto 124:2241e3a39974 1151 __ASM volatile ("mcr p15, 0, %0, c2, c0, 0" : : "r" (ttbr0));
Kojto 124:2241e3a39974 1152 #else
Kojto 124:2241e3a39974 1153 register uint32_t __regTTBR0 __ASM("cp15:0:c2:c0:0");
Kojto 124:2241e3a39974 1154 __regTTBR0 = ttbr0;
Kojto 124:2241e3a39974 1155 #endif
Kojto 124:2241e3a39974 1156 __ISB();
Kojto 124:2241e3a39974 1157 }
Kojto 124:2241e3a39974 1158
Kojto 124:2241e3a39974 1159 /** \brief Get DACR
Kojto 124:2241e3a39974 1160
Kojto 124:2241e3a39974 1161 This function returns the value of the Domain Access Control Register.
Kojto 124:2241e3a39974 1162
Kojto 124:2241e3a39974 1163 \return Domain Access Control Register value
Kojto 124:2241e3a39974 1164 */
Kojto 124:2241e3a39974 1165 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_DACR() {
Kojto 124:2241e3a39974 1166 #if 1
Kojto 124:2241e3a39974 1167 register uint32_t __regDACR;
Kojto 124:2241e3a39974 1168 __ASM volatile ("mrc p15, 0, %0, c3, c0, 0" : "=r" (__regDACR));
Kojto 124:2241e3a39974 1169 #else
Kojto 124:2241e3a39974 1170 register uint32_t __regDACR __ASM("cp15:0:c3:c0:0");
Kojto 124:2241e3a39974 1171 #endif
Kojto 124:2241e3a39974 1172 return(__regDACR);
Kojto 124:2241e3a39974 1173 }
Kojto 124:2241e3a39974 1174
Kojto 124:2241e3a39974 1175 /** \brief Set DACR
Kojto 124:2241e3a39974 1176
Kojto 124:2241e3a39974 1177 This function assigns the given value to the Domain Access Control Register.
Kojto 124:2241e3a39974 1178
Kojto 124:2241e3a39974 1179 \param [in] dacr Domain Access Control Register value to set
Kojto 124:2241e3a39974 1180 */
Kojto 124:2241e3a39974 1181 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_DACR(uint32_t dacr) {
Kojto 124:2241e3a39974 1182 #if 1
Kojto 124:2241e3a39974 1183 __ASM volatile ("mcr p15, 0, %0, c3, c0, 0" : : "r" (dacr));
Kojto 124:2241e3a39974 1184 #else
Kojto 124:2241e3a39974 1185 register uint32_t __regDACR __ASM("cp15:0:c3:c0:0");
Kojto 124:2241e3a39974 1186 __regDACR = dacr;
Kojto 124:2241e3a39974 1187 #endif
Kojto 124:2241e3a39974 1188 __ISB();
Kojto 124:2241e3a39974 1189 }
Kojto 124:2241e3a39974 1190
Kojto 124:2241e3a39974 1191 /******************************** Cache and BTAC enable ****************************************************/
Kojto 124:2241e3a39974 1192
Kojto 124:2241e3a39974 1193 /** \brief Set SCTLR
Kojto 124:2241e3a39974 1194
Kojto 124:2241e3a39974 1195 This function assigns the given value to the System Control Register.
Kojto 124:2241e3a39974 1196
Kojto 124:2241e3a39974 1197 \param [in] sctlr System Control Register value to set
Kojto 124:2241e3a39974 1198 */
Kojto 124:2241e3a39974 1199 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_SCTLR(uint32_t sctlr)
Kojto 124:2241e3a39974 1200 {
Kojto 124:2241e3a39974 1201 #if 1
Kojto 124:2241e3a39974 1202 __ASM volatile ("mcr p15, 0, %0, c1, c0, 0" : : "r" (sctlr));
Kojto 124:2241e3a39974 1203 #else
Kojto 124:2241e3a39974 1204 register uint32_t __regSCTLR __ASM("cp15:0:c1:c0:0");
Kojto 124:2241e3a39974 1205 __regSCTLR = sctlr;
Kojto 124:2241e3a39974 1206 #endif
Kojto 124:2241e3a39974 1207 }
Kojto 124:2241e3a39974 1208
Kojto 124:2241e3a39974 1209 /** \brief Get SCTLR
Kojto 124:2241e3a39974 1210
Kojto 124:2241e3a39974 1211 This function returns the value of the System Control Register.
Kojto 124:2241e3a39974 1212
Kojto 124:2241e3a39974 1213 \return System Control Register value
Kojto 124:2241e3a39974 1214 */
Kojto 124:2241e3a39974 1215 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_SCTLR() {
Kojto 124:2241e3a39974 1216 #if 1
Kojto 124:2241e3a39974 1217 register uint32_t __regSCTLR;
Kojto 124:2241e3a39974 1218 __ASM volatile ("mrc p15, 0, %0, c1, c0, 0" : "=r" (__regSCTLR));
Kojto 124:2241e3a39974 1219 #else
Kojto 124:2241e3a39974 1220 register uint32_t __regSCTLR __ASM("cp15:0:c1:c0:0");
Kojto 124:2241e3a39974 1221 #endif
Kojto 124:2241e3a39974 1222 return(__regSCTLR);
Kojto 124:2241e3a39974 1223 }
Kojto 124:2241e3a39974 1224
Kojto 124:2241e3a39974 1225 /** \brief Enable Caches
Kojto 124:2241e3a39974 1226
Kojto 124:2241e3a39974 1227 Enable Caches
Kojto 124:2241e3a39974 1228 */
Kojto 124:2241e3a39974 1229 __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_caches(void) {
Kojto 124:2241e3a39974 1230 // Set I bit 12 to enable I Cache
Kojto 124:2241e3a39974 1231 // Set C bit 2 to enable D Cache
Kojto 124:2241e3a39974 1232 __set_SCTLR( __get_SCTLR() | (1 << 12) | (1 << 2));
Kojto 124:2241e3a39974 1233 }
Kojto 124:2241e3a39974 1234
Kojto 124:2241e3a39974 1235 /** \brief Disable Caches
Kojto 124:2241e3a39974 1236
Kojto 124:2241e3a39974 1237 Disable Caches
Kojto 124:2241e3a39974 1238 */
Kojto 124:2241e3a39974 1239 __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_caches(void) {
Kojto 124:2241e3a39974 1240 // Clear I bit 12 to disable I Cache
Kojto 124:2241e3a39974 1241 // Clear C bit 2 to disable D Cache
Kojto 124:2241e3a39974 1242 __set_SCTLR( __get_SCTLR() & ~(1 << 12) & ~(1 << 2));
Kojto 124:2241e3a39974 1243 __ISB();
Kojto 124:2241e3a39974 1244 }
Kojto 124:2241e3a39974 1245
Kojto 124:2241e3a39974 1246 /** \brief Enable BTAC
Kojto 124:2241e3a39974 1247
Kojto 124:2241e3a39974 1248 Enable BTAC
Kojto 124:2241e3a39974 1249 */
Kojto 124:2241e3a39974 1250 __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_btac(void) {
Kojto 124:2241e3a39974 1251 // Set Z bit 11 to enable branch prediction
Kojto 124:2241e3a39974 1252 __set_SCTLR( __get_SCTLR() | (1 << 11));
Kojto 124:2241e3a39974 1253 __ISB();
Kojto 124:2241e3a39974 1254 }
Kojto 124:2241e3a39974 1255
Kojto 124:2241e3a39974 1256 /** \brief Disable BTAC
Kojto 124:2241e3a39974 1257
Kojto 124:2241e3a39974 1258 Disable BTAC
Kojto 124:2241e3a39974 1259 */
Kojto 124:2241e3a39974 1260 __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_btac(void) {
Kojto 124:2241e3a39974 1261 // Clear Z bit 11 to disable branch prediction
Kojto 124:2241e3a39974 1262 __set_SCTLR( __get_SCTLR() & ~(1 << 11));
Kojto 124:2241e3a39974 1263 }
Kojto 124:2241e3a39974 1264
Kojto 124:2241e3a39974 1265
Kojto 124:2241e3a39974 1266 /** \brief Enable MMU
Kojto 124:2241e3a39974 1267
Kojto 124:2241e3a39974 1268 Enable MMU
Kojto 124:2241e3a39974 1269 */
Kojto 124:2241e3a39974 1270 __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_mmu(void) {
Kojto 124:2241e3a39974 1271 // Set M bit 0 to enable the MMU
Kojto 124:2241e3a39974 1272 // Set AFE bit to enable simplified access permissions model
Kojto 124:2241e3a39974 1273 // Clear TRE bit to disable TEX remap and A bit to disable strict alignment fault checking
Kojto 124:2241e3a39974 1274 __set_SCTLR( (__get_SCTLR() & ~(1 << 28) & ~(1 << 1)) | 1 | (1 << 29));
Kojto 124:2241e3a39974 1275 __ISB();
Kojto 124:2241e3a39974 1276 }
Kojto 124:2241e3a39974 1277
Kojto 124:2241e3a39974 1278 /** \brief Disable MMU
Kojto 124:2241e3a39974 1279
Kojto 124:2241e3a39974 1280 Disable MMU
Kojto 124:2241e3a39974 1281 */
Kojto 124:2241e3a39974 1282 __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_mmu(void) {
Kojto 124:2241e3a39974 1283 // Clear M bit 0 to disable the MMU
Kojto 124:2241e3a39974 1284 __set_SCTLR( __get_SCTLR() & ~1);
Kojto 124:2241e3a39974 1285 __ISB();
Kojto 124:2241e3a39974 1286 }
Kojto 124:2241e3a39974 1287
Kojto 124:2241e3a39974 1288 /******************************** TLB maintenance operations ************************************************/
Kojto 124:2241e3a39974 1289 /** \brief Invalidate the whole tlb
Kojto 124:2241e3a39974 1290
Kojto 124:2241e3a39974 1291 TLBIALL. Invalidate the whole tlb
Kojto 124:2241e3a39974 1292 */
Kojto 124:2241e3a39974 1293
Kojto 124:2241e3a39974 1294 __attribute__( ( always_inline ) ) __STATIC_INLINE void __ca9u_inv_tlb_all(void) {
Kojto 124:2241e3a39974 1295 #if 1
Kojto 124:2241e3a39974 1296 __ASM volatile ("mcr p15, 0, %0, c8, c7, 0" : : "r" (0));
Kojto 124:2241e3a39974 1297 #else
Kojto 124:2241e3a39974 1298 register uint32_t __TLBIALL __ASM("cp15:0:c8:c7:0");
Kojto 124:2241e3a39974 1299 __TLBIALL = 0;
Kojto 124:2241e3a39974 1300 #endif
Kojto 124:2241e3a39974 1301 __DSB();
Kojto 124:2241e3a39974 1302 __ISB();
Kojto 124:2241e3a39974 1303 }
Kojto 124:2241e3a39974 1304
Kojto 124:2241e3a39974 1305 /******************************** BTB maintenance operations ************************************************/
Kojto 124:2241e3a39974 1306 /** \brief Invalidate entire branch predictor array
Kojto 124:2241e3a39974 1307
Kojto 124:2241e3a39974 1308 BPIALL. Branch Predictor Invalidate All.
Kojto 124:2241e3a39974 1309 */
Kojto 124:2241e3a39974 1310
Kojto 124:2241e3a39974 1311 __attribute__( ( always_inline ) ) __STATIC_INLINE void __v7_inv_btac(void) {
Kojto 124:2241e3a39974 1312 #if 1
Kojto 124:2241e3a39974 1313 __ASM volatile ("mcr p15, 0, %0, c7, c5, 6" : : "r" (0));
Kojto 124:2241e3a39974 1314 #else
Kojto 124:2241e3a39974 1315 register uint32_t __BPIALL __ASM("cp15:0:c7:c5:6");
Kojto 124:2241e3a39974 1316 __BPIALL = 0;
Kojto 124:2241e3a39974 1317 #endif
Kojto 124:2241e3a39974 1318 __DSB(); //ensure completion of the invalidation
Kojto 124:2241e3a39974 1319 __ISB(); //ensure instruction fetch path sees new state
Kojto 124:2241e3a39974 1320 }
Kojto 124:2241e3a39974 1321
Kojto 124:2241e3a39974 1322
Kojto 124:2241e3a39974 1323 /******************************** L1 cache operations ******************************************************/
Kojto 124:2241e3a39974 1324
Kojto 124:2241e3a39974 1325 /** \brief Invalidate the whole I$
Kojto 124:2241e3a39974 1326
Kojto 124:2241e3a39974 1327 ICIALLU. Instruction Cache Invalidate All to PoU
Kojto 124:2241e3a39974 1328 */
Kojto 124:2241e3a39974 1329 __attribute__( ( always_inline ) ) __STATIC_INLINE void __v7_inv_icache_all(void) {
Kojto 124:2241e3a39974 1330 #if 1
Kojto 124:2241e3a39974 1331 __ASM volatile ("mcr p15, 0, %0, c7, c5, 0" : : "r" (0));
Kojto 124:2241e3a39974 1332 #else
Kojto 124:2241e3a39974 1333 register uint32_t __ICIALLU __ASM("cp15:0:c7:c5:0");
Kojto 124:2241e3a39974 1334 __ICIALLU = 0;
Kojto 124:2241e3a39974 1335 #endif
Kojto 124:2241e3a39974 1336 __DSB(); //ensure completion of the invalidation
Kojto 124:2241e3a39974 1337 __ISB(); //ensure instruction fetch path sees new I cache state
Kojto 124:2241e3a39974 1338 }
Kojto 124:2241e3a39974 1339
Kojto 124:2241e3a39974 1340 /** \brief Clean D$ by MVA
Kojto 124:2241e3a39974 1341
Kojto 124:2241e3a39974 1342 DCCMVAC. Data cache clean by MVA to PoC
Kojto 124:2241e3a39974 1343 */
Kojto 124:2241e3a39974 1344 __attribute__( ( always_inline ) ) __STATIC_INLINE void __v7_clean_dcache_mva(void *va) {
Kojto 124:2241e3a39974 1345 #if 1
Kojto 124:2241e3a39974 1346 __ASM volatile ("mcr p15, 0, %0, c7, c10, 1" : : "r" ((uint32_t)va));
Kojto 124:2241e3a39974 1347 #else
Kojto 124:2241e3a39974 1348 register uint32_t __DCCMVAC __ASM("cp15:0:c7:c10:1");
Kojto 124:2241e3a39974 1349 __DCCMVAC = (uint32_t)va;
Kojto 124:2241e3a39974 1350 #endif
Kojto 124:2241e3a39974 1351 __DMB(); //ensure the ordering of data cache maintenance operations and their effects
Kojto 124:2241e3a39974 1352 }
Kojto 124:2241e3a39974 1353
Kojto 124:2241e3a39974 1354 /** \brief Invalidate D$ by MVA
Kojto 124:2241e3a39974 1355
Kojto 124:2241e3a39974 1356 DCIMVAC. Data cache invalidate by MVA to PoC
Kojto 124:2241e3a39974 1357 */
Kojto 124:2241e3a39974 1358 __attribute__( ( always_inline ) ) __STATIC_INLINE void __v7_inv_dcache_mva(void *va) {
Kojto 124:2241e3a39974 1359 #if 1
Kojto 124:2241e3a39974 1360 __ASM volatile ("mcr p15, 0, %0, c7, c6, 1" : : "r" ((uint32_t)va));
Kojto 124:2241e3a39974 1361 #else
Kojto 124:2241e3a39974 1362 register uint32_t __DCIMVAC __ASM("cp15:0:c7:c6:1");
Kojto 124:2241e3a39974 1363 __DCIMVAC = (uint32_t)va;
Kojto 124:2241e3a39974 1364 #endif
Kojto 124:2241e3a39974 1365 __DMB(); //ensure the ordering of data cache maintenance operations and their effects
Kojto 124:2241e3a39974 1366 }
Kojto 124:2241e3a39974 1367
Kojto 124:2241e3a39974 1368 /** \brief Clean and Invalidate D$ by MVA
Kojto 124:2241e3a39974 1369
Kojto 124:2241e3a39974 1370 DCCIMVAC. Data cache clean and invalidate by MVA to PoC
Kojto 124:2241e3a39974 1371 */
Kojto 124:2241e3a39974 1372 __attribute__( ( always_inline ) ) __STATIC_INLINE void __v7_clean_inv_dcache_mva(void *va) {
Kojto 124:2241e3a39974 1373 #if 1
Kojto 124:2241e3a39974 1374 __ASM volatile ("mcr p15, 0, %0, c7, c14, 1" : : "r" ((uint32_t)va));
Kojto 124:2241e3a39974 1375 #else
Kojto 124:2241e3a39974 1376 register uint32_t __DCCIMVAC __ASM("cp15:0:c7:c14:1");
Kojto 124:2241e3a39974 1377 __DCCIMVAC = (uint32_t)va;
Kojto 124:2241e3a39974 1378 #endif
Kojto 124:2241e3a39974 1379 __DMB(); //ensure the ordering of data cache maintenance operations and their effects
Kojto 124:2241e3a39974 1380 }
Kojto 124:2241e3a39974 1381
Kojto 124:2241e3a39974 1382 /** \brief Clean and Invalidate the entire data or unified cache
Kojto 124:2241e3a39974 1383
Kojto 124:2241e3a39974 1384 Generic mechanism for cleaning/invalidating the entire data or unified cache to the point of coherency.
Kojto 124:2241e3a39974 1385 */
Kojto 124:2241e3a39974 1386 extern void __v7_all_cache(uint32_t op);
Kojto 124:2241e3a39974 1387
Kojto 124:2241e3a39974 1388
Kojto 124:2241e3a39974 1389 /** \brief Invalidate the whole D$
Kojto 124:2241e3a39974 1390
Kojto 124:2241e3a39974 1391 DCISW. Invalidate by Set/Way
Kojto 124:2241e3a39974 1392 */
Kojto 124:2241e3a39974 1393
Kojto 124:2241e3a39974 1394 __attribute__( ( always_inline ) ) __STATIC_INLINE void __v7_inv_dcache_all(void) {
Kojto 124:2241e3a39974 1395 __v7_all_cache(0);
Kojto 124:2241e3a39974 1396 }
Kojto 124:2241e3a39974 1397
Kojto 124:2241e3a39974 1398 /** \brief Clean the whole D$
Kojto 124:2241e3a39974 1399
Kojto 124:2241e3a39974 1400 DCCSW. Clean by Set/Way
Kojto 124:2241e3a39974 1401 */
Kojto 124:2241e3a39974 1402
Kojto 124:2241e3a39974 1403 __attribute__( ( always_inline ) ) __STATIC_INLINE void __v7_clean_dcache_all(void) {
Kojto 124:2241e3a39974 1404 __v7_all_cache(1);
Kojto 124:2241e3a39974 1405 }
Kojto 124:2241e3a39974 1406
Kojto 124:2241e3a39974 1407 /** \brief Clean and invalidate the whole D$
Kojto 124:2241e3a39974 1408
Kojto 124:2241e3a39974 1409 DCCISW. Clean and Invalidate by Set/Way
Kojto 124:2241e3a39974 1410 */
Kojto 124:2241e3a39974 1411
Kojto 124:2241e3a39974 1412 __attribute__( ( always_inline ) ) __STATIC_INLINE void __v7_clean_inv_dcache_all(void) {
Kojto 124:2241e3a39974 1413 __v7_all_cache(2);
Kojto 124:2241e3a39974 1414 }
Kojto 124:2241e3a39974 1415
Kojto 124:2241e3a39974 1416 #include "core_ca_mmu.h"
Kojto 124:2241e3a39974 1417
Kojto 124:2241e3a39974 1418 #elif (defined (__TASKING__)) /*--------------- TASKING Compiler -----------------*/
Kojto 124:2241e3a39974 1419
Kojto 124:2241e3a39974 1420 #error TASKING Compiler support not implemented for Cortex-A
Kojto 124:2241e3a39974 1421
Kojto 124:2241e3a39974 1422 #endif
Kojto 124:2241e3a39974 1423
Kojto 124:2241e3a39974 1424 /*@} end of CMSIS_Core_RegAccFunctions */
Kojto 124:2241e3a39974 1425
Kojto 124:2241e3a39974 1426
Kojto 124:2241e3a39974 1427 #endif /* __CORE_CAFUNC_H__ */