ads1115 only

Fork of mbed by mbed official

Committer:
Kojto
Date:
Tue May 10 12:23:43 2016 -0500
Revision:
120:7c328cabac7e
Child:
121:6c34061e7c34
Release 120 of the mbed library

Changes:
- ST - STMF3XX/F4XX - directories removal
- STMF3 - pwm range fix
- STMF1 - Cube driver update
- Renesas - RZ_A1H - async i2c, serial and spi addition
- Freescale - KSDK2 update

Who changed what in which revision?

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