I2CInterface: Add process call methods
Add C++ methods to perform the following SMBus commands:
* Process Call
* Block Write-Block Read Process Call
For Block Write-Block Read Process Call, implement support for writes up
to 255 bytes. SMBus 2.0 supported a maximum of 32 bytes, and SMBus 3.0
supports a maximum of 255 bytes. The current Linux SMBus function only
supports 32 byte writes. Provide an alternate implementation using the
lower level I2C_RDWR ioctl() to support up to 255 bytes.
Tested:
* Verified Process Call worked correctly
* Verified Block Write-Block Read Process Call worked correctly
* When using SMBus function
* When using I2C_RDWR ioctl()
* Tested error cases
* See complete test plan at
https://gist.github.com/smccarney/96eda4c7c11fe4f89e4491c768f76047
Change-Id: Icc1ba840741b1e26a50fe32bad8b2181a01dbb24
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
diff --git a/tools/i2c/i2c_interface.hpp b/tools/i2c/i2c_interface.hpp
index 637794b..7f5b68b 100644
--- a/tools/i2c/i2c_interface.hpp
+++ b/tools/i2c/i2c_interface.hpp
@@ -184,6 +184,44 @@
*/
virtual void write(uint8_t addr, uint8_t size, const uint8_t* data,
Mode mode = Mode::SMBUS) = 0;
+
+ /** @brief SMBus Process Call protocol to write and then read word data
+ *
+ * @param[in] addr - The register address of the i2c device
+ * @param[in] writeData - The data to write to the i2c device
+ * @param[out] readData - The data read from the i2c device
+ *
+ * @throw I2CException on error
+ */
+ virtual void processCall(uint8_t addr, uint16_t writeData,
+ uint16_t& readData) = 0;
+
+ /** @brief SMBus Block Write-Block Read Process Call protocol
+ *
+ * The maximum write size depends on the SMBus version being used and what
+ * functionality the I2C adapter supports.
+ *
+ * If SMBus version 2.0 is being used, the maximum write size is 32 bytes.
+ * The read size + write size must be <= 32 bytes.
+ *
+ * If SMBus version 3.0 is being used and the I2C adapter supports plain
+ * I2C-level commands, the maximum write size is 255 bytes. The read size +
+ * write size must be <= 255 bytes.
+ *
+ * @param[in] addr - The register address of the i2c device
+ * @param[in] writeSize - The size of data to write
+ * @param[in] writeData - The data to write to the i2c device
+ * @param[out] readSize - The size of data read from i2c device. Max read
+ * size is 32 bytes.
+ * @param[out] readData - Pointer to buffer to hold the data read from the
+ * i2c device. Must be large enough to hold the data
+ * returned by the device (max is 32 bytes).
+ *
+ * @throw I2CException on error
+ */
+ virtual void processCall(uint8_t addr, uint8_t writeSize,
+ const uint8_t* writeData, uint8_t& readSize,
+ uint8_t* readData) = 0;
};
/** @brief Create an I2CInterface instance