Skip to content

Commit

Permalink
pw_clock_tree_mcuxpresso: Make Mclk and ClkIn dependent elements
Browse files Browse the repository at this point in the history
This change switches Mclk and ClkIn from being derived
from the ClockSource class to the DependentElement class,
so that it can be used by platforms that require another
clock tree element to enable the Mclk and ClkIn clock sources,
as well as platforms that can directly enable these clock
sources by using the `ClockSourceNoOp` dependent clock source
element.

Test: pw presubmit --step=gn_mimxrt595_build
Test: pw presubmit --step=gn_mimxrt595_freertos_build

Bug: 331672574
Change-Id: I878884e9f2d6d433501ab659da1d5f91cc41bdea
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/213853
Reviewed-by: Austin Foxley <[email protected]>
Commit-Queue: Christoph Klee <[email protected]>
Lint: Lint 🤖 <[email protected]>
  • Loading branch information
Christoph Klee authored and CQ Bot Account committed Jun 4, 2024
1 parent 1aa7f44 commit a31661c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 23 deletions.
7 changes: 6 additions & 1 deletion pw_clock_tree_mcuxpresso/examples.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ PW_CONSTINIT pw::clock_tree::ClockMcuxpressoDividerNonBlocking i3c0_divider(
// inclusive-language: disable
// DOCSTAG: [pw_clock_tree_mcuxpresso-examples-ClockTreeElementDefs-Ctimer0]

// Need to define `ClockSourceNoOp` clock tree element to satisfy dependency for
// `ClockMcuxpressoMclk` class.
PW_CONSTINIT pw::clock_tree::ClockSourceNoOp clock_source_no_op;

// Define Master clock
PW_CONSTINIT pw::clock_tree::ClockMcuxpressoMclk mclk(19200000);
PW_CONSTINIT pw::clock_tree::ClockMcuxpressoMclkNonBlocking mclk(
clock_source_no_op, 19200000);

// Define clock selector CTIMER0
PW_CONSTINIT pw::clock_tree::ClockMcuxpressoSelectorNonBlocking ctimer_0(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,17 @@ class ClockMcuxpressoLpOsc final
}
};

