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