Loading...
Searching...
No Matches
mpu.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Loci Controls Inc.
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
19
20#include <stdbool.h>
21#include <stdint.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
30#define MPU_NUM_REGIONS ( (MPU->TYPE & MPU_TYPE_DREGION_Msk) >> MPU_TYPE_DREGION_Pos )
31
35enum {
42};
43
47enum {
76};
77
85#define MPU_SIZE_TO_BYTES(size) ( (uintptr_t)1 << ((size) + 1) )
86
100static inline uint32_t MPU_ATTR(
101 uint32_t xn,
102 uint32_t ap,
103 uint32_t tex,
104 uint32_t c,
105 uint32_t b,
106 uint32_t s,
107 uint32_t size)
108{
109 return
110 (xn << 28) |
111 (ap << 24) |
112 (tex << 19) |
113 (s << 18) |
114 (c << 17) |
115 (b << 16) |
116 (size << 1);
117}
118
125int mpu_disable(void);
126
133int mpu_enable(void);
134
141bool mpu_enabled(void);
142
153int mpu_configure(uint_fast8_t region, uintptr_t base, uint_fast32_t attr);
154
155#ifdef __cplusplus
156}
157#endif
int mpu_configure(uint_fast8_t region, uintptr_t base, uint_fast32_t attr)
configure the base address and attributes for an MPU region
@ AP_NO_NO
no access for all levels
Definition mpu.h:36
@ AP_RW_NO
read/write for privileged level, no access from user level
Definition mpu.h:37
@ AP_RW_RW
read/write for all levels
Definition mpu.h:39
@ AP_RO_NO
read-only for privileged level, no access from user level
Definition mpu.h:40
@ AP_RW_RO
read/write for privileged level, read-only for user level
Definition mpu.h:38
@ AP_RO_RO
read-only for all levels
Definition mpu.h:41
bool mpu_enabled(void)
test if the MPU is enabled
@ MPU_SIZE_256K
256 kilobytes
Definition mpu.h:61
@ MPU_SIZE_512K
512 kilobytes
Definition mpu.h:62
@ MPU_SIZE_2M
2 megabytes
Definition mpu.h:64
@ MPU_SIZE_4M
4 megabytes
Definition mpu.h:65
@ MPU_SIZE_64K
64 kilobytes
Definition mpu.h:59
@ MPU_SIZE_2K
2 kilobytes
Definition mpu.h:54
@ MPU_SIZE_32M
32 megabytes
Definition mpu.h:68
@ MPU_SIZE_2G
2 gigabytes
Definition mpu.h:74
@ MPU_SIZE_256B
256 bytes
Definition mpu.h:51
@ MPU_SIZE_64B
64 bytes
Definition mpu.h:49
@ MPU_SIZE_8M
8 megabytes
Definition mpu.h:66
@ MPU_SIZE_4G
4 gigabytes
Definition mpu.h:75
@ MPU_SIZE_1G
1 gigabytes
Definition mpu.h:73
@ MPU_SIZE_128B
128 bytes
Definition mpu.h:50
@ MPU_SIZE_1M
1 megabytes
Definition mpu.h:63
@ MPU_SIZE_16K
16 kilobytes
Definition mpu.h:57
@ MPU_SIZE_32B
32 bytes
Definition mpu.h:48
@ MPU_SIZE_16M
16 megabytes
Definition mpu.h:67
@ MPU_SIZE_32K
32 kilobytes
Definition mpu.h:58
@ MPU_SIZE_4K
4 kilobytes
Definition mpu.h:55
@ MPU_SIZE_128K
128 kilobytes
Definition mpu.h:60
@ MPU_SIZE_256M
256 megabytes
Definition mpu.h:71
@ MPU_SIZE_128M
128 megabytes
Definition mpu.h:70
@ MPU_SIZE_1K
1 kilobytes
Definition mpu.h:53
@ MPU_SIZE_64M
64 megabytes
Definition mpu.h:69
@ MPU_SIZE_512B
512 bytes
Definition mpu.h:52
@ MPU_SIZE_8K
8 kilobytes
Definition mpu.h:56
@ MPU_SIZE_512M
512 megabytes
Definition mpu.h:72
int mpu_disable(void)
disable the MPU
int mpu_enable(void)
enable the MPU
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:100