diff --git a/os/hal/templates/can_lld.c b/os/hal/templates/can_lld.c
index 1496ea172..f9385fe77 100644
--- a/os/hal/templates/can_lld.c
+++ b/os/hal/templates/can_lld.c
@@ -70,7 +70,7 @@ void can_lld_init(void) {
#if PLATFORM_CAN_USE_CAN1
/* Driver initialization.*/
canObjectInit(&CAND1);
-#endif
+#endif /* PLATFORM_CAN_USE_CAN1 */
}
/**
@@ -82,14 +82,16 @@ void can_lld_init(void) {
*/
void can_lld_start(CANDriver *canp) {
- /* Clock activation.*/
if (canp->state == CAN_STOP) {
+ /* Enables the pehipheral.*/
#if PLATFORM_CAN_USE_CAN1
if (&CAND1 == canp) {
}
-#endif
+#endif /* PLATFORM_CAN_USE_CAN1 */
}
+ /* Configures the peripheral.*/
+
}
/**
@@ -101,9 +103,15 @@ void can_lld_start(CANDriver *canp) {
*/
void can_lld_stop(CANDriver *canp) {
- /* If in ready state then disables the CAN peripheral.*/
if (canp->state == CAN_READY) {
+ /* Resets the peripheral.*/
+ /* Disables the peripheral.*/
+#if PLATFORM_CAN_USE_CAN1
+ if (&CAND1 == canp) {
+
+ }
+#endif /* PLATFORM_CAN_USE_CAN1 */
}
}
diff --git a/os/hal/templates/i2c_lld.c b/os/hal/templates/i2c_lld.c
index bd1484e99..e4a08f848 100644
--- a/os/hal/templates/i2c_lld.c
+++ b/os/hal/templates/i2c_lld.c
@@ -39,6 +39,11 @@
/* Driver exported variables. */
/*===========================================================================*/
+/** @brief I2C1 driver identifier.*/
+#if PLATFORM_I2C_USE_I2C1 || defined(__DOXYGEN__)
+I2CDriver I2CD1;
+#endif
+
/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
@@ -62,6 +67,9 @@
*/
void i2c_lld_init(void) {
+#if PLATFORM_I2C_USE_I2C1
+ i2cObjectInit(&I2CD1);
+#endif /* PLATFORM_I2C_USE_I2C1 */
}
/**
@@ -73,10 +81,16 @@ void i2c_lld_init(void) {
*/
void i2c_lld_start(I2CDriver *i2cp) {
- if (i2cp->i2c_state == I2C_STOP) {
- /* Clock activation.*/
+ if (i2cp->state == I2C_STOP) {
+ /* Enables the pehipheral.*/
+#if PLATFORM_I2C_USE_I2C1
+ if (&I2CD1 == i2cp) {
+
+ }
+#endif /* PLATFORM_I2C_USE_I2C1 */
}
- /* Configuration.*/
+ /* Configures the peripheral.*/
+
}
/**
@@ -88,70 +102,79 @@ void i2c_lld_start(I2CDriver *i2cp) {
*/
void i2c_lld_stop(I2CDriver *i2cp) {
+ if (i2cp->state != I2C_STOP) {
+ /* Resets the peripheral.*/
+
+ /* Disables the peripheral.*/
+#if PLATFORM_I2C_USE_I2C1
+ if (&I2CD1 == i2cp) {
+
+ }
+#endif /* PLATFORM_I2C_USE_I2C1 */
+ }
}
/**
- * @brief Initiates a master bus transaction.
- * @details This function sends a start bit followed by an one or two bytes
- * header.
+ * @brief Receives data via the I2C bus as master.
+ * @details Number of receiving bytes must be more than 1 on STM32F1x. This is
+ * hardware restriction.
*
* @param[in] i2cp pointer to the @p I2CDriver object
- * @param[in] header transaction header
+ * @param[in] addr slave device address
+ * @param[out] rxbuf pointer to the receive buffer
+ * @param[in] rxbytes number of bytes to be received
+ * @param[in] timeout the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return The operation status.
+ * @retval RDY_OK if the function succeeded.
+ * @retval RDY_RESET if one or more I2C errors occurred, the errors can
+ * be retrieved using @p i2cGetErrors().
+ * @retval RDY_TIMEOUT if a timeout occurred before operation end. After a
+ * timeout the driver must be stopped and restarted
+ * because the bus is in an uncertain state.
*
* @notapi
*/
-void i2c_lld_master_start(I2CDriver *i2cp, uint16_t header) {
+msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
+ uint8_t *rxbuf, size_t rxbytes,
+ systime_t timeout) {
+ return RDY_OK;
}
/**
- * @brief Terminates a master bus transaction.
+ * @brief Transmits data via the I2C bus as master.
+ * @details Number of receiving bytes must be 0 or more than 1 on STM32F1x.
+ * This is hardware restriction.
*
* @param[in] i2cp pointer to the @p I2CDriver object
+ * @param[in] addr slave device address
+ * @param[in] txbuf pointer to the transmit buffer
+ * @param[in] txbytes number of bytes to be transmitted
+ * @param[out] rxbuf pointer to the receive buffer
+ * @param[in] rxbytes number of bytes to be received
+ * @param[in] timeout the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return The operation status.
+ * @retval RDY_OK if the function succeeded.
+ * @retval RDY_RESET if one or more I2C errors occurred, the errors can
+ * be retrieved using @p i2cGetErrors().
+ * @retval RDY_TIMEOUT if a timeout occurred before operation end. After a
+ * timeout the driver must be stopped and restarted
+ * because the bus is in an uncertain state.
*
* @notapi
*/
-void i2c_lld_master_stop(I2CDriver *i2cp) {
-
-}
-
-/**
- * @brief Sends a restart bit.
- * @details Restart bits are required by some types of I2C transactions.
- *
- * @param[in] i2cp pointer to the @p I2CDriver object
- *
- * @notapi
- */
-void i2c_lld_master_restart(I2CDriver *i2cp) {
-
-}
-
-/**
- * @brief Master transmission.
- *
- * @param[in] i2cp pointer to the @p I2CDriver object
- * @param[in] n number of bytes to be transmitted
- * @param[in] txbuf transmit data buffer pointer
- *
- * @notapi
- */
-void i2c_lld_master_transmit(I2CDriver *i2cp, size_t n,
- const uint8_t *txbuf) {
-
-}
-
-/**
- * @brief Master receive.
- *
- * @param[in] i2cp pointer to the @p I2CDriver object
- * @param[in] n number of bytes to be transmitted
- * @param[in] rxbuf receive data buffer pointer
- *
- * @notapi
- */
-void i2c_lld_master_receive(I2CDriver *i2cp, size_t n, uint8_t *rxbuf) {
+msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
+ const uint8_t *txbuf, size_t txbytes,
+ uint8_t *rxbuf, size_t rxbytes,
+ systime_t timeout) {
+ return RDY_OK;
}
#endif /* HAL_USE_I2C */
diff --git a/os/hal/templates/i2c_lld.h b/os/hal/templates/i2c_lld.h
index 59fe8beee..2018142cb 100644
--- a/os/hal/templates/i2c_lld.h
+++ b/os/hal/templates/i2c_lld.h
@@ -39,6 +39,19 @@
/* Driver pre-compile time settings. */
/*===========================================================================*/
+/**
+ * @name Configuration options
+ * @{
+ */
+/**
+ * @brief I2C1 driver enable switch.
+ * @details If set to @p TRUE the support for I2C1 is included.
+ * @note The default is @p FALSE.
+ */
+#if !defined(PLATFORM_I2C_USE_I2C1) || defined(__DOXYGEN__)
+#define PLATFORM_I2C_USE_I2C1 FALSE
+#endif
+
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
@@ -47,11 +60,15 @@
/* Driver data structures and types. */
/*===========================================================================*/
+/**
+ * @brief Type representing I2C address.
+ */
+typedef uint16_t i2caddr_t;
/**
- * @brief Type of a structure representing an I2C driver.
+ * @brief Type of I2C Driver condition flags.
*/
-typedef struct I2CDriver I2CDriver;
+typedef uint32_t i2cflags_t;
/**
* @brief I2C completion callback type.
@@ -66,24 +83,45 @@ typedef void (*i2ccallback_t)(I2CDriver *i2cp, i2cstatus_t sts);
* @note Implementations may extend this structure to contain more,
* architecture dependent, fields.
*/
+
+/**
+ * @brief Driver configuration structure.
+ */
typedef struct {
- /** @brief I2C bus bit rate.*/
- uint32_t ic_speed;
- /* End of the mandatory fields.*/
+ uint32_t dummy;
} I2CConfig;
/**
- * @brief Structure representing an I2C driver.
- * @note Implementations may extend this structure to contain more,
- * architecture dependent, fields.
+ * @brief Type of a structure representing an I2C driver.
*/
-struct I2CDriver {
- /** @brief Driver state.*/
- i2cstate_t id_state;
- /** @brief Current configuration data.*/
- const I2CConfig *id_config;
- /** @brief Current callback.*/
- i2ccallback_t id_callback;
+typedef struct I2CDriver I2CDriver;
+
+/**
+ * @brief Structure representing an I2C driver.
+ */
+struct I2CDriver{
+ /**
+ * @brief Driver state.
+ */
+ i2cstate_t state;
+ /**
+ * @brief Current configuration data.
+ */
+ const I2CConfig *config;
+ /**
+ * @brief Error flags.
+ */
+ i2cflags_t errors;
+#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__)
+#if CH_USE_MUTEXES || defined(__DOXYGEN__)
+ /**
+ * @brief Mutex protecting the bus.
+ */
+ Mutex mutex;
+#elif CH_USE_SEMAPHORES
+ Semaphore semaphore;
+#endif
+#endif /* I2C_USE_MUTUAL_EXCLUSION */
#if defined(I2C_DRIVER_EXT_FIELDS)
I2C_DRIVER_EXT_FIELDS
#endif
@@ -94,22 +132,37 @@ struct I2CDriver {
/* Driver macros. */
/*===========================================================================*/
+/**
+ * @brief Get errors from I2C driver.
+ *
+ * @param[in] i2cp pointer to the @p I2CDriver object
+ *
+ * @notapi
+ */
+#define i2c_lld_get_errors(i2cp) ((i2cp)->errors)
+
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
+#if !defined(__DOXYGEN__)
+#if PLATFORM_I2C_USE_I2C1
+extern I2CDriver I2CD1;
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
void i2c_lld_init(void);
void i2c_lld_start(I2CDriver *i2cp);
void i2c_lld_stop(I2CDriver *i2cp);
- void i2c_lld_master_start(I2CDriver *i2cp, uint16_t header);
- void i2c_lld_master_stop(I2CDriver *i2cp);
- void i2c_lld_master_restart(I2CDriver *i2cp);
- void i2c_lld_master_transmit(I2CDriver *i2cp, size_t n,
- const uint8_t *txbuf);
- void i2c_lld_master_receive(I2CDriver *i2cp, size_t n, uint8_t *rxbuf);
+ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
+ const uint8_t *txbuf, size_t txbytes,
+ uint8_t *rxbuf, size_t rxbytes,
+ systime_t timeout);
+ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
+ uint8_t *rxbuf, size_t rxbytes,
+ systime_t timeout);
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/templates/meta/driver_lld.c b/os/hal/templates/meta/driver_lld.c
index 6c0386332..95d1b1063 100644
--- a/os/hal/templates/meta/driver_lld.c
+++ b/os/hal/templates/meta/driver_lld.c
@@ -39,6 +39,11 @@
/* Driver exported variables. */
/*===========================================================================*/
+/** @brief XXX1 driver identifier.*/
+#if PLATFORM_XXX_USE_XXX1 || defined(__DOXYGEN__)
+XXXDriver XXXD1;
+#endif
+
/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
@@ -62,6 +67,10 @@
*/
void xxx_lld_init(void) {
+#if PLATFORM_XXX_USE_XXX1
+ /* Driver initialization.*/
+ xxxObjectInit(&XXXD1);
+#endif /* PLATFORM_XXX_USE_XXX1 */
}
/**
@@ -74,9 +83,15 @@ void xxx_lld_init(void) {
void xxx_lld_start(XXXDriver *xxxp) {
if (xxxp->state == XXX_STOP) {
- /* Clock activation.*/
+ /* Enables the pehipheral.*/
+#if PLATFORM_XXX_USE_XXX1
+ if (&XXXD1 == xxxp) {
+
+ }
+#endif /* PLATFORM_XXX_USE_XXX1 */
}
- /* Configuration.*/
+ /* Configures the peripheral.*/
+
}
/**
@@ -89,8 +104,14 @@ void xxx_lld_start(XXXDriver *xxxp) {
void xxx_lld_stop(XXXDriver *xxxp) {
if (xxxp->state == XXX_READY) {
- /* Clock deactivation.*/
+ /* Resets the peripheral.*/
+ /* Disables the peripheral.*/
+#if PLATFORM_XXX_USE_XXX1
+ if (&XXXD1 == xxxp) {
+
+ }
+#endif /* PLATFORM_XXX_USE_XXX1 */
}
}
diff --git a/os/hal/templates/meta/driver_lld.h b/os/hal/templates/meta/driver_lld.h
index bc0b29972..3dcdb5c4b 100644
--- a/os/hal/templates/meta/driver_lld.h
+++ b/os/hal/templates/meta/driver_lld.h
@@ -83,6 +83,10 @@ struct XXXDriver {
/* External declarations. */
/*===========================================================================*/
+#if PLATFORM_XXX_USE_XXX1 && !defined(__DOXYGEN__)
+extern XXXDriver XXXD1;
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif