|
DUDS
|
Distributed Update of Data from Something
|
A synchronous serial implementation using the SPI userspace interface provided by the Linux kernel. More...
#include <SpiMasterSyncSerial.hpp>
Public Member Functions | |
| SpiMasterSyncSerial () | |
| Creates the object without a SPI device to use. More... | |
| SpiMasterSyncSerial (const std::string &path, Flags flags=MssSpiMode0, int freq=100000) | |
| Creates the object and attempts to open the SPI device. More... | |
| SpiMasterSyncSerial (Flags flags) | |
| Creates the object with SPI mode flags but no SPI device. More... | |
| ~SpiMasterSyncSerial () | |
| void | open (const std::string &path, Flags flags=MssSpiMode0, int freq=100000) |
| Opens the SPI device file and configures it. More... | |
| void | setClockFrequency (unsigned int freq) |
| Changes the maximum clock frequency. More... | |
| void | setClockPeriod (unsigned int nanos) |
| Changes the minimum clock period. More... | |
Public Member Functions inherited from duds::hardware::interface::MasterSyncSerial | |
| MasterSyncSerial () | |
| Builds a MasterSyncSerial with an invalid clock period and all configuration flags clear. More... | |
| MasterSyncSerial (Flags flags, int period) | |
| Builds a MasterSyncSerial object. More... | |
| virtual | ~MasterSyncSerial ()=0 |
| Derived class destructors should assure that communication has stopped by calling forceClose(). More... | |
| std::unique_ptr< MasterSyncSerialAccess > | access () |
| Obtain access for communication; transitions the object from the ready (MssReady) to the open (MssOpen) state. More... | |
| void | access (MasterSyncSerialAccess &acc) |
| Obtain access for communication; transitions the object from the ready (MssReady) to the open (MssOpen) state. More... | |
| std::unique_ptr< MasterSyncSerialAccess > | accessStart () |
| Obtain access for communication; transitions the object from the ready (MssReady) to the communicating (MssCommunicating) state. More... | |
| void | accessStart (MasterSyncSerialAccess &acc) |
| Obtain access for communication; transitions the object from the ready (MssReady) to the communicating (MssCommunicating) state. More... | |
| unsigned int | clockFrequency () const noexcept |
| Computes and returns the maximum clock frequency in Hertz. More... | |
| unsigned int | clockPeriod () const noexcept |
| Returns the minimum clock period in nanoseconds. More... | |
| Flags | configFlags () const noexcept |
| Returns the current set of configuration flags. More... | |
| virtual void | converse (Conversation &conv) |
| Has a half-duplex Conversation with the connected device. More... | |
| bool | inUse () const noexcept |
| Returns true when this serial interface is in use by checking for the existence of an access object. More... | |
Public Member Functions inherited from duds::hardware::interface::Conversationalist | |
| virtual | ~Conversationalist ()=0 |
| Allow proper destruction using a Conversationalist pointer. More... | |
Protected Member Functions | |
| virtual void | close () |
| Transitions the object from the open (MssOpen) to the ready (MssReady) state. More... | |
| virtual void | open () |
| Transitions the object from the ready (MssReady) to the open (MssOpen) state. More... | |
| virtual void | start () |
| Denotes the start of a conversation; transitions from the open state to the communicating state. More... | |
| virtual void | stop () |
| Denotes the end of a conversation; transitions from the communicating state to the open state. More... | |
| virtual void | transfer (const std::uint8_t *__restrict__ out, std::uint8_t *__restrict__ in, duds::general::Bits bits) |
| Moves data about. More... | |
Protected Member Functions inherited from duds::hardware::interface::MasterSyncSerial | |
| void | clockFrequency (unsigned int freq) |
| Changes the maximum clock frequency. More... | |
| void | clockPeriod (unsigned int nanos) |
| Changes the minimum clock period. More... | |
| void | condStart () |
| Calls start() if not currently communicating (clear MssCommunicating flag). More... | |
| void | condStop () |
| Calls stop() if currently communicating (set MssCommunicating flag). More... | |
| void | converseAlreadyOpen (Conversation &conv) |
| Has a half-duplex Conversation with the connected device. More... | |
| void | forceClose () |
| Attempts to forcibly cease communications by calling condStop() and close(). More... | |
| virtual void | receive (std::uint8_t *buff, duds::general::Bits bits) |
| Receives bits of data. More... | |
| virtual void | transmit (const std::uint8_t *buff, duds::general::Bits bits) |
| Sends bits of data. More... | |
Private Attributes | |
| int | spifd |
| The file descriptor for SPI access. More... | |
| spi_ioc_transfer | xfer |
| Data for telling the kernel what to send and receive. More... | |
Additional Inherited Members | |
Public Types inherited from duds::hardware::interface::MasterSyncSerial | |
| typedef duds::general::BitFlags< struct MssFlags > | Flags |
| Configuration flags for various synchronous serial options. More... | |
Static Public Attributes inherited from duds::hardware::interface::MasterSyncSerial | |
| static constexpr Flags | MssClockIdleHigh = Flags(2) |
| Before communication begins, and after it ends, the clock line should have a high logic level. More... | |
| static constexpr Flags | MssCommunicating = Flags(128) |
| Indicates that communication is underway. More... | |
| static constexpr Flags | MssConfigMask = Flags(31) |
| All the flags that are used for configuration rather than the current state. More... | |
| static constexpr Flags | MssFirstDerivedClassFlag = Flags(256) |
| The first flag that may be defined by a derived class. More... | |
| static constexpr Flags | MssFullDuplex = Flags(16) |
| Communication is full duplex. More... | |
| static constexpr Flags | MssMSbFirst = Flags(8) |
| Send data MSb first, little endian. More... | |
| static constexpr Flags | MssOpen = Flags(64) |
| Indicates that all required resources for communication have been acquired. More... | |
| static constexpr Flags | MssOutFallInRise = Flags(4) |
| Output on the falling edge of the clock and read on the rising edge. More... | |
| static constexpr Flags | MssReady = Flags(32) |
| Indictates that all required resources for communication have been identified and passed a validity check. More... | |
| static constexpr Flags | MssSpiMode0 |
| Flags for SPI mode 0. More... | |
| static constexpr Flags | MssSpiMode0LSb = MssOutFallInRise | MssFullDuplex |
| Flags for SPI mode 0 with the LSb transfered first. More... | |
| static constexpr Flags | MssSpiMode1 = MssMSbFirst | MssFullDuplex |
| Flags for SPI mode 1. More... | |
| static constexpr Flags | MssSpiMode1LSb = MssFullDuplex |
| Flags for SPI mode 1 with the LSb transfered first. More... | |
| static constexpr Flags | MssSpiMode2 |
| Flags for SPI mode 2. More... | |
| static constexpr Flags | MssSpiMode2LSb = MssClockIdleHigh | MssFullDuplex |
| Flags for SPI mode 2 with the LSb transfered first. More... | |
| static constexpr Flags | MssSpiMode3 |
| Flags for SPI mode 3. More... | |
| static constexpr Flags | MssSpiMode3LSb |
| Flags for SPI mode 3 with the LSb transfered first. More... | |
| static constexpr Flags | MssUseSelect = Flags(1) |
| Use a select line to tell a device to pay attention to the master. More... | |
Protected Attributes inherited from duds::hardware::interface::MasterSyncSerial | |
| Flags | flags |
| Configuration flags. More... | |
| unsigned int | minHalfPeriod |
| The minimum time between changing the clock edge in nanoseconds. More... | |
A synchronous serial implementation using the SPI userspace interface provided by the Linux kernel.
This requires proper kernel support for the hardware. In addition to a number of SPI master controllers, Linux also has support for SPI using GPIOs. The SPI using GPIO support should have less overhead and better performance than DigitalPinMasterSyncSerial. This class supports only 8-bit words, but otherwise supports all SPI modes. Specific master controllers may not support all modes.
This could be expanded upon by a class that uses a ChipSelect object to allow multiple devices on the same device file so that more devices can be used on the same bus. However, any process using another device file for the same bus can interrupt communications between transfers. This will need to be handled properly by the circuit to deselect the device selected by the ChipSelect object, and by the devices at the other end of the bus.
Definition at line 47 of file SpiMasterSyncSerial.hpp.
| duds::hardware::interface::linux::SpiMasterSyncSerial::SpiMasterSyncSerial | ( | ) |
Creates the object without a SPI device to use.
Definition at line 20 of file SpiMasterSyncSerial.cpp.
| duds::hardware::interface::linux::SpiMasterSyncSerial::SpiMasterSyncSerial | ( | const std::string & | path, |
| Flags | flags = MssSpiMode0, |
||
| int | freq = 100000 |
||
| ) |
Creates the object and attempts to open the SPI device.
| path | The path to the SPI device file. |
| flags | The flags specifying the SPI mode to use. Not all modes may be supported. |
| freq | The maximum clock frequency in hertz. |
Definition at line 22 of file SpiMasterSyncSerial.cpp.
| duds::hardware::interface::linux::SpiMasterSyncSerial::SpiMasterSyncSerial | ( | Flags | flags | ) |
Creates the object with SPI mode flags but no SPI device.
| flags | The flags specifying the SPI mode to use. Not all modes may be supported. |
Definition at line 31 of file SpiMasterSyncSerial.cpp.
| duds::hardware::interface::linux::SpiMasterSyncSerial::~SpiMasterSyncSerial | ( | ) |
Definition at line 34 of file SpiMasterSyncSerial.cpp.
|
protectedvirtual |
Transitions the object from the open (MssOpen) to the ready (MssReady) state.
This should relinquish access to any required shared resources.
Implements duds::hardware::interface::MasterSyncSerial.
Definition at line 131 of file SpiMasterSyncSerial.cpp.
Referenced by open(), and ~SpiMasterSyncSerial().
|
protectedvirtual |
Transitions the object from the ready (MssReady) to the open (MssOpen) state.
This should acquire access to any required shared resources.
| boost::exception | Badness; state transision did not occur. |
Implements duds::hardware::interface::MasterSyncSerial.
Definition at line 129 of file SpiMasterSyncSerial.cpp.
Referenced by open(), and SpiMasterSyncSerial().
| void duds::hardware::interface::linux::SpiMasterSyncSerial::open | ( | const std::string & | path, |
| Flags | flags = MssSpiMode0, |
||
| int | freq = 100000 |
||
| ) |
Opens the SPI device file and configures it.
| path | The path to the SPI device file. |
| flags | The flags specifying the SPI mode to use. Not all modes may be supported. If all bits are cleared, the already set flags will be used. |
| freq | The maximum clock frequency in hertz. |
| SyncSerialIoError | A failure ocurred when opening the file, or when setting the SPI communication parameters. The hardware may not support all SPI modes of operation, but the kernel's SPI over GPIO support should. |
| SyncSerialInUse | The object is in the open (MssOpen) or communicating (MssCommunicating) state. |
Definition at line 39 of file SpiMasterSyncSerial.cpp.
| void duds::hardware::interface::linux::SpiMasterSyncSerial::setClockFrequency | ( | unsigned int | freq | ) |
Changes the maximum clock frequency.
| freq | The requested maximum clock frequence in hertz. |
| SyncSerialInUse | Called while communication is in progress. |
Definition at line 100 of file SpiMasterSyncSerial.cpp.
Referenced by open(), and SpiMasterSyncSerial().
| void duds::hardware::interface::linux::SpiMasterSyncSerial::setClockPeriod | ( | unsigned int | nanos | ) |
Changes the minimum clock period.
| nanos | The requested minimum clock period in nanoseconds. |
| SyncSerialInUse | Called while communication is in progress. |
Definition at line 110 of file SpiMasterSyncSerial.cpp.
|
protectedvirtual |
Denotes the start of a conversation; transitions from the open state to the communicating state.
Implements duds::hardware::interface::MasterSyncSerial.
Definition at line 133 of file SpiMasterSyncSerial.cpp.
|
protectedvirtual |
Denotes the end of a conversation; transitions from the communicating state to the open state.
Implements duds::hardware::interface::MasterSyncSerial.
Definition at line 135 of file SpiMasterSyncSerial.cpp.
|
protectedvirtual |
Moves data about.
Implements duds::hardware::interface::MasterSyncSerial.
Definition at line 137 of file SpiMasterSyncSerial.cpp.
|
private |
The file descriptor for SPI access.
Definition at line 56 of file SpiMasterSyncSerial.hpp.
Referenced by open(), setClockFrequency(), setClockPeriod(), transfer(), and ~SpiMasterSyncSerial().
|
private |
Data for telling the kernel what to send and receive.
Placed here to avoid initializing the whole struct before every transfer.
Definition at line 52 of file SpiMasterSyncSerial.hpp.
Referenced by open(), and transfer().