From 551a1c1f22fb53085ab9485115fc3d27af92083c Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 30 Jun 2011 21:37:34 +0000 Subject: I2C. Added dirty hack to realize thread safe dirver. Needs to be rewrited. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3100 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/i2c.h | 6 ++++++ os/hal/src/i2c.c | 16 ++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'os/hal') diff --git a/os/hal/include/i2c.h b/os/hal/include/i2c.h index 953bd88dd..60b2c322d 100644 --- a/os/hal/include/i2c.h +++ b/os/hal/include/i2c.h @@ -210,10 +210,16 @@ struct I2CSlaveConfig{ (i2cp)->id_state = I2C_COMPLETE; \ if(((i2cp)->id_slave_config)->id_callback) { \ ((i2cp)->id_slave_config)->id_callback(i2cp, i2cscfg); \ + if((i2cp)->id_state == I2C_COMPLETE) \ + (i2cp)->id_state = I2C_READY; \ } \ + else \ + (i2cp)->id_state = I2C_READY; \ _i2c_wakeup_isr(i2cp); \ + i2cReleaseBus(i2cp); \ } + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index dca7c6125..725e92d65 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -71,6 +71,8 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_config = NULL; i2cp->rxbuff_p = NULL; i2cp->txbuff_p = NULL; + i2cp->rxbuf = NULL; + i2cp->txbuf = NULL; i2cp->id_slave_config = NULL; #if I2C_USE_WAIT @@ -154,6 +156,8 @@ void i2cMasterTransmit(I2CDriver *i2cp, uint8_t *rxbuf, size_t rxbytes) { + i2cAcquireBus(i2cp); + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ (txbytes > 0) &&\ @@ -180,11 +184,6 @@ void i2cMasterTransmit(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE; i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); _i2c_wait_s(i2cp); -#if !I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); -#endif - if (i2cp->id_state == I2C_COMPLETE) - i2cp->id_state = I2C_READY; chSysUnlock(); } @@ -205,6 +204,8 @@ void i2cMasterReceive(I2CDriver *i2cp, uint8_t *rxbuf, size_t rxbytes){ + i2cAcquireBus(i2cp); + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ (rxbytes > 0) && \ @@ -231,11 +232,6 @@ void i2cMasterReceive(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE; i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); _i2c_wait_s(i2cp); -#if !I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); -#endif - if (i2cp->id_state == I2C_COMPLETE) - i2cp->id_state = I2C_READY; chSysUnlock(); } -- cgit v1.2.3