File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change 77
88use 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
1114pub 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>;
4148impl 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 ( ) ) ;
You can’t perform that action at this time.
0 commit comments