diff options
author | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-06-23 18:05:20 +0000 |
---|---|---|
committer | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-06-23 18:05:20 +0000 |
commit | fbeff97d9230af12326c94e3875adf9438f16ed4 (patch) | |
tree | 912dfad317c006ca57113725cf911395ed58e8be /os | |
parent | 3f2e823d2aafa5e8ab70fd51b643de12c8989e76 (diff) | |
download | ChibiOS-fbeff97d9230af12326c94e3875adf9438f16ed4.tar.gz ChibiOS-fbeff97d9230af12326c94e3875adf9438f16ed4.tar.bz2 ChibiOS-fbeff97d9230af12326c94e3875adf9438f16ed4.zip |
I2C. Variables shared among I2C1 and I2C2 interrupt handlers moved to driver structure.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3070 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r-- | os/hal/platforms/STM32/i2c_lld.c | 15 | ||||
-rw-r--r-- | os/hal/platforms/STM32/i2c_lld.h | 6 | ||||
-rw-r--r-- | os/hal/src/i2c.c | 2 |
3 files changed, 14 insertions, 9 deletions
diff --git a/os/hal/platforms/STM32/i2c_lld.c b/os/hal/platforms/STM32/i2c_lld.c index 729e14eb3..e59ef8d45 100644 --- a/os/hal/platforms/STM32/i2c_lld.c +++ b/os/hal/platforms/STM32/i2c_lld.c @@ -42,7 +42,8 @@ static uint32_t i2c_get_event(I2CDriver *i2cp){ } static void i2c_serve_event_interrupt(I2CDriver *i2cp) { - static __IO uint8_t *txBuffp, *rxBuffp, *datap; +#define txBuffp (i2cp->txBuffp) +#define rxBuffp (i2cp->rxBuffp) I2C_TypeDef *dp = i2cp->id_i2c; @@ -71,26 +72,24 @@ static void i2c_serve_event_interrupt(I2CDriver *i2cp) { } //Initialize the transmit buffer pointer txBuffp = (uint8_t*)i2cp->id_slave_config->txbuf; - datap = txBuffp; - txBuffp++; i2cp->txbytes--; /* If no further data to be sent, disable the I2C ITBUF in order to not have a TxE interrupt */ if(i2cp->txbytes == 0) { dp->CR2 &= (uint16_t)~I2C_CR2_ITBUFEN; } //EV8_1 write the first data - dp->DR = *datap; + dp->DR = *txBuffp; + txBuffp++; break; case I2C_EV8_MASTER_BYTE_TRANSMITTING: if(i2cp->txbytes > 0) { - datap = txBuffp; - txBuffp++; i2cp->txbytes--; if(i2cp->txbytes == 0) { /* If no further data to be sent, disable the ITBUF in order to not have a TxE interrupt */ dp->CR2 &= (uint16_t)~I2C_CR2_ITBUFEN; } - dp->DR = *datap; + dp->DR = *txBuffp; + txBuffp++; } break; case I2C_EV8_2_MASTER_BYTE_TRANSMITTED: @@ -195,6 +194,8 @@ static void i2c_serve_event_interrupt(I2CDriver *i2cp) { } break; } +#undef rxBuffp +#undef txBuffp } static void i2c_serve_error_interrupt(I2CDriver *i2cp) { diff --git a/os/hal/platforms/STM32/i2c_lld.h b/os/hal/platforms/STM32/i2c_lld.h index c3df51b07..66ee95dd9 100644 --- a/os/hal/platforms/STM32/i2c_lld.h +++ b/os/hal/platforms/STM32/i2c_lld.h @@ -163,8 +163,10 @@ struct I2CDriver{ */ const I2CSlaveConfig *id_slave_config; - size_t txbytes; /*!< Number of bytes to transmitted. */ - size_t rxbytes; /*!< Number of bytes to received. */ + size_t txbytes; /*!< Number of bytes to be transmitted. */ + size_t rxbytes; /*!< Number of bytes to be received. */ + uint8_t *rxBuffp; /*!< Pointer to the current byte in slave rx buffer. */ + uint8_t *txBuffp; /*!< Pointer to the current byte in slave tx buffer. */ i2cflags_t errors; /*!< Error flags.*/ i2cflags_t flags; /*!< State flags.*/ diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 4e3f5e5b9..56e2f4484 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -69,6 +69,8 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_state = I2C_STOP;
i2cp->id_config = NULL;
+ i2cp->rxBuffp = NULL;
+ i2cp->txBuffp = NULL;
i2cp->id_slave_config = NULL;
#if I2C_USE_WAIT
|