Embedded Artistry Framework
Embedded Systems C++ Framework
Modules | Classes
Simulator Drivers

Drivers intended for use with simulator applications (run on host machine) More...

Collaboration diagram for Simulator Drivers:

Modules

 Aardvark Adapter Drivers
 Aardvark Adapter drivers, usable for Simulator applications.
 

Classes

class  embdrv::SimulatorSystemClock
 Simulator system clock driver. More...
 
class  embdrv::SimulatorTimer
 Simulator timer driver. More...
 

Detailed Description

Drivers intended for use with simulator applications (run on host machine)


Class Documentation

◆ embdrv::SimulatorSystemClock

class embdrv::SimulatorSystemClock

Simulator system clock driver.

This driver uses the std::chrono::steady_clock to represent a SystemClock driver for simulator applications.

Inheritance diagram for embdrv::SimulatorSystemClock:
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

 SimulatorSystemClock () noexcept
 Create a generic simulator system clock. More...
 
 ~SimulatorSystemClock () noexcept final
 Default destructor. More...
 
embvm::clk::freq_hz_t::rep frequency () const noexcept final
 Get the frequency of the system clock. More...
 
tick_duration_t::rep ticks () const noexcept final
 Check the ticks elapsed since boot. More...
 
void spin (spin_duration_t::rep count) noexcept final
 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

void start_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
void stop_ () noexcept final
 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...
 

Member Typedef Documentation

◆ spin_duration_t

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

Default spin increment is microseconds.

◆ tick_duration_t

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

Constructor & Destructor Documentation

◆ SimulatorSystemClock()

embdrv::SimulatorSystemClock::SimulatorSystemClock ( )
inlinenoexcept

Create a generic simulator system clock.

◆ ~SimulatorSystemClock()

SimulatorSystemClock::~SimulatorSystemClock ( )
finalnoexcept

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()

embvm::clk::freq_hz_t::rep embdrv::SimulatorSystemClock::frequency ( ) const
inlinefinalvirtualnoexcept

Get the frequency of the system clock.

Returns
the frequency of the system clock, in Hz.

Implements embvm::clk::SystemClock.

◆ 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()

void embdrv::SimulatorSystemClock::spin ( spin_duration_t::rep  count)
inlinefinalvirtualnoexcept

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.

Implements embvm::clk::SystemClock.

References embvm::this_thread::sleep_for().

◆ start()

◆ start_()

void embdrv::SimulatorSystemClock::start_ ( )
inlinefinalprotectedvirtualnoexcept

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

(Template Method Pattern)

Implements embvm::clk::SystemClock.

◆ 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()

◆ stop_()

void embdrv::SimulatorSystemClock::stop_ ( )
inlinefinalprotectedvirtualnoexcept

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

(Template Method Pattern)

Implements embvm::clk::SystemClock.

◆ ticks()

tick_duration_t::rep embdrv::SimulatorSystemClock::ticks ( ) const
inlinefinalvirtualnoexcept

Check the ticks elapsed since boot.

Derived classes must implement the ticks() function.

Returns
ticks elapsed since boot.

Implements embvm::clk::SystemClock.

◆ type()

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

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().

◆ embdrv::SimulatorTimer

class embdrv::SimulatorTimer

Simulator timer driver.

This driver uses a thread object to simulate a timer with a callback.

Inheritance diagram for embdrv::SimulatorTimer:
Inheritance graph

Public Member Functions

 SimulatorTimer () noexcept
 Create a simulator timer with default options. More...
 
 SimulatorTimer (embvm::timer::timer_period_t period, embvm::timer::config config=embvm::timer::config::oneshot) noexcept
 Create a timer and set configuration options. More...
 
 SimulatorTimer (embvm::timer::timer_period_t period, embvm::timer::cb_t cb, embvm::timer::config config=embvm::timer::config::oneshot) noexcept
 Create a timer and set configuration options and callback. More...
 
 SimulatorTimer (embvm::timer::timer_period_t period, embvm::timer::cb_t &&cb, embvm::timer::config config=embvm::timer::config::oneshot) noexcept
 Create a timer and set configuration options and callback. More...
 
 ~SimulatorTimer () noexcept final
 Destructor, which cleans up the timer thread. More...
 
void registerCallback (const embvm::timer::cb_t &cb) noexcept final
 Register a timer callback. More...
 
void registerCallback (embvm::timer::cb_t &&cb) noexcept final
 Register a timer callback. More...
 
embvm::timer::timer_period_t count () const noexcept final
 Read the current timer count. More...
 
void enableInterrupts () noexcept final
 
void disableInterrupts () noexcept final
 
timer_period_t period () const noexcept
 Get the current timer period. More...
 
timer_period_t period (timer_period_t period) noexcept
 Set the timer period. More...
 
virtual void restart (const timer_period_t period) noexcept
 Restart the timer with a specific period. More...
 
void restart (const timer_period_t::rep period) noexcept
 Restart the timer with a specific period. More...
 
void restart () noexcept
 Restart the timer with the currently configured period. More...
 
virtual timer::state state () const noexcept
 Check the state of the timer. More...
 
virtual timer::config config () const noexcept
 Check the configuration of the timer. More...
 
virtual timer::config config (timer::config c) noexcept
 Set the timer configuration. More...
 
void start () noexcept
 Start the driver. More...
 
void stop () noexcept
 Stop 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...
 
void setBottomHalfDispatcher (const embutil::IRQDispatcherFunc_t &dispatcher) noexcept
 
template<typename TCallback >
void invokeCallback (TCallback &cb) noexcept
 
template<typename TCallback , typename... TArgs>
void invokeCallback (TCallback &cb, TArgs &... args) noexcept
 

Static Public Member Functions

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

Protected Attributes

timer_period_t period_ {0}
 The configured timer period. More...
 
timer::state state_ = timer::state::stopped
 The current state of the timer. More...
 
timer::config config_ = timer::config::oneshot
 The timer configuratoin. More...
 
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...
 
embutil::IRQDispatcherFunc_t dispatcher_
 

Private Member Functions

void start_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
void stop_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
void timer_thread () noexcept
 Thread which simulates a timer. More...
 

Private Attributes

std::thread timer_thread_
 
embvm::timer::cb_t cb_
 
std::atomic< boolquit_ = false
 
std::mutex mutex_
 
std::condition_variable cv_
 
embvm::timer::timer_period_t time_base_ {0}
 

Constructor & Destructor Documentation

◆ SimulatorTimer() [1/4]

embdrv::SimulatorTimer::SimulatorTimer ( )
inlinenoexcept

Create a simulator timer with default options.

References embvm::timer::Timer::config_, embvm::timer::oneshot, and embvm::timer::Timer::period_.

◆ SimulatorTimer() [2/4]

embdrv::SimulatorTimer::SimulatorTimer ( embvm::timer::timer_period_t  period,
embvm::timer::config  config = embvm::timer::config::oneshot 
)
inlineexplicitnoexcept

Create a timer and set configuration options.

Parameters
periodThe desired timer period.
configThe desired timer configuration (oneshot or periodic).

References embvm::timer::Timer::config(), embvm::timer::Timer::config_, embvm::timer::Timer::period(), and embvm::timer::Timer::period_.

◆ SimulatorTimer() [3/4]

embdrv::SimulatorTimer::SimulatorTimer ( embvm::timer::timer_period_t  period,
embvm::timer::cb_t  cb,
embvm::timer::config  config = embvm::timer::config::oneshot 
)
inlineexplicitnoexcept

Create a timer and set configuration options and callback.

Parameters
periodThe desired timer period.
cbThe callback function to invoke when the timer expires.
configThe desired timer configuration (oneshot or periodic).

References embvm::timer::Timer::config(), embvm::timer::Timer::config_, embvm::timer::Timer::period(), and embvm::timer::Timer::period_.

◆ SimulatorTimer() [4/4]

embdrv::SimulatorTimer::SimulatorTimer ( embvm::timer::timer_period_t  period,
embvm::timer::cb_t &&  cb,
embvm::timer::config  config = embvm::timer::config::oneshot 
)
inlineexplicitnoexcept

