18#include "pw_clock_tree/clock_tree.h"
20namespace pw::clock_tree {
24 :
public ClockSource<ElementNonBlockingCannotFail> {
28 : fro_output_(fro_output) {}
33 CLOCK_EnableFroClk(CLKCTL0->FRODIVOEN | fro_output_);
39 CLOCK_EnableFroClk(CLKCTL0->FRODIVOEN & ~fro_output_);
44 const uint32_t fro_output_;
49 :
public ClockSource<ElementNonBlockingCannotFail> {
54 POWER_DisablePD(kPDRUNCFG_PD_LPOSC);
58 CLOCK_EnableLpOscClk();
65 POWER_EnablePD(kPDRUNCFG_PD_LPOSC);
75template <
typename ElementType>
87 CLOCK_SetMclkFreq(frequency_);
105using ClockMcuxpressoMclkBlocking = ClockMcuxpressoMclk<ElementBlocking>;
109using ClockMcuxpressoMclkNonBlocking =
110 ClockMcuxpressoMclk<ElementNonBlockingCannotFail>;
117template <
typename ElementType>
129 CLOCK_SetClkinFreq(frequency_);
132 const uint8_t kCLOCK_OscClkIn = CLKCTL0_SYSOSCBYPASS_SEL(1);
133 CLKCTL0->SYSOSCBYPASS = kCLOCK_OscClkIn;
140 CLOCK_SetClkinFreq(0);
143 const uint8_t kCLOCK_OscNone = CLKCTL0_SYSOSCBYPASS_SEL(7);
144 CLKCTL0->SYSOSCBYPASS = kCLOCK_OscNone;
155using ClockMcuxpressoClkInBlocking = ClockMcuxpressoClkIn<ElementBlocking>;
159using ClockMcuxpressoClkInNonBlocking =
160 ClockMcuxpressoClkIn<ElementNonBlockingCannotFail>;
166template <
typename ElementType>
171 const clock_frg_clk_config_t& config)
177 const uint8_t kCLOCK_FrgNone = 7;
181 CLOCK_SetFRGClock(&config_);
187 clock_frg_clk_config_t disable_config = config_;
188 static_assert(
sizeof(disable_config.sfg_clock_src) ==
189 sizeof(kCLOCK_FrgNone));
190 disable_config.sfg_clock_src =
191 static_cast<decltype(disable_config.sfg_clock_src)
>(kCLOCK_FrgNone);
192 CLOCK_SetFRGClock(&disable_config);
197 const clock_frg_clk_config_t& config_;
201using ClockMcuxpressoFrgBlocking = ClockMcuxpressoFrg<ElementBlocking>;
204using ClockMcuxpressoFrgNonBlocking =
205 ClockMcuxpressoFrg<ElementNonBlockingCannotFail>;
211template <
typename ElementType>
218 clock_attach_id_t selector_enable,
219 clock_attach_id_t selector_disable)
221 selector_enable_(selector_enable),
222 selector_disable_(selector_disable) {}
227 CLOCK_AttachClk(selector_enable_);
233 CLOCK_AttachClk(selector_disable_);
238 clock_attach_id_t selector_enable_;
240 clock_attach_id_t selector_disable_;
244using ClockMcuxpressoSelectorBlocking =
245 ClockMcuxpressoSelector<ElementBlocking>;
249using ClockMcuxpressoSelectorNonBlocking =
250 ClockMcuxpressoSelector<ElementNonBlockingCannotFail>;
256template <
typename ElementType>
262 clock_div_name_t divider_name,
265 divider_name_(divider_name) {}
270 CLOCK_SetClkDiv(divider_name_, this->
divider());
275 clock_div_name_t divider_name_;
279using ClockMcuxpressoDividerBlocking = ClockMcuxpressoDivider<ElementBlocking>;
283using ClockMcuxpressoDividerNonBlocking =
284 ClockMcuxpressoDivider<ElementNonBlockingCannotFail>;
297template <
typename ElementType>
302 const clock_audio_pll_config_t& config,
303 uint8_t audio_pfd_divider)
306 audio_pfd_divider_(audio_pfd_divider) {}
310 audio_pll_src_t bypass_source)
320 if (config_ !=
nullptr) {
322 CLOCK_InitAudioPll(config_);
323 CLOCK_InitAudioPfd(kCLOCK_Pfd0, audio_pfd_divider_);
326 CLKCTL1->AUDIOPLL0CLKSEL = bypass_source_;
327 CLKCTL1->AUDIOPLL0CTL0 |= CLKCTL1_AUDIOPLL0CTL0_BYPASS_MASK;
334 if (config_ !=
nullptr) {
336 CLOCK_DeinitAudioPfd(kCLOCK_Pfd0);
340 CLOCK_DeinitAudioPll();
345 const clock_audio_pll_config_t* config_ =
nullptr;
348 const uint8_t audio_pfd_divider_ = 0;
351 const audio_pll_src_t bypass_source_ = kCLOCK_AudioPllNone;
355using ClockMcuxpressoAudioPllBlocking =
356 ClockMcuxpressoAudioPll<ElementBlocking>;
360using ClockMcuxpressoAudioPllNonBlocking =
361 ClockMcuxpressoAudioPll<ElementNonBlockingCannotFail>;
367template <
typename ElementType>
379 CLOCK_EnableOsc32K(
true);
386 CLOCK_EnableOsc32K(
false);
394using ClockMcuxpressoRtcBlocking = ClockMcuxpressoRtc<ElementBlocking>;
398using ClockMcuxpressoRtcNonBlocking =
399 ClockMcuxpressoRtc<ElementNonBlockingCannotFail>;
407template <
typename ElementType>
418 CLOCK_EnableClock(clock_);
424 CLOCK_DisableClock(clock_);
428 clock_ip_name_t clock_;
434using ClockMcuxpressoClockIpBlocking = ClockMcuxpressoClockIp<ElementBlocking>;
438using ClockMcuxpressoClockIpNonBlocking =
439 ClockMcuxpressoClockIp<ElementNonBlockingCannotFail>;
Definition: clock_tree.h:365
uint32_t divider() const
Get current divider value.
Definition: clock_tree.h:396
Definition: clock_tree.h:298
constexpr ClockMcuxpressoAudioPll(ElementType &source, const clock_audio_pll_config_t &config, uint8_t audio_pfd_divider)
Constructor specifying the configuration for the enabled Audio PLL.
Definition: clock_tree.h:301
Status DoEnable() override
Definition: clock_tree.h:316
constexpr ClockMcuxpressoAudioPll(ElementType &source, audio_pll_src_t bypass_source)
Constructor to place the Audio PLL into bypass mode.
Definition: clock_tree.h:309
Status DoDisable() override
Disables the audio PLL logic.
Definition: clock_tree.h:333
Definition: clock_tree.h:118
Status DoEnable() final
Set CLK IN clock frequency.
Definition: clock_tree.h:127
constexpr ClockMcuxpressoClkIn(ElementType &source, uint32_t frequency)
Definition: clock_tree.h:122
Status DoDisable() final
Set CLK IN clock frequency to 0 Hz.
Definition: clock_tree.h:138
Definition: clock_tree.h:408
Status DoEnable() final
Enable the clock.
Definition: clock_tree.h:417
Status DoDisable() final
Disable the clock.
Definition: clock_tree.h:423
constexpr ClockMcuxpressoClockIp(ElementType &source, clock_ip_name_t clock)
Definition: clock_tree.h:412
Definition: clock_tree.h:257
constexpr ClockMcuxpressoDivider(ElementType &source, clock_div_name_t divider_name, uint32_t divider)
Definition: clock_tree.h:261
Status DoEnable() final
Set the divider configuration.
Definition: clock_tree.h:269
Definition: clock_tree.h:167
constexpr ClockMcuxpressoFrg(ElementType &source, const clock_frg_clk_config_t &config)
Constructor specifying the source clock and FRG configuration.
Definition: clock_tree.h:170
Status DoDisable() final
Disable FRG configuration.
Definition: clock_tree.h:186
Status DoEnable() final
Enable FRG configuration.
Definition: clock_tree.h:180
Class implementing an FRO clock source.
Definition: clock_tree.h:24
constexpr ClockMcuxpressoFro(clock_fro_output_en_t fro_output)
Constructor specifying the FRO divider output to manage.
Definition: clock_tree.h:27
Status DoDisable() final
Disable this FRO divider.
Definition: clock_tree.h:38
Status DoEnable() final
Enable this FRO divider.
Definition: clock_tree.h:32
Class implementing the low power oscillator clock source.
Definition: clock_tree.h:49
Status DoDisable() final
Disable low power oscillator.
Definition: clock_tree.h:63
Status DoEnable() final
Enable low power oscillator.
Definition: clock_tree.h:52
Definition: clock_tree.h:76
Status DoEnable() final
Set MCLK IN clock frequency.
Definition: clock_tree.h:85
constexpr ClockMcuxpressoMclk(ElementType &source, uint32_t frequency)
Definition: clock_tree.h:80
Status DoDisable() final
Set MCLK IN clock frequency to 0 Hz.
Definition: clock_tree.h:92
Definition: clock_tree.h:368
Status DoDisable() final
Disable 32 kHz RTS oscillator.
Definition: clock_tree.h:384
Status DoEnable() final
Enable 32 kHz RTC oscillator.
Definition: clock_tree.h:377
constexpr ClockMcuxpressoRtc(ElementType &source)
Definition: clock_tree.h:372
Definition: clock_tree.h:212
Status DoEnable() final
Enable selector.
Definition: clock_tree.h:226
constexpr ClockMcuxpressoSelector(ElementType &source, clock_attach_id_t selector_enable, clock_attach_id_t selector_disable)
Definition: clock_tree.h:217
Status DoDisable() final
Disable selector.
Definition: clock_tree.h:232
Definition: clock_tree.h:147
Definition: clock_tree.h:208
constexpr Status OkStatus()
Definition: status.h:234