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 Jan 13 09:48:29 2016 +0000
Revision:
112:6f327212ef96
Child:
115:87f2f5183dfb
Release 112 of the mbed library

Changes:
- new platforms - STM32 B96B F446, MOTE_L152RC
- nrf51 - fix serial init bug (character sent)
- stm all devices - fix RTC clocking in the init
- stm f0 - SystemInit clock fix, for SetVector()
- RawSerial - fix for microlib (vsnprintf with size 0)

Who changed what in which revision?

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