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
master
barthess 2011-06-23 18:05:20 +00:00
parent 3f2e823d2a
commit fbeff97d92
3 changed files with 14 additions and 9 deletions

View File

@ -42,7 +42,8 @@ static uint32_t i2c_get_event(I2CDriver *i2cp){
} }
static void i2c_serve_event_interrupt(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; I2C_TypeDef *dp = i2cp->id_i2c;
@ -71,26 +72,24 @@ static void i2c_serve_event_interrupt(I2CDriver *i2cp) {
} }
//Initialize the transmit buffer pointer //Initialize the transmit buffer pointer
txBuffp = (uint8_t*)i2cp->id_slave_config->txbuf; txBuffp = (uint8_t*)i2cp->id_slave_config->txbuf;
datap = txBuffp;
txBuffp++;
i2cp->txbytes--; i2cp->txbytes--;
/* If no further data to be sent, disable the I2C ITBUF in order to not have a TxE interrupt */ /* If no further data to be sent, disable the I2C ITBUF in order to not have a TxE interrupt */
if(i2cp->txbytes == 0) { if(i2cp->txbytes == 0) {
dp->CR2 &= (uint16_t)~I2C_CR2_ITBUFEN; dp->CR2 &= (uint16_t)~I2C_CR2_ITBUFEN;
} }
//EV8_1 write the first data //EV8_1 write the first data
dp->DR = *datap; dp->DR = *txBuffp;
txBuffp++;
break; break;
case I2C_EV8_MASTER_BYTE_TRANSMITTING: case I2C_EV8_MASTER_BYTE_TRANSMITTING:
if(i2cp->txbytes > 0) { if(i2cp->txbytes > 0) {
datap = txBuffp;
txBuffp++;
i2cp->txbytes--; i2cp->txbytes--;
if(i2cp->txbytes == 0) { if(i2cp->txbytes == 0) {
/* If no further data to be sent, disable the ITBUF in order to not have a TxE interrupt */ /* 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->CR2 &= (uint16_t)~I2C_CR2_ITBUFEN;
} }
dp->DR = *datap; dp->DR = *txBuffp;
txBuffp++;
} }
break; break;
case I2C_EV8_2_MASTER_BYTE_TRANSMITTED: case I2C_EV8_2_MASTER_BYTE_TRANSMITTED:
@ -195,6 +194,8 @@ static void i2c_serve_event_interrupt(I2CDriver *i2cp) {
} }
break; break;
} }
#undef rxBuffp
#undef txBuffp
} }
static void i2c_serve_error_interrupt(I2CDriver *i2cp) { static void i2c_serve_error_interrupt(I2CDriver *i2cp) {

View File

@ -163,8 +163,10 @@ struct I2CDriver{
*/ */
const I2CSlaveConfig *id_slave_config; const I2CSlaveConfig *id_slave_config;
size_t txbytes; /*!< Number of bytes to transmitted. */ size_t txbytes; /*!< Number of bytes to be transmitted. */
size_t rxbytes; /*!< Number of bytes to received. */ 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 errors; /*!< Error flags.*/
i2cflags_t flags; /*!< State flags.*/ i2cflags_t flags; /*!< State flags.*/

View File

@ -69,6 +69,8 @@ void i2cObjectInit(I2CDriver *i2cp) {
i2cp->id_state = I2C_STOP; i2cp->id_state = I2C_STOP;
i2cp->id_config = NULL; i2cp->id_config = NULL;
i2cp->rxBuffp = NULL;
i2cp->txBuffp = NULL;
i2cp->id_slave_config = NULL; i2cp->id_slave_config = NULL;
#if I2C_USE_WAIT #if I2C_USE_WAIT