aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/platforms
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/platforms')
-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(); \
}
/**