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:
<>
Date:
Tue Mar 14 16:20:51 2017 +0000
Revision:
138:093f2bd7b9eb
Parent:
130:d75b3fe1f5cb
Release 138 of the mbed library

Ports for Upcoming Targets


Fixes and Changes

3716: fix for issue #3715: correction in startup files for ARM and IAR, alignment of system_stm32f429xx.c files https://github.com/ARMmbed/mbed-os/pull/3716
3741: STM32 remove warning in hal_tick_32b.c file https://github.com/ARMmbed/mbed-os/pull/3741
3780: STM32L4 : Fix GPIO G port compatibility https://github.com/ARMmbed/mbed-os/pull/3780
3831: NCS36510: SPISLAVE enabled (Conflict resolved) https://github.com/ARMmbed/mbed-os/pull/3831
3836: Allow to redefine nRF's PSTORAGE_NUM_OF_PAGES outside of the mbed-os https://github.com/ARMmbed/mbed-os/pull/3836
3840: STM32: gpio SPEED - always set High Speed by default https://github.com/ARMmbed/mbed-os/pull/3840
3844: STM32 GPIO: Typo correction. Update comment (GPIO_IP_WITHOUT_BRR) https://github.com/ARMmbed/mbed-os/pull/3844
3850: STM32: change spi error to debug warning https://github.com/ARMmbed/mbed-os/pull/3850
3860: Define GPIO_IP_WITHOUT_BRR for xDot platform https://github.com/ARMmbed/mbed-os/pull/3860
3880: DISCO_F469NI: allow the use of CAN2 instance when CAN1 is not activated https://github.com/ARMmbed/mbed-os/pull/3880
3795: Fix pwm period calc https://github.com/ARMmbed/mbed-os/pull/3795
3828: STM32 CAN API: correct format and type https://github.com/ARMmbed/mbed-os/pull/3828
3842: TARGET_NRF: corrected spi_init() to properly handle re-initialization https://github.com/ARMmbed/mbed-os/pull/3842
3843: STM32L476xG: set APB2 clock to 80MHz (instead of 40MHz) https://github.com/ARMmbed/mbed-os/pull/3843
3879: NUCLEO_F446ZE: Add missing AnalogIn pins on PF_3, PF_5 and PF_10. https://github.com/ARMmbed/mbed-os/pull/3879
3902: Fix heap and stack size for NUCLEO_F746ZG https://github.com/ARMmbed/mbed-os/pull/3902
3829: can_write(): return error code when no tx mailboxes are available https://github.com/ARMmbed/mbed-os/pull/3829

Who changed what in which revision?

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