1*a8f7f3fcSMatthias Ringwald /******************************************************************************
2*a8f7f3fcSMatthias Ringwald * @file mpu_armv7.h
3*a8f7f3fcSMatthias Ringwald * @brief CMSIS MPU API for Armv7-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_ARMV7_H
32*a8f7f3fcSMatthias Ringwald #define ARM_MPU_ARMV7_H
33*a8f7f3fcSMatthias Ringwald
34*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_32B ((uint8_t)0x04U) ///!< MPU Region Size 32 Bytes
35*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_64B ((uint8_t)0x05U) ///!< MPU Region Size 64 Bytes
36*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_128B ((uint8_t)0x06U) ///!< MPU Region Size 128 Bytes
37*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_256B ((uint8_t)0x07U) ///!< MPU Region Size 256 Bytes
38*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_512B ((uint8_t)0x08U) ///!< MPU Region Size 512 Bytes
39*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_1KB ((uint8_t)0x09U) ///!< MPU Region Size 1 KByte
40*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_2KB ((uint8_t)0x0AU) ///!< MPU Region Size 2 KBytes
41*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_4KB ((uint8_t)0x0BU) ///!< MPU Region Size 4 KBytes
42*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_8KB ((uint8_t)0x0CU) ///!< MPU Region Size 8 KBytes
43*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_16KB ((uint8_t)0x0DU) ///!< MPU Region Size 16 KBytes
44*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_32KB ((uint8_t)0x0EU) ///!< MPU Region Size 32 KBytes
45*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_64KB ((uint8_t)0x0FU) ///!< MPU Region Size 64 KBytes
46*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_128KB ((uint8_t)0x10U) ///!< MPU Region Size 128 KBytes
47*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_256KB ((uint8_t)0x11U) ///!< MPU Region Size 256 KBytes
48*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_512KB ((uint8_t)0x12U) ///!< MPU Region Size 512 KBytes
49*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_1MB ((uint8_t)0x13U) ///!< MPU Region Size 1 MByte
50*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_2MB ((uint8_t)0x14U) ///!< MPU Region Size 2 MBytes
51*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_4MB ((uint8_t)0x15U) ///!< MPU Region Size 4 MBytes
52*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_8MB ((uint8_t)0x16U) ///!< MPU Region Size 8 MBytes
53*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_16MB ((uint8_t)0x17U) ///!< MPU Region Size 16 MBytes
54*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_32MB ((uint8_t)0x18U) ///!< MPU Region Size 32 MBytes
55*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_64MB ((uint8_t)0x19U) ///!< MPU Region Size 64 MBytes
56*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_128MB ((uint8_t)0x1AU) ///!< MPU Region Size 128 MBytes
57*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_256MB ((uint8_t)0x1BU) ///!< MPU Region Size 256 MBytes
58*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_512MB ((uint8_t)0x1CU) ///!< MPU Region Size 512 MBytes
59*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_1GB ((uint8_t)0x1DU) ///!< MPU Region Size 1 GByte
60*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_2GB ((uint8_t)0x1EU) ///!< MPU Region Size 2 GBytes
61*a8f7f3fcSMatthias Ringwald #define ARM_MPU_REGION_SIZE_4GB ((uint8_t)0x1FU) ///!< MPU Region Size 4 GBytes
62*a8f7f3fcSMatthias Ringwald
63*a8f7f3fcSMatthias Ringwald #define ARM_MPU_AP_NONE 0U ///!< MPU Access Permission no access
64*a8f7f3fcSMatthias Ringwald #define ARM_MPU_AP_PRIV 1U ///!< MPU Access Permission privileged access only
65*a8f7f3fcSMatthias Ringwald #define ARM_MPU_AP_URO 2U ///!< MPU Access Permission unprivileged access read-only
66*a8f7f3fcSMatthias Ringwald #define ARM_MPU_AP_FULL 3U ///!< MPU Access Permission full access
67*a8f7f3fcSMatthias Ringwald #define ARM_MPU_AP_PRO 5U ///!< MPU Access Permission privileged access read-only
68*a8f7f3fcSMatthias Ringwald #define ARM_MPU_AP_RO 6U ///!< MPU Access Permission read-only access
69*a8f7f3fcSMatthias Ringwald
70*a8f7f3fcSMatthias Ringwald /** MPU Region Base Address Register Value
71*a8f7f3fcSMatthias Ringwald *
72*a8f7f3fcSMatthias Ringwald * \param Region The region to be configured, number 0 to 15.
73*a8f7f3fcSMatthias Ringwald * \param BaseAddress The base address for the region.
74*a8f7f3fcSMatthias Ringwald */
75*a8f7f3fcSMatthias Ringwald #define ARM_MPU_RBAR(Region, BaseAddress) \
76*a8f7f3fcSMatthias Ringwald (((BaseAddress) & MPU_RBAR_ADDR_Msk) | \
77*a8f7f3fcSMatthias Ringwald ((Region) & MPU_RBAR_REGION_Msk) | \
78*a8f7f3fcSMatthias Ringwald (MPU_RBAR_VALID_Msk))
79*a8f7f3fcSMatthias Ringwald
80*a8f7f3fcSMatthias Ringwald /**
81*a8f7f3fcSMatthias Ringwald * MPU Memory Access Attributes
82*a8f7f3fcSMatthias Ringwald *
83*a8f7f3fcSMatthias Ringwald * \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral.
84*a8f7f3fcSMatthias Ringwald * \param IsShareable Region is shareable between multiple bus masters.
85*a8f7f3fcSMatthias Ringwald * \param IsCacheable Region is cacheable, i.e. its value may be kept in cache.
86*a8f7f3fcSMatthias Ringwald * \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy.
87*a8f7f3fcSMatthias Ringwald */
88*a8f7f3fcSMatthias Ringwald #define ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable) \
89*a8f7f3fcSMatthias Ringwald ((((TypeExtField ) << MPU_RASR_TEX_Pos) & MPU_RASR_TEX_Msk) | \
90*a8f7f3fcSMatthias Ringwald (((IsShareable ) << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | \
91*a8f7f3fcSMatthias Ringwald (((IsCacheable ) << MPU_RASR_C_Pos) & MPU_RASR_C_Msk) | \
92*a8f7f3fcSMatthias Ringwald (((IsBufferable ) << MPU_RASR_B_Pos) & MPU_RASR_B_Msk))
93*a8f7f3fcSMatthias Ringwald
94*a8f7f3fcSMatthias Ringwald /**
95*a8f7f3fcSMatthias Ringwald * MPU Region Attribute and Size Register Value
96*a8f7f3fcSMatthias Ringwald *
97*a8f7f3fcSMatthias Ringwald * \param DisableExec Instruction access disable bit, 1= disable instruction fetches.
98*a8f7f3fcSMatthias Ringwald * \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode.
99*a8f7f3fcSMatthias Ringwald * \param AccessAttributes Memory access attribution, see \ref ARM_MPU_ACCESS_.
100*a8f7f3fcSMatthias Ringwald * \param SubRegionDisable Sub-region disable field.
101*a8f7f3fcSMatthias Ringwald * \param Size Region size of the region to be configured, for example 4K, 8K.
102*a8f7f3fcSMatthias Ringwald */
103*a8f7f3fcSMatthias Ringwald #define ARM_MPU_RASR_EX(DisableExec, AccessPermission, AccessAttributes, SubRegionDisable, Size) \
104*a8f7f3fcSMatthias Ringwald ((((DisableExec ) << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) | \
105*a8f7f3fcSMatthias Ringwald (((AccessPermission) << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | \
106*a8f7f3fcSMatthias Ringwald (((AccessAttributes) ) & (MPU_RASR_TEX_Msk | MPU_RASR_S_Msk | MPU_RASR_C_Msk | MPU_RASR_B_Msk)))
107*a8f7f3fcSMatthias Ringwald
108*a8f7f3fcSMatthias Ringwald /**
109*a8f7f3fcSMatthias Ringwald * MPU Region Attribute and Size Register Value
110*a8f7f3fcSMatthias Ringwald *
111*a8f7f3fcSMatthias Ringwald * \param DisableExec Instruction access disable bit, 1= disable instruction fetches.
112*a8f7f3fcSMatthias Ringwald * \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode.
113*a8f7f3fcSMatthias Ringwald * \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral.
114*a8f7f3fcSMatthias Ringwald * \param IsShareable Region is shareable between multiple bus masters.
115*a8f7f3fcSMatthias Ringwald * \param IsCacheable Region is cacheable, i.e. its value may be kept in cache.
116*a8f7f3fcSMatthias Ringwald * \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy.
117*a8f7f3fcSMatthias Ringwald * \param SubRegionDisable Sub-region disable field.
118*a8f7f3fcSMatthias Ringwald * \param Size Region size of the region to be configured, for example 4K, 8K.
119*a8f7f3fcSMatthias Ringwald */
120*a8f7f3fcSMatthias Ringwald #define ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size) \
121*a8f7f3fcSMatthias Ringwald ARM_MPU_RASR_EX(DisableExec, AccessPermission, ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable), SubRegionDisable, Size)
122*a8f7f3fcSMatthias Ringwald
123*a8f7f3fcSMatthias Ringwald /**
124*a8f7f3fcSMatthias Ringwald * MPU Memory Access Attribute for strongly ordered memory.
125*a8f7f3fcSMatthias Ringwald * - TEX: 000b
126*a8f7f3fcSMatthias Ringwald * - Shareable
127*a8f7f3fcSMatthias Ringwald * - Non-cacheable
128*a8f7f3fcSMatthias Ringwald * - Non-bufferable
129*a8f7f3fcSMatthias Ringwald */
130*a8f7f3fcSMatthias Ringwald #define ARM_MPU_ACCESS_ORDERED ARM_MPU_ACCESS_(0U, 1U, 0U, 0U)
131*a8f7f3fcSMatthias Ringwald
132*a8f7f3fcSMatthias Ringwald /**
133*a8f7f3fcSMatthias Ringwald * MPU Memory Access Attribute for device memory.
134*a8f7f3fcSMatthias Ringwald * - TEX: 000b (if non-shareable) or 010b (if shareable)
135*a8f7f3fcSMatthias Ringwald * - Shareable or non-shareable
136*a8f7f3fcSMatthias Ringwald * - Non-cacheable
137*a8f7f3fcSMatthias Ringwald * - Bufferable (if shareable) or non-bufferable (if non-shareable)
138*a8f7f3fcSMatthias Ringwald *
139*a8f7f3fcSMatthias Ringwald * \param IsShareable Configures the device memory as shareable or non-shareable.
140*a8f7f3fcSMatthias Ringwald */
141*a8f7f3fcSMatthias Ringwald #define ARM_MPU_ACCESS_DEVICE(IsShareable) ((IsShareable) ? ARM_MPU_ACCESS_(0U, 1U, 0U, 1U) : ARM_MPU_ACCESS_(2U, 0U, 0U, 0U))
142*a8f7f3fcSMatthias Ringwald
143*a8f7f3fcSMatthias Ringwald /**
144*a8f7f3fcSMatthias Ringwald * MPU Memory Access Attribute for normal memory.
145*a8f7f3fcSMatthias Ringwald * - TEX: 1BBb (reflecting outer cacheability rules)
146*a8f7f3fcSMatthias Ringwald * - Shareable or non-shareable
147*a8f7f3fcSMatthias Ringwald * - Cacheable or non-cacheable (reflecting inner cacheability rules)
148*a8f7f3fcSMatthias Ringwald * - Bufferable or non-bufferable (reflecting inner cacheability rules)
149*a8f7f3fcSMatthias Ringwald *
150*a8f7f3fcSMatthias Ringwald * \param OuterCp Configures the outer cache policy.
151*a8f7f3fcSMatthias Ringwald * \param InnerCp Configures the inner cache policy.
152*a8f7f3fcSMatthias Ringwald * \param IsShareable Configures the memory as shareable or non-shareable.
153*a8f7f3fcSMatthias Ringwald */
154*a8f7f3fcSMatthias Ringwald #define ARM_MPU_ACCESS_NORMAL(OuterCp, InnerCp, IsShareable) ARM_MPU_ACCESS_((4U | (OuterCp)), IsShareable, ((InnerCp) & 2U), ((InnerCp) & 1U))
155*a8f7f3fcSMatthias Ringwald
156*a8f7f3fcSMatthias Ringwald /**
157*a8f7f3fcSMatthias Ringwald * MPU Memory Access Attribute non-cacheable policy.
158*a8f7f3fcSMatthias Ringwald */
159*a8f7f3fcSMatthias Ringwald #define ARM_MPU_CACHEP_NOCACHE 0U
160*a8f7f3fcSMatthias Ringwald
161*a8f7f3fcSMatthias Ringwald /**
162*a8f7f3fcSMatthias Ringwald * MPU Memory Access Attribute write-back, write and read allocate policy.
163*a8f7f3fcSMatthias Ringwald */
164*a8f7f3fcSMatthias Ringwald #define ARM_MPU_CACHEP_WB_WRA 1U
165*a8f7f3fcSMatthias Ringwald
166*a8f7f3fcSMatthias Ringwald /**
167*a8f7f3fcSMatthias Ringwald * MPU Memory Access Attribute write-through, no write allocate policy.
168*a8f7f3fcSMatthias Ringwald */
169*a8f7f3fcSMatthias Ringwald #define ARM_MPU_CACHEP_WT_NWA 2U
170*a8f7f3fcSMatthias Ringwald
171*a8f7f3fcSMatthias Ringwald /**
172*a8f7f3fcSMatthias Ringwald * MPU Memory Access Attribute write-back, no write allocate policy.
173*a8f7f3fcSMatthias Ringwald */
174*a8f7f3fcSMatthias Ringwald #define ARM_MPU_CACHEP_WB_NWA 3U
175*a8f7f3fcSMatthias Ringwald
176*a8f7f3fcSMatthias Ringwald
177*a8f7f3fcSMatthias Ringwald /**
178*a8f7f3fcSMatthias Ringwald * Struct for a single MPU Region
179*a8f7f3fcSMatthias Ringwald */
180*a8f7f3fcSMatthias Ringwald typedef struct {
181*a8f7f3fcSMatthias Ringwald uint32_t RBAR; //!< The region base address register value (RBAR)
182*a8f7f3fcSMatthias Ringwald uint32_t RASR; //!< The region attribute and size register value (RASR) \ref MPU_RASR
183*a8f7f3fcSMatthias Ringwald } ARM_MPU_Region_t;
184*a8f7f3fcSMatthias Ringwald
185*a8f7f3fcSMatthias Ringwald /** Enable the MPU.
186*a8f7f3fcSMatthias Ringwald * \param MPU_Control Default access permissions for unconfigured regions.
187*a8f7f3fcSMatthias Ringwald */
ARM_MPU_Enable(uint32_t MPU_Control)188*a8f7f3fcSMatthias Ringwald __STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control)
189*a8f7f3fcSMatthias Ringwald {
190*a8f7f3fcSMatthias Ringwald __DSB();
191*a8f7f3fcSMatthias Ringwald __ISB();
192*a8f7f3fcSMatthias Ringwald MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
193*a8f7f3fcSMatthias Ringwald #ifdef SCB_SHCSR_MEMFAULTENA_Msk
194*a8f7f3fcSMatthias Ringwald SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
195*a8f7f3fcSMatthias Ringwald #endif
196*a8f7f3fcSMatthias Ringwald }
197*a8f7f3fcSMatthias Ringwald
198*a8f7f3fcSMatthias Ringwald /** Disable the MPU.
199*a8f7f3fcSMatthias Ringwald */
ARM_MPU_Disable(void)200*a8f7f3fcSMatthias Ringwald __STATIC_INLINE void ARM_MPU_Disable(void)
201*a8f7f3fcSMatthias Ringwald {
202*a8f7f3fcSMatthias Ringwald __DSB();
203*a8f7f3fcSMatthias Ringwald __ISB();
204*a8f7f3fcSMatthias Ringwald #ifdef SCB_SHCSR_MEMFAULTENA_Msk
205*a8f7f3fcSMatthias Ringwald SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
206*a8f7f3fcSMatthias Ringwald #endif
207*a8f7f3fcSMatthias Ringwald MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
208*a8f7f3fcSMatthias Ringwald }
209*a8f7f3fcSMatthias Ringwald
210*a8f7f3fcSMatthias Ringwald /** Clear and disable the given MPU region.
211*a8f7f3fcSMatthias Ringwald * \param rnr Region number to be cleared.
212*a8f7f3fcSMatthias Ringwald */
ARM_MPU_ClrRegion(uint32_t rnr)213*a8f7f3fcSMatthias Ringwald __STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr)
214*a8f7f3fcSMatthias Ringwald {
215*a8f7f3fcSMatthias Ringwald MPU->RNR = rnr;
216*a8f7f3fcSMatthias Ringwald MPU->RASR = 0U;
217*a8f7f3fcSMatthias Ringwald }
218*a8f7f3fcSMatthias Ringwald
219*a8f7f3fcSMatthias Ringwald /** Configure an MPU region.
220*a8f7f3fcSMatthias Ringwald * \param rbar Value for RBAR register.
221*a8f7f3fcSMatthias Ringwald * \param rsar Value for RSAR register.
222*a8f7f3fcSMatthias Ringwald */
ARM_MPU_SetRegion(uint32_t rbar,uint32_t rasr)223*a8f7f3fcSMatthias Ringwald __STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr)
224*a8f7f3fcSMatthias Ringwald {
225*a8f7f3fcSMatthias Ringwald MPU->RBAR = rbar;
226*a8f7f3fcSMatthias Ringwald MPU->RASR = rasr;
227*a8f7f3fcSMatthias Ringwald }
228*a8f7f3fcSMatthias Ringwald
229*a8f7f3fcSMatthias Ringwald /** Configure the given MPU region.
230*a8f7f3fcSMatthias Ringwald * \param rnr Region number to be configured.
231*a8f7f3fcSMatthias Ringwald * \param rbar Value for RBAR register.
232*a8f7f3fcSMatthias Ringwald * \param rsar Value for RSAR register.
233*a8f7f3fcSMatthias Ringwald */
ARM_MPU_SetRegionEx(uint32_t rnr,uint32_t rbar,uint32_t rasr)234*a8f7f3fcSMatthias Ringwald __STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr)
235*a8f7f3fcSMatthias Ringwald {
236*a8f7f3fcSMatthias Ringwald MPU->RNR = rnr;
237*a8f7f3fcSMatthias Ringwald MPU->RBAR = rbar;
238*a8f7f3fcSMatthias Ringwald MPU->RASR = rasr;
239*a8f7f3fcSMatthias Ringwald }
240*a8f7f3fcSMatthias Ringwald
241*a8f7f3fcSMatthias Ringwald /** Memcopy with strictly ordered memory access, e.g. for register targets.
242*a8f7f3fcSMatthias Ringwald * \param dst Destination data is copied to.
243*a8f7f3fcSMatthias Ringwald * \param src Source data is copied from.
244*a8f7f3fcSMatthias Ringwald * \param len Amount of data words to be copied.
245*a8f7f3fcSMatthias Ringwald */
orderedCpy(volatile uint32_t * dst,const uint32_t * __RESTRICT src,uint32_t len)246*a8f7f3fcSMatthias Ringwald __STATIC_INLINE void orderedCpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len)
247*a8f7f3fcSMatthias Ringwald {
248*a8f7f3fcSMatthias Ringwald uint32_t i;
249*a8f7f3fcSMatthias Ringwald for (i = 0U; i < len; ++i)
250*a8f7f3fcSMatthias Ringwald {
251*a8f7f3fcSMatthias Ringwald dst[i] = src[i];
252*a8f7f3fcSMatthias Ringwald }
253*a8f7f3fcSMatthias Ringwald }
254*a8f7f3fcSMatthias Ringwald
255*a8f7f3fcSMatthias Ringwald /** Load the given number of MPU regions from a table.
256*a8f7f3fcSMatthias Ringwald * \param table Pointer to the MPU configuration table.
257*a8f7f3fcSMatthias Ringwald * \param cnt Amount of regions to be configured.
258*a8f7f3fcSMatthias Ringwald */
ARM_MPU_Load(ARM_MPU_Region_t const * table,uint32_t cnt)259*a8f7f3fcSMatthias Ringwald __STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const* table, uint32_t cnt)
260*a8f7f3fcSMatthias Ringwald {
261*a8f7f3fcSMatthias Ringwald const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U;
262*a8f7f3fcSMatthias Ringwald while (cnt > MPU_TYPE_RALIASES) {
263*a8f7f3fcSMatthias Ringwald orderedCpy(&(MPU->RBAR), &(table->RBAR), MPU_TYPE_RALIASES*rowWordSize);
264*a8f7f3fcSMatthias Ringwald table += MPU_TYPE_RALIASES;
265*a8f7f3fcSMatthias Ringwald cnt -= MPU_TYPE_RALIASES;
266*a8f7f3fcSMatthias Ringwald }
267*a8f7f3fcSMatthias Ringwald orderedCpy(&(MPU->RBAR), &(table->RBAR), cnt*rowWordSize);
268*a8f7f3fcSMatthias Ringwald }
269*a8f7f3fcSMatthias Ringwald
270*a8f7f3fcSMatthias Ringwald #endif
271