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