Embedded Artistry Framework
Embedded Systems C++ Framework
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
embvm::spi::activeMaster< TQueueSize, TLock, TCond > Class Template Referencefinalabstract

#include <active_spi.hpp>

Inheritance diagram for embvm::spi::activeMaster< TQueueSize, TLock, TCond >:
Inheritance graph

Public Member Functions

 activeMaster (embvm::spi::master &m) noexcept
 
 ~activeMaster ()=default
 
void process_ (ao_storage pair) noexcept
 
virtual void configure (spi::baud_t baud) noexcept
 Configure the SPI bus. More...
 
spi::mode mode () const noexcept
 Get the current SPI bus mode. More...
 
spi::mode mode (spi::mode mode) noexcept
 Set the SPI bus mode. More...
 
spi::order order () const noexcept
 Get the current SPI bus byte order. More...
 
spi::order order (spi::order order) noexcept
 Set the SPI bus byte order. 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...
 
size_t queuedCount () const noexcept
 Get the number of operations in the queue. More...
 
bool enqueue (embvm::spi::ao_storage t) noexcept
 Add an operation to the queue. More...
 
void shutdown () noexcept
 Shutdown the active object. More...
 

Static Public Member Functions

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

Protected Member Functions

embvm::comm::status transfer_ (const spi::op_t &op, const cb_t &cb) noexcept override=0
 

Protected Attributes

spi::mode mode_ = spi::mode::mode0
 Stores the active SPI mode configuration. More...
 
spi::order order_ = spi::order::msbFirst
 Stores the active SPI byte ordering. 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...
 

Private Types

using ao_base = embutil::activeObject< activeMaster, ao_storage, TQueueSize, TLock, TCond >
 

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 configure_ () noexcept final
 Configure the SPI bus for operation. More...
 
void setMode_ (embvm::spi::mode mode) noexcept final
 Set the SPI bus mode. More...
 
void setOrder_ (embvm::spi::order order) noexcept final
 Set the SPI bus byte order. More...
 
embvm::spi::status transfer_ (const embvm::spi::op_t &op, const embvm::spi::master::cb_t &cb) noexcept final
 
embvm::spi::baud_t baudrate_ (embvm::spi::baud_t baud) noexcept final
 

Private Attributes

embvm::spi::masterm_
 

Member Typedef Documentation

◆ ao_base

template<size_t TQueueSize = 0, typename TLock = std::mutex, typename TCond = std::condition_variable>
using embvm::spi::activeMaster< TQueueSize, TLock, TCond >::ao_base = embutil::activeObject<activeMaster, ao_storage, TQueueSize, TLock, TCond>
private

Constructor & Destructor Documentation

◆ activeMaster()

template<size_t TQueueSize = 0, typename TLock = std::mutex, typename TCond = std::condition_variable>
embvm::spi::activeMaster< TQueueSize, TLock, TCond >::activeMaster ( embvm::spi::master m)
inlineexplicitnoexcept

◆ ~activeMaster()

template<size_t TQueueSize = 0, typename TLock = std::mutex, typename TCond = std::condition_variable>
embvm::spi::activeMaster< TQueueSize, TLock, TCond >::~activeMaster ( )
default

Member Function Documentation

◆ baudrate_()

template<size_t TQueueSize = 0, typename TLock = std::mutex, typename TCond = std::condition_variable>
embvm::spi::baud_t embvm::spi::activeMaster< TQueueSize, TLock, TCond >::baudrate_ ( embvm::spi::baud_t  baud)
inlinefinalprivatevirtualnoexcept

◆ configure()

virtual void embvm::spi::master::configure ( spi::baud_t  baud)
inlinevirtualnoexceptinherited

Configure the SPI bus.

Configures the SPI bus for operation and sets the target baud rate.

Derived classes must implement the configure_() function to set up the target hardware.

Parameters
baudThe target baudrate, in Hz. TODO: Tolerance - allowed relative tolerance for the resulting baudrate

References embvm::spi::master::configure_().

◆ configure_()

template<size_t TQueueSize = 0, typename TLock = std::mutex, typename TCond = std::condition_variable>
void embvm::spi::activeMaster< TQueueSize, TLock, TCond >::configure_ ( )
inlinefinalprivatevirtualnoexcept

Configure the SPI bus for operation.

This function is implemented by the derived class. It is responsible for configuring the target hardware for operation.

Implements embvm::spi::master.

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

◆ enqueue()

bool embutil::activeObject< embvm::spi::activeMaster< TQueueSize, TLock, TCond > , embvm::spi::ao_storage , TQueueSize, TLock, TCond >::enqueue ( embvm::spi::ao_storage  t)
inlinenoexceptinherited

Add an operation to the queue.

This function can be called directly, or by functions internal to the activeObject. For example, the "transfer" API enqueues transfer operations.

This function is marked noexcept because we want the program to terminate if an exception results from this call. For example, the underlying queue may throw on push.

Parameters
tThe operation data object to enqueue for later processing.

◆ mode() [1/2]

spi::mode embvm::spi::master::mode ( ) const
inlinenoexceptinherited

Get the current SPI bus mode.

Returns
The currently configured mode.

References embvm::spi::master::mode_.

Referenced by embvm::spi::master::mode(), and embvm::spi::activeMaster< TQueueSize, TLock, TCond >::setMode_().

◆ mode() [2/2]

spi::mode embvm::spi::master::mode ( spi::mode  mode)
inlinenoexceptinherited

Set the SPI bus mode.

Derived classes must implement the setMode_() function, which is reponsible for configuring the target hardware.

Parameters
modeThe desired SPI bus mode.
Returns
The new SPI bus mode.

References embvm::spi::master::mode(), embvm::spi::master::mode_, and embvm::spi::master::setMode_().

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

