git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5310 35acf78f-673a-0410-8e92-d51de3d6d3f4

master
gdisirio 2013-02-24 10:07:54 +00:00
parent 679520b160
commit 4e6bb0ddf4
5 changed files with 186 additions and 77 deletions

View File

@ -70,7 +70,7 @@ void can_lld_init(void) {
#if PLATFORM_CAN_USE_CAN1 #if PLATFORM_CAN_USE_CAN1
/* Driver initialization.*/ /* Driver initialization.*/
canObjectInit(&CAND1); canObjectInit(&CAND1);
#endif #endif /* PLATFORM_CAN_USE_CAN1 */
} }
/** /**
@ -82,14 +82,16 @@ void can_lld_init(void) {
*/ */
void can_lld_start(CANDriver *canp) { void can_lld_start(CANDriver *canp) {
/* Clock activation.*/
if (canp->state == CAN_STOP) { if (canp->state == CAN_STOP) {
/* Enables the pehipheral.*/
#if PLATFORM_CAN_USE_CAN1 #if PLATFORM_CAN_USE_CAN1
if (&CAND1 == canp) { 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) { void can_lld_stop(CANDriver *canp) {
/* If in ready state then disables the CAN peripheral.*/
if (canp->state == CAN_READY) { if (canp->state == CAN_READY) {
/* Resets the peripheral.*/
/* Disables the peripheral.*/
#if PLATFORM_CAN_USE_CAN1
if (&CAND1 == canp) {
}
#endif /* PLATFORM_CAN_USE_CAN1 */
} }
} }

View File

@ -39,6 +39,11 @@
/* Driver exported variables. */ /* Driver exported variables. */
/*===========================================================================*/ /*===========================================================================*/
/** @brief I2C1 driver identifier.*/
#if PLATFORM_I2C_USE_I2C1 || defined(__DOXYGEN__)
I2CDriver I2CD1;
#endif
/*===========================================================================*/ /*===========================================================================*/
/* Driver local variables. */ /* Driver local variables. */
/*===========================================================================*/ /*===========================================================================*/
@ -62,6 +67,9 @@
*/ */
void i2c_lld_init(void) { 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) { void i2c_lld_start(I2CDriver *i2cp) {
if (i2cp->i2c_state == I2C_STOP) { if (i2cp->state == I2C_STOP) {
/* Clock activation.*/ /* Enables the pehipheral.*/
#if PLATFORM_I2C_USE_I2C1
if (&I2CD1 == i2cp) {
} }
/* Configuration.*/ #endif /* PLATFORM_I2C_USE_I2C1 */
}
/* Configures the peripheral.*/
} }
/** /**
@ -88,70 +102,79 @@ void i2c_lld_start(I2CDriver *i2cp) {
*/ */
void i2c_lld_stop(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. * @brief Receives data via the I2C bus as master.
* @details This function sends a start bit followed by an one or two bytes * @details Number of receiving bytes must be more than 1 on STM32F1x. This is
* header. * hardware restriction.
* *
* @param[in] i2cp pointer to the @p I2CDriver object * @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. <b>After a
* timeout the driver must be stopped and restarted
* because the bus is in an uncertain state</b>.
* *
* @notapi * @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] 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. <b>After a
* timeout the driver must be stopped and restarted
* because the bus is in an uncertain state</b>.
* *
* @notapi * @notapi
*/ */
void i2c_lld_master_stop(I2CDriver *i2cp) { 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) {
/**
* @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) {
return RDY_OK;
} }
#endif /* HAL_USE_I2C */ #endif /* HAL_USE_I2C */

View File

@ -39,6 +39,19 @@
/* Driver pre-compile time settings. */ /* 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. */ /* Derived constants and error checks. */
/*===========================================================================*/ /*===========================================================================*/
@ -47,11 +60,15 @@
/* Driver data structures and types. */ /* 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. * @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, * @note Implementations may extend this structure to contain more,
* architecture dependent, fields. * architecture dependent, fields.
*/ */
/**
* @brief Driver configuration structure.
*/
typedef struct { typedef struct {
/** @brief I2C bus bit rate.*/ uint32_t dummy;
uint32_t ic_speed;
/* End of the mandatory fields.*/
} I2CConfig; } I2CConfig;
/**
* @brief Type of a structure representing an I2C driver.
*/
typedef struct I2CDriver I2CDriver;
/** /**
* @brief Structure representing an I2C driver. * @brief Structure representing an I2C driver.
* @note Implementations may extend this structure to contain more,
* architecture dependent, fields.
*/ */
struct I2CDriver{ struct I2CDriver{
/** @brief Driver state.*/ /**
i2cstate_t id_state; * @brief Driver state.
/** @brief Current configuration data.*/ */
const I2CConfig *id_config; i2cstate_t state;
/** @brief Current callback.*/ /**
i2ccallback_t id_callback; * @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) #if defined(I2C_DRIVER_EXT_FIELDS)
I2C_DRIVER_EXT_FIELDS I2C_DRIVER_EXT_FIELDS
#endif #endif
@ -94,22 +132,37 @@ struct I2CDriver {
/* Driver macros. */ /* 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. */ /* External declarations. */
/*===========================================================================*/ /*===========================================================================*/
#if !defined(__DOXYGEN__)
#if PLATFORM_I2C_USE_I2C1
extern I2CDriver I2CD1;
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void i2c_lld_init(void); void i2c_lld_init(void);
void i2c_lld_start(I2CDriver *i2cp); void i2c_lld_start(I2CDriver *i2cp);
void i2c_lld_stop(I2CDriver *i2cp); void i2c_lld_stop(I2CDriver *i2cp);
void i2c_lld_master_start(I2CDriver *i2cp, uint16_t header); msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
void i2c_lld_master_stop(I2CDriver *i2cp); const uint8_t *txbuf, size_t txbytes,
void i2c_lld_master_restart(I2CDriver *i2cp); uint8_t *rxbuf, size_t rxbytes,
void i2c_lld_master_transmit(I2CDriver *i2cp, size_t n, systime_t timeout);
const uint8_t *txbuf); msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
void i2c_lld_master_receive(I2CDriver *i2cp, size_t n, uint8_t *rxbuf); uint8_t *rxbuf, size_t rxbytes,
systime_t timeout);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -39,6 +39,11 @@
/* Driver exported variables. */ /* Driver exported variables. */
/*===========================================================================*/ /*===========================================================================*/
/** @brief XXX1 driver identifier.*/
#if PLATFORM_XXX_USE_XXX1 || defined(__DOXYGEN__)
XXXDriver XXXD1;
#endif
/*===========================================================================*/ /*===========================================================================*/
/* Driver local variables. */ /* Driver local variables. */
/*===========================================================================*/ /*===========================================================================*/
@ -62,6 +67,10 @@
*/ */
void xxx_lld_init(void) { 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) { void xxx_lld_start(XXXDriver *xxxp) {
if (xxxp->state == XXX_STOP) { if (xxxp->state == XXX_STOP) {
/* Clock activation.*/ /* Enables the pehipheral.*/
#if PLATFORM_XXX_USE_XXX1
if (&XXXD1 == xxxp) {
} }
/* Configuration.*/ #endif /* PLATFORM_XXX_USE_XXX1 */
}
/* Configures the peripheral.*/
} }
/** /**
@ -89,8 +104,14 @@ void xxx_lld_start(XXXDriver *xxxp) {
void xxx_lld_stop(XXXDriver *xxxp) { void xxx_lld_stop(XXXDriver *xxxp) {
if (xxxp->state == XXX_READY) { 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 */
} }
} }

View File

@ -83,6 +83,10 @@ struct XXXDriver {
/* External declarations. */ /* External declarations. */
/*===========================================================================*/ /*===========================================================================*/
#if PLATFORM_XXX_USE_XXX1 && !defined(__DOXYGEN__)
extern XXXDriver XXXD1;
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif