summaryrefslogtreecommitdiffstats
path: root/cpukit/include/dev/i2c/i2c.h
diff options
context:
space:
mode:
authorChristian Mauderer <christian.mauderer@embedded-brains.de>2021-05-26 16:33:40 +0200
committerChristian Mauderer <christian.mauderer@embedded-brains.de>2021-06-22 13:51:17 +0200
commit5bb5e013563ed6825aa5ca0c93e1b01db7e721cd (patch)
treed5aa3c9ee5e8aa05141fa03ca7c9155954a5827e /cpukit/include/dev/i2c/i2c.h
parentb47dbbc5f7c8518634c7c5fccd57d78c65444f2d (diff)
downloadrtems-5bb5e013563ed6825aa5ca0c93e1b01db7e721cd.tar.bz2
i2c: Add non blocking read / write
This adds the possibility to open an I2C bus with O_NONBLOCK (or set it later via fcntl) to get non-blocking transmissions. This means that if the bus is busy, a read, write or transfer ioctl will return with a EAGAIN errno.
Diffstat (limited to '')
-rw-r--r--cpukit/include/dev/i2c/i2c.h44
1 files changed, 43 insertions, 1 deletions
diff --git a/cpukit/include/dev/i2c/i2c.h b/cpukit/include/dev/i2c/i2c.h
index ac2c369785..5aa45e390c 100644
--- a/cpukit/include/dev/i2c/i2c.h
+++ b/cpukit/include/dev/i2c/i2c.h
@@ -243,6 +243,16 @@ int i2c_bus_register(
);
/**
+ * @brief Try to obtain the bus.
+ *
+ * @param[in] bus The bus control.
+ *
+ * @retval 0 Successful operation.
+ * @retval EBUSY if mutex is already locked.
+ */
+int i2c_bus_try_obtain(i2c_bus *bus);
+
+/**
* @brief Obtains the bus.
*
* @param[in] bus The bus control.
@@ -259,7 +269,8 @@ void i2c_bus_release(i2c_bus *bus);
/**
* @brief Transfers I2C messages.
*
- * The bus is obtained before the transfer and released afterwards.
+ * The bus is obtained before the transfer and released afterwards. This is the
+ * same like calling @ref i2c_bus_do_transfer with flags set to 0.
*
* @param[in] bus The bus control.
* @param[in] msgs The messages to transfer.
@@ -271,6 +282,37 @@ void i2c_bus_release(i2c_bus *bus);
*/
int i2c_bus_transfer(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count);
+/**
+ * @brief Transfers I2C messages with optional flags.
+ *
+ * The bus is obtained before the transfer and released afterwards. If the flag
+ * I2C_BUS_NOBLOCK is set and the bus is already obtained, nothing will be
+ * transfered and the function returns with an -EAGAIN.
+ *
+ * @param[in] bus The bus control.
+ * @param[in] msgs The messages to transfer.
+ * @param[in] msg_count The count of messages to transfer. It must be
+ * positive.
+ * @param[in] flags Options for the whole transfer.
+ *
+ * @retval 0 Successful operation.
+ * @retval -EAGAIN if @ref I2C_BUS_NOBLOCK is set and the bus is already
+ * obtained.
+ * @retval negative Negative error number in case of an error.
+ */
+int i2c_bus_do_transfer(
+ i2c_bus *bus,
+ i2c_msg *msgs,
+ uint32_t msg_count,
+ uint32_t flags
+);
+
+/**
+ * @brief I2C bus transfer flag to indicate that the task should not block if
+ * the bus is busy on a new transfer.
+ */
+#define I2C_BUS_NOBLOCK (1u << 0)
+
/** @} */
/**