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