|
DUDS
|
Distributed Update of Data from Something
|
Implementation of the I2c interface using the Linux kernel's user-space support. More...
#include <DevI2c.hpp>
Public Member Functions | |
| DevI2c (const std::string &devname, int devaddr) | |
| Opens the device file for the bus. More... | |
| ~DevI2c () | |
| 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 void | converse (Conversation &conv) |
| Conducts I2C communication with a device using the Linux i2c-dev driver. More... | |
Public Member Functions inherited from duds::hardware::interface::Conversationalist | |
| virtual | ~Conversationalist ()=0 |
| Allow proper destruction using a Conversationalist pointer. More... | |
Private Member Functions | |
| void | io (i2c_rdwr_ioctl_data &idat) |
| Calls ioctl to request the kernel do the I2C communication, the check for error conditions and throw corresponding exception on error. More... | |
Private Attributes | |
| int | addr |
| The device (slave) address. 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 I2c interface using the Linux kernel's user-space support.
This requires that the kernel be built with support for the 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 I2C 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 I2cDeviceAddr.
Definition at line 36 of file DevI2c.hpp.
| duds::hardware::interface::linux::DevI2c::DevI2c | ( | const std::string & | devname, |
| int | devaddr | ||
| ) |
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. |
| I2cErrorUnsupported | A 10-bit address was requested but is not supported by the kernel's driver. |
| I2cErrorNoBus | The device file could not be opened. |
Definition at line 23 of file DevI2c.cpp.
| duds::hardware::interface::linux::DevI2c::~DevI2c | ( | ) |
Closes the device file.
Definition at line 39 of file DevI2c.cpp.
|
virtual |
Returns the address of the device that this object will attempt to communicate with.
Implements duds::hardware::interface::I2c.
Definition at line 164 of file DevI2c.cpp.
|
virtual |
Conducts I2C communication with a device using the Linux i2c-dev driver.
The MpfVarlen flag of ConversationPart is honored. Input parts using this must have a buffer longer than 32 bytes; 32 for data, and 1 for the length.
The MpfBreak flag of ConversationPart objects is honored by separating the conversation into multiple ioctl() calls. The combination of the kernel's scheduling and other running software will determine if any other I2C communication from the same master will occur between the ioctl() calls here.
| conv | The conversation to have with the device on the other end. |
| I2cErrorConversationLength | The conversation has too many parts for the implementation to handle. |
| I2cErrorPartLength | A variable length input part had a buffer that was not longer than 32 bytes. |
| I2cErrorBusy | The bus was in use for an inordinate length of time. This is not caused by scheduling on the same host computer. It can be caused by another I2C master on a mulit-master bus. |
| I2cErrorNoDevice | The device did not respond to its address. |
| I2cErrorUnsupported | An operation is unsupported by the master. |
| I2cErrorProtocol | Data from the device does not conform to the I2C protocol. |
| I2cErrorTimeout | The operation took too long resulting in a bus timeout. |
| I2cError | A general error that doesn't fit one of the other exceptions. |
Implements duds::hardware::interface::I2c.
Definition at line 98 of file DevI2c.cpp.
|
private |
Calls ioctl to request the kernel do the I2C communication, the check for error conditions and throw corresponding exception on error.
Definition at line 43 of file DevI2c.cpp.
Referenced by converse().
|
private |
The device (slave) address.
Definition at line 48 of file DevI2c.hpp.
Referenced by address(), converse(), DevI2c(), and io().
|
private |
Stores the device file name for later error reporting.
Definition at line 40 of file DevI2c.hpp.
Referenced by converse(), DevI2c(), and io().
|
private |
The file descriptor for the open device.
Definition at line 44 of file DevI2c.hpp.