SPKT

Dependencies:   F746_GUI SD_PlayerSkeleton F746_SAI_IO

Committer:
phungductung
Date:
Tue Jun 04 21:37:21 2019 +0000
Revision:
0:8ede47d38d10
SPKT

Who changed what in which revision?

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