aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-01-02 19:04:50 +0000
committerbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-01-02 19:04:50 +0000
commit86b3f07923ebbcff11950efc4d5b9a76f5b33710 (patch)
tree882ce914d5e6fb8769b031257eabf9a766f8e0a0
parentfc44d8dbc601e9fa20c8c32402944faf11fe67c2 (diff)
downloadChibiOS-86b3f07923ebbcff11950efc4d5b9a76f5b33710.tar.gz
ChibiOS-86b3f07923ebbcff11950efc4d5b9a76f5b33710.tar.bz2
ChibiOS-86b3f07923ebbcff11950efc4d5b9a76f5b33710.zip
I2C. Reorganized locks.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3711 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--os/hal/platforms/STM32/i2c_lld.c10
-rw-r--r--os/hal/platforms/STM32/i2c_lld.h16
2 files changed, 12 insertions, 14 deletions
diff --git a/os/hal/platforms/STM32/i2c_lld.c b/os/hal/platforms/STM32/i2c_lld.c
index 352d213f8..51e41d4fe 100644
--- a/os/hal/platforms/STM32/i2c_lld.c
+++ b/os/hal/platforms/STM32/i2c_lld.c
@@ -666,7 +666,9 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp,
dmaStreamSetTransactionSize(i2cp->dmarx, rxbytes);
dmaStreamSetMode(i2cp->dmarx, ((i2cp->dmamode) | STM32_DMA_CR_DIR_P2M));
- i2c_lld_wait_bus_free(i2cp);
+ /* Wait until BUSY flag is reset. */
+ while(i2cp->i2c->SR2 & I2C_SR2_BUSY)
+ ;
/* wait stop bit from previous transaction*/
while(i2cp->i2c->CR1 & I2C_CR1_STOP)
@@ -675,6 +677,7 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp,
i2cp->i2c->CR2 |= I2C_CR2_ITERREN | I2C_CR2_ITEVTEN;
i2cp->i2c->CR1 |= I2C_CR1_START | I2C_CR1_ACK;
+ chSysLock(); /* this lock will be released in high level part */
i2c_lld_wait_s(i2cp, timeout, rdymsg);
return rdymsg;
@@ -724,7 +727,9 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, uint8_t slave_addr,
dmaStreamSetTransactionSize(i2cp->dmatx, txbytes);
dmaStreamSetMode(i2cp->dmatx, ((i2cp->dmamode) | STM32_DMA_CR_DIR_M2P));
- i2c_lld_wait_bus_free(i2cp);
+ /* Wait until BUSY flag is reset. */
+ while(i2cp->i2c->SR2 & I2C_SR2_BUSY)
+ ;
/* wait stop bit from previous transaction*/
while(i2cp->i2c->CR1 & I2C_CR1_STOP)
@@ -733,6 +738,7 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, uint8_t slave_addr,
i2cp->i2c->CR2 |= I2C_CR2_ITERREN | I2C_CR2_ITEVTEN;
i2cp->i2c->CR1 |= I2C_CR1_START;
+ chSysLock(); /* this lock will be released in high level part */
i2c_lld_wait_s(i2cp, timeout, rdymsg);
return rdymsg;
diff --git a/os/hal/platforms/STM32/i2c_lld.h b/os/hal/platforms/STM32/i2c_lld.h
index 5a3757d88..f770be615 100644
--- a/os/hal/platforms/STM32/i2c_lld.h
+++ b/os/hal/platforms/STM32/i2c_lld.h
@@ -328,13 +328,6 @@ struct I2CDriver{
/*===========================================================================*/
/**
- * Wait until BUSY flag is reset.
- */
-#define i2c_lld_wait_bus_free(i2cp) { \
- while(i2cp->i2c->SR2 & I2C_SR2_BUSY) \
- ; \
-}
-/**
* @brief Waits for operation completion.
* @details This function waits for the driver to complete the current
* operation.
@@ -349,7 +342,6 @@ struct I2CDriver{
#define i2c_lld_wait_s(i2cp, timeout, rdymsg) { \
chDbgAssert((i2cp)->thread == NULL, \
"_i2c_wait(), #1", "already waiting"); \
- chSysLock(); /* this lock will be disarmed in high level part */ \
(i2cp)->thread = chThdSelf(); \
rdymsg = chSchGoSleepTimeoutS(THD_STATE_SUSPENDED, timeout); \
}
@@ -362,13 +354,13 @@ struct I2CDriver{
* @notapi
*/
#define i2c_lld_wakeup_isr(i2cp) { \
+ chSysLockFromIsr(); \
if ((i2cp)->thread != NULL) { \
Thread *tp = (i2cp)->thread; \
(i2cp)->thread = NULL; \
- chSysLockFromIsr(); \
chSchReadyI(tp); \
- chSysUnlockFromIsr(); \
} \
+ chSysUnlockFromIsr(); \
}
/**
@@ -379,14 +371,14 @@ struct I2CDriver{
* @notapi
*/
#define i2c_lld_error_wakeup_isr(i2cp) { \
+ chSysLockFromIsr(); \
if ((i2cp)->thread != NULL) { \
Thread *tp = (i2cp)->thread; \
(i2cp)->thread = NULL; \
- chSysLockFromIsr(); \
tp->p_u.rdymsg = RDY_RESET; \
chSchReadyI(tp); \
- chSysUnlockFromIsr(); \
} \
+ chSysUnlockFromIsr(); \
}
/**