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