|
DUDS
|
Distributed Update of Data from Something
|
An interface for communication with a SMBus device. More...
#include <Smbus.hpp>
Classes | |
| struct | NoPec |
| Use with constructors to specify that Packet Error Checking (PEC) will not be used. More... | |
| struct | UsePec |
| Use with constructors to explicitly specify that Packet Error Checking (PEC) be used. More... | |
Public Member Functions | |
| virtual | ~Smbus ()=0 |
| virtual int | address () const =0 |
| Returns the address of the device that this object will attempt to communicate with. More... | |
| virtual std::uint16_t | call (std::uint8_t cmd, std::uint16_t word)=0 |
| Does a process call operation. More... | |
| virtual void | call (std::uint8_t cmd, const std::vector< std::uint8_t > &out, std::vector< std::uint8_t > &in)=0 |
| Does a block process call operation. More... | |
| virtual int | receive (std::uint8_t cmd, std::uint8_t *in, const int maxlen)=0 |
| Sends a command byte, then reads a block of data from the device. More... | |
| virtual void | receive (std::uint8_t cmd, std::vector< std::uint8_t > &in)=0 |
| Sends a command byte, then reads a block of data from the device. More... | |
| virtual std::uint8_t | receiveByte ()=0 |
| Read a single byte from the device without sending a command/register byte first. More... | |
| virtual std::uint8_t | receiveByte (std::uint8_t cmd)=0 |
| Sends a command byte, then reads a single byte from the device. More... | |
| virtual std::uint16_t | receiveWord (std::uint8_t cmd)=0 |
| Sends a command byte, then reads a word, two bytes, from the device. More... | |
| std::uint16_t | receiveWordBe (std::uint8_t cmd) |
| Sends a command byte, then reads a big-endian word from the device. More... | |
| virtual void | transmit (std::uint8_t cmd, const std::uint8_t *out, const int len)=0 |
| Sends a command byte and a block of data to the device. More... | |
| void | transmit (std::uint8_t cmd, const std::vector< std::uint8_t > &out) |
| Sends a command byte and a block of data to the device. More... | |
| virtual void | transmitBool (bool out)=0 |
| Sends a single bit to the device. More... | |
| virtual void | transmitByte (std::uint8_t byte)=0 |
| Sends a single byte to the device. More... | |
| virtual void | transmitByte (std::uint8_t cmd, std::uint8_t byte)=0 |
| Sends a command byte and a data byte to the device. More... | |
| virtual void | transmitWord (std::uint8_t cmd, std::uint16_t word)=0 |
| Sends a command byte and a data word to the device. More... | |
| void | transmitWordBe (std::uint8_t cmd, std::uint16_t word) |
| Sends a command byte and a big-endian data word to the device. More... | |
An interface for communication with a SMBus device.
This is intended to communicate with a single device. Use one for each device, even if they use the same bus. As a result, implementations need not be thread-safe since it makes little sense to attempt multiple communications with the same device. However, the bus should be handled in a thread-safe manner; multiple simultaneous attempts to use the same bus to communicate with different devices should work.
Some I2C devices communicate in a manner that allows them to be handled as SMBus devices. Such devices should use Smbus instead of I2c to take advantage of the easier-to-use interface of Smbus. The Linux kernel documentation implies that SMBus master hardware exists, so favoring the use of Smbus may also increase compatibility without requiring the use of a software master using GPIOs.
Whenever possible, use Packet Error Checking (PEC) with communications. It will help prevent bad data on the bus from causing trouble by noticing the bad data and generating an error. It is not part of the I2C specification, so it should be disabled for use with SMBus-like I2C devices.
All word, two byte, std::uint16_t data is in host endianness. The SMBus protocol specifies that words are sent in little endian order. This must work on both little and big endian hosts. To assist in dealing with devices that are not SMBus compliant and use big-endian data, the receiveWordBe() and transmitWordBe() functions will do an endianness conversion on the data. They allow the code to use host endianness while communicating with big-endian data.
There isn't a matching access object because SMBus is specified in such a way that it shouldn't be required.
|
pure virtual |
Returns the address of the device that this object will attempt to communicate with.
Implemented in duds::hardware::interface::linux::DevSmbus.
Referenced by transmit().
|
pure virtual |
Does a process call operation.
Sends a command byte and a word to the device, then receives a word.
| cmd | The command or register byte. |
| word | The word to send. |
| SmbusErrorPec | The PEC checksum was not valid for the data. |
| SmbusErrorBusy | The bus was in use for an inordinate length of time. This is not caused by scheduling on the same host computer. |
| SmbusErrorNoDevice | The device did not respond to its address. |
| SmbusErrorUnsupported | This operation is unsupported by the master. |
| SmbusErrorProtocol | Data from the device does not conform to the SMBus protocol. |
| SmbusErrorTimeout | The operation took too long resulting in a bus timeout. |
| SmbusError | A general error that doesn't fit one of the other exceptions. |
Implemented in duds::hardware::interface::linux::DevSmbus.
Referenced by transmit().
|
pure virtual |
Does a block process call operation.
Sends a command byte and block of data to the device, then receives a block of data.
| cmd | The command or register byte. |
| out | The data block to send. It must not have more than 32 bytes. |
| in | The data block received from the device. |
| SmbusErrorMessageLength | A request was made to send a block of more than 32 bytes. |
| SmbusErrorPec | The PEC checksum was not valid for the data. |
| SmbusErrorBusy | The bus was in use for an inordinate length of time. This is not caused by scheduling on the same host computer. |
| SmbusErrorNoDevice | The device did not respond to its address. |
| SmbusErrorUnsupported | This operation is unsupported by the master. |
| SmbusErrorProtocol | Data from the device does not conform to the SMBus protocol. |
| SmbusErrorTimeout | The operation took too long resulting in a bus timeout. |
| SmbusError | A general error that doesn't fit one of the other exceptions. |
Implemented in duds::hardware::interface::linux::DevSmbus.
|
pure virtual |
Sends a command byte, then reads a block of data from the device.
| cmd | The command or register byte. |
| in | The input buffer. |
| maxlen | The maximum amount of data to write into in. |
| SmbusErrorMessageLength | The buffer in could not hold all the received data. |
| SmbusErrorPec | The PEC checksum was not valid for the data. |
| SmbusErrorBusy | The bus was in use for an inordinate length of time. This is not caused by scheduling on the same host computer. |
| SmbusErrorNoDevice | The device did not respond to its address. |
| SmbusErrorUnsupported | This operation is unsupported by the master. |
| SmbusErrorProtocol | Data from the device does not conform to the SMBus protocol. |
| SmbusErrorTimeout | The operation took too long resulting in a bus timeout. |
| SmbusError | A general error that doesn't fit one of the other exceptions. |
Implemented in duds::hardware::interface::linux::DevSmbus.
Referenced by receiveWordBe().
|
pure virtual |
Sends a command byte, then reads a block of data from the device.
| cmd | The command or register byte. |
| in | The input vector. Upon success, the vector will be resized to match the received data. |
| SmbusErrorPec | The PEC checksum was not valid for the data. |
| SmbusErrorBusy | The bus was in use for an inordinate length of time. This is not caused by scheduling on the same host computer. |
| SmbusErrorNoDevice | The device did not respond to its address. |
| SmbusErrorUnsupported | This operation is unsupported by the master. |
| SmbusErrorProtocol | Data from the device does not conform to the SMBus protocol. |
| SmbusErrorTimeout | The operation took too long resulting in a bus timeout. |
| SmbusError | A general error that doesn't fit one of the other exceptions. |
Implemented in duds::hardware::interface::linux::DevSmbus.
|
pure virtual |
Read a single byte from the device without sending a command/register byte first.
| SmbusErrorPec | The PEC checksum was not valid for the data. |
| SmbusErrorBusy | The bus was in use for an inordinate length of time. This is not caused by scheduling on the same host computer. |
| SmbusErrorNoDevice | The device did not respond to its address. |
| SmbusErrorUnsupported | This operation is unsupported by the master. |
| SmbusErrorProtocol | Data from the device does not conform to the SMBus protocol. |
| SmbusErrorTimeout | The operation took too long resulting in a bus timeout. |
| SmbusError | A general error that doesn't fit one of the other exceptions. |
Implemented in duds::hardware::interface::linux::DevSmbus.
Referenced by duds::hardware::devices::instruments::MCP9808::MCP9808().
|
pure virtual |
Sends a command byte, then reads a single byte from the device.
| cmd | The command or register byte. |
| SmbusErrorPec | The PEC checksum was not valid for the data. |
| SmbusErrorBusy | The bus was in use for an inordinate length of time. This is not caused by scheduling on the same host computer. |
| SmbusErrorNoDevice | The device did not respond to its address. |
| SmbusErrorUnsupported | This operation is unsupported by the master. |
| SmbusErrorProtocol | Data from the device does not conform to the SMBus protocol. |
| SmbusErrorTimeout | The operation took too long resulting in a bus timeout. |
| SmbusError | A general error that doesn't fit one of the other exceptions. |
Implemented in duds::hardware::interface::linux::DevSmbus.
|
pure virtual |
Sends a command byte, then reads a word, two bytes, from the device.
| cmd | The command or register byte. |
| SmbusErrorPec | The PEC checksum was not valid for the data. |
| SmbusErrorBusy | The bus was in use for an inordinate length of time. This is not caused by scheduling on the same host computer. |
| SmbusErrorNoDevice | The device did not respond to its address. |
| SmbusErrorUnsupported | This operation is unsupported by the master. |
| SmbusErrorProtocol | Data from the device does not conform to the SMBus protocol. |
| SmbusErrorTimeout | The operation took too long resulting in a bus timeout. |
| SmbusError | A general error that doesn't fit one of the other exceptions. |
Implemented in duds::hardware::interface::linux::DevSmbus.
Referenced by receiveWordBe().
|
inline |
Sends a command byte, then reads a big-endian word from the device.
| cmd | The command or register byte. |
| SmbusErrorPec | The PEC checksum was not valid for the data. |
| SmbusErrorBusy | The bus was in use for an inordinate length of time. This is not caused by scheduling on the same host computer. |
| SmbusErrorNoDevice | The device did not respond to its address. |
| SmbusErrorUnsupported | This operation is unsupported by the master. |
| SmbusErrorProtocol | Data from the device does not conform to the SMBus protocol. |
| SmbusErrorTimeout | The operation took too long resulting in a bus timeout. |
| SmbusError | A general error that doesn't fit one of the other exceptions. |
Definition at line 146 of file Smbus.hpp.
Referenced by duds::hardware::devices::instruments::MCP9808::MCP9808().
|
pure virtual |
Sends a command byte and a block of data to the device.
| cmd | The command or register byte. |
| out | The data to send. |
| len | The number of bytes in the buffer out to send. It must be between 1 and 32, inclusive. |
| SmbusErrorMessageLength | A request was made to send a block of less than 1 or more than 32 bytes. |
| SmbusErrorPec | The PEC checksum was not valid for the data. |
| SmbusErrorBusy | The bus was in use for an inordinate length of time. This is not caused by scheduling on the same host computer. |
| SmbusErrorNoDevice | The device did not respond to its address. |
| SmbusErrorUnsupported | This operation is unsupported by the master. |
| SmbusErrorProtocol | Data from the device does not conform to the SMBus protocol. |
| SmbusErrorTimeout | The operation took too long resulting in a bus timeout. |
| SmbusError | A general error that doesn't fit one of the other exceptions. |
Implemented in duds::hardware::interface::linux::DevSmbus.
Referenced by transmit(), and transmitWordBe().
|
inline |
Sends a command byte and a block of data to the device.
| cmd | The command or register byte. |
| out | The data to send. It must have between 1 and 32 bytes, inclusive. |
| SmbusErrorMessageLength | A request was made to send a block of less than 1 or more than 32 bytes. |
| SmbusErrorPec | The PEC checksum was not valid for the data. |
| SmbusErrorBusy | The bus was in use for an inordinate length of time. This is not caused by scheduling on the same host computer. |
| SmbusErrorNoDevice | The device did not respond to its address. |
| SmbusErrorUnsupported | This operation is unsupported by the master. |
| SmbusErrorProtocol | Data from the device does not conform to the SMBus protocol. |
| SmbusErrorTimeout | The operation took too long resulting in a bus timeout. |
| SmbusError | A general error that doesn't fit one of the other exceptions. |
|
pure virtual |
Sends a single bit to the device.
| SmbusErrorPec | The PEC checksum was not valid for the data. |
| SmbusErrorBusy | The bus was in use for an inordinate length of time. This is not caused by scheduling on the same host computer. |
| SmbusErrorNoDevice | The device did not respond to its address. |
| SmbusErrorUnsupported | This operation is unsupported by the master. |
| SmbusErrorProtocol | Data from the device does not conform to the SMBus protocol. |
| SmbusErrorTimeout | The operation took too long resulting in a bus timeout. |
| SmbusError | A general error that doesn't fit one of the other exceptions. |
Implemented in duds::hardware::interface::linux::DevSmbus.
Referenced by receiveWordBe().
|
pure virtual |
Sends a single byte to the device.
| byte | The byte to send. |
| SmbusErrorPec | The PEC checksum was not valid for the data. |
| SmbusErrorBusy | The bus was in use for an inordinate length of time. This is not caused by scheduling on the same host computer. |
| SmbusErrorNoDevice | The device did not respond to its address. |
| SmbusErrorUnsupported | This operation is unsupported by the master. |
| SmbusErrorProtocol | Data from the device does not conform to the SMBus protocol. |
| SmbusErrorTimeout | The operation took too long resulting in a bus timeout. |
| SmbusError | A general error that doesn't fit one of the other exceptions. |
Implemented in duds::hardware::interface::linux::DevSmbus.
Referenced by receiveWordBe().
|
pure virtual |
Sends a command byte and a data byte to the device.
| cmd | The command or register byte. |
| byte | The data byte to send. |
| SmbusErrorPec | The PEC checksum was not valid for the data. |
| SmbusErrorBusy | The bus was in use for an inordinate length of time. This is not caused by scheduling on the same host computer. |
| SmbusErrorNoDevice | The device did not respond to its address. |
| SmbusErrorUnsupported | This operation is unsupported by the master. |
| SmbusErrorProtocol | Data from the device does not conform to the SMBus protocol. |
| SmbusErrorTimeout | The operation took too long resulting in a bus timeout. |
| SmbusError | A general error that doesn't fit one of the other exceptions. |
Implemented in duds::hardware::interface::linux::DevSmbus.
|
pure virtual |
Sends a command byte and a data word to the device.
| cmd | The command or register byte. |
| word | The data word to send. |
| SmbusErrorPec | The PEC checksum was not valid for the data. |
| SmbusErrorBusy | The bus was in use for an inordinate length of time. This is not caused by scheduling on the same host computer. |
| SmbusErrorNoDevice | The device did not respond to its address. |
| SmbusErrorUnsupported | This operation is unsupported by the master. |
| SmbusErrorProtocol | Data from the device does not conform to the SMBus protocol. |
| SmbusErrorTimeout | The operation took too long resulting in a bus timeout. |
| SmbusError | A general error that doesn't fit one of the other exceptions. |
Implemented in duds::hardware::interface::linux::DevSmbus.
Referenced by receiveWordBe(), and transmitWordBe().
|
inline |
Sends a command byte and a big-endian data word to the device.
| cmd | The command or register byte. |
| word | The data word to send in host endianness. |
| SmbusErrorPec | The PEC checksum was not valid for the data. |
| SmbusErrorBusy | The bus was in use for an inordinate length of time. This is not caused by scheduling on the same host computer. |
| SmbusErrorNoDevice | The device did not respond to its address. |
| SmbusErrorUnsupported | This operation is unsupported by the master. |
| SmbusErrorProtocol | Data from the device does not conform to the SMBus protocol. |
| SmbusErrorTimeout | The operation took too long resulting in a bus timeout. |
| SmbusError | A general error that doesn't fit one of the other exceptions. |
Definition at line 281 of file Smbus.hpp.
Referenced by duds::hardware::devices::instruments::INA219::INA219().