Skip to content

Commit 8edb781

Browse files
committed
stash 5 - reset, stash 5 - osculp32k
1 parent 4ac487e commit 8edb781

File tree

3 files changed

+54
-151
lines changed

3 files changed

+54
-151
lines changed

hal/src/clock/v2/osculp32k.rs

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
//! ## Overview
44
//!
55
//! The `osculp32k` module provides access to the 32 kHz ultra low power
6-
//! internal oscillator (OSCULP32K) within the `OSC32KCTRL` peripheral.
6+
//! internal oscillator (OSCULP32K) within the `OSC32KCTRL` or `SYSCTRL`
7+
//! peripheral.
78
//!
89
//! The `OSCULP32K` clock is unlike most other clocks. First, it is an internal
910
//! clock that is always enabled and can't be disabled. And second, it has two
@@ -13,9 +14,9 @@
1314
//! We can see, then, that the `OSCULP32K` peripheral forms its own, miniature
1415
//! clock tree. There is a 1:N producer clock that is always enabled; and there
1516
//! are two possible consumer clocks that can be independently and optionally
16-
//! enabled. In fact, this structure is illustrated by the `OSCULP32K`
17-
//! register, which has no regular `ENABLE` bit and two different enable bits
18-
//! for clock output, `EN32K` and `EN1K`.
17+
//! enabled. In fact, this structure is illustrated by the `OSCULP32K` register,
18+
//! which has no regular `ENABLE` bit and two different enable bits for clock
19+
//! output, `EN32K` and `EN1K`.
1920
//!
2021
//! To represent this structure in the type system, we divide the `OSCULP32K`
2122
//! peripheral into these three clocks. Users get access to the 1:N
@@ -165,21 +166,16 @@ use atsamd_hal_macros::hal_cfg;
165166
use fugit::RateExtU32;
166167
use typenum::U0;
167168

168-
#[hal_cfg("clock-d5x")]
169-
mod imports {
170-
pub use crate::pac::osc32kctrl::Osculp32k;
171-
pub use crate::typelevel::{Decrement, Increment};
172-
}
173-
174-
#[hal_cfg(any("clock-d11", "clock-d21"))]
175-
mod imports {
176-
pub use crate::pac::sysctrl::Osculp32k;
177-
}
169+
#[hal_cfg("osc32kctrl")]
170+
use crate::pac::osc32kctrl::Osculp32k;
171+
#[hal_cfg("osc32kctrl")]
172+
use crate::typelevel::{Decrement, Increment, PrivateDecrement, PrivateIncrement};
178173

179-
use imports::*;
174+
#[hal_cfg("sysctrl")]
175+
use crate::pac::sysctrl::Osculp32k;
180176

181177
use crate::time::Hertz;
182-
use crate::typelevel::{PrivateDecrement, PrivateIncrement, Sealed};
178+
use crate::typelevel::Sealed;
183179

184180
use super::{Enabled, Source};
185181

@@ -223,39 +219,17 @@ pub struct OscUlp1kToken(());
223219
/// first exchange the token for an actual clock with [`OscUlp32k::enable`].
224220
pub struct OscUlp32kToken(());
225221

226-
/// Set of tokens representing the disabled OSCULP32K clocks power-on reset
227-
pub struct OscUlp32kTokens {
228-
pub osculp1k: OscUlp1kToken,
229-
pub osculp32k: OscUlp32kToken,
230-
}
231-
232-
impl OscUlp32kTokens {
233-
/// Create the set of tokens
234-
///
235-
/// # Safety
236-
///
237-
/// There must never be more than one instance of each token at any given
238-
/// time. See the notes on `Token` types and memory safety in the root of
239-
/// the `clock` module for more details.
240-
pub(super) unsafe fn new() -> Self {
241-
Self {
242-
osculp1k: OscUlp1kToken(()),
243-
osculp32k: OscUlp32kToken(()),
244-
}
245-
}
246-
}
247-
248222
impl OscUlp32kBaseToken {
249223
#[inline]
250224
fn osculp32k(&self) -> &Osculp32k {
251225
// Safety: The `OscUlp32kBaseToken` has exclusive access to the
252226
// `OSCULP32K` register. See the notes on `Token` types and memory
253227
// safety in the root of the `clock` module for more details.
254-
#[hal_cfg("clock-d5x")]
228+
#[hal_cfg("osc32kctrl")]
255229
unsafe {
256230
&(*crate::pac::Osc32kctrl::PTR).osculp32k()
257231
}
258-
#[hal_cfg(any("clock-d11", "clock-d21"))]
232+
#[hal_cfg("sysctrl")]
259233
unsafe {
260234
&(*crate::pac::Sysctrl::PTR).osculp32k()
261235
}
@@ -336,9 +310,9 @@ impl OscUlp32kBase {
336310
/// the notes on `Token` types and memory safety in the root of the `clock`
337311
/// module for more details.
338312
#[inline]
339-
pub(super) unsafe fn new() -> EnabledOscUlp32kBase {
313+
pub(super) unsafe fn new() -> Self {
340314
let token = OscUlp32kBaseToken(());
341-
Enabled::new(Self { token })
315+
Self { token }
342316
}
343317
}
344318

@@ -401,7 +375,15 @@ pub struct OscUlp1k {
401375
pub type EnabledOscUlp1k<N = U0> = Enabled<OscUlp1k, N>;
402376

403377
impl OscUlp1k {
404-
#[hal_cfg(any("clock-d11", "clock-d21"))]
378+
/// Create the ultra-low power base oscillator
379+
///
380+
/// # Safety
381+
///
382+
/// Because an `OscUlp1k` contains an `OscUlp1kToken`, there must never be
383+
/// more than one instance of this struct at any given time. See the notes
384+
/// on `Token` types and memory safety in the root of the `clock` module for
385+
/// more details.
386+
#[inline]
405387
pub(super) unsafe fn new() -> Self {
406388
let token = OscUlp1kToken(());
407389
Self { token }
@@ -473,7 +455,15 @@ pub struct OscUlp32k {
473455
pub type EnabledOscUlp32k<N = U0> = Enabled<OscUlp32k, N>;
474456

475457
impl OscUlp32k {
476-
#[hal_cfg(any("clock-d11", "clock-d21"))]
458+
/// Create the ultra-low power base oscillator
459+
///
460+
/// # Safety
461+
///
462+
/// Because an `OscUlp32k` contains an `OscUlp32kToken`, there must never be
463+
/// more than one instance of this struct at any given time. See the notes
464+
/// on `Token` types and memory safety in the root of the `clock` module for
465+
/// more details.
466+
#[inline]
477467
pub(super) unsafe fn new() -> Self {
478468
let token = OscUlp32kToken(());
479469
Self { token }

hal/src/clock/v2/reset_thumbv6m.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct Buses {
5656
pub apb: apb::Apb,
5757
}
5858

59-
pub struct OscUlp32kClocks {
59+
pub struct OscUlpClocks {
6060
pub base: osculp32k::EnabledOscUlp32kBase,
6161
pub osculp1k: osculp32k::EnabledOscUlp1k,
6262
pub osculp32k: osculp32k::EnabledOscUlp32k<U1>,
@@ -93,10 +93,10 @@ pub struct Clocks {
9393
pub gclk2: Enabled<gclk::Gclk2<osculp32k::OscUlp32kId>, U1>,
9494
/// 8 MHz internal oscillator, divided by 8 for a 1 MHz output
9595
pub osc: Enabled<osc::Osc, U1>,
96+
/// Always-enabled OSCULP oscillators
97+
pub osculp: OscUlpClocks,
9698
/// [`Pclk`](pclk::Pclk) for the watchdog timer, sourced from [`Gclk2`](gclk::Gclk2)
9799
pub wdt: pclk::Pclk<types::Wdt, gclk::Gclk2Id>,
98-
/// Always-enabled OSCULP oscillators
99-
pub osculp32k: OscUlp32kClocks,
100100
}
101101

102102
/// Type-level tokens for unused clocks at power-on reset
@@ -147,13 +147,13 @@ pub fn clock_system_at_reset(gclk: Gclk, pm: Pm, sysctrl: Sysctrl) -> (Buses, Cl
147147
let osc = Enabled::<_, U0>::new(osc::Osc::new(osc::OscToken::new()));
148148
let (gclk0, osc) = gclk::Gclk0::from_source(gclk::GclkToken::new(), osc);
149149
let gclk0 = Enabled::new(gclk0);
150-
let base = osculp32k::OscUlp32kBase::new();
150+
let base = Enabled::new(osculp32k::OscUlp32kBase::new());
151151
let osculp1k = Enabled::new(osculp32k::OscUlp1k::new());
152-
let osculp32k = Enabled::new(osculp32k::OscUlp32k::new());
152+
let osculp32k = Enabled::<_, U0>::new(osculp32k::OscUlp32k::new());
153153
let (gclk2, osculp32k) = gclk::Gclk2::from_source(gclk::GclkToken::new(), osculp32k);
154154
let gclk2 = Enabled::new(gclk2);
155155
let wdt = pclk::Pclk::new(pclk::PclkToken::new(), gclk2.freq());
156-
let osculp32k = OscUlp32kClocks {
156+
let osculp = OscUlpClocks {
157157
base,
158158
osculp1k,
159159
osculp32k,
@@ -166,7 +166,7 @@ pub fn clock_system_at_reset(gclk: Gclk, pm: Pm, sysctrl: Sysctrl) -> (Buses, Cl
166166
gclk2,
167167
osc,
168168
wdt,
169-
osculp32k,
169+
osculp,
170170
};
171171
let tokens = Tokens {
172172
apbs: apb::ApbTokens::new(),

hal/src/clock/v2/reset_thumbv7em.rs

Lines changed: 13 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//! from the `v2` module, which is where the corresponding documentation will
33
//! appear.
44
5-
use atsamd_hal_macros::hal_cfg;
65
use typenum::U1;
76

87
use crate::pac::{Gclk, Mclk, Osc32kctrl, Oscctrl};
@@ -58,18 +57,10 @@ pub struct Buses {
5857
pub apb: apb::Apb,
5958
}
6059

61-
#[hal_cfg("clock-d5x")]
62-
#[allow(dead_code)]
63-
pub struct OscUlp32kClocks {
64-
base: osculp32k::EnabledOscUlp32kBase,
65-
}
66-
67-
#[hal_cfg(any("clock-d11", "clock-d21"))]
68-
#[allow(dead_code)]
69-
pub struct OscUlp32kClocks {
70-
base: osculp32k::EnabledOscUlp32kBase,
71-
osculp1k: EnabledOscUlp1k,
72-
osculp32k: EnabledOscUlp32k,
60+
pub struct OscUlpClocks {
61+
pub base: osculp32k::EnabledOscUlp32kBase,
62+
pub osculp1k: osculp32k::EnabledOscUlp1k,
63+
pub osculp32k: osculp32k::EnabledOscUlp32k,
7364
}
7465

7566
/// Enabled clocks at power-on reset
@@ -103,7 +94,7 @@ pub struct Clocks {
10394
pub dfll: Enabled<dfll::Dfll, U1>,
10495
/// Always-enabled base oscillator for the [`OscUlp1k`](osculp32k::OscUlp1k)
10596
/// and [`OscUlp32k`](osculp32k::OscUlp32k) clocks.
106-
pub osculp32k: OscUlp32kClocks,
97+
pub osculp: OscUlpClocks,
10798
}
10899

109100
/// Type-level tokens for unused clocks at power-on reset
@@ -115,32 +106,6 @@ pub struct Clocks {
115106
/// As described in the [top-level](super::super) documentation for the `clock`
116107
/// module, token types are used to guanrantee the uniqueness of each clock. To
117108
/// configure or enable a clock, you must provide the corresponding token.
118-
#[hal_cfg("clock-d5x")]
119-
pub struct Tokens {
120-
/// Tokens to create [`apb::ApbClk`]s
121-
pub apbs: apb::ApbTokens,
122-
/// Token to create [`dpll::Dpll0`]
123-
pub dpll0: dpll::DpllToken<dpll::Dpll0Id>,
124-
/// Token to create [`dpll::Dpll1`]
125-
pub dpll1: dpll::DpllToken<dpll::Dpll1Id>,
126-
/// Tokens to create [`gclk::Gclk`]
127-
pub gclks: gclk::GclkTokens,
128-
/// Tokens to create [`pclk::Pclk`]s
129-
pub pclks: pclk::PclkTokens,
130-
/// Tokens to create [`rtcosc::RtcOsc`]
131-
pub rtcosc: rtcosc::RtcOscToken,
132-
/// Tokens [`xosc::Xosc0`]
133-
pub xosc0: xosc::XoscToken<xosc::Xosc0Id>,
134-
/// Token to create [`xosc::Xosc1`]
135-
pub xosc1: xosc::XoscToken<xosc::Xosc1Id>,
136-
/// Tokens to create [`xosc32k::Xosc32kBase`], [`xosc32k::Xosc1k`] and
137-
/// [`xosc32k::Xosc32k`]
138-
pub xosc32k: xosc32k::Xosc32kTokens,
139-
/// Tokens to create [`osculp32k::OscUlp1k`] and [`osculp32k::OscUlp32k`]
140-
pub osculp32k: osculp32k::OscUlp32kTokens,
141-
}
142-
143-
#[hal_cfg(any("clock-d11", "clock-d21"))]
144109
pub struct Tokens {
145110
/// Tokens to create [`apb::ApbClk`]s
146111
pub apbs: apb::ApbTokens,
@@ -170,59 +135,6 @@ pub struct Tokens {
170135
/// [`Mclk`] PAC structs and returns the [`Buses`], [`Clocks`] and [`Tokens`].
171136
///
172137
/// See the [module-level documentation](super) for more details.
173-
#[hal_cfg("clock-d5x")]
174-
#[inline]
175-
pub fn clock_system_at_reset(
176-
oscctrl: Oscctrl,
177-
osc32kctrl: Osc32kctrl,
178-
gclk: Gclk,
179-
mclk: Mclk,
180-
) -> (Buses, Clocks, Tokens) {
181-
// Safety: No bus, clock or token is instantiated more than once
182-
unsafe {
183-
let buses = Buses {
184-
ahb: ahb::Ahb::new(),
185-
apb: apb::Apb::new(),
186-
};
187-
let pac = Pac {
188-
oscctrl,
189-
osc32kctrl,
190-
gclk,
191-
mclk,
192-
};
193-
let dfll = Enabled::<_>::new(dfll::Dfll::open_loop(dfll::DfllToken::new()));
194-
let (gclk0, dfll) = gclk::Gclk0::from_source(gclk::GclkToken::new(), dfll);
195-
let gclk0 = Enabled::new(gclk0);
196-
let osculp32k_clocks = {
197-
OscUlp32kClocks {
198-
base: osculp32k::OscUlp32kBase::new(),
199-
}
200-
};
201-
let clocks = Clocks {
202-
pac,
203-
ahbs: ahb::AhbClks::new(),
204-
apbs: apb::ApbClks::new(),
205-
gclk0,
206-
dfll,
207-
osculp32k: osculp32k_clocks,
208-
};
209-
let tokens = Tokens {
210-
apbs: apb::ApbTokens::new(),
211-
dpll0: dpll::DpllToken::new(),
212-
dpll1: dpll::DpllToken::new(),
213-
gclks: gclk::GclkTokens::new(),
214-
pclks: pclk::PclkTokens::new(),
215-
rtcosc: rtcosc::RtcOscToken::new(),
216-
xosc0: xosc::XoscToken::new(),
217-
xosc1: xosc::XoscToken::new(),
218-
xosc32k: xosc32k::Xosc32kTokens::new(),
219-
osculp32k: osculp32k::OscUlp32kTokens::new(),
220-
};
221-
(buses, clocks, tokens)
222-
}
223-
}
224-
225-
#[hal_cfg(any("clock-d11", "clock-d21"))]
226138
#[inline]
227139
pub fn clock_system_at_reset(
228140
oscctrl: Oscctrl,
@@ -245,20 +157,21 @@ pub fn clock_system_at_reset(
245157
let dfll = Enabled::<_>::new(dfll::Dfll::open_loop(dfll::DfllToken::new()));
246158
let (gclk0, dfll) = gclk::Gclk0::from_source(gclk::GclkToken::new(), dfll);
247159
let gclk0 = Enabled::new(gclk0);
248-
let osculp32k_clocks = {
249-
OscUlp32kClocks {
250-
base: osculp32k::OscUlp32kBase::new(),
251-
osculp1k: Enabled::new(osculp32k::OscUlp1k::new()),
252-
osculp32k: Enabled::new(osculp32k::OscUlp32k::new()),
253-
}
160+
let base = Enabled::new(osculp32k::OscUlp32kBase::new());
161+
let osculp1k = Enabled::new(osculp32k::OscUlp1k::new());
162+
let osculp32k = Enabled::new(osculp32k::OscUlp32k::new());
163+
let osculp = OscUlpClocks {
164+
base,
165+
osculp1k,
166+
osculp32k,
254167
};
255168
let clocks = Clocks {
256169
pac,
257170
ahbs: ahb::AhbClks::new(),
258171
apbs: apb::ApbClks::new(),
259172
gclk0,
260173
dfll,
261-
osculp32k: osculp32k_clocks,
174+
osculp,
262175
};
263176
let tokens = Tokens {
264177
apbs: apb::ApbTokens::new(),

0 commit comments

Comments
 (0)