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:
Wed Apr 29 10:16:23 2015 +0100
Revision:
98:8ab26030e058
Child:
108:34e6b704fe68
Release 98 of the mbed library

Changes:
- Silabs new targets (Giant, Zero, Happy, Leopard, Wonder Geckos)
- Asynchronous SPI, I2C, Serial
- LowPower classes
- Nordic - nordic SDK v8.0 update
- Teensy - gcc arm fix for startup
- Nucleo F411 - usb freq fix

Who changed what in which revision?

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