|
DUDS
|
Distributed Update of Data from Something
|
Implementation of the Smbus interface using the Linux kernel's user-space support. More...
#include <DevSmbus.hpp>
Public Member Functions | |
| DevSmbus (const std::string &devname, int devaddr, bool pec=true) | |
| Opens the device file for the bus. More... | |
| DevSmbus (const std::string &devname, int devaddr, UsePec) | |
| Opens the device file for the bus and specifies that Packet Error Checking (PEC) will be used. More... | |
| DevSmbus (const std::string &devname, int devaddr, NoPec) | |
| Opens the device file for the bus and specifies that Packet Error Checking (PEC) will not be used. More... | |
| ~DevSmbus () | |
| Closes the device file. More... | |
| virtual int | address () const |
| 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) |
| 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) |
| Does a block process call operation. More... | |
| virtual int | receive (std::uint8_t cmd, std::uint8_t *in, const int maxlen) |
| 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) |
| Sends a command byte, then reads a block of data from the device. More... | |
| virtual std::uint8_t | receiveByte () |
| Read a single byte from the device without sending a command/register byte first. More... | |
| virtual std::uint8_t | receiveByte (std::uint8_t cmd) |
| Sends a command byte, then reads a single byte from the device. More... | |
| virtual std::uint16_t | receiveWord (std::uint8_t cmd) |
| Sends a command byte, then reads a word, two bytes, from the device. More... | |
| virtual void | transmit (std::uint8_t cmd, const std::uint8_t *out, const int len) |
| Sends a command byte and a block of data to the device. More... | |
| virtual void | transmitBool (bool out) |
| Sends a single bit to the device. More... | |
| virtual void | transmitByte (std::uint8_t byte) |
| Sends a single byte to the device. More... | |
| virtual void | transmitByte (std::uint8_t cmd, std::uint8_t byte) |
| Sends a command byte and a data byte to the device. More... | |
| virtual void | transmitWord (std::uint8_t cmd, std::uint16_t word) |
| Sends a command byte and a data word to the device. More... | |
Public Member Functions inherited from duds::hardware::interface::Smbus | |
| virtual | ~Smbus ()=0 |
| std::uint16_t | receiveWordBe (std::uint8_t cmd) |
| Sends a command byte, then reads a big-endian word from 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... | |
| void | transmitWordBe (std::uint8_t cmd, std::uint16_t word) |
| Sends a command byte and a big-endian data word to the device. More... | |
Private Member Functions | |
| void | io (i2c_smbus_ioctl_data &sdat) |
| Sends I/O requests to the kernel, then checks for an error and if found throws the appropriate exception. More... | |
Private Attributes | |
| int | addr |
| The device (slave) address; used for error reporting. More... | |
| std::string | dev |
| Stores the device file name for later error reporting. More... | |
| int | fd |
| The file descriptor for the open device. More... | |
Implementation of the Smbus interface using the Linux kernel's user-space support.
This requires that the kernel be built with support for the SMBus or I2C master, and support for user-space I2C access. If the support is in kernel modules, they must be loaded along with the i2c-dev module. Using the kernel's i2c-gpio driver should be more efficient than implementing the SMBus protocol with user-space GPIO support.
All thrown exceptions will include an attribute of boost::errinfo_file_name with the device file name, along with SmbusDeviceAddr.
The name follows SysFsGpio in naming the kernel interface, and it avoids using the same name as the base class which I figured might lessen confusion.
Definition at line 40 of file DevSmbus.hpp.
| duds::hardware::interface::linux::DevSmbus::DevSmbus | ( | const std::string & | devname, |
| int | devaddr, | ||
| bool | pec = true |
||
| ) |
Opens the device file for the bus.
| devname | The path to the device file, usually /dev/i2c-N where N is the number assigned to the bus. |
| devaddr | The device, or slave, address used as the destination of communications. |
| pec | True (default) to enable use of Packet Error Checking. If the device supports PEC, this should be used to help prevent bad data over the bus from causing trouble. |
| SmbusErrorUnsupported | Either PEC requested but not supported, or a 10-bit address was requested but is not supported by the kernel's driver. |
| SmbusErrorNoBus | The device file could not be opened or failed to accept the device address. |
Definition at line 24 of file DevSmbus.cpp.
|
inline |
Opens the device file for the bus and specifies that Packet Error Checking (PEC) will be used.
| devname | The path to the device file, usually /dev/i2c-N where N is the number assigned to the bus. |
| devaddr | The device, or slave, address used as the destination of communications. |
| SmbusErrorUnsupported | Either PEC requested but not supported, or a 10-bit address was requested but is not supported by the kernel's driver. |
| SmbusError | The device file could not be opened or failed to accept the device address. |
Definition at line 88 of file DevSmbus.hpp.
|
inline |
Opens the device file for the bus and specifies that Packet Error Checking (PEC) will not be used.
| devname | The path to the device file, usually /dev/i2c-N where N is the number assigned to the bus. |
| devaddr | The device, or slave, address used as the destination of communications. |
| SmbusErrorUnsupported | A 10-bit address was requested but is not supported by the kernel's driver. |
| SmbusError | The device file could not be opened or failed to accept the device address. |
Definition at line 102 of file DevSmbus.hpp.
| duds::hardware::interface::linux::DevSmbus::~DevSmbus | ( | ) |
|
virtual |
Returns the address of the device that this object will attempt to communicate with.
Implements duds::hardware::interface::Smbus.
Definition at line 285 of file DevSmbus.cpp.
Referenced by DevSmbus().
|
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. |
Implements duds::hardware::interface::Smbus.
Definition at line 248 of file DevSmbus.cpp.
Referenced by DevSmbus().
|
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. |
Implements duds::hardware::interface::Smbus.
Definition at line 261 of file DevSmbus.cpp.
|
private |
Sends I/O requests to the kernel, then checks for an error and if found throws the appropriate exception.
Definition at line 57 of file DevSmbus.cpp.
Referenced by call(), receive(), receiveByte(), receiveWord(), transmit(), transmitBool(), transmitByte(), and transmitWord().
|
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. |
Implements duds::hardware::interface::Smbus.
Definition at line 194 of file DevSmbus.cpp.
Referenced by DevSmbus().
|
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. |
Implements duds::hardware::interface::Smbus.
Definition at line 213 of file DevSmbus.cpp.
|
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. |
Implements duds::hardware::interface::Smbus.
Definition at line 122 of file DevSmbus.cpp.
Referenced by DevSmbus().
|
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. |
Implements duds::hardware::interface::Smbus.
Definition at line 146 of file DevSmbus.cpp.
|
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. |
Implements duds::hardware::interface::Smbus.
Definition at line 170 of file DevSmbus.cpp.
Referenced by DevSmbus().
|
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. |
Implements duds::hardware::interface::Smbus.
Definition at line 226 of file DevSmbus.cpp.
Referenced by DevSmbus().
|
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. |
Implements duds::hardware::interface::Smbus.
Definition at line 112 of file DevSmbus.cpp.
Referenced by DevSmbus().
|
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. |
Implements duds::hardware::interface::Smbus.
Definition at line 134 of file DevSmbus.cpp.
Referenced by DevSmbus().
|
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. |
Implements duds::hardware::interface::Smbus.
Definition at line 158 of file DevSmbus.cpp.
|
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. |
Implements duds::hardware::interface::Smbus.
Definition at line 182 of file DevSmbus.cpp.
Referenced by DevSmbus().
|
private |
The device (slave) address; used for error reporting.
Definition at line 52 of file DevSmbus.hpp.
Referenced by address(), call(), DevSmbus(), io(), receive(), and transmit().
|
private |
Stores the device file name for later error reporting.
Definition at line 44 of file DevSmbus.hpp.
Referenced by call(), DevSmbus(), io(), receive(), and transmit().
|
private |
The file descriptor for the open device.
Definition at line 48 of file DevSmbus.hpp.
Referenced by DevSmbus(), io(), and ~DevSmbus().