Skip to content

Commit 0eea25a

Browse files
committed
Move Pmpcfg structures out of individual modules and combine
1 parent 40e480e commit 0eea25a

File tree

3 files changed

+29
-71
lines changed

3 files changed

+29
-71
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ bit_field = "0.10.0"
1616
riscv-target = "0.1.2"
1717

1818
[features]
19-
inline-asm = []
19+
inline-asm = []

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ extern crate bit_field;
2222
pub mod asm;
2323
pub mod interrupt;
2424
pub mod register;
25-

src/register/pmpcfgx.rs

Lines changed: 28 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ pub enum Range {
2323
NAPOT = 3,
2424
}
2525

26+
#[derive(Clone, Copy, Debug)]
27+
pub struct Pmpcfg {
28+
pub bits: usize,
29+
}
30+
31+
impl Pmpcfg {
32+
#[inline]
33+
pub fn get_byte(&self, index: usize) -> PmpByte {
34+
#[cfg(riscv32)]
35+
assert!(index < 4);
36+
37+
#[cfg(riscv64)]
38+
assert!(index < 8);
39+
40+
PmpByte {
41+
byte: self.bits.get_bits(8 * index..8 * (index + 1)) as u8,
42+
}
43+
}
44+
}
45+
2646
/// PmpByte holds the a single pmp configuration
2747
#[derive(Clone, Copy, Debug)]
2848
pub struct PmpByte {
@@ -69,29 +89,9 @@ impl PmpByte {
6989
/// Pmpcfg0 struct contains pmp0cfg - pmp3cfg for RV32, or pmp0cfg - pmp7cfg for RV64
7090
/// get_byte() method retrieves a single pmp<x>cfg held in a PmpByte struct
7191
pub mod pmpcfg0 {
72-
use super::{BitField, Permission, PmpByte, Range};
73-
74-
#[derive(Clone, Copy, Debug)]
75-
pub struct Pmpcfg0 {
76-
pub bits: usize,
77-
}
78-
79-
impl Pmpcfg0 {
80-
#[inline]
81-
pub fn get_byte(&self, index: usize) -> PmpByte {
82-
#[cfg(riscv32)]
83-
assert!(index < 4);
84-
85-
#[cfg(riscv64)]
86-
assert!(index < 8);
92+
use super::{Permission, Pmpcfg, Range};
8793

88-
PmpByte {
89-
byte: self.bits.get_bits(8 * index..8 * (index + 1)) as u8,
90-
}
91-
}
92-
}
93-
94-
read_csr_as!(Pmpcfg0, 0x3A0, __read_pmpcfg0);
94+
read_csr_as!(Pmpcfg, 0x3A0, __read_pmpcfg0);
9595
write_csr!(0x3A0, __write_pmpcfg0);
9696
set!(0x3A0, __set_pmpcfg0);
9797
clear!(0x3A0, __clear_pmpcfg0);
@@ -134,23 +134,9 @@ pub mod pmpcfg0 {
134134
/// Pmpcfg1 struct contains pmp4cfg - pmp7cfg for RV32 only
135135
/// get_byte() method retrieves a single pmp<x>cfg held in a PmpByte struct
136136
pub mod pmpcfg1 {
137-
use super::{BitField, Permission, PmpByte, Range};
138-
139-
#[derive(Clone, Copy, Debug)]
140-
pub struct Pmpcfg1 {
141-
pub bits: usize,
142-
}
137+
use super::{Permission, Pmpcfg, Range};
143138

144-
impl Pmpcfg1 {
145-
#[inline]
146-
pub fn get_byte(&self, index: usize) -> PmpByte {
147-
PmpByte {
148-
byte: self.bits.get_bits(8 * index..8 * (index + 1)) as u8,
149-
}
150-
}
151-
}
152-
153-
read_csr_as!(Pmpcfg1, 0x3A1, __read_pmpcfg1);
139+
read_csr_as!(Pmpcfg, 0x3A1, __read_pmpcfg1);
154140
write_csr!(0x3A1, __write_pmpcfg1);
155141
set!(0x3A1, __set_pmpcfg1);
156142
clear!(0x3A1, __clear_pmpcfg1);
@@ -193,23 +179,9 @@ pub mod pmpcfg1 {
193179
/// Pmpcfg0 struct contains pmp8cfg - pmp11cfg for RV32, or pmp8cfg - pmp15cfg for RV64
194180
/// get_byte() method retrieves a single pmp<x>cfg held in a PmpByte struct
195181
pub mod pmpcfg2 {
196-
use super::{BitField, Permission, PmpByte, Range};
182+
use super::{Permission, Pmpcfg, Range};
197183

198-
#[derive(Clone, Copy, Debug)]
199-
pub struct Pmpcfg2 {
200-
pub bits: usize,
201-
}
202-
203-
impl Pmpcfg2 {
204-
#[inline]
205-
pub fn get_byte(&self, index: usize) -> PmpByte {
206-
PmpByte {
207-
byte: self.bits.get_bits(8 * index..8 * (index + 1)) as u8,
208-
}
209-
}
210-
}
211-
212-
read_csr_as!(Pmpcfg2, 0x3A2, __read_pmpcfg2);
184+
read_csr_as!(Pmpcfg, 0x3A2, __read_pmpcfg2);
213185
write_csr!(0x3A2, __write_pmpcfg2);
214186
set!(0x3A2, __set_pmpcfg2);
215187
clear!(0x3A2, __clear_pmpcfg2);
@@ -252,22 +224,9 @@ pub mod pmpcfg2 {
252224
/// Pmpcfg0 struct contains pmp12cfg - pmp15cfg for RV32 only
253225
/// get_byte() method retrieves a single pmp<x>cfg held in a PmpByte struct
254226
pub mod pmpcfg3 {
255-
use super::{BitField, Permission, PmpByte, Range};
256-
257-
#[derive(Clone, Copy, Debug)]
258-
pub struct Pmpcfg3 {
259-
pub bits: usize,
260-
}
261-
impl Pmpcfg3 {
262-
#[inline]
263-
pub fn get_byte(&self, index: usize) -> PmpByte {
264-
PmpByte {
265-
byte: self.bits.get_bits(8 * index..8 * (index + 1)) as u8,
266-
}
267-
}
268-
}
227+
use super::{Permission, Pmpcfg, Range};
269228

270-
read_csr_as!(Pmpcfg3, 0x3A3, __read_pmpcfg3);
229+
read_csr_as!(Pmpcfg, 0x3A3, __read_pmpcfg3);
271230
write_csr!(0x3A3, __write_pmpcfg3);
272231
set!(0x3A3, __set_pmpcfg3);
273232
clear!(0x3A3, __clear_pmpcfg3);

0 commit comments

Comments
 (0)