12 #include <boost/exception/errinfo_file_name.hpp> 14 #include <sys/ioctl.h> 18 namespace duds {
namespace hardware {
namespace interface {
namespace linux {
23 const std::string &path,
40 const std::string &path,
59 boost::errinfo_file_name(path));
61 std::uint8_t byte = 0;
72 if (ioctl(
spifd, SPI_IOC_WR_MODE, &byte) < 0) {
74 boost::errinfo_file_name(path));
82 if (ioctl(
spifd, SPI_IOC_WR_LSB_FIRST, &byte) < 0) {
84 boost::errinfo_file_name(path));
88 if (ioctl(
spifd, SPI_IOC_WR_BITS_PER_WORD, &byte) < 0) {
90 boost::errinfo_file_name(path));
104 if (ioctl(
spifd, SPI_IOC_WR_MAX_SPEED_HZ, &freq) < 0) {
121 if (ioctl(
spifd, SPI_IOC_WR_MAX_SPEED_HZ, &nanos) < 0) {
138 const std::uint8_t * __restrict__ out,
139 std::uint8_t * __restrict__ in,
149 xfer.tx_buf = (ptrdiff_t)out;
150 xfer.rx_buf = (ptrdiff_t)in;
152 if (ioctl(
spifd, SPI_IOC_MESSAGE(1), &
xfer) < 0) {
unsigned int clockFrequency() const noexcept
Computes and returns the maximum clock frequency in Hertz.
static constexpr Flags MssMSbFirst
Send data MSb first, little endian.
static constexpr Flags MssCommunicating
Indicates that communication is underway.
virtual void transfer(const std::uint8_t *__restrict__ out, std::uint8_t *__restrict__ in, duds::general::Bits bits)
Moves data about.
unsigned int clockPeriod() const noexcept
Returns the minimum clock period in nanoseconds.
virtual void close()
Transitions the object from the open (MssOpen) to the ready (MssReady) state.
void setClockFrequency(unsigned int freq)
Changes the maximum clock frequency.
SpiMasterSyncSerial()
Creates the object without a SPI device to use.
unsigned int minHalfPeriod
The minimum time between changing the clock edge in nanoseconds.
static constexpr Flags MssOpen
Indicates that all required resources for communication have been acquired.
The requested mode of operation is unsupported; intended for use by implementing classes that must im...
spi_ioc_transfer xfer
Data for telling the kernel what to send and receive.
constexpr std::size_t blocks() const
Returns the size specified as a multuple of Bits.
An abstraction for the master side of a simple synchronous serial communication connection to some de...
virtual void stop()
Denotes the end of a conversation; transitions from the communicating state to the open state...
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...
A transfer operation was requested when not in the communicating state.
void forceClose()
Attempts to forcibly cease communications by calling condStop() and close().
The requested operation requires communication to not already be in use.
int spifd
The file descriptor for SPI access.
virtual void open()
Transitions the object from the ready (MssReady) to the open (MssOpen) state.
static constexpr Flags MssClockIdleHigh
Before communication begins, and after it ends, the clock line should have a high logic level...
void setClockPeriod(unsigned int nanos)
Changes the minimum clock period.
Flags flags
Configuration flags.
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
virtual void start()
Denotes the start of a conversation; transitions from the open state to the communicating state...
DataSize< 8 > Bytes
DataSize type for a size in bytes.