50
50
(((ENCODE_MEMORY_TYPE(memtype)) << (12)) | \
51
51
(((access) & (0xf)) << (8)))
52
52
53
+ struct mpu_region_s
54
+ {
55
+ uintptr_t base ; /* Region Base Address */
56
+ size_t size ; /* Unused */
57
+ uint32_t acc ; /* Access permissions */
58
+ uint32_t memtype ; /* memory type */
59
+ };
60
+
53
61
/****************************************************************************
54
62
* MPU access rights constants
55
63
****************************************************************************/
@@ -185,7 +193,18 @@ extern "C"
185
193
* Name: mpu_allocregion
186
194
*
187
195
* Description:
188
- * Allocate the next region
196
+ * Allocate the next region
197
+ *
198
+ * Assumptions:
199
+ * - Regions are never deallocated
200
+ * - Regions are only allocated early in initialization, so no special
201
+ * protection against re-entrancy is required;
202
+ *
203
+ * Input Parameters:
204
+ * None.
205
+ *
206
+ * Returned Value:
207
+ * The index of the allocated region.
189
208
*
190
209
****************************************************************************/
191
210
@@ -197,20 +216,91 @@ unsigned int mpu_allocregion(void);
197
216
* Description:
198
217
* Configure and enable (or disable) the MPU
199
218
*
219
+ * Input Parameters:
220
+ * enable - Flag indicating whether to enable the MPU.
221
+ *
222
+ * Returned Value:
223
+ * None.
224
+ *
200
225
****************************************************************************/
201
226
202
227
void mpu_control (bool enable );
203
228
229
+ /****************************************************************************
230
+ * Name: mpu_modify_region
231
+ *
232
+ * Description:
233
+ * Modify a region for privileged, strongly ordered memory
234
+ *
235
+ * Input Parameters:
236
+ * region - Region number to modify.
237
+ * base - Base address of the region.
238
+ * size - Unused.
239
+ * acc - A uint32_t value representing the access permissions of
240
+ * the region.
241
+ * memtype - A uint32_t value representing the memory type of the region.
242
+ *
243
+ * Returned Value:
244
+ * None.
245
+ *
246
+ ****************************************************************************/
247
+
248
+ void mpu_modify_region (unsigned int region , uintptr_t base , size_t size ,
249
+ uint32_t acc , uint32_t memtype );
250
+
204
251
/****************************************************************************
205
252
* Name: mpu_configure_region
206
253
*
207
254
* Description:
255
+ * Configure a region
256
+ *
257
+ * Input Parameters:
258
+ * base - Base address of the region.
259
+ * size - Unused.
260
+ * acc - A uint32_t value representing the access permissions of
261
+ * the region.
262
+ * memtype - A uint32_t value representing the memory type of the region.
263
+ *
264
+ * Returned Value:
265
+ * The region number allocated for the configured region.
266
+ *
267
+ ****************************************************************************/
268
+
269
+ unsigned int mpu_configure_region (uintptr_t base , size_t size ,
270
+ uint32_t acc , uint32_t memtype );
271
+
272
+ /****************************************************************************
273
+ * Name: mpu_initialize
274
+ *
275
+ * Description:
208
276
* Configure a region for privileged, strongly ordered memory
209
277
*
278
+ * Input Parameters:
279
+ * table - MPU initialization table.
280
+ * count - Initialize the number of entries in the region table.
281
+ *
282
+ * Returned Value:
283
+ * NULL.
284
+ *
285
+ ****************************************************************************/
286
+
287
+ void mpu_initialize (const struct mpu_region_s * table , size_t count );
288
+
289
+ /****************************************************************************
290
+ * Name: mpu_dump_region
291
+ *
292
+ * Description:
293
+ * Dump the region that has been used.
294
+ *
295
+ * Input Parameters:
296
+ * None.
297
+ *
298
+ * Returned Value:
299
+ * None.
300
+ *
210
301
****************************************************************************/
211
302
212
- void mpu_configure_region (uintptr_t base , size_t size ,
213
- uint32_t acc , uint32_t memtype );
303
+ void mpu_dump_region (void );
214
304
215
305
/****************************************************************************
216
306
* Name: mpu_priv_stronglyordered
@@ -221,13 +311,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
221
311
****************************************************************************/
222
312
223
313
#define mpu_priv_stronglyordered (base , size ) \
224
- do \
225
- { \
226
- /* The configure the region */ \
227
- mpu_configure_region (base , size , \
228
- MPU_AR_RWX , \
229
- MPU_MEM_DEVICE ); \
230
- } while (0 )
314
+ /* The configure the region */ \
315
+ mpu_configure_region(base, size, \
316
+ MPU_AR_RWX, \
317
+ MPU_MEM_DEVICE)
231
318
232
319
/****************************************************************************
233
320
* Name: mpu_user_flash
@@ -238,13 +325,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
238
325
****************************************************************************/
239
326
240
327
#define mpu_user_flash (base , size ) \
241
- do \
242
- { \
243
- /* The configure the region */ \
244
- mpu_configure_region (base , size , \
245
- MPU_AR_RXrx , \
246
- MPU_MEM_WRITEBACK );\
247
- } while (0 )
328
+ /* The configure the region */ \
329
+ mpu_configure_region(base, size, \
330
+ MPU_AR_RXrx, \
331
+ MPU_MEM_WRITEBACK)
248
332
249
333
/****************************************************************************
250
334
* Name: mpu_priv_flash
@@ -255,13 +339,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
255
339
****************************************************************************/
256
340
257
341
#define mpu_priv_flash (base , size ) \
258
- do \
259
- { \
260
- /* The configure the region */ \
261
- mpu_configure_region (base , size , \
262
- MPU_AR_RX , \
263
- MPU_MEM_WRITEBACK );\
264
- } while (0 )
342
+ /* The configure the region */ \
343
+ mpu_configure_region(base, size, \
344
+ MPU_AR_RX, \
345
+ MPU_MEM_WRITEBACK)
265
346
266
347
/****************************************************************************
267
348
* Name: mpu_user_intsram
@@ -272,13 +353,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
272
353
****************************************************************************/
273
354
274
355
#define mpu_user_intsram (base , size ) \
275
- do \
276
- { \
277
- /* The configure the region */ \
278
- mpu_configure_region (base , size , \
279
- MPU_AR_RWXrwx , \
280
- MPU_MEM_WRITEBACK );\
281
- } while (0 )
356
+ /* The configure the region */ \
357
+ mpu_configure_region(base, size, \
358
+ MPU_AR_RWXrwx, \
359
+ MPU_MEM_WRITEBACK)
282
360
283
361
/****************************************************************************
284
362
* Name: mpu_priv_intsram
@@ -289,13 +367,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
289
367
****************************************************************************/
290
368
291
369
#define mpu_priv_intsram (base , size ) \
292
- do \
293
- { \
294
- /* The configure the region */ \
295
- mpu_configure_region (base , size ,\
296
- MPU_AR_RWX , \
297
- MPU_MEM_WRITEBACK );\
298
- } while (0 )
370
+ /* The configure the region */ \
371
+ mpu_configure_region(base, size,\
372
+ MPU_AR_RWX, \
373
+ MPU_MEM_WRITEBACK)
299
374
300
375
/****************************************************************************
301
376
* Name: mpu_user_extsram
@@ -306,13 +381,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
306
381
****************************************************************************/
307
382
308
383
#define mpu_user_extsram (base , size ) \
309
- do \
310
- { \
311
- /* The configure the region */ \
312
- mpu_configure_region (base , size , \
313
- MPU_AR_RWXrwx , \
314
- MPU_MEM_WRITEBACK );\
315
- } while (0 )
384
+ /* The configure the region */ \
385
+ mpu_configure_region(base, size, \
386
+ MPU_AR_RWXrwx, \
387
+ MPU_MEM_WRITEBACK)
316
388
317
389
/****************************************************************************
318
390
* Name: mpu_priv_extsram
@@ -323,13 +395,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
323
395
****************************************************************************/
324
396
325
397
#define mpu_priv_extsram (base , size ) \
326
- do \
327
- { \
328
- /* The configure the region */ \
329
- mpu_configure_region (base , size , \
330
- MPU_AR_RWX , \
331
- MPU_MEM_WRITEBACK );\
332
- } while (0 )
398
+ /* The configure the region */ \
399
+ mpu_configure_region(base, size, \
400
+ MPU_AR_RWX, \
401
+ MPU_MEM_WRITEBACK)
333
402
334
403
/****************************************************************************
335
404
* Name: mpu_peripheral
@@ -340,13 +409,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
340
409
****************************************************************************/
341
410
342
411
#define mpu_peripheral (base , size ) \
343
- do \
344
- { \
345
- /* Then configure the region */ \
346
- mpu_configure_region (base , size , \
347
- MPU_AR_RW , \
348
- MPU_MEM_DEVICE );\
349
- } while (0 )
412
+ /* Then configure the region */ \
413
+ mpu_configure_region(base, size, \
414
+ MPU_AR_RW, \
415
+ MPU_MEM_DEVICE)
350
416
351
417
/****************************************************************************
352
418
* Name: mpu_user_peripheral
@@ -357,13 +423,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
357
423
****************************************************************************/
358
424
359
425
#define mpu_user_peripheral (base , size ) \
360
- do \
361
- { \
362
- /* Then configure the region */ \
363
- mpu_configure_region (base , size , \
364
- MPU_AR_RWrw , \
365
- MPU_MEM_DEVICE );\
366
- } while (0 )
426
+ /* Then configure the region */ \
427
+ mpu_configure_region(base, size, \
428
+ MPU_AR_RWrw, \
429
+ MPU_MEM_DEVICE)
367
430
368
431
#undef EXTERN
369
432
#if defined(__cplusplus )
0 commit comments