1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

pios_i2c: fixed a race condition with wrong bus locking when using FreeRTOS

When more than one task is concurrently trying to access
the same i2c bus and a timeout occurs on bus lock the
transfer would just continue and blow up the pios_i2c
driver. This has been fixed.
This commit is contained in:
lilvinz 2012-12-07 00:29:51 +01:00 committed by Alessio Morale
parent 37df2bcbf4
commit 6daed46ecc
2 changed files with 6 additions and 3 deletions

View File

@ -933,7 +933,8 @@ int32_t PIOS_I2C_Transfer(uint32_t i2c_id, const struct pios_i2c_txn txn_list[],
/* Lock the bus */
portTickType timeout;
timeout = i2c_adapter->cfg->transfer_timeout_ms / portTICK_RATE_MS;
semaphore_success &= (xSemaphoreTake(i2c_adapter->sem_busy, timeout) == pdTRUE);
if (xSemaphoreTake(i2c_adapter->sem_busy, timeout) == pdFALSE)
return -2;
#else
uint32_t timeout = 0xfff;
while(i2c_adapter->busy && --timeout);

View File

@ -970,7 +970,8 @@ int32_t PIOS_I2C_Transfer(uint32_t i2c_id, const struct pios_i2c_txn txn_list[],
/* Lock the bus */
portTickType timeout;
timeout = i2c_adapter->cfg->transfer_timeout_ms / portTICK_RATE_MS;
semaphore_success &= (xSemaphoreTake(i2c_adapter->sem_busy, timeout) == pdTRUE);
if (xSemaphoreTake(i2c_adapter->sem_busy, timeout) == pdFALSE)
return -2;
#else
PIOS_IRQ_Disable();
if(i2c_adapter->busy) {
@ -1046,7 +1047,8 @@ int32_t PIOS_I2C_Transfer_Callback(uint32_t i2c_id, const struct pios_i2c_txn tx
/* Lock the bus */
portTickType timeout;
timeout = i2c_adapter->cfg->transfer_timeout_ms / portTICK_RATE_MS;
semaphore_success &= (xSemaphoreTake(i2c_adapter->sem_busy, timeout) == pdTRUE);
if (xSemaphoreTake(i2c_adapter->sem_busy, timeout) == pdFALSE)
return -2;
#else
if(i2c_adapter->busy) {
PIOS_IRQ_Enable();