Loading...
Searching...
No Matches
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
28extern "C" {
29#endif
30
34#define MPU_NUM_REGIONS ( (MPU->TYPE & MPU_TYPE_DREGION_Msk) >> MPU_TYPE_DREGION_Pos )
35
39enum {
46};
47
51enum {
80};
81
89#define MPU_SIZE_TO_BYTES(size) ( (uintptr_t)1 << ((size) + 1) )
90
104static 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
129int mpu_disable(void);
130
137int mpu_enable(void);
138
145bool mpu_enabled(void);
146
157int 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 */
int mpu_configure(uint_fast8_t region, uintptr_t base, uint_fast32_t attr)
configure the base address and attributes for an MPU region
bool mpu_enabled(void)
test if the MPU is enabled
@ AP_NO_NO
no access for all levels
Definition mpu.h:40
@ AP_RW_NO
read/write for privileged level, no access from user level
Definition mpu.h:41
@ AP_RW_RW
read/write for all levels
Definition mpu.h:43
@ AP_RO_NO
read-only for privileged level, no access from user level
Definition mpu.h:44
@ AP_RW_RO
read/write for privileged level, read-only for user level
Definition mpu.h:42
@ AP_RO_RO
read-only for all levels
Definition mpu.h:45
int mpu_disable(void)
disable the MPU
int mpu_enable(void)
enable the MPU
@ MPU_SIZE_256K
256 kilobytes
Definition mpu.h:65
@ MPU_SIZE_512K
512 kilobytes
Definition mpu.h:66
@ MPU_SIZE_2M
2 megabytes
Definition mpu.h:68
@ MPU_SIZE_4M
4 megabytes
Definition mpu.h:69
@ MPU_SIZE_64K
64 kilobytes
Definition mpu.h:63
@ MPU_SIZE_2K
2 kilobytes
Definition mpu.h:58
@ MPU_SIZE_32M
32 megabytes
Definition mpu.h:72
@ MPU_SIZE_2G
2 gigabytes
Definition mpu.h:78
@ MPU_SIZE_256B
256 bytes
Definition mpu.h:55
@ MPU_SIZE_64B
64 bytes
Definition mpu.h:53
@ MPU_SIZE_8M
8 megabytes
Definition mpu.h:70
@ MPU_SIZE_4G
4 gigabytes
Definition mpu.h:79
@ MPU_SIZE_1G
1 gigabytes
Definition mpu.h:77
@ MPU_SIZE_128B
128 bytes
Definition mpu.h:54
@ MPU_SIZE_1M
1 megabytes
Definition mpu.h:67
@ MPU_SIZE_16K
16 kilobytes
Definition mpu.h:61
@ MPU_SIZE_32B
32 bytes
Definition mpu.h:52
@ MPU_SIZE_16M
16 megabytes
Definition mpu.h:71
@ MPU_SIZE_32K
32 kilobytes
Definition mpu.h:62
@ MPU_SIZE_4K
4 kilobytes
Definition mpu.h:59
@ MPU_SIZE_128K
128 kilobytes
Definition mpu.h:64
@ MPU_SIZE_256M
256 megabytes
Definition mpu.h:75
@ MPU_SIZE_128M
128 megabytes
Definition mpu.h:74
@ MPU_SIZE_1K
1 kilobytes
Definition mpu.h:57
@ MPU_SIZE_64M
64 megabytes
Definition mpu.h:73
@ MPU_SIZE_512B
512 bytes
Definition mpu.h:56
@ MPU_SIZE_8K
8 kilobytes
Definition mpu.h:60
@ MPU_SIZE_512M
512 megabytes
Definition mpu.h:76
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