diff options
author | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-07-31 21:06:23 +0000 |
---|---|---|
committer | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-07-31 21:06:23 +0000 |
commit | 28b3dd95f1a5fe8ea51df21bc6eba7cd5f78c071 (patch) | |
tree | eea9b95a48d19254babdd1b1fdcba10d4c25e53e /os/hal/platforms | |
parent | b913fe956cc2d46a8bd7aad24a2ac4d792923422 (diff) | |
download | ChibiOS-28b3dd95f1a5fe8ea51df21bc6eba7cd5f78c071.tar.gz ChibiOS-28b3dd95f1a5fe8ea51df21bc6eba7cd5f78c071.tar.bz2 ChibiOS-28b3dd95f1a5fe8ea51df21bc6eba7cd5f78c071.zip |
I2C. Code cleanups.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3187 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/platforms')
-rw-r--r-- | os/hal/platforms/STM32/i2c_lld.c | 79 | ||||
-rw-r--r-- | os/hal/platforms/STM32/i2c_lld.h | 4 |
2 files changed, 46 insertions, 37 deletions
diff --git a/os/hal/platforms/STM32/i2c_lld.c b/os/hal/platforms/STM32/i2c_lld.c index 20db34fff..033077f2c 100644 --- a/os/hal/platforms/STM32/i2c_lld.c +++ b/os/hal/platforms/STM32/i2c_lld.c @@ -26,8 +26,10 @@ /*===========================================================================*/ /* Driver constants. */ /*===========================================================================*/ -#define I2C_STOP_GPT_TIMEOUT 50 /* waiting timer value */ -#define I2C_START_GPT_TIMEOUT 50 /* waiting timer value */ +/* TODO: may be? move this defines in i2c_lld.h and mcuconf.h */ +#define I2C_STOP_GPT_TIMEOUT 50 /* waiting timer value */ +#define I2C_START_GPT_TIMEOUT 50 /* waiting timer value */ +#define I2C_POLLING_TIMEOUT 0xFFFF /* timeout for syncronouse driver */ /*===========================================================================*/ /* Driver exported variables. */ @@ -705,17 +707,20 @@ void i2c_lld_master_transmit(I2CDriver *i2cp, uint16_t slave_addr, uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, size_t rxbytes) { /* "waiting" for STOP bit routine*/ - chDbgAssert(!(i2cp->flags & I2C_FLG_TIMER_ARMED), - "i2c_lld_master_transmit(), #1", "time to STOP is out"); - if ((i2cp->id_i2c->CR1 & I2C_CR1_STOP) && i2cp->timer != NULL && i2cp->timer_cfg != NULL){ - gptStartOneShot(i2cp->timer, I2C_STOP_GPT_TIMEOUT); - i2cp->flags |= I2C_FLG_TIMER_ARMED; - return; - } - else{ - while(i2cp->id_i2c->CR1 & I2C_CR1_STOP) - ; - } + #if STM32_I2C_I2C1_USE_POLLING_WAIT + uint32_t timeout = I2C_POLLING_TIMEOUT; + /* TODO: timeout and Assert here */ + while((i2cp->id_i2c->CR1 & I2C_CR1_STOP) && timeout) + timeout--; + chDbgAssert((timeout > 0), "i2c_lld_master_transmit(), #1", "time to STOP is out"); + #else + chDbgAssert(!(i2cp->flags & I2C_FLG_TIMER_ARMED), "i2c_lld_master_transmit(), #1", "time to STOP is out"); + if ((i2cp->id_i2c->CR1 & I2C_CR1_STOP) && i2cp->timer != NULL && i2cp->timer_cfg != NULL){ + gptStartOneShot(i2cp->timer, I2C_STOP_GPT_TIMEOUT); + i2cp->flags |= I2C_FLG_TIMER_ARMED; + return; + } + #endif /* STM32_I2C_I2C1_USE_POLLING_WAIT */ /* init driver fields */ i2cp->slave_addr = slave_addr; @@ -762,17 +767,19 @@ void i2c_lld_master_receive(I2CDriver *i2cp, uint16_t slave_addr, "some interrupt sources not clear"); /* "waiting" for STOP bit routine*/ - chDbgAssert(!(i2cp->flags & I2C_FLG_TIMER_ARMED), - "i2c_lld_master_receive(), #1", "time to STOP is out"); - if ((i2cp->id_i2c->CR1 & I2C_CR1_STOP) && i2cp->timer != NULL && i2cp->timer_cfg != NULL){ - gptStartOneShot(i2cp->timer, I2C_STOP_GPT_TIMEOUT); - i2cp->flags |= I2C_FLG_TIMER_ARMED; - return; - } - else{ - while(i2cp->id_i2c->CR1 & I2C_CR1_STOP) - ; - } + #if STM32_I2C_I2C1_USE_POLLING_WAIT + uint32_t timeout = I2C_POLLING_TIMEOUT; + while((i2cp->id_i2c->CR1 & I2C_CR1_STOP) && timeout) + timeout--; + chDbgAssert((timeout > 0), "i2c_lld_master_receive(), #1", "time to STOP is out"); + #else + chDbgAssert(!(i2cp->flags & I2C_FLG_TIMER_ARMED), "i2c_lld_master_receive(), #1", "time to STOP is out"); + if ((i2cp->id_i2c->CR1 & I2C_CR1_STOP) && i2cp->timer != NULL && i2cp->timer_cfg != NULL){ + gptStartOneShot(i2cp->timer, I2C_STOP_GPT_TIMEOUT); + i2cp->flags |= I2C_FLG_TIMER_ARMED; + return; + } + #endif /* STM32_I2C_I2C1_USE_POLLING_WAIT */ /* init driver fields */ i2cp->slave_addr = slave_addr; @@ -826,17 +833,19 @@ void i2c_lld_master_transceive(I2CDriver *i2cp){ i2cp->id_state = I2C_ACTIVE_TRANSCEIVE; /* "waiting" for START bit routine*/ - chDbgAssert(!(i2cp->flags & I2C_FLG_TIMER_ARMED), - "i2c_lld_master_transceive(), #1", "time to START is out"); - if ((i2cp->id_i2c->CR1 & I2C_CR1_START) && i2cp->timer != NULL && i2cp->timer_cfg != NULL){ - gptStartOneShot(i2cp->timer, I2C_START_GPT_TIMEOUT); - i2cp->flags |= I2C_FLG_TIMER_ARMED; - return; - } - else{ - while(i2cp->id_i2c->CR1 & I2C_CR1_START) - ; - } + #if STM32_I2C_I2C1_USE_POLLING_WAIT + uint32_t timeout = I2C_POLLING_TIMEOUT; + while((i2cp->id_i2c->CR1 & I2C_CR1_START) && timeout); + timeout--; + chDbgAssert((timeout > 0), "i2c_lld_master_transceive(), #1", "time to START is out"); + #else + chDbgAssert(!(i2cp->flags & I2C_FLG_TIMER_ARMED), "i2c_lld_master_transceive(), #1", "time to START is out"); + if ((i2cp->id_i2c->CR1 & I2C_CR1_START) && i2cp->timer != NULL && i2cp->timer_cfg != NULL){ + gptStartOneShot(i2cp->timer, I2C_START_GPT_TIMEOUT); + i2cp->flags |= I2C_FLG_TIMER_ARMED; + return; + } + #endif /* STM32_I2C_I2C1_USE_POLLING_WAIT */ /* init address fields */ if(i2cp->slave_addr & 0x8000){ /* 10-bit mode used */ diff --git a/os/hal/platforms/STM32/i2c_lld.h b/os/hal/platforms/STM32/i2c_lld.h index 44ecdf70e..6de73f6b0 100644 --- a/os/hal/platforms/STM32/i2c_lld.h +++ b/os/hal/platforms/STM32/i2c_lld.h @@ -113,7 +113,7 @@ /*===========================================================================*/ /** - * @brief Serial Driver condition flags type. + * @brief I2C Driver condition flags type. */ typedef uint32_t i2cflags_t; @@ -211,7 +211,7 @@ struct I2CDriver{ /** * @brief Timer for waiting STOP condition on the bus. - * @details Workaround for STM32 buggy I2C cell. + * @details This is workaround for STM32 buggy I2C cell. */ GPTDriver *timer; |