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 May 25 16:44:06 2016 +0100
Revision:
121:6c34061e7c34
Parent:
115:87f2f5183dfb
Child:
130:d75b3fe1f5cb
Release 121 of the mbed library

Changes:
- new targets - EFM32PG_STK3401, NUCLEO_L031K6
- ST - F7 - analogin conversion fix
- F1, F4 - serial flushed prior init fix
- CAN added for F042K6,F072RB,F091RC
- NUCLE_L053R8/F030R8/F070RB,F103RB - ticker 16bit counter fix
- NXP - LPC812 PWMOut conflict issue fix
- KSDK - PWMout fix

Who changed what in which revision?

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