From 2459b2beb0af669675d93c57fc132c734981667c Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 4 May 2011 13:12:34 +0000 Subject: I2C. My driver really sucks. I'll try to use alberto driver with my improvements git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2918 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c_brts.c | 64 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 15 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/i2c_brts.c b/os/hal/src/i2c_brts.c index 5a0471e0f..ad9a5d0ac 100644 --- a/os/hal/src/i2c_brts.c +++ b/os/hal/src/i2c_brts.c @@ -69,6 +69,19 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_state = I2C_STOP; i2cp->id_config = NULL; i2cp->id_slave_config = NULL; + +#if I2C_USE_WAIT + i2cp->id_thread = NULL; +#endif /* I2C_USE_WAIT */ + +#if I2C_USE_MUTUAL_EXCLUSION +#if CH_USE_MUTEXES + chMtxInit(&i2cp->id_mutex); +#else + chSemInit(&i2cp->id_semaphore, 1); +#endif /* CH_USE_MUTEXES */ +#endif /* I2C_USE_MUTUAL_EXCLUSION */ + #if defined(I2C_DRIVER_EXT_INIT_HOOK) I2C_DRIVER_EXT_INIT_HOOK(i2cp); #endif @@ -116,14 +129,38 @@ void i2cStop(I2CDriver *i2cp) { chSysUnlock(); } +/** + * @brief Generate (re)start on the bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cMasterStart(I2CDriver *i2cp){ + + chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); + + chSysLock(); + i2c_lld_master_start(i2cp); + chSysUnlock(); +} + +/** + * @brief Generate stop on the bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cMasterStop(I2CDriver *i2cp){ + + chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); + chSysLock(); + i2c_lld_master_stop(i2cp); + chSysUnlock(); +} + /** * @brief Sends data ever the I2C bus. * * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr1 7-bit address of the slave - * @param[in] slave_addr1 used in 10-bit address mode - * @param[in] n number of words to send - * @param[in] txbuf the pointer to the transmit buffer + * @param[in] i2cscfg pointer to the @p I2CSlaveConfig object * */ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { @@ -134,19 +171,17 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterTransmit(), #1", "not active"); - i2c_lld_master_transmitI(i2cp, i2cscfg); + chSysLock(); + i2c_lld_master_transmit(i2cp, i2cscfg); + chSysUnlock(); } /** * @brief Receives data from the I2C bus. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr1 7-bit address of the slave - * @param[in] slave_addr1 used in 10-bit address mode - * @param[in] n number of words to receive - * @param[out] rxbuf the pointer to the receive buffer - * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] i2cscfg pointer to the @p I2CSlaveConfig object */ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { @@ -156,14 +191,13 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterReceive(), #1", "not active"); - i2c_lld_master_receiveI(i2cp, i2cscfg); + chSysLock(); + i2c_lld_master_receive(i2cp, i2cscfg); + chSysUnlock(); } - - - #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** * @brief Gains exclusive access to the I2C bus. -- cgit v1.2.3