Create a timer and set configuration options and callback.

Parameters
periodThe desired timer period.
cbThe callback function to invoke when the timer expires.
configThe desired timer configuration (oneshot or periodic).

References embvm::timer::Timer::config(), embvm::timer::Timer::config_, embvm::timer::Timer::period(), and embvm::timer::Timer::period_.

◆ ~SimulatorTimer()

SimulatorTimer::~SimulatorTimer ( )
finalnoexcept

Destructor, which cleans up the timer thread.

References embvm::this_thread::sleep_for(), and embvm::DriverBase::stop().

Member Function Documentation

◆ config() [1/2]

virtual timer::config embvm::timer::Timer::config ( ) const
inlinevirtualnoexceptinherited

Check the configuration of the timer.

Returns
the current timer configuration.

References embvm::timer::Timer::config_.

Referenced by SimulatorTimer().

◆ config() [2/2]

virtual timer::config embvm::timer::Timer::config ( timer::config  c)
inlinevirtualnoexceptinherited

Set the timer configuration.

Parameters
cThe desired timer configuration (periodic or oneshot).
Returns
the current timer configuration.

References embvm::timer::Timer::config_.

◆ count()

embvm::timer::timer_period_t embdrv::SimulatorTimer::count ( ) const
inlinefinalvirtualnoexcept

Read the current timer count.

Returns
the current count of the timer

Implements embvm::timer::Timer.

References time_base_.

◆ disableInterrupts()

void SimulatorTimer::disableInterrupts ( )
finalvirtualnoexcept

Implements embvm::HALDriverBase.

◆ 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_.

◆ enableInterrupts()

void SimulatorTimer::enableInterrupts ( )
finalvirtualnoexcept

Implements embvm::HALDriverBase.

◆ invokeCallback() [1/2]

template<typename TCallback >
void embvm::HALDriverBase::invokeCallback ( TCallback &  cb)
inlinenoexceptinherited

◆ invokeCallback() [2/2]

template<typename TCallback , typename... TArgs>
void embvm::HALDriverBase::invokeCallback ( TCallback &  cb,
TArgs &...  args 
)
inlinenoexceptinherited

◆ 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.

◆ period() [1/2]

timer_period_t embvm::timer::Timer::period ( ) const
inlinenoexceptinherited

Get the current timer period.

Returns
the currently configured timer period.

References embvm::timer::Timer::period_.

Referenced by embvm::timer::Timer::period(), embvm::timer::Timer::restart(), and SimulatorTimer().

◆ period() [2/2]

timer_period_t embvm::timer::Timer::period ( timer_period_t  period)
inlinenoexceptinherited

Set the timer period.

If the timer is currently running, this call has no effect. Use restart() instead.

Parameters
periodthe desired timer period.
Returns
the currently configured timer period.

References embvm::timer::Timer::period(), and embvm::timer::Timer::period_.

◆ registerCallback() [1/2]

void embdrv::SimulatorTimer::registerCallback ( const embvm::timer::cb_t cb)
inlinefinalvirtualnoexcept

Register a timer callback.

The timer callback function is called whenever the timer expires.

Derived classes must implement this function. Derived classes can choose to support either a single callback or multiple callbacks.

Parameters
cbA callback to invoke when the timer expires.

Implements embvm::timer::Timer.

References cb_.

◆ registerCallback() [2/2]

void embdrv::SimulatorTimer::registerCallback ( embvm::timer::cb_t &&  cb)
inlinefinalvirtualnoexcept

Register a timer callback.

The timer callback function is called whenever the timer expires.

Derived classes must implement this function. Derived classes can choose to support either a single callback or multiple callbacks.

Parameters
cbA callback to invoke when the timer expires.

Implements embvm::timer::Timer.

References cb_.

◆ restart() [1/3]

virtual void embvm::timer::Timer::restart ( const timer_period_t  period)
inlinevirtualnoexceptinherited

Restart the timer with a specific period.

Parameters
periodThe desired timer period to reset the timer to use. Accepts a std::chrono value.

References embvm::timer::Timer::period(), embvm::timer::Timer::period_, embvm::DriverBase::start(), and embvm::DriverBase::stop().

