The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Kojto
Date:
Fri Oct 02 07:35:07 2015 +0200
Revision:
108:34e6b704fe68
Parent:
99:dbbf35b96557
Child:
115:87f2f5183dfb
Release 108  of the mbed library

Changes:
- new platforms - ELMO_F411RE, WIZNET_7500P, ARM_MPS2_BEID
- EFM32 - bugfixes in rtc, serial
- Cortex A cmsis - update files
- STML4 - RAM fixes

Who changed what in which revision?

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