◆ order() [1/2]

spi::order embvm::spi::master::order ( ) const
inlinenoexceptinherited

Get the current SPI bus byte order.

Returns
The currently configured byte order.

References embvm::spi::master::order_.

Referenced by embvm::spi::master::order(), and embvm::spi::activeMaster< TQueueSize, TLock, TCond >::setOrder_().

◆ order() [2/2]

spi::order embvm::spi::master::order ( spi::order  order)
inlinenoexceptinherited

Set the SPI bus byte order.

Derived classes must implement the setOrder_() function, which is reponsible for configuring the target hardware.

Parameters
orderThe desired byte ordering.
Returns
The new byte ordering.

References embvm::spi::master::order(), embvm::spi::master::order_, and embvm::spi::master::setOrder_().

◆ process_()

template<size_t TQueueSize = 0, typename TLock = std::mutex, typename TCond = std::condition_variable>
void embvm::spi::activeMaster< TQueueSize, TLock, TCond >::process_ ( ao_storage  pair)
inlinenoexcept

◆ queuedCount()

size_t embutil::activeObject< embvm::spi::activeMaster< TQueueSize, TLock, TCond > , embvm::spi::ao_storage , TQueueSize, TLock, TCond >::queuedCount ( ) const
inlinenoexceptinherited

Get the number of operations in the queue.

Returns
the number of queued operations.

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

◆ setMode_()

template<size_t TQueueSize = 0, typename TLock = std::mutex, typename TCond = std::condition_variable>
void embvm::spi::activeMaster< TQueueSize, TLock, TCond >::setMode_ ( embvm::spi::mode  mode)
inlinefinalprivatevirtualnoexcept

Set the SPI bus mode.

This function is implemented by the derived class. It is responsible for configuring the target hardware to use the new mode.

Parameters
modeThe desired byte ordering.

Implements embvm::spi::master.

References embvm::spi::activeMaster< TQueueSize, TLock, TCond >::m_, and embvm::spi::master::mode().

◆ setOrder_()

template<size_t TQueueSize = 0, typename TLock = std::mutex, typename TCond = std::condition_variable>
void embvm::spi::activeMaster< TQueueSize, TLock, TCond >::setOrder_ ( embvm::spi::order  order)
inlinefinalprivatevirtualnoexcept

Set the SPI bus byte order.

This function is implemented by the derived class. It is responsible for configuring the target hardware to use the new byte ordering.

Parameters
orderThe desired byte ordering.

Implements embvm::spi::master.

References embvm::spi::activeMaster< TQueueSize, TLock, TCond >::m_, and embvm::spi::master::order().

◆ shutdown()

void embutil::activeObject< embvm::spi::activeMaster< TQueueSize, TLock, TCond > , embvm::spi::ao_storage , TQueueSize, TLock, TCond >::shutdown ( )
inlinenoexceptinherited

Shutdown the active object.

Call this function in the parent class destructor to stop the AO thread operation before destroying the parent class. This will prevent memory access problems due to race conidtions during destruction.

This function is marked noexcept because we want the program to terminate if an exception results from this call.

The shutdown process is permanent and cannot be reversed without recreating the object.

◆ start()

void embvm::DriverBase::start ( )
inlinenoexceptinherited

◆ start_()

template<size_t TQueueSize = 0, typename TLock = std::mutex, typename TCond = std::condition_variable>
void embvm::spi::activeMaster< TQueueSize, TLock, TCond >::start_ ( )
inlinefinalprivatevirtualnoexcept

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

(Template Method Pattern)

Implements embvm::spi::master.

References embvm::spi::activeMaster< TQueueSize, TLock, TCond >::m_, and embvm::DriverBase::start().

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

template<size_t TQueueSize = 0, typename TLock = std::mutex, typename TCond = std::condition_variable>
void embvm::spi::activeMaster< TQueueSize, TLock, TCond >::stop_ ( )
inlinefinalprivatevirtualnoexcept

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

(Template Method Pattern)

Implements embvm::spi::master.

References embvm::spi::activeMaster< TQueueSize, TLock, TCond >::m_, and embvm::DriverBase::stop().

◆ transfer_() [1/2]

template<size_t TQueueSize = 0, typename TLock = std::mutex, typename TCond = std::condition_variable>
embvm::spi::status embvm::spi::activeMaster< TQueueSize, TLock, TCond >::transfer_ ( const embvm::spi::op_t op,
const embvm::spi::master::cb_t &  cb 
)
inlinefinalprivatenoexcept

◆ transfer_() [2/2]

embvm::comm::status embvm::spi::master::transfer_ ( const spi::op_t op,
const cb_t &  cb 
)
overrideprotectedpure virtualnoexceptinherited

◆ type()

static constexpr embvm::DriverType embvm::spi::master::type ( )
inlinestaticnoexceptinherited

SPI Driver Type ID.

Returns
SPI type ID.

References embvm::SPI.

Member Data Documentation

◆ m_

template<size_t TQueueSize = 0, typename TLock = std::mutex, typename TCond = std::condition_variable>
embvm::spi::master& embvm::spi::activeMaster< TQueueSize, TLock, TCond >::m_
private

◆ mode_

spi::mode embvm::spi::master::mode_ = spi::mode::mode0
protectedinherited

Stores the active SPI mode configuration.

Referenced by embdrv::aardvarkSPIMaster::configure_(), and embvm::spi::master::mode().

◆ name_

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

Name of the driver instance.

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

◆ order_

spi::order embvm::spi::master::order_ = spi::order::msbFirst
protectedinherited

Stores the active SPI byte ordering.

Referenced by embdrv::aardvarkSPIMaster::configure_(), and embvm::spi::master::order().

◆ 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 file: