mpu.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Loci Controls Inc.
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
21 #ifndef MPU_H
22 #define MPU_H
23 
24 #include <stdbool.h>
25 #include <stdint.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
34 #define MPU_NUM_REGIONS ( (MPU->TYPE & MPU_TYPE_DREGION_Msk) >> MPU_TYPE_DREGION_Pos )
35 
39 enum {
40  AP_NO_NO = 0,
41  AP_RW_NO = 1,
42  AP_RW_RO = 2,
43  AP_RW_RW = 3,
44  AP_RO_NO = 5,
45  AP_RO_RO = 6,
46 };
47 
51 enum {
58  MPU_SIZE_2K = 10,
59  MPU_SIZE_4K = 11,
60  MPU_SIZE_8K = 12,
61  MPU_SIZE_16K = 13,
62  MPU_SIZE_32K = 14,
63  MPU_SIZE_64K = 15,
67  MPU_SIZE_1M = 19,
68  MPU_SIZE_2M = 20,
69  MPU_SIZE_4M = 21,
70  MPU_SIZE_8M = 22,
71  MPU_SIZE_16M = 23,
72  MPU_SIZE_32M = 24,
73  MPU_SIZE_64M = 25,
77  MPU_SIZE_1G = 29,
78  MPU_SIZE_2G = 30,
79  MPU_SIZE_4G = 31,
80 };
81 
89 #define MPU_SIZE_TO_BYTES(size) ( (uintptr_t)1 << ((size) + 1) )
90 
104 static inline uint32_t MPU_ATTR(
105  uint32_t xn,
106  uint32_t ap,
107  uint32_t tex,
108  uint32_t c,
109  uint32_t b,
110  uint32_t s,
111  uint32_t size)
112 {
113  return
114  (xn << 28) |
115  (ap << 24) |
116  (tex << 19) |
117  (s << 18) |
118  (c << 17) |
119  (b << 16) |
120  (size << 1);
121 }
122 
129 int mpu_disable(void);
130 
137 int mpu_enable(void);
138 
145 bool mpu_enabled(void);
146 
157 int mpu_configure(uint_fast8_t region, uintptr_t base, uint_fast32_t attr);
158 
159 #ifdef __cplusplus
160 }
161 #endif
162 
163 #endif /* MPU_H */
2 megabytes
Definition: mpu.h:68
bool mpu_enabled(void)
test if the MPU is enabled
1 megabytes
Definition: mpu.h:67
32 bytes
Definition: mpu.h:52
128 bytes
Definition: mpu.h:54
4 kilobytes
Definition: mpu.h:59
256 bytes
Definition: mpu.h:55
read/write for privileged level, no access from user level
Definition: mpu.h:41
512 megabytes
Definition: mpu.h:76
64 kilobytes
Definition: mpu.h:63
2 gigabytes
Definition: mpu.h:78
4 gigabytes
Definition: mpu.h:79
no access for all levels
Definition: mpu.h:40
read/write for all levels
Definition: mpu.h:43
512 bytes
Definition: mpu.h:56
static uint32_t MPU_ATTR(uint32_t xn, uint32_t ap, uint32_t tex, uint32_t c, uint32_t b, uint32_t s, uint32_t size)
generate an MPU attribute word suitable for writing to the RASR register
Definition: mpu.h:104
read-only for all levels
Definition: mpu.h:45
read/write for privileged level, read-only for user level
Definition: mpu.h:42
128 kilobytes
Definition: mpu.h:64
1 gigabytes
Definition: mpu.h:77
32 kilobytes
Definition: mpu.h:62
16 megabytes
Definition: mpu.h:71
512 kilobytes
Definition: mpu.h:66
64 megabytes
Definition: mpu.h:73
256 megabytes
Definition: mpu.h:75
256 kilobytes
Definition: mpu.h:65
8 kilobytes
Definition: mpu.h:60
128 megabytes
Definition: mpu.h:74
int mpu_disable(void)
disable the MPU
int mpu_configure(uint_fast8_t region, uintptr_t base, uint_fast32_t attr)
configure the base address and attributes for an MPU region
int mpu_enable(void)
enable the MPU
16 kilobytes
Definition: mpu.h:61
read-only for privileged level, no access from user level
Definition: mpu.h:44
2 kilobytes
Definition: mpu.h:58
8 megabytes
Definition: mpu.h:70
1 kilobytes
Definition: mpu.h:57
64 bytes
Definition: mpu.h:53
4 megabytes
Definition: mpu.h:69
32 megabytes
Definition: mpu.h:72