Fork of the official mbed C/C SDK provides the software platform and libraries to build your applications for RenBED.

Dependents:   1-RenBuggyTimed RenBED_RGB RenBED_RGB_PWM RenBED_RGB

Fork of mbed by mbed official

Committer:
Kojto
Date:
Tue Feb 02 14:43:35 2016 +0000
Revision:
113:f141b2784e32
Child:
115:87f2f5183dfb
Release 113 of the mbed library

Changes:
- new targets - Silabs Perl Gecko, TY51822
- Silabs - emlib update to 4.1.0, various bugfixes as result
- STM B96B_F446VE - add async serial support
- Freescale KLXX - rtc lock fix
- LPC11U68 and LPC1549 - pwm bugfixes - duty cycle

Who changed what in which revision?

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