/// Class implementing the MCLK IN clock source.
class ClockMcuxpressoMclk final
: public ClockSource<ElementNonBlockingCannotFail> {
/// Class template implementing the MCLK IN clock source.
///
/// Template argument `ElementType` can be of class `ElementBlocking` or
/// `ElementNonBlockingCannotFail`.
template <typename ElementType>
class ClockMcuxpressoMclk final : public DependentElement<ElementType> {
public:
/// Constructor specifying the MCLK IN clock frequency in Hz.
constexpr ClockMcuxpressoMclk(uint32_t frequency) : frequency_(frequency) {}
/// Constructor specifying the MCLK IN clock frequency in Hz and
/// the dependent clock tree element to enable the MCLK clock source.
constexpr ClockMcuxpressoMclk(ElementType& source, uint32_t frequency)
: DependentElement<ElementType>(source), frequency_(frequency) {}

private:
/// Set MCLK IN clock frequency.
Expand All @@ -88,12 +93,25 @@ class ClockMcuxpressoMclk final
uint32_t frequency_;
};

/// Class implementing the CLK IN pin clock source.
class ClockMcuxpressoClkIn final
: public ClockSource<ElementNonBlockingCannotFail> {
/// Alias for a blocking MCLK IN clock tree element.
using ClockMcuxpressoMclkBlocking = ClockMcuxpressoMclk<ElementBlocking>;

/// Alias for a non-blocking MCLK IN clock tree element where updates cannot
/// fail.
using ClockMcuxpressoMclkNonBlocking =
ClockMcuxpressoMclk<ElementNonBlockingCannotFail>;

/// Class template implementing the CLK IN pin clock source.
///
/// Template argument `ElementType` can be of class `ElementBlocking` or
/// `ElementNonBlockingCannotFail`.
template <typename ElementType>
class ClockMcuxpressoClkIn final : public DependentElement<ElementType> {
public:
/// Constructor specifying the CLK IN pin clock frequency in Hz.
constexpr ClockMcuxpressoClkIn(uint32_t frequency) : frequency_(frequency) {}
/// Constructor specifying the CLK IN pin clock frequency in Hz and
/// the dependent clock tree element to enable the CLK IN pin clock source.
constexpr ClockMcuxpressoClkIn(ElementType& source, uint32_t frequency)
: DependentElement<ElementType>(source), frequency_(frequency) {}

private:
/// Set CLK IN clock frequency.
Expand All @@ -113,11 +131,18 @@ class ClockMcuxpressoClkIn final
uint32_t frequency_;
};

/// Class implementing the FRG clock tree element.
/// Alias for a blocking CLK IN pin clock tree element.
using ClockMcuxpressoClkInBlocking = ClockMcuxpressoClkIn<ElementBlocking>;

/// Alias for a non-blocking CLK IN pin clock tree element where updates cannot
/// fail.
using ClockMcuxpressoClkInNonBlocking =
ClockMcuxpressoClkIn<ElementNonBlockingCannotFail>;

/// Class template implementing the FRG clock tree element.
///
/// Template argument `ElementType` can be of class `ElementBlocking`,
/// `ElementNonBlockingCannotFail` or
/// `ElementNonBlockingMightFail.`
/// Template argument `ElementType` can be of class `ElementBlocking` or
/// `ElementNonBlockingCannotFail`.
template <typename ElementType>
class ClockMcuxpressoFrg final : public DependentElement<ElementType> {
public:
Expand Down Expand Up @@ -152,15 +177,17 @@ class ClockMcuxpressoFrg final : public DependentElement<ElementType> {
const clock_frg_clk_config_t& config_;
};

/// Alias for a blocking FRG clock tree element.
using ClockMcuxpressoFrgBlocking = ClockMcuxpressoFrg<ElementBlocking>;

/// Alias for a non-blocking FRG clock tree element where updates cannot fail.
using ClockMcuxpressoFrgNonBlocking =
ClockMcuxpressoFrg<ElementNonBlockingCannotFail>;

/// Class implementing the clock selector element.
/// Class template implementing the clock selector element.
///
/// Template argument `ElementType` can be of class `ElementBlocking`,
/// `ElementNonBlockingCannotFail` or
/// `ElementNonBlockingMightFail.`
/// Template argument `ElementType` can be of class `ElementBlocking` or
/// `ElementNonBlockingCannotFail`.
template <typename ElementType>
class ClockMcuxpressoSelector : public DependentElement<ElementType> {
public:
Expand Down Expand Up @@ -193,16 +220,19 @@ class ClockMcuxpressoSelector : public DependentElement<ElementType> {
clock_attach_id_t selector_disable_;
};

/// Alias for a blocking clock selector clock tree element.
using ClockMcuxpressoSelectorBlocking =
ClockMcuxpressoSelector<ElementBlocking>;

/// Alias for a non-blocking clock selector clock tree element where updates
/// cannot fail.
using ClockMcuxpressoSelectorNonBlocking =
ClockMcuxpressoSelector<ElementNonBlockingCannotFail>;

/// Class implementing the clock divider element.
/// Class template implementing the clock divider element.
///
/// Template argument `ElementType` can be of class `ElementBlocking`,
/// `ElementNonBlockingCannotFail` or
/// `ElementNonBlockingMightFail.`
/// Template argument `ElementType` can be of class `ElementBlocking` or
/// `ElementNonBlockingCannotFail`.
template <typename ElementType>
class ClockMcuxpressoDivider final : public ClockDividerElement<ElementType> {
public:
Expand All @@ -225,7 +255,11 @@ class ClockMcuxpressoDivider final : public ClockDividerElement<ElementType> {
clock_div_name_t divider_name_;
};

/// Alias for a blocking clock divider clock tree element.
using ClockMcuxpressoDividerBlocking = ClockMcuxpressoDivider<ElementBlocking>;

/// Alias for a non-blocking clock divider clock tree element where updates
/// cannot fail.
using ClockMcuxpressoDividerNonBlocking =
ClockMcuxpressoDivider<ElementNonBlockingCannotFail>;

Expand Down

0 comments on commit a31661c

Please sign in to comment.