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