10 #ifndef MASTERSYNCSERIAL_HPP 11 #define MASTERSYNCSERIAL_HPP 15 #include <boost/noncopyable.hpp> 20 namespace duds {
namespace hardware {
namespace interface {
22 class MasterSyncSerialAccess;
96 public std::enable_shared_from_this<MasterSyncSerial> {
170 static constexpr Flags
MssSpiMode0 = MssMSbFirst | MssOutFallInRise
181 static constexpr Flags
MssSpiMode2 = MssMSbFirst | MssClockIdleHigh
187 static constexpr Flags
MssSpiMode3 = MssMSbFirst | MssClockIdleHigh |
239 virtual void open() = 0;
247 virtual void close() = 0;
258 virtual void start() = 0;
268 virtual void stop() = 0;
324 const std::uint8_t * __restrict__ out,
325 std::uint8_t * __restrict__ in,
412 return mssacc !=
nullptr;
419 return minHalfPeriod << 1;
438 std::unique_ptr<MasterSyncSerialAccess>
access();
468 std::unique_ptr<MasterSyncSerialAccess>
accessStart();
506 #endif // #ifndef MASTERSYNCSERIAL_HPP unsigned int clockFrequency() const noexcept
Computes and returns the maximum clock frequency in Hertz.
MasterSyncSerial()
Builds a MasterSyncSerial with an invalid clock period and all configuration flags clear...
static constexpr Flags MssSpiMode2LSb
Flags for SPI mode 2 with the LSb transfered first.
virtual void open()=0
Transitions the object from the ready (MssReady) to the open (MssOpen) state.
virtual void close()=0
Transitions the object from the open (MssOpen) to the ready (MssReady) state.
void condStop()
Calls stop() if currently communicating (set MssCommunicating flag).
static constexpr Flags MssSpiMode2
Flags for SPI mode 2.
bool inUse() const noexcept
Returns true when this serial interface is in use by checking for the existence of an access object...
static constexpr Flags MssMSbFirst
Send data MSb first, little endian.
static constexpr Flags MssFullDuplex
Communication is full duplex.
static constexpr Flags MssCommunicating
Indicates that communication is underway.
static constexpr Flags MssSpiMode1
Flags for SPI mode 1.
std::unique_ptr< MasterSyncSerialAccess > access()
Obtain access for communication; transitions the object from the ready (MssReady) to the open (MssOpe...
static constexpr Flags MssSpiMode1LSb
Flags for SPI mode 1 with the LSb transfered first.
duds::general::BitFlags< struct MssFlags > Flags
Configuration flags for various synchronous serial options.
unsigned int clockPeriod() const noexcept
Returns the minimum clock period in nanoseconds.
virtual void transmit(const std::uint8_t *buff, duds::general::Bits bits)
Sends bits of data.
static constexpr Flags MssConfigMask
All the flags that are used for configuration rather than the current state.
void converseAlreadyOpen(Conversation &conv)
Has a half-duplex Conversation with the connected device.
static constexpr Flags MssSpiMode3
Flags for SPI mode 3.
Allows a common interface for using Conversation objects for communication.
virtual void converse(Conversation &conv)
Has a half-duplex Conversation with the connected device.
static constexpr Flags MssUseSelect
Use a select line to tell a device to pay attention to the master.
unsigned int minHalfPeriod
The minimum time between changing the clock edge in nanoseconds.
virtual ~MasterSyncSerial()=0
Derived class destructors should assure that communication has stopped by calling forceClose()...
static constexpr Flags MssSpiMode0
Flags for SPI mode 0.
std::unique_ptr< MasterSyncSerialAccess > accessStart()
Obtain access for communication; transitions the object from the ready (MssReady) to the communicatin...
static constexpr Flags MssOpen
Indicates that all required resources for communication have been acquired.
static constexpr Flags MssSpiMode0LSb
Flags for SPI mode 0 with the LSb transfered first.
virtual void stop()=0
Denotes the end of a conversation; transitions from the communicating state to the open state...
static std::wstring_convert< std::codecvt_utf8< char32_t >, char32_t > conv
String converter; UTF-8 to/from UTF-32.
static constexpr Flags MssSpiMode3LSb
Flags for SPI mode 3 with the LSb transfered first.
Flags configFlags() const noexcept
Returns the current set of configuration flags.
An abstraction for the master side of a simple synchronous serial communication connection to some de...
Provides access for communicating using a MasterSyncSerial object.
static constexpr Flags MssReady
Indictates that all required resources for communication have been identified and passed a validity c...
static constexpr Flags MssOutFallInRise
Output on the falling edge of the clock and read on the rising edge.
A class to assist with specifiying the sizes of data with scaling units, much like std::chrono::durat...
void forceClose()
Attempts to forcibly cease communications by calling condStop() and close().
virtual void start()=0
Denotes the start of a conversation; transitions from the open state to the communicating state...
MasterSyncSerialAccess * mssacc
A pointer to the current access object or nullptr.
virtual void transfer(const std::uint8_t *__restrict__ out, std::uint8_t *__restrict__ in, duds::general::Bits bits)=0
Sends and/or receives bits of data.
static constexpr Flags MssClockIdleHigh
Before communication begins, and after it ends, the clock line should have a high logic level...
virtual void receive(std::uint8_t *buff, duds::general::Bits bits)
Receives bits of data.
static constexpr Flags MssFirstDerivedClassFlag
The first flag that may be defined by a derived class.
void condStart()
Calls start() if not currently communicating (clear MssCommunicating flag).
void retire(MasterSyncSerialAccess *acc)
Removes the access object from use.
Flags flags
Configuration flags.
Represents a two-way conversation with a device.