aboutsummaryrefslogtreecommitdiff
path: root/embassy-mcxa/src/clocks/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-mcxa/src/clocks/config.rs')
-rw-r--r--embassy-mcxa/src/clocks/config.rs115
1 files changed, 114 insertions, 1 deletions
diff --git a/embassy-mcxa/src/clocks/config.rs b/embassy-mcxa/src/clocks/config.rs
index 9f97160ff..4beca5f27 100644
--- a/embassy-mcxa/src/clocks/config.rs
+++ b/embassy-mcxa/src/clocks/config.rs
@@ -121,8 +121,12 @@ pub struct ClocksConfig {
121 pub fro16k: Option<Fro16KConfig>, 121 pub fro16k: Option<Fro16KConfig>,
122 /// SOSC, clk_in clock source 122 /// SOSC, clk_in clock source
123 pub sosc: Option<SoscConfig>, 123 pub sosc: Option<SoscConfig>,
124 /// SPLL
125 pub spll: Option<SpllConfig>,
124} 126}
125 127
128// SOSC
129
126/// The mode of the external reference clock 130/// The mode of the external reference clock
127#[derive(Copy, Clone)] 131#[derive(Copy, Clone)]
128pub enum SoscMode { 132pub enum SoscMode {
@@ -132,7 +136,7 @@ pub enum SoscMode {
132 ActiveClock, 136 ActiveClock,
133} 137}
134 138
135// SOSC/clk_in configuration 139/// SOSC/clk_in configuration
136#[derive(Copy, Clone)] 140#[derive(Copy, Clone)]
137pub struct SoscConfig { 141pub struct SoscConfig {
138 /// Mode of the external reference clock 142 /// Mode of the external reference clock
@@ -143,6 +147,114 @@ pub struct SoscConfig {
143 pub power: PoweredClock, 147 pub power: PoweredClock,
144} 148}
145 149
150// SPLL
151
152/// PLL1/SPLL configuration
153pub struct SpllConfig {
154 /// Input clock source for the PLL1/SPLL
155 pub source: SpllSource,
156 /// Mode of operation for the PLL1/SPLL
157 pub mode: SpllMode,
158 /// Power state of the SPLL
159 pub power: PoweredClock,
160 /// Is the "pll1_clk_div" clock enabled?
161 pub pll1_clk_div: Option<Div8>,
162}
163
164/// Input clock source for the PLL1/SPLL
165pub enum SpllSource {
166 /// External Oscillator (8-50MHz)
167 Sosc,
168 /// Fast Internal Oscillator (45MHz)
169 // NOTE: Figure 69 says "firc_45mhz"/"clk_45m", not "fro_hf_gated",
170 // so this is is always 45MHz.
171 Firc,
172 /// S Internal Oscillator (12M)
173 Sirc,
174 // TODO: the reference manual hints that ROSC is possible,
175 // however the minimum input frequency is 32K, but ROSC is 16K.
176 // Some diagrams show this option, and some diagrams omit it.
177 // SVD shows it as "reserved".
178 //
179 // /// Realtime Internal Oscillator (16K Osc)
180 // Rosc,
181}
182
183/// Mode of operation for the SPLL/PLL1
184///
185/// NOTE: Currently, only "Mode 1" normal operational modes are implemented,
186/// as described in the Reference Manual.
187#[non_exhaustive]
188pub enum SpllMode {
189 /// Mode 1a does not use the Pre/Post dividers.
190 ///
191 /// `Fout = m_mult x SpllSource`
192 ///
193 /// Both of the following constraints must be met:
194 ///
195 /// * Fout: 275MHz to 550MHz
196 /// * Fout: 4.3MHz to 2x Max CPU Frequency
197 Mode1a {
198 /// PLL Multiplier. Must be in the range 1..=65535.
199 m_mult: u16,
200 },
201
202 /// Mode 1b does not use the Pre-divider.
203 ///
204 /// * `if !bypass_p2_div: Fout = (M / (2 x P)) x Fin`
205 /// * `if bypass_p2_div: Fout = (M / P ) x Fin`
206 ///
207 /// Both of the following constraints must be met:
208 ///
209 /// * Fcco: 275MHz to 550MHz
210 /// * `Fcco = m_mult x SpllSource`
211 /// * Fout: 4.3MHz to 2x Max CPU Frequency
212 Mode1b {
213 /// PLL Multiplier. `m_mult` must be in the range 1..=65535.
214 m_mult: u16,
215 /// Post Divider. `p_div` must be in the range 1..=31.
216 p_div: u8,
217 /// Bonus post divider
218 bypass_p2_div: bool,
219 },
220
221 /// Mode 1c does use the Pre-divider, but does not use the Post-divider
222 ///
223 /// `Fout = (M / N) x Fin`
224 ///
225 /// Both of the following constraints must be met:
226 ///
227 /// * Fout: 275MHz to 550MHz
228 /// * Fout: 4.3MHz to 2x Max CPU Frequency
229 Mode1c {
230 /// PLL Multiplier. `m_mult` must be in the range 1..=65535.
231 m_mult: u16,
232 /// Pre Divider. `n_div` must be in the range 1..=255.
233 n_div: u8,
234 },
235
236 /// Mode 1b uses both the Pre and Post dividers.
237 ///
238 /// * `if !bypass_p2_div: Fout = (M / (N x 2 x P)) x Fin`
239 /// * `if bypass_p2_div: Fout = (M / ( N x P )) x Fin`
240 ///
241 /// Both of the following constraints must be met:
242 ///
243 /// * Fcco: 275MHz to 550MHz
244 /// * `Fcco = (m_mult x SpllSource) / (n_div x p_div (x 2))`
245 /// * Fout: 4.3MHz to 2x Max CPU Frequency
246 Mode1d {
247 /// PLL Multiplier. `m_mult` must be in the range 1..=65535.
248 m_mult: u16,
249 /// Pre Divider. `n_div` must be in the range 1..=255.
250 n_div: u8,
251 /// Post Divider. `p_div` must be in the range 1..=31.
252 p_div: u8,
253 /// Bonus post divider
254 bypass_p2_div: bool,
255 },
256}
257
146// FIRC/FRO180M 258// FIRC/FRO180M
147 259
148/// ```text 260/// ```text
@@ -222,6 +334,7 @@ impl Default for ClocksConfig {
222 vdd_core_domain_active: true, 334 vdd_core_domain_active: true,
223 }), 335 }),
224 sosc: None, 336 sosc: None,
337 spll: None,
225 } 338 }
226 } 339 }
227} 340}