aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/include/i2c.h
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/include/i2c.h')
-rw-r--r--os/hal/include/i2c.h47
1 files changed, 35 insertions, 12 deletions
diff --git a/os/hal/include/i2c.h b/os/hal/include/i2c.h
index 2e45450ee..dfae26e64 100644
--- a/os/hal/include/i2c.h
+++ b/os/hal/include/i2c.h
@@ -39,19 +39,20 @@
/* Driver constants. */
/*===========================================================================*/
+/* TODO: To be reviewed, too STM32-centric.*/
/**
* @name I2C bus error conditions
* @{
*/
-#define I2CD_NO_ERROR 0x00 /**< @brief No error. */
-#define I2CD_BUS_ERROR 0x01 /**< @brief Bus Error. */
-#define I2CD_ARBITRATION_LOST 0x02 /**< @brief Arbitration Lost. */
-#define I2CD_ACK_FAILURE 0x04 /**< @brief Acknowledge Failure. */
-#define I2CD_OVERRUN 0x08 /**< @brief Overrun/Underrun. */
-#define I2CD_PEC_ERROR 0x10 /**< @brief PEC Error in
+#define I2C_NO_ERROR 0x00 /**< @brief No error. */
+#define I2C_BUS_ERROR 0x01 /**< @brief Bus Error. */
+#define I2C_ARBITRATION_LOST 0x02 /**< @brief Arbitration Lost. */
+#define I2C_ACK_FAILURE 0x04 /**< @brief Acknowledge Failure. */
+#define I2C_OVERRUN 0x08 /**< @brief Overrun/Underrun. */
+#define I2C_PEC_ERROR 0x10 /**< @brief PEC Error in
reception. */
-#define I2CD_TIMEOUT 0x20 /**< @brief Hardware timeout. */
-#define I2CD_SMB_ALERT 0x40 /**< @brief SMBus Alert. */
+#define I2C_TIMEOUT 0x20 /**< @brief Hardware timeout. */
+#define I2C_SMB_ALERT 0x40 /**< @brief SMBus Alert. */
/** @} */
/*===========================================================================*/
@@ -69,10 +70,6 @@
/* Derived constants and error checks. */
/*===========================================================================*/
-#if I2C_USE_MUTUAL_EXCLUSION && !CH_USE_MUTEXES && !CH_USE_SEMAPHORES
-#error "I2C_USE_MUTUAL_EXCLUSION requires CH_USE_MUTEXES and/or CH_USE_SEMAPHORES"
-#endif
-
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
@@ -96,6 +93,32 @@ typedef enum {
/*===========================================================================*/
/**
+ * @brief Wakes up the waiting thread notifying no errors.
+ *
+ * @param[in] i2cp pointer to the @p I2CDriver object
+ *
+ * @notapi
+ */
+#define _i2c_wakeup_isr(i2cp) do { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(i2cp)->thread, MSG_OK); \
+ osalSysUnlockFromISR(); \
+} while(0)
+
+/**
+ * @brief Wakes up the waiting thread notifying errors.
+ *
+ * @param[in] i2cp pointer to the @p I2CDriver object
+ *
+ * @notapi
+ */
+#define _i2c_wakeup_error_isr(i2cp) do { \
+ osalSysLockFromISR(); \
+ osalThreadResumeI(&(i2cp)->thread, MSG_RESET); \
+ osalSysUnlockFromISR(); \
+} while(0)
+
+/**
* @brief Wrap i2cMasterTransmitTimeout function with TIME_INFINITE timeout.
* @api
*/