APIs#
pw_clock_tree: Clock tree management for embedded devices
ClockTree#
-
class ClockTree#
Clock tree class that manages the state of clock tree elements.
The
ClockTree
provides theAcquire
andRelease
methods to acquire a reference toElementNonBlockingCannotFail
,ElementNonBlockingMightFail
, orElementBlocking
elements or to the genericElement
element. These functions will acquire the proper lock to ensure that clock updates are synchronized.The
SetDividerValue
method allows to change the divider value forClockDividerNonBlockingCannotFail
,ClockDividerNonBlockingMightFail
orClockDividerBlocking
elements, or to the genericClockDivider
element.Public Functions
-
inline void Acquire(ElementNonBlockingCannotFail &element)#
Acquire a reference to a non-blocking clock tree element. Acquiring the clock tree element will succeed.
-
inline Status Acquire(ElementNonBlockingMightFail &element)#
Acquire a reference to a non-blocking clock tree element. Acquiring the clock tree element might fail.
-
inline Status Acquire(ElementBlocking &element)#
Acquire a reference to a blocking clock tree element. Acquiring the clock tree element might fail.
-
inline Status Acquire(Element &element)#
Acquire a reference to a clock tree element. Acquiring the clock tree element might fail.
Note: May not be called from inside an interrupt context or with interrupts disabled.
-
inline Status AcquireWith(Element &element, Element &element_with)#
Acquire a reference to clock tree element
element
whileelement_with
clock tree is enabled. Acquiring the clock tree element might fail.Note: May not be called from inside an interrupt context or with interrupts disabled.
-
inline void Release(ElementNonBlockingCannotFail &element)#
Release a reference to a non-blocking clock tree element. Releasing the clock tree element will succeed.
-
inline Status Release(ElementNonBlockingMightFail &element)#
Release a reference to a non-blocking clock tree element. Releasing the clock tree element might fail.
-
inline Status Release(ElementBlocking &element)#
Release a reference to a blocking clock tree element. Releasing the clock tree element might fail.
-
inline Status Release(Element &element)#
Release a reference to a clock tree element. Releasing the clock tree element might fail.
Note: May not be called from inside an interrupt context or with interrupts disabled.
-
inline void SetDividerValue(ClockDividerNonBlockingCannotFail &clock_divider, uint32_t divider_value)#
Set divider value for a non-blocking clock divider element. Setting the clock divider value will succeed.
-
inline Status SetDividerValue(ClockDividerNonBlockingMightFail &clock_divider, uint32_t divider_value)#
Set divider value for a non-blocking clock divider element. Setting the clock divider value might fail.
-
inline Status SetDividerValue(ClockDividerBlocking &clock_divider, uint32_t divider_value)#
Set divider value for a blocking clock divider element. Setting the clock divider value might fail.
-
inline Status SetDividerValue(ClockDivider &clock_divider, uint32_t divider_value)#
Set divider value for a clock divider element. Setting the clock divider value might fail.
Note: May not be called from inside an interrupt context or with interrupts disabled.
-
inline void Acquire(ElementNonBlockingCannotFail &element)#
Element#
-
class Element#
Abstract base class for a clock tree element of a clock tree.
Class implementations of
Element
must implementAcquire
andRelease
functions. For clock tree elements that only get enabled / configured, it is sufficient to only override theDoEnable
function, otherwise it is required to override theDoDisable
function to disable the respective clock tree element.Note: Clock tree element classes shouldn’t be directly derived from the
Element
class, but from theElementBlocking
,ElementNonBlockingCannotFail
orElementNonBlockingMightFail
class.Subclassed by pw::clock_tree::ElementBlocking, pw::clock_tree::ElementNonBlockingCannotFail, pw::clock_tree::ElementNonBlockingMightFail
Public Functions
-
inline uint32_t ref_count() const#
Get reference count for this clock tree element.
-
inline bool may_block() const#
Check whether acquiring or releasing the element may block.
Protected Functions
-
virtual Status Acquire() = 0#
Acquire a reference to the clock tree element.
Acquiring a reference to a clock tree element ensures that the clock tree element is configured and enabled.
If the clock tree element depends on another clock tree element, a reference to the dependent clock tree element will get acquired when the first reference to this clock tree element gets acquired. This ensures that all dependent clock tree elements have been enabled before this clock tree element gets configured and enabled.
-
virtual Status Release() = 0#
Release a reference to the clock tree element.
Releasing the last reference to the clock tree element will disable the clock tree element.
When the last reference to the clock tree element gets released, the clock tree element gets disabled if the
DoDisable
function is overridden.If the clock tree element depends on another clock tree element, a reference to the dependent clock tree element will get released once the last reference to this clock tree element has been released and the clock tree element has been disabled. This ensures that the clock tree element gets disabled before all dependent clock tree elements have been disabled.
-
inline uint32_t IncRef()#
Increment reference count and return incremented value.
-
inline uint32_t DecRef()#
Decrement reference count and return decremented value.
-
inline uint32_t ref_count() const#
ElementBlocking#
ElementNonBlockingCannotFail#
-
class ElementNonBlockingCannotFail : public pw::clock_tree::Element#
Abstract class of a clock tree element that will not block to perform element updates and will not fail when performing clock updates.
Subclassed by pw::clock_tree::ClockSource< ElementNonBlockingCannotFail >
ElementNonBlockingMightFail#
ClockSource#
-
template<typename ElementType>
class ClockSource : public ElementType# Abstract class template of a clock tree element that provides a clock source.
A
ClockSource
clock tree element does not depend on any other clock tree element, but provides a clock to the system that is not derived from another clock.Class implementations of
ClockSource
must implementAcquire
andRelease
functions. For clock sources that only get enabled / configured, it is sufficient to only override theDoEnable
function, otherwise it is required to override theDoDisable
function to disable the clock source.Template argument
ElementType
can be of classElementBlocking
,ElementNonBlockingCannotFail
orElementNonBlockingMightFail.
ClockSourceNoOp#
-
class ClockSourceNoOp : public pw::clock_tree::ClockSource<ElementNonBlockingCannotFail>#
Class that represents a no-op clock source clock tree element that can be used to satisfy the dependent source clock tree element dependency for clock source classes that expect a source clock tree element.
DependentElement#
-
template<typename ElementType>
class DependentElement : public ElementType# Abstract class template of a clock tree element that depends on another clock tree element.
A
DependentElement
clock tree element depends on another clock tree element.Class implementations of
DependentElement
must override theDoEnable
function, theDoDisable
function can be overridden to disable the dependent clock tree element to save power.Template argument
ElementType
can be of classElementBlocking
,ElementNonBlockingCannotFail
orElementNonBlockingMightFail.
Subclassed by pw::clock_tree::ClockDividerElement< ElementType >, pw::clock_tree::ClockMcuxpressoAudioPll< ElementType >, pw::clock_tree::ClockMcuxpressoClkIn< ElementType >, pw::clock_tree::ClockMcuxpressoClockIp< ElementType >, pw::clock_tree::ClockMcuxpressoFrg< ElementType >, pw::clock_tree::ClockMcuxpressoMclk< ElementType >, pw::clock_tree::ClockMcuxpressoRtc< ElementType >, pw::clock_tree::ClockMcuxpressoSelector< ElementType >
Public Functions
-
inline constexpr DependentElement(ElementType &source)#
Create a dependent clock tree element that depends on
source
.
Protected Functions
-
inline Status UpdateSource(ElementType &new_source, bool permit_change_if_in_use)#
Update source dependency.
It is the responsibility of the derived class to ensure that the source dependency can only be changed when permitted, i.e. only if reference count is zero. If the update is permitted while the reference count is greater than zero, the caller of this function must make sure that the
DoEnable
method has access to the updated configuration matching the newsource
dependency. Only if theUpdateSource
call succeeds, the new source has been configured as thesource_
element for this element, otherwise the old source element is still configured assource_
element for this element. If theDoEnable
call of the new source fails, the current element will be disabled, since the previous source got already released, and the old source remains configured as the dependent element.
-
inline constexpr DependentElement(ElementType &source)#
ClockDivider#
-
class ClockDivider#
Abstract class of the clock divider specific interface.
The clock divider interface allows APIs to accept a
ClockDivider
element, if they want to use theClockTree
’sSetDividerValue
method. They can use theelement
method to call theClockTree
’sAcquire
andRelease
methods.Subclassed by pw::clock_tree::ClockDividerElement< ElementType >
ClockDividerElement#
-
template<typename ElementType>
class ClockDividerElement : public pw::clock_tree::DependentElement<ElementType>, public pw::clock_tree::ClockDivider# Abstract class template of a clock divider element.
A
ClockDivider
clock tree element depends on another clock tree element and has a divider value that gets configured when the clock divider gets enabled.Class implementations of
ClockDivider
must override theDoEnable
function.Template argument
ElementType
can be of classElementBlocking
,ElementNonBlockingCannotFail
orElementNonBlockingMightFail.
Subclassed by pw::clock_tree::ClockMcuxpressoDivider< ElementType >
Public Functions
-
inline constexpr ClockDividerElement(ElementType &source, uint32_t divider)#
Create a clock divider element that depends on
source
and gets configured withdivider
value when enabled.
Protected Functions
-
inline uint32_t divider() const#
Get current divider value.
-
inline constexpr ClockDividerElement(ElementType &source, uint32_t divider)#
ElementController#
-
class ElementController#
Helper class that allows drivers to accept optional clock tree information and streamline clock tree operations.
Public Functions
-
inline constexpr ElementController(ClockTree *clock_tree = nullptr, Element *element = nullptr)#
Create an element controller that accepts optional clock tree and element information.
-
inline Status Acquire()#
Acquire a reference to the optional clock tree element.
If not both optional clock_tree and element pointers are non-null, the function just returns
pw::OkStatus()
.
-
inline Status Release()#
Release a reference to the optional clock tree element.
If not both optional clock_tree and element pointers are non-null, the function just returns
pw::OkStatus()
.
-
inline constexpr ElementController(ClockTree *clock_tree = nullptr, Element *element = nullptr)#