Skip to content

Commit bc658c1

Browse files
committed
Move common structs and enums to the parent module of pmpcfgx
1 parent b1d12b7 commit bc658c1

File tree

1 file changed

+61
-60
lines changed

1 file changed

+61
-60
lines changed

src/register/pmpcfgx.rs

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,73 @@
11
/// Physical memory protection configuration
2+
use bit_field::BitField;
3+
4+
#[derive(Clone, Copy, Debug)]
5+
pub enum Permission {
6+
NONE = 0,
7+
R = 1,
8+
W = 2,
9+
RW = 3,
10+
X = 4,
11+
RX = 5,
12+
WX = 6,
13+
RWX = 7,
14+
}
215

3-
pub mod pmpcfg0 {
4-
use bit_field::BitField;
5-
6-
#[derive(Clone, Copy, Debug)]
7-
pub enum Permission {
8-
NONE = 0,
9-
R = 1,
10-
W = 2,
11-
RW = 3,
12-
X = 4,
13-
RX = 5,
14-
WX = 6,
15-
RWX = 7,
16-
}
17-
18-
#[derive(Clone, Copy, Debug)]
19-
pub enum Range {
20-
OFF = 0,
21-
TOR = 1,
22-
NA4 = 2,
23-
NAPOT = 3,
24-
}
16+
#[derive(Clone, Copy, Debug)]
17+
pub enum Range {
18+
OFF = 0,
19+
TOR = 1,
20+
NA4 = 2,
21+
NAPOT = 3,
22+
}
2523

26-
#[derive(Clone, Copy, Debug)]
27-
pub struct Pmpconfig {
28-
pub permission: Permission,
29-
pub range_type: Range,
30-
pub locked: bool,
31-
}
24+
#[derive(Clone, Copy, Debug)]
25+
pub struct Pmpconfig {
26+
pub permission: Permission,
27+
pub range_type: Range,
28+
pub locked: bool,
29+
}
3230

33-
#[derive(Clone, Copy, Debug)]
34-
pub struct PmpByte {
35-
byte: u8,
36-
}
31+
#[derive(Clone, Copy, Debug)]
32+
pub struct PmpByte {
33+
byte: u8,
34+
}
3735

38-
impl PmpByte {
39-
#[inline]
40-
fn range(&self) -> Range {
41-
match self.byte.get_bits(4..=5) {
42-
0 => Range::OFF,
43-
1 => Range::TOR,
44-
2 => Range::NA4,
45-
3 => Range::NAPOT,
46-
_ => unreachable!(),
47-
}
36+
impl PmpByte {
37+
#[inline]
38+
fn range(&self) -> Range {
39+
match self.byte.get_bits(4..=5) {
40+
0 => Range::OFF,
41+
1 => Range::TOR,
42+
2 => Range::NA4,
43+
3 => Range::NAPOT,
44+
_ => unreachable!(),
4845
}
46+
}
4947

50-
#[inline]
51-
fn permission(&self) -> Option<Permission> {
52-
match self.byte.get_bits(0..=2) {
53-
0 => None,
54-
1 => Some(Permission::R),
55-
2 => Some(Permission::W),
56-
3 => Some(Permission::RW),
57-
4 => Some(Permission::X),
58-
5 => Some(Permission::RX),
59-
6 => Some(Permission::WX),
60-
7 => Some(Permission::RWX),
61-
_ => None,
62-
}
48+
#[inline]
49+
fn permission(&self) -> Option<Permission> {
50+
match self.byte.get_bits(0..=2) {
51+
0 => None,
52+
1 => Some(Permission::R),
53+
2 => Some(Permission::W),
54+
3 => Some(Permission::RW),
55+
4 => Some(Permission::X),
56+
5 => Some(Permission::RX),
57+
6 => Some(Permission::WX),
58+
7 => Some(Permission::RWX),
59+
_ => None,
6360
}
61+
}
6462

65-
#[inline]
66-
fn locked(&self) -> bool {
67-
self.byte.get_bit(7)
68-
}
63+
#[inline]
64+
fn locked(&self) -> bool {
65+
self.byte.get_bit(7)
6966
}
67+
}
68+
pub mod pmpcfg0 {
69+
use crate::register::{Permission, PmpByte, Pmpconfig, Range};
70+
use bit_field::BitField;
7071

7172
#[derive(Clone, Copy, Debug)]
7273
pub struct Pmpcfg0 {
@@ -88,7 +89,7 @@ pub mod pmpcfg0 {
8889
}
8990
}
9091

91-
///Returns pmp[x]cfg configuration structure
92+
///Returns pmpxcfg configuration structure
9293
#[inline]
9394
pub fn pmp_cfg(&self, index: usize) -> Pmpconfig {
9495
let byte = self.pmp_byte(index);

0 commit comments

Comments
 (0)