Fixed bug 3530043.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/stable_2.4.x@4243 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
gdisirio 2012-05-27 14:49:50 +00:00
parent 7b7650ed6e
commit 78d70f48b5
3 changed files with 20 additions and 19 deletions

View File

@ -173,9 +173,11 @@ static void i2c_lld_safety_timeout(void *p) {
I2CDriver *i2cp = (I2CDriver *)p; I2CDriver *i2cp = (I2CDriver *)p;
if (i2cp->thread) { if (i2cp->thread) {
Thread *tp = i2cp->thread;
i2c_lld_abort_operation(i2cp); i2c_lld_abort_operation(i2cp);
i2cp->thread->p_u.rdymsg = RDY_TIMEOUT; i2cp->thread = NULL;
chSchReadyI(i2cp->thread); tp->p_u.rdymsg = RDY_TIMEOUT;
chSchReadyI(tp);
} }
} }
@ -773,11 +775,11 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
systime_t timeout) { systime_t timeout) {
I2C_TypeDef *dp = i2cp->i2c; I2C_TypeDef *dp = i2cp->i2c;
VirtualTimer vt; VirtualTimer vt;
msg_t rdymsg;
chDbgCheck((rxbytes > 1), "i2c_lld_master_receive_timeout"); chDbgCheck((rxbytes > 1), "i2c_lld_master_receive_timeout");
/* Global timeout for the whole operation.*/ /* Global timeout for the whole operation.*/
if (timeout != TIME_INFINITE)
chVTSetI(&vt, timeout, i2c_lld_safety_timeout, (void *)i2cp); chVTSetI(&vt, timeout, i2c_lld_safety_timeout, (void *)i2cp);
/* Releases the lock from high level driver.*/ /* Releases the lock from high level driver.*/
@ -794,10 +796,10 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
/* Waits until BUSY flag is reset and the STOP from the previous operation /* Waits until BUSY flag is reset and the STOP from the previous operation
is completed, alternatively for a timeout condition.*/ is completed, alternatively for a timeout condition.*/
while ((dp->SR2 & I2C_SR2_BUSY) || (dp->CR1 & I2C_CR1_STOP)) { while ((dp->SR2 & I2C_SR2_BUSY) || (dp->CR1 & I2C_CR1_STOP)) {
if (!chVTIsArmedI(&vt)) {
chSysLock(); chSysLock();
if (!chVTIsArmedI(&vt))
return RDY_TIMEOUT; return RDY_TIMEOUT;
} chSysUnlock();
} }
/* This lock will be released in high level driver.*/ /* This lock will be released in high level driver.*/
@ -815,11 +817,10 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
/* Waits for the operation completion or a timeout.*/ /* Waits for the operation completion or a timeout.*/
i2cp->thread = chThdSelf(); i2cp->thread = chThdSelf();
chSchGoSleepS(THD_STATE_SUSPENDED); chSchGoSleepS(THD_STATE_SUSPENDED);
rdymsg = chThdSelf()->p_u.rdymsg; if (chVTIsArmedI(&vt))
if (rdymsg != RDY_TIMEOUT)
chVTResetI(&vt); chVTResetI(&vt);
return rdymsg; return chThdSelf()->p_u.rdymsg;
} }
/** /**
@ -853,12 +854,12 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
systime_t timeout) { systime_t timeout) {
I2C_TypeDef *dp = i2cp->i2c; I2C_TypeDef *dp = i2cp->i2c;
VirtualTimer vt; VirtualTimer vt;
msg_t rdymsg;
chDbgCheck(((rxbytes == 0) || ((rxbytes > 1) && (rxbuf != NULL))), chDbgCheck(((rxbytes == 0) || ((rxbytes > 1) && (rxbuf != NULL))),
"i2c_lld_master_transmit_timeout"); "i2c_lld_master_transmit_timeout");
/* Global timeout for the whole operation.*/ /* Global timeout for the whole operation.*/
if (timeout != TIME_INFINITE)
chVTSetI(&vt, timeout, i2c_lld_safety_timeout, (void *)i2cp); chVTSetI(&vt, timeout, i2c_lld_safety_timeout, (void *)i2cp);
/* Releases the lock from high level driver.*/ /* Releases the lock from high level driver.*/
@ -879,10 +880,10 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
/* Waits until BUSY flag is reset and the STOP from the previous operation /* Waits until BUSY flag is reset and the STOP from the previous operation
is completed, alternatively for a timeout condition.*/ is completed, alternatively for a timeout condition.*/
while ((dp->SR2 & I2C_SR2_BUSY) || (dp->CR1 & I2C_CR1_STOP)) { while ((dp->SR2 & I2C_SR2_BUSY) || (dp->CR1 & I2C_CR1_STOP)) {
if (!chVTIsArmedI(&vt)) {
chSysLock(); chSysLock();
if (!chVTIsArmedI(&vt))
return RDY_TIMEOUT; return RDY_TIMEOUT;
} chSysUnlock();
} }
/* This lock will be released in high level driver.*/ /* This lock will be released in high level driver.*/
@ -900,11 +901,10 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
/* Waits for the operation completion or a timeout.*/ /* Waits for the operation completion or a timeout.*/
i2cp->thread = chThdSelf(); i2cp->thread = chThdSelf();
chSchGoSleepS(THD_STATE_SUSPENDED); chSchGoSleepS(THD_STATE_SUSPENDED);
rdymsg = chThdSelf()->p_u.rdymsg; if (chVTIsArmedI(&vt))
if (rdymsg != RDY_TIMEOUT)
chVTResetI(&vt); chVTResetI(&vt);
return rdymsg; return chThdSelf()->p_u.rdymsg;
} }
#endif /* HAL_USE_I2C */ #endif /* HAL_USE_I2C */

View File

@ -79,6 +79,7 @@
***************************************************************************** *****************************************************************************
*** 2.4.2 *** *** 2.4.2 ***
- FIX: Fixed timeout related race condition in STM32 I2C driver (bug 3530043).
- FIX: Fixed wrong macro check in STM32 MAC driver (bug 3527179). - FIX: Fixed wrong macro check in STM32 MAC driver (bug 3527179).
- FIX: Fixed error in STM32L-Discovery board.h file (bug 3526918). - FIX: Fixed error in STM32L-Discovery board.h file (bug 3526918).