◆ restart() [2/3]

void embvm::timer::Timer::restart ( const timer_period_t::rep  period)
inlinenoexceptinherited

Restart the timer with a specific period.

Parameters
periodThe desired timer period to reset the timer to use. Accepts an integral count representing the period in microseonds.

References embvm::timer::Timer::period(), and embvm::timer::Timer::restart().

◆ restart() [3/3]

void embvm::timer::Timer::restart ( )
inlinenoexceptinherited

Restart the timer with the currently configured period.

References embvm::timer::Timer::period_.

Referenced by embvm::timer::Timer::restart().

◆ setBottomHalfDispatcher()

void embvm::HALDriverBase::setBottomHalfDispatcher ( const embutil::IRQDispatcherFunc_t dispatcher)
inlinenoexceptinherited

◆ start()

◆ start_()

void SimulatorTimer::start_ ( )
finalprivatevirtualnoexcept

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

(Template Method Pattern)

Implements embvm::timer::Timer.

References embvm::timer::armed, mutex_, quit_, embvm::timer::Timer::state_, time_base_, timer_thread(), and timer_thread_.

◆ 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_().

◆ state()

virtual timer::state embvm::timer::Timer::state ( ) const
inlinevirtualnoexceptinherited

Check the state of the timer.

Returns
the current timer state.

References embvm::timer::Timer::state_.

◆ stop()

◆ stop_()

void SimulatorTimer::stop_ ( )
finalprivatevirtualnoexcept

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

(Template Method Pattern)

Implements embvm::timer::Timer.

References cv_, mutex_, quit_, embvm::timer::Timer::state_, embvm::timer::stopped, and timer_thread_.

◆ timer_thread()

void SimulatorTimer::timer_thread ( )
privatenoexcept

Thread which simulates a timer.

We sleep the thread for the requested period using a std::condition_variable::wait_for(). When the timer expires, we call the callback. We can also be notified early to cancel the timer.

References cb_, embvm::timer::Timer::config_, cv_, embvm::timer::expired, embvm::HALDriverBase::invokeCallback(), mutex_, embvm::timer::Timer::period_, embvm::timer::periodic, quit_, and embvm::timer::Timer::state_.

Referenced by start_().

◆ type()

static constexpr embvm::DriverType embvm::timer::Timer::type ( )
inlinestaticnoexceptinherited

Timer Driver Type ID.

Returns
Timer type ID.

References embvm::TIMER.

Member Data Documentation

◆ cb_

embvm::timer::cb_t embdrv::SimulatorTimer::cb_
private

Referenced by registerCallback(), and timer_thread().

◆ config_

timer::config embvm::timer::Timer::config_ = timer::config::oneshot
protectedinherited

The timer configuratoin.

Referenced by embvm::timer::Timer::config(), SimulatorTimer(), and timer_thread().

◆ cv_

std::condition_variable embdrv::SimulatorTimer::cv_
private

Referenced by stop_(), and timer_thread().

◆ dispatcher_

embutil::IRQDispatcherFunc_t embvm::HALDriverBase::dispatcher_
protectedinherited

◆ mutex_

std::mutex embdrv::SimulatorTimer::mutex_
private

Referenced by start_(), stop_(), and timer_thread().

◆ name_

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

Name of the driver instance.

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

◆ period_

timer_period_t embvm::timer::Timer::period_ {0}
protectedinherited

◆ quit_

std::atomic<bool> embdrv::SimulatorTimer::quit_ = false
private

Referenced by start_(), stop_(), and timer_thread().

◆ 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().

◆ state_

timer::state embvm::timer::Timer::state_ = timer::state::stopped
protectedinherited

The current state of the timer.

Referenced by start_(), embvm::timer::Timer::state(), stop_(), and timer_thread().

◆ time_base_

embvm::timer::timer_period_t embdrv::SimulatorTimer::time_base_ {0}
private

Referenced by count(), and start_().

◆ timer_thread_

std::thread embdrv::SimulatorTimer::timer_thread_
private

Referenced by start_(), and stop_().

◆ type_

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

Type ID of the driver instance.

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