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:
Anna Bridge
Date:
Fri Jun 22 15:38:59 2018 +0100
Revision:
169:a7c7b631e539
Parent:
163:e59c8e839560
mbed library. Release version 162

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 161:aa5281ff4a02 1 /******************************************************************************
AnnaBridge 161:aa5281ff4a02 2 * @file mpu_armv8.h
Anna Bridge 169:a7c7b631e539 3 * @brief CMSIS MPU API for Armv8-M MPU
Anna Bridge 169:a7c7b631e539 4 * @version V5.0.4
Anna Bridge 169:a7c7b631e539 5 * @date 10. January 2018
AnnaBridge 161:aa5281ff4a02 6 ******************************************************************************/
AnnaBridge 161:aa5281ff4a02 7 /*
Anna Bridge 169:a7c7b631e539 8 * Copyright (c) 2017-2018 Arm Limited. All rights reserved.
AnnaBridge 161:aa5281ff4a02 9 *
AnnaBridge 161:aa5281ff4a02 10 * SPDX-License-Identifier: Apache-2.0
AnnaBridge 161:aa5281ff4a02 11 *
AnnaBridge 161:aa5281ff4a02 12 * Licensed under the Apache License, Version 2.0 (the License); you may
AnnaBridge 161:aa5281ff4a02 13 * not use this file except in compliance with the License.
AnnaBridge 161:aa5281ff4a02 14 * You may obtain a copy of the License at
AnnaBridge 161:aa5281ff4a02 15 *
AnnaBridge 161:aa5281ff4a02 16 * www.apache.org/licenses/LICENSE-2.0
AnnaBridge 161:aa5281ff4a02 17 *
AnnaBridge 161:aa5281ff4a02 18 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 161:aa5281ff4a02 19 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
AnnaBridge 161:aa5281ff4a02 20 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 161:aa5281ff4a02 21 * See the License for the specific language governing permissions and
AnnaBridge 161:aa5281ff4a02 22 * limitations under the License.
AnnaBridge 161:aa5281ff4a02 23 */
Anna Bridge 169:a7c7b631e539 24
Anna Bridge 169:a7c7b631e539 25 #if defined ( __ICCARM__ )
Anna Bridge 169:a7c7b631e539 26 #pragma system_include /* treat file as system include file for MISRA check */
Anna Bridge 169:a7c7b631e539 27 #elif defined (__clang__)
Anna Bridge 169:a7c7b631e539 28 #pragma clang system_header /* treat file as system include file */
Anna Bridge 169:a7c7b631e539 29 #endif
Anna Bridge 169:a7c7b631e539 30
AnnaBridge 161:aa5281ff4a02 31 #ifndef ARM_MPU_ARMV8_H
AnnaBridge 161:aa5281ff4a02 32 #define ARM_MPU_ARMV8_H
AnnaBridge 161:aa5281ff4a02 33
AnnaBridge 161:aa5281ff4a02 34 /** \brief Attribute for device memory (outer only) */
AnnaBridge 161:aa5281ff4a02 35 #define ARM_MPU_ATTR_DEVICE ( 0U )
AnnaBridge 161:aa5281ff4a02 36
AnnaBridge 161:aa5281ff4a02 37 /** \brief Attribute for non-cacheable, normal memory */
AnnaBridge 161:aa5281ff4a02 38 #define ARM_MPU_ATTR_NON_CACHEABLE ( 4U )
AnnaBridge 161:aa5281ff4a02 39
AnnaBridge 161:aa5281ff4a02 40 /** \brief Attribute for normal memory (outer and inner)
AnnaBridge 161:aa5281ff4a02 41 * \param NT Non-Transient: Set to 1 for non-transient data.
AnnaBridge 161:aa5281ff4a02 42 * \param WB Write-Back: Set to 1 to use write-back update policy.
AnnaBridge 161:aa5281ff4a02 43 * \param RA Read Allocation: Set to 1 to use cache allocation on read miss.
AnnaBridge 161:aa5281ff4a02 44 * \param WA Write Allocation: Set to 1 to use cache allocation on write miss.
AnnaBridge 161:aa5281ff4a02 45 */
AnnaBridge 161:aa5281ff4a02 46 #define ARM_MPU_ATTR_MEMORY_(NT, WB, RA, WA) \
AnnaBridge 161:aa5281ff4a02 47 (((NT & 1U) << 3U) | ((WB & 1U) << 2U) | ((RA & 1U) << 1U) | (WA & 1U))
AnnaBridge 161:aa5281ff4a02 48
AnnaBridge 161:aa5281ff4a02 49 /** \brief Device memory type non Gathering, non Re-ordering, non Early Write Acknowledgement */
AnnaBridge 161:aa5281ff4a02 50 #define ARM_MPU_ATTR_DEVICE_nGnRnE (0U)
AnnaBridge 161:aa5281ff4a02 51
AnnaBridge 161:aa5281ff4a02 52 /** \brief Device memory type non Gathering, non Re-ordering, Early Write Acknowledgement */
AnnaBridge 161:aa5281ff4a02 53 #define ARM_MPU_ATTR_DEVICE_nGnRE (1U)
AnnaBridge 161:aa5281ff4a02 54
AnnaBridge 161:aa5281ff4a02 55 /** \brief Device memory type non Gathering, Re-ordering, Early Write Acknowledgement */
AnnaBridge 161:aa5281ff4a02 56 #define ARM_MPU_ATTR_DEVICE_nGRE (2U)
AnnaBridge 161:aa5281ff4a02 57
AnnaBridge 161:aa5281ff4a02 58 /** \brief Device memory type Gathering, Re-ordering, Early Write Acknowledgement */
AnnaBridge 161:aa5281ff4a02 59 #define ARM_MPU_ATTR_DEVICE_GRE (3U)
AnnaBridge 161:aa5281ff4a02 60
AnnaBridge 161:aa5281ff4a02 61 /** \brief Memory Attribute
AnnaBridge 161:aa5281ff4a02 62 * \param O Outer memory attributes
AnnaBridge 161:aa5281ff4a02 63 * \param I O == ARM_MPU_ATTR_DEVICE: Device memory attributes, else: Inner memory attributes
AnnaBridge 161:aa5281ff4a02 64 */
AnnaBridge 161:aa5281ff4a02 65 #define ARM_MPU_ATTR(O, I) (((O & 0xFU) << 4U) | (((O & 0xFU) != 0U) ? (I & 0xFU) : ((I & 0x3U) << 2U)))
AnnaBridge 161:aa5281ff4a02 66
AnnaBridge 161:aa5281ff4a02 67 /** \brief Normal memory non-shareable */
AnnaBridge 161:aa5281ff4a02 68 #define ARM_MPU_SH_NON (0U)
AnnaBridge 161:aa5281ff4a02 69
AnnaBridge 161:aa5281ff4a02 70 /** \brief Normal memory outer shareable */
AnnaBridge 161:aa5281ff4a02 71 #define ARM_MPU_SH_OUTER (2U)
AnnaBridge 161:aa5281ff4a02 72
AnnaBridge 161:aa5281ff4a02 73 /** \brief Normal memory inner shareable */
AnnaBridge 161:aa5281ff4a02 74 #define ARM_MPU_SH_INNER (3U)
AnnaBridge 161:aa5281ff4a02 75
AnnaBridge 161:aa5281ff4a02 76 /** \brief Memory access permissions
AnnaBridge 161:aa5281ff4a02 77 * \param RO Read-Only: Set to 1 for read-only memory.
AnnaBridge 161:aa5281ff4a02 78 * \param NP Non-Privileged: Set to 1 for non-privileged memory.
AnnaBridge 161:aa5281ff4a02 79 */
AnnaBridge 161:aa5281ff4a02 80 #define ARM_MPU_AP_(RO, NP) (((RO & 1U) << 1U) | (NP & 1U))
AnnaBridge 161:aa5281ff4a02 81
AnnaBridge 161:aa5281ff4a02 82 /** \brief Region Base Address Register value
AnnaBridge 161:aa5281ff4a02 83 * \param BASE The base address bits [31:5] of a memory region. The value is zero extended. Effective address gets 32 byte aligned.
AnnaBridge 161:aa5281ff4a02 84 * \param SH Defines the Shareability domain for this memory region.
AnnaBridge 161:aa5281ff4a02 85 * \param RO Read-Only: Set to 1 for a read-only memory region.
AnnaBridge 161:aa5281ff4a02 86 * \param NP Non-Privileged: Set to 1 for a non-privileged memory region.
AnnaBridge 161:aa5281ff4a02 87 * \oaram XN eXecute Never: Set to 1 for a non-executable memory region.
AnnaBridge 161:aa5281ff4a02 88 */
AnnaBridge 161:aa5281ff4a02 89 #define ARM_MPU_RBAR(BASE, SH, RO, NP, XN) \
AnnaBridge 161:aa5281ff4a02 90 ((BASE & MPU_RBAR_BASE_Pos) | \
AnnaBridge 161:aa5281ff4a02 91 ((SH << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk) | \
AnnaBridge 161:aa5281ff4a02 92 ((ARM_MPU_AP_(RO, NP) << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk) | \
AnnaBridge 161:aa5281ff4a02 93 ((XN << MPU_RBAR_XN_Pos) & MPU_RBAR_XN_Msk))
AnnaBridge 161:aa5281ff4a02 94
AnnaBridge 161:aa5281ff4a02 95 /** \brief Region Limit Address Register value
AnnaBridge 161:aa5281ff4a02 96 * \param LIMIT The limit address bits [31:5] for this memory region. The value is one extended.
AnnaBridge 161:aa5281ff4a02 97 * \param IDX The attribute index to be associated with this memory region.
AnnaBridge 161:aa5281ff4a02 98 */
AnnaBridge 161:aa5281ff4a02 99 #define ARM_MPU_RLAR(LIMIT, IDX) \
AnnaBridge 161:aa5281ff4a02 100 ((LIMIT & MPU_RLAR_LIMIT_Msk) | \
AnnaBridge 161:aa5281ff4a02 101 ((IDX << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \
AnnaBridge 161:aa5281ff4a02 102 (MPU_RLAR_EN_Msk))
AnnaBridge 161:aa5281ff4a02 103
AnnaBridge 161:aa5281ff4a02 104 /**
AnnaBridge 161:aa5281ff4a02 105 * Struct for a single MPU Region
AnnaBridge 161:aa5281ff4a02 106 */
Anna Bridge 169:a7c7b631e539 107 typedef struct {
AnnaBridge 161:aa5281ff4a02 108 uint32_t RBAR; /*!< Region Base Address Register value */
AnnaBridge 161:aa5281ff4a02 109 uint32_t RLAR; /*!< Region Limit Address Register value */
AnnaBridge 161:aa5281ff4a02 110 } ARM_MPU_Region_t;
AnnaBridge 161:aa5281ff4a02 111
AnnaBridge 161:aa5281ff4a02 112 /** Enable the MPU.
AnnaBridge 161:aa5281ff4a02 113 * \param MPU_Control Default access permissions for unconfigured regions.
AnnaBridge 161:aa5281ff4a02 114 */
AnnaBridge 161:aa5281ff4a02 115 __STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control)
AnnaBridge 161:aa5281ff4a02 116 {
AnnaBridge 161:aa5281ff4a02 117 __DSB();
AnnaBridge 161:aa5281ff4a02 118 __ISB();
AnnaBridge 161:aa5281ff4a02 119 MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
AnnaBridge 161:aa5281ff4a02 120 #ifdef SCB_SHCSR_MEMFAULTENA_Msk
AnnaBridge 161:aa5281ff4a02 121 SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
AnnaBridge 161:aa5281ff4a02 122 #endif
AnnaBridge 161:aa5281ff4a02 123 }
AnnaBridge 161:aa5281ff4a02 124
AnnaBridge 161:aa5281ff4a02 125 /** Disable the MPU.
AnnaBridge 161:aa5281ff4a02 126 */
AnnaBridge 161:aa5281ff4a02 127 __STATIC_INLINE void ARM_MPU_Disable(void)
AnnaBridge 161:aa5281ff4a02 128 {
AnnaBridge 161:aa5281ff4a02 129 __DSB();
AnnaBridge 161:aa5281ff4a02 130 __ISB();
AnnaBridge 161:aa5281ff4a02 131 #ifdef SCB_SHCSR_MEMFAULTENA_Msk
AnnaBridge 161:aa5281ff4a02 132 SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
AnnaBridge 161:aa5281ff4a02 133 #endif
AnnaBridge 161:aa5281ff4a02 134 MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
AnnaBridge 161:aa5281ff4a02 135 }
AnnaBridge 161:aa5281ff4a02 136
AnnaBridge 161:aa5281ff4a02 137 #ifdef MPU_NS
AnnaBridge 161:aa5281ff4a02 138 /** Enable the Non-secure MPU.
AnnaBridge 161:aa5281ff4a02 139 * \param MPU_Control Default access permissions for unconfigured regions.
AnnaBridge 161:aa5281ff4a02 140 */
AnnaBridge 161:aa5281ff4a02 141 __STATIC_INLINE void ARM_MPU_Enable_NS(uint32_t MPU_Control)
AnnaBridge 161:aa5281ff4a02 142 {
AnnaBridge 161:aa5281ff4a02 143 __DSB();
AnnaBridge 161:aa5281ff4a02 144 __ISB();
AnnaBridge 161:aa5281ff4a02 145 MPU_NS->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
AnnaBridge 161:aa5281ff4a02 146 #ifdef SCB_SHCSR_MEMFAULTENA_Msk
AnnaBridge 161:aa5281ff4a02 147 SCB_NS->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
AnnaBridge 161:aa5281ff4a02 148 #endif
AnnaBridge 161:aa5281ff4a02 149 }
AnnaBridge 161:aa5281ff4a02 150
AnnaBridge 161:aa5281ff4a02 151 /** Disable the Non-secure MPU.
AnnaBridge 161:aa5281ff4a02 152 */
AnnaBridge 161:aa5281ff4a02 153 __STATIC_INLINE void ARM_MPU_Disable_NS(void)
AnnaBridge 161:aa5281ff4a02 154 {
AnnaBridge 161:aa5281ff4a02 155 __DSB();
AnnaBridge 161:aa5281ff4a02 156 __ISB();
AnnaBridge 161:aa5281ff4a02 157 #ifdef SCB_SHCSR_MEMFAULTENA_Msk
AnnaBridge 161:aa5281ff4a02 158 SCB_NS->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
AnnaBridge 161:aa5281ff4a02 159 #endif
AnnaBridge 161:aa5281ff4a02 160 MPU_NS->CTRL &= ~MPU_CTRL_ENABLE_Msk;
AnnaBridge 161:aa5281ff4a02 161 }
AnnaBridge 161:aa5281ff4a02 162 #endif
AnnaBridge 161:aa5281ff4a02 163
AnnaBridge 161:aa5281ff4a02 164 /** Set the memory attribute encoding to the given MPU.
AnnaBridge 161:aa5281ff4a02 165 * \param mpu Pointer to the MPU to be configured.
AnnaBridge 161:aa5281ff4a02 166 * \param idx The attribute index to be set [0-7]
AnnaBridge 161:aa5281ff4a02 167 * \param attr The attribute value to be set.
AnnaBridge 161:aa5281ff4a02 168 */
AnnaBridge 161:aa5281ff4a02 169 __STATIC_INLINE void ARM_MPU_SetMemAttrEx(MPU_Type* mpu, uint8_t idx, uint8_t attr)
AnnaBridge 161:aa5281ff4a02 170 {
AnnaBridge 161:aa5281ff4a02 171 const uint8_t reg = idx / 4U;
AnnaBridge 161:aa5281ff4a02 172 const uint32_t pos = ((idx % 4U) * 8U);
AnnaBridge 161:aa5281ff4a02 173 const uint32_t mask = 0xFFU << pos;
AnnaBridge 161:aa5281ff4a02 174
Anna Bridge 169:a7c7b631e539 175 if (reg >= (sizeof(mpu->MAIR) / sizeof(mpu->MAIR[0]))) {
AnnaBridge 161:aa5281ff4a02 176 return; // invalid index
AnnaBridge 161:aa5281ff4a02 177 }
AnnaBridge 161:aa5281ff4a02 178
Anna Bridge 169:a7c7b631e539 179 mpu->MAIR[reg] = ((mpu->MAIR[reg] & ~mask) | ((attr << pos) & mask));
AnnaBridge 161:aa5281ff4a02 180 }
AnnaBridge 161:aa5281ff4a02 181
AnnaBridge 161:aa5281ff4a02 182 /** Set the memory attribute encoding.
AnnaBridge 161:aa5281ff4a02 183 * \param idx The attribute index to be set [0-7]
AnnaBridge 161:aa5281ff4a02 184 * \param attr The attribute value to be set.
AnnaBridge 161:aa5281ff4a02 185 */
AnnaBridge 161:aa5281ff4a02 186 __STATIC_INLINE void ARM_MPU_SetMemAttr(uint8_t idx, uint8_t attr)
AnnaBridge 161:aa5281ff4a02 187 {
AnnaBridge 161:aa5281ff4a02 188 ARM_MPU_SetMemAttrEx(MPU, idx, attr);
AnnaBridge 161:aa5281ff4a02 189 }
AnnaBridge 161:aa5281ff4a02 190
AnnaBridge 161:aa5281ff4a02 191 #ifdef MPU_NS
AnnaBridge 161:aa5281ff4a02 192 /** Set the memory attribute encoding to the Non-secure MPU.
AnnaBridge 161:aa5281ff4a02 193 * \param idx The attribute index to be set [0-7]
AnnaBridge 161:aa5281ff4a02 194 * \param attr The attribute value to be set.
AnnaBridge 161:aa5281ff4a02 195 */
AnnaBridge 161:aa5281ff4a02 196 __STATIC_INLINE void ARM_MPU_SetMemAttr_NS(uint8_t idx, uint8_t attr)
AnnaBridge 161:aa5281ff4a02 197 {
AnnaBridge 161:aa5281ff4a02 198 ARM_MPU_SetMemAttrEx(MPU_NS, idx, attr);
AnnaBridge 161:aa5281ff4a02 199 }
AnnaBridge 161:aa5281ff4a02 200 #endif
AnnaBridge 161:aa5281ff4a02 201
AnnaBridge 161:aa5281ff4a02 202 /** Clear and disable the given MPU region of the given MPU.
AnnaBridge 161:aa5281ff4a02 203 * \param mpu Pointer to MPU to be used.
AnnaBridge 161:aa5281ff4a02 204 * \param rnr Region number to be cleared.
AnnaBridge 161:aa5281ff4a02 205 */
AnnaBridge 161:aa5281ff4a02 206 __STATIC_INLINE void ARM_MPU_ClrRegionEx(MPU_Type* mpu, uint32_t rnr)
AnnaBridge 161:aa5281ff4a02 207 {
Anna Bridge 169:a7c7b631e539 208 mpu->RNR = rnr;
Anna Bridge 169:a7c7b631e539 209 mpu->RLAR = 0U;
AnnaBridge 161:aa5281ff4a02 210 }
AnnaBridge 161:aa5281ff4a02 211
AnnaBridge 161:aa5281ff4a02 212 /** Clear and disable the given MPU region.
AnnaBridge 161:aa5281ff4a02 213 * \param rnr Region number to be cleared.
AnnaBridge 161:aa5281ff4a02 214 */
AnnaBridge 161:aa5281ff4a02 215 __STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr)
AnnaBridge 161:aa5281ff4a02 216 {
AnnaBridge 161:aa5281ff4a02 217 ARM_MPU_ClrRegionEx(MPU, rnr);
AnnaBridge 161:aa5281ff4a02 218 }
AnnaBridge 161:aa5281ff4a02 219
AnnaBridge 161:aa5281ff4a02 220 #ifdef MPU_NS
AnnaBridge 161:aa5281ff4a02 221 /** Clear and disable the given Non-secure MPU region.
AnnaBridge 161:aa5281ff4a02 222 * \param rnr Region number to be cleared.
AnnaBridge 161:aa5281ff4a02 223 */
AnnaBridge 161:aa5281ff4a02 224 __STATIC_INLINE void ARM_MPU_ClrRegion_NS(uint32_t rnr)
AnnaBridge 161:aa5281ff4a02 225 {
AnnaBridge 161:aa5281ff4a02 226 ARM_MPU_ClrRegionEx(MPU_NS, rnr);
AnnaBridge 161:aa5281ff4a02 227 }
AnnaBridge 161:aa5281ff4a02 228 #endif
AnnaBridge 161:aa5281ff4a02 229
AnnaBridge 161:aa5281ff4a02 230 /** Configure the given MPU region of the given MPU.
AnnaBridge 161:aa5281ff4a02 231 * \param mpu Pointer to MPU to be used.
AnnaBridge 161:aa5281ff4a02 232 * \param rnr Region number to be configured.
AnnaBridge 161:aa5281ff4a02 233 * \param rbar Value for RBAR register.
AnnaBridge 161:aa5281ff4a02 234 * \param rlar Value for RLAR register.
AnnaBridge 161:aa5281ff4a02 235 */
AnnaBridge 161:aa5281ff4a02 236 __STATIC_INLINE void ARM_MPU_SetRegionEx(MPU_Type* mpu, uint32_t rnr, uint32_t rbar, uint32_t rlar)
AnnaBridge 161:aa5281ff4a02 237 {
Anna Bridge 169:a7c7b631e539 238 mpu->RNR = rnr;
Anna Bridge 169:a7c7b631e539 239 mpu->RBAR = rbar;
Anna Bridge 169:a7c7b631e539 240 mpu->RLAR = rlar;
AnnaBridge 161:aa5281ff4a02 241 }
AnnaBridge 161:aa5281ff4a02 242
AnnaBridge 161:aa5281ff4a02 243 /** Configure the given MPU region.
AnnaBridge 161:aa5281ff4a02 244 * \param rnr Region number to be configured.
AnnaBridge 161:aa5281ff4a02 245 * \param rbar Value for RBAR register.
AnnaBridge 161:aa5281ff4a02 246 * \param rlar Value for RLAR register.
AnnaBridge 161:aa5281ff4a02 247 */
AnnaBridge 161:aa5281ff4a02 248 __STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rnr, uint32_t rbar, uint32_t rlar)
AnnaBridge 161:aa5281ff4a02 249 {
AnnaBridge 161:aa5281ff4a02 250 ARM_MPU_SetRegionEx(MPU, rnr, rbar, rlar);
AnnaBridge 161:aa5281ff4a02 251 }
AnnaBridge 161:aa5281ff4a02 252
AnnaBridge 161:aa5281ff4a02 253 #ifdef MPU_NS
AnnaBridge 161:aa5281ff4a02 254 /** Configure the given Non-secure MPU region.
AnnaBridge 161:aa5281ff4a02 255 * \param rnr Region number to be configured.
AnnaBridge 161:aa5281ff4a02 256 * \param rbar Value for RBAR register.
AnnaBridge 161:aa5281ff4a02 257 * \param rlar Value for RLAR register.
AnnaBridge 161:aa5281ff4a02 258 */
AnnaBridge 161:aa5281ff4a02 259 __STATIC_INLINE void ARM_MPU_SetRegion_NS(uint32_t rnr, uint32_t rbar, uint32_t rlar)
AnnaBridge 161:aa5281ff4a02 260 {
AnnaBridge 161:aa5281ff4a02 261 ARM_MPU_SetRegionEx(MPU_NS, rnr, rbar, rlar);
AnnaBridge 161:aa5281ff4a02 262 }
AnnaBridge 161:aa5281ff4a02 263 #endif
AnnaBridge 161:aa5281ff4a02 264
AnnaBridge 161:aa5281ff4a02 265 /** Memcopy with strictly ordered memory access, e.g. for register targets.
AnnaBridge 161:aa5281ff4a02 266 * \param dst Destination data is copied to.
AnnaBridge 161:aa5281ff4a02 267 * \param src Source data is copied from.
AnnaBridge 161:aa5281ff4a02 268 * \param len Amount of data words to be copied.
AnnaBridge 161:aa5281ff4a02 269 */
AnnaBridge 161:aa5281ff4a02 270 __STATIC_INLINE void orderedCpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len)
AnnaBridge 161:aa5281ff4a02 271 {
AnnaBridge 161:aa5281ff4a02 272 uint32_t i;
AnnaBridge 161:aa5281ff4a02 273 for (i = 0U; i < len; ++i)
AnnaBridge 161:aa5281ff4a02 274 {
AnnaBridge 161:aa5281ff4a02 275 dst[i] = src[i];
AnnaBridge 161:aa5281ff4a02 276 }
AnnaBridge 161:aa5281ff4a02 277 }
AnnaBridge 161:aa5281ff4a02 278
AnnaBridge 161:aa5281ff4a02 279 /** Load the given number of MPU regions from a table to the given MPU.
AnnaBridge 161:aa5281ff4a02 280 * \param mpu Pointer to the MPU registers to be used.
AnnaBridge 161:aa5281ff4a02 281 * \param rnr First region number to be configured.
AnnaBridge 161:aa5281ff4a02 282 * \param table Pointer to the MPU configuration table.
AnnaBridge 161:aa5281ff4a02 283 * \param cnt Amount of regions to be configured.
AnnaBridge 161:aa5281ff4a02 284 */
AnnaBridge 161:aa5281ff4a02 285 __STATIC_INLINE void ARM_MPU_LoadEx(MPU_Type* mpu, uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt)
AnnaBridge 161:aa5281ff4a02 286 {
Anna Bridge 169:a7c7b631e539 287 const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U;
AnnaBridge 161:aa5281ff4a02 288 if (cnt == 1U) {
AnnaBridge 161:aa5281ff4a02 289 mpu->RNR = rnr;
AnnaBridge 161:aa5281ff4a02 290 orderedCpy(&(mpu->RBAR), &(table->RBAR), rowWordSize);
AnnaBridge 161:aa5281ff4a02 291 } else {
AnnaBridge 161:aa5281ff4a02 292 uint32_t rnrBase = rnr & ~(MPU_TYPE_RALIASES-1U);
AnnaBridge 161:aa5281ff4a02 293 uint32_t rnrOffset = rnr % MPU_TYPE_RALIASES;
AnnaBridge 161:aa5281ff4a02 294
AnnaBridge 161:aa5281ff4a02 295 mpu->RNR = rnrBase;
Anna Bridge 169:a7c7b631e539 296 while ((rnrOffset + cnt) > MPU_TYPE_RALIASES) {
AnnaBridge 161:aa5281ff4a02 297 uint32_t c = MPU_TYPE_RALIASES - rnrOffset;
AnnaBridge 161:aa5281ff4a02 298 orderedCpy(&(mpu->RBAR)+(rnrOffset*2U), &(table->RBAR), c*rowWordSize);
Anna Bridge 169:a7c7b631e539 299 table += c;
Anna Bridge 169:a7c7b631e539 300 cnt -= c;
Anna Bridge 169:a7c7b631e539 301 rnrOffset = 0U;
Anna Bridge 169:a7c7b631e539 302 rnrBase += MPU_TYPE_RALIASES;
Anna Bridge 169:a7c7b631e539 303 mpu->RNR = rnrBase;
AnnaBridge 161:aa5281ff4a02 304 }
Anna Bridge 169:a7c7b631e539 305
Anna Bridge 169:a7c7b631e539 306 orderedCpy(&(mpu->RBAR)+(rnrOffset*2U), &(table->RBAR), cnt*rowWordSize);
AnnaBridge 161:aa5281ff4a02 307 }
AnnaBridge 161:aa5281ff4a02 308 }
AnnaBridge 161:aa5281ff4a02 309
AnnaBridge 161:aa5281ff4a02 310 /** Load the given number of MPU regions from a table.
AnnaBridge 161:aa5281ff4a02 311 * \param rnr First region number to be configured.
AnnaBridge 161:aa5281ff4a02 312 * \param table Pointer to the MPU configuration table.
AnnaBridge 161:aa5281ff4a02 313 * \param cnt Amount of regions to be configured.
AnnaBridge 161:aa5281ff4a02 314 */
AnnaBridge 161:aa5281ff4a02 315 __STATIC_INLINE void ARM_MPU_Load(uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt)
AnnaBridge 161:aa5281ff4a02 316 {
AnnaBridge 161:aa5281ff4a02 317 ARM_MPU_LoadEx(MPU, rnr, table, cnt);
AnnaBridge 161:aa5281ff4a02 318 }
AnnaBridge 161:aa5281ff4a02 319
AnnaBridge 161:aa5281ff4a02 320 #ifdef MPU_NS
AnnaBridge 161:aa5281ff4a02 321 /** Load the given number of MPU regions from a table to the Non-secure MPU.
AnnaBridge 161:aa5281ff4a02 322 * \param rnr First region number to be configured.
AnnaBridge 161:aa5281ff4a02 323 * \param table Pointer to the MPU configuration table.
AnnaBridge 161:aa5281ff4a02 324 * \param cnt Amount of regions to be configured.
AnnaBridge 161:aa5281ff4a02 325 */
AnnaBridge 161:aa5281ff4a02 326 __STATIC_INLINE void ARM_MPU_Load_NS(uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt)
AnnaBridge 161:aa5281ff4a02 327 {
AnnaBridge 161:aa5281ff4a02 328 ARM_MPU_LoadEx(MPU_NS, rnr, table, cnt);
AnnaBridge 161:aa5281ff4a02 329 }
AnnaBridge 161:aa5281ff4a02 330 #endif
AnnaBridge 161:aa5281ff4a02 331
AnnaBridge 161:aa5281ff4a02 332 #endif
AnnaBridge 161:aa5281ff4a02 333