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