Embedded Artistry Framework
Embedded Systems C++ Framework
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
embvm::clk::SystemClock Class Referenceabstract

This class defines common system clock interfaces. More...

#include <system_clock.hpp>

Inheritance diagram for embvm::clk::SystemClock:
Inheritance graph

Public Types

using spin_duration_t = std::chrono::duration< uint32_t, std::micro >
 Default spin increment is microseconds. More...
 
using tick_duration_t = std::chrono::duration< uint64_t, std::micro >
 

Public Member Functions

virtual freq_hz_t::rep frequency () const noexcept=0
 Get the frequency of the system clock. More...
 
virtual tick_duration_t::rep ticks () const noexcept=0
 Check the ticks elapsed since boot. More...
 
virtual void spin (spin_duration_t::rep count) noexcept=0
 Spin the processor for the specified number of ticks. More...
 
void start () noexcept
 Start the driver. More...
 
void stop () noexcept
 Stop the driver. More...
 
void restart () noexcept
 Restart the driver. More...
 
type_safe::boolean started () const noexcept
 Check if the driver has been started. More...
 
constexpr embvm::DriverType_t DriverType () const noexcept
 Returns the registered type ID of the driver. More...
 
constexpr const std::string_view & name () const noexcept
 Provides a string_view reference of the driver name. More...
 
constexpr const char * name_cstr () const noexcept
 Provides a c-string version of the driver name. More...
 
virtual DriverBaseoperator++ () noexcept
 Increment operator is a no-op, but is used for iterator compatibility. More...
 

Static Public Member Functions

static constexpr embvm::DriverType type () noexcept
 SystemClock Driver Type ID. More...
 

Protected Member Functions

 SystemClock () noexcept
 Default constructor. More...
 
 ~SystemClock () noexcept
 Default destructor. More...
 
void start_ () noexcept override=0
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
void stop_ () noexcept override=0
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 

Protected Attributes

type_safe::boolean started_ = false
 Tracks the driver state. More...
 
const std::string_view name_
 Name of the driver instance. More...
 
const embvm::DriverType_t type_
 Type ID of the driver instance. More...
 

Detailed Description

This class defines common system clock interfaces.

Define a system clock driver

To create a system clock driver, derive from the SystemClock object:

class SimulatorSystemClock final : public SystemClock
{ ... };

Derived classes must implement the following interfaces:

Derived classes must also implement pure virtual embvm::DriverBase functions:

Member Typedef Documentation

◆ spin_duration_t

using embvm::clk::SystemClock::spin_duration_t = std::chrono::duration<uint32_t, std::micro>

Default spin increment is microseconds.

◆ tick_duration_t

using embvm::clk::SystemClock::tick_duration_t = std::chrono::duration<uint64_t, std::micro>

Constructor & Destructor Documentation

◆ SystemClock()

embvm::clk::SystemClock::SystemClock ( )
inlineprotectednoexcept

Default constructor.

Initializes the SystemClock instance with a generic name.

◆ ~SystemClock()

SystemClock::~SystemClock ( )
protecteddefaultnoexcept

Default destructor.

Member Function Documentation

◆ DriverType()

constexpr embvm::DriverType_t embvm::DriverBase::DriverType ( ) const
inlinenoexceptinherited

Returns the registered type ID of the driver.

When using DriverBase interfaces, clients can retrieve the registered driver type in order to up-cast to the correct interface.

The type is returned as a embvm::DriverType_t rather than a embvm::DriverType enum to work with custom user-defined types. Enforcing a embvm::DriverType return value would prevent clients from defining and using their own custom types.

Returns
the registered driver type as a embvm::DriverType_t value

References embvm::DriverBase::type_.

◆ frequency()

virtual freq_hz_t::rep embvm::clk::SystemClock::frequency ( ) const
pure virtualnoexcept

Get the frequency of the system clock.

Returns
the frequency of the system clock, in Hz.

Implemented in embdrv::SimulatorSystemClock.

◆ name()

constexpr const std::string_view& embvm::DriverBase::name ( ) const
inlinenoexceptinherited

Provides a string_view reference of the driver name.

Returns
std::string_view ref containing the driver name.

References embvm::DriverBase::name_.

◆ name_cstr()

constexpr const char* embvm::DriverBase::name_cstr ( ) const
inlinenoexceptinherited

Provides a c-string version of the driver name.

Returns
c-string containing the driver name

References embvm::DriverBase::name_.

◆ operator++()

virtual DriverBase& embvm::DriverBase::operator++ ( )
inlinevirtualnoexceptinherited

Increment operator is a no-op, but is used for iterator compatibility.

◆ restart()

void embvm::DriverBase::restart ( )
inlinenoexceptinherited

Restart the driver.

Calls stop() and then start() on the driver. If the driver is not started, then it will be started after the start() function is invoked.

References embvm::DriverBase::start(), and embvm::DriverBase::stop().

◆ spin()

virtual void embvm::clk::SystemClock::spin ( spin_duration_t::rep  count)
pure virtualnoexcept

Spin the processor for the specified number of ticks.

Derived classes must implement the spin() function.

Parameters
countThe number of ticks to spin the processor for.

Implemented in embdrv::SimulatorSystemClock.

◆ start()

void embvm::DriverBase::start ( )
inlinenoexceptinherited

◆ start_()

void embvm::clk::SystemClock::start_ ( )
overrideprotectedpure virtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::DriverBase.

Implemented in embdrv::SimulatorSystemClock.

◆ started()

type_safe::boolean embvm::DriverBase::started ( ) const
inlinenoexceptinherited

Check if the driver has been started.

Returns
true if the driver is running (started), false if not running (stopped).

References embvm::DriverBase::started_.

Referenced by embdrv::aardvarkSPIMaster::configure_(), embdrv::aardvarkGPIOInput< 4 >::get(), embdrv::aardvarkGPIOOutput< 5 >::set(), embdrv::vl53l1x::start_(), embdrv::aardvarkAdapter::start_(), and embdrv::aardvarkAdapter::stop_().

◆ stop()

void embvm::DriverBase::stop ( )
inlinenoexceptinherited

◆ stop_()

void embvm::clk::SystemClock::stop_ ( )
overrideprotectedpure virtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::DriverBase.

Implemented in embdrv::SimulatorSystemClock.

◆ ticks()

virtual tick_duration_t::rep embvm::clk::SystemClock::ticks ( ) const
pure virtualnoexcept

Check the ticks elapsed since boot.

Derived classes must implement the ticks() function.

Returns
ticks elapsed since boot.

Implemented in embdrv::SimulatorSystemClock.

Referenced by embvm::LoggerBase< TLock >::log().

◆ type()

static constexpr embvm::DriverType embvm::clk::SystemClock::type ( )
inlinestaticnoexcept

SystemClock Driver Type ID.

Returns
SystemClock type ID.

References embvm::SYSTEM_CLOCK.

Member Data Documentation

◆ name_

const std::string_view embvm::DriverBase::name_
protectedinherited

Name of the driver instance.

Referenced by embvm::DriverBase::name(), and embvm::DriverBase::name_cstr().

◆ started_

type_safe::boolean embvm::DriverBase::started_ = false
protectedinherited

Tracks the driver state.

True if the driver has been started, false if it has been stopped or not yet started.

Referenced by embvm::DriverBase::start(), embvm::DriverBase::started(), and embvm::DriverBase::stop().

◆ type_

const embvm::DriverType_t embvm::DriverBase::type_
protectedinherited

Type ID of the driver instance.

Referenced by embvm::DriverBase::DriverType().


The documentation for this class was generated from the following files: