Skip to content

Commit 77fa96e

Browse files
Dan Whitmankyp44
authored andcommitted
feat(dsu): Migrates the dsu::Dsu peripheral to use the clock::v2.
* `Dsu::new` now requires ownership of its `AhbClk` and `ApbClk`. * Adds the `Dsu::free` method to free the `pac::Dsu` and bus clocks.
1 parent cfbc4ad commit 77fa96e

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

hal/src/peripherals/dsu.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@
77

88
use crate::pac::{self, Pac};
99

10+
type DsuAhbClk = crate::clock::v2::ahb::AhbClk<crate::clock::v2::types::Dsu>;
11+
type DsuApbClk = crate::clock::v2::apb::ApbClk<crate::clock::v2::types::Dsu>;
12+
1013
/// Device Service Unit
1114
pub struct Dsu {
1215
/// PAC peripheral
1316
dsu: pac::Dsu,
17+
// AHB clock
18+
_ahb_clk: DsuAhbClk,
19+
// APB clock
20+
_apb_clk: DsuApbClk,
1421
}
1522

1623
/// Errors from hardware
@@ -41,7 +48,12 @@ pub type Result<T> = core::result::Result<T, Error>;
4148
impl Dsu {
4249
/// Unlock the DSU and instantiate peripheral
4350
#[inline]
44-
pub fn new(dsu: pac::Dsu, pac: &Pac) -> Result<Self> {
51+
pub fn new(
52+
dsu: pac::Dsu,
53+
ahb_clk: DsuAhbClk,
54+
apb_clk: DsuApbClk,
55+
pac: &mut Pac,
56+
) -> Result<Self> {
4557
// Attempt to unlock DSU
4658
pac.wrctrl()
4759
.write(|w| unsafe { w.perid().bits(33).key().clr() });
@@ -50,10 +62,23 @@ impl Dsu {
5062
if pac.statusb().read().dsu_().bit_is_set() {
5163
Err(Error::PacUnlockFailed)
5264
} else {
53-
Ok(Self { dsu })
65+
Ok(Self {
66+
dsu,
67+
_ahb_clk: ahb_clk,
68+
_apb_clk: apb_clk,
69+
})
5470
}
5571
}
5672

73+
/// Lock and destroy the DSU peripheral, freeing its resources
74+
pub fn free(self, pac: &mut Pac) -> (pac::Dsu, DsuAhbClk, DsuApbClk) {
75+
// Attempt to lock the DSU, but if this fails there we still want to proceed
76+
pac.wrctrl()
77+
.write(|w| unsafe { w.perid().bits(33).key().set_() });
78+
79+
(self.dsu, self._ahb_clk, self._apb_clk)
80+
}
81+
5782
/// Clear bus error bit
5883
fn clear_bus_error(&mut self) {
5984
self.dsu.statusa().write(|w| w.berr().set_bit());

0 commit comments

Comments
 (0)