1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::svd::create_peripheral;
use crate::Result;
pub mod registers;
/// Represents a Synopsys DesignWare 10/100 Ethernet MAC (compatible) peripheral
pub struct DwMac {
peripheral: svd::Peripheral,
}
impl DwMac {
/// Creates a new [DwMac] peripheral.
pub fn create(
name: &str,
base_address: u64,
size: u32,
interrupt: Option<Vec<svd::Interrupt>>,
dim: u32,
) -> Result<Self> {
let dim_element = if dim > 0 {
Some(
svd::DimElement::builder()
.dim(dim)
.dim_increment(size)
.build(svd::ValidateLevel::Strict)?,
)
} else {
None
};
let peripheral = create_peripheral(
name,
format!("Synopsys DesignWare 10/100 Ethernet MAC: {name}").as_str(),
base_address,
size,
interrupt,
Some(registers::create()?),
dim_element,
)?;
Ok(Self { peripheral })
}
/// Gets a reference to the SVD [`Peripheral`](svd::Peripheral).
pub const fn peripheral(&self) -> &svd::Peripheral {
&self.peripheral
}
/// Gets a mutable reference to the SVD [`Peripheral`](svd::Peripheral).
pub fn peripheral_mut(&mut self) -> &mut svd::Peripheral {
&mut self.peripheral
}
/// Converts the [DwMac] into the inner SVD [`Peripheral`](svd::Peripheral).
pub fn to_inner(self) -> svd::Peripheral {
self.peripheral
}
}