1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-19 04:52:12 +01:00

PiOS I2C: Swap the expected return value of the F2 pios i2c calls

This commit is contained in:
James Cotton 2011-09-06 16:21:06 -05:00
parent 627c931c79
commit d7ea1fc306
6 changed files with 39 additions and 45 deletions

View File

@ -305,7 +305,7 @@ bool PIOS_HMC5843_NewDataAvailable(void)
* \param[in] len number of bytes which should be read
* \return 0 if operation was successful
* \return -1 if error during I2C transfer
* \return -4 if invalid length
* \return -2 if unable to claim i2c device
*/
static bool PIOS_HMC5843_Read(uint8_t address, uint8_t * buffer, uint8_t len)
{
@ -331,7 +331,7 @@ static bool PIOS_HMC5843_Read(uint8_t address, uint8_t * buffer, uint8_t len)
}
};
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)) == 0;
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list));
}
/**
@ -339,7 +339,8 @@ static bool PIOS_HMC5843_Read(uint8_t address, uint8_t * buffer, uint8_t len)
* \param[in] address Register address
* \param[in] buffer source buffer
* \return 0 if operation was successful
* \return -1 if error during I2C transfer
* \retval -1 if error during I2C transfer
* \retval -2 if unable to claim i2c device
*/
static bool PIOS_HMC5843_Write(uint8_t address, uint8_t buffer)
{
@ -359,7 +360,7 @@ static bool PIOS_HMC5843_Write(uint8_t address, uint8_t buffer)
,
};
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)) == 0;
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list));
}
void PIOS_HMC5843_IRQHandler(void)

View File

@ -222,7 +222,7 @@ int32_t PIOS_BMP085_Read(uint8_t address, uint8_t * buffer, uint8_t len)
}
};
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)) ? 0 : -1;
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list));
}
/**
@ -250,7 +250,7 @@ int32_t PIOS_BMP085_Write(uint8_t address, uint8_t buffer)
,
};
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)) ? 0 : -1;
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list));
}
/**

View File

@ -252,7 +252,7 @@ bool PIOS_HMC5883_NewDataAvailable(void)
* \param[in] len number of bytes which should be read
* \return 0 if operation was successful
* \return -1 if error during I2C transfer
* \return -4 if invalid length
* \return -2 if unable to claim i2c device
*/
static int32_t PIOS_HMC5883_Read(uint8_t address, uint8_t * buffer, uint8_t len)
{
@ -278,7 +278,7 @@ static int32_t PIOS_HMC5883_Read(uint8_t address, uint8_t * buffer, uint8_t len)
}
};
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)) ? 0 : -1;
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list));
}
/**
@ -287,6 +287,7 @@ static int32_t PIOS_HMC5883_Read(uint8_t address, uint8_t * buffer, uint8_t len)
* \param[in] buffer source buffer
* \return 0 if operation was successful
* \return -1 if error during I2C transfer
* \return -2 if unable to claim i2c device
*/
static int32_t PIOS_HMC5883_Write(uint8_t address, uint8_t buffer)
{
@ -305,8 +306,8 @@ static int32_t PIOS_HMC5883_Write(uint8_t address, uint8_t buffer)
}
,
};
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list)) ? 0 : -1;
;
return PIOS_I2C_Transfer(PIOS_I2C_MAIN_ADAPTER, txn_list, NELEMENTS(txn_list));
}
/**

View File

@ -952,7 +952,7 @@ out_fail:
return(-1);
}
bool PIOS_I2C_Transfer(uint32_t i2c_id, const struct pios_i2c_txn txn_list[], uint32_t num_txns)
int32_t PIOS_I2C_Transfer(uint32_t i2c_id, const struct pios_i2c_txn txn_list[], uint32_t num_txns)
{
struct pios_i2c_adapter * i2c_adapter = (struct pios_i2c_adapter *)i2c_id;
@ -970,14 +970,11 @@ bool PIOS_I2C_Transfer(uint32_t i2c_id, const struct pios_i2c_txn txn_list[], ui
timeout = i2c_adapter->cfg->transfer_timeout_ms / portTICK_RATE_MS;
semaphore_success &= (xSemaphoreTake(i2c_adapter->sem_busy, timeout) == pdTRUE);
#else
uint32_t timeout = 0xfff;
while(i2c_adapter->busy && --timeout);
if(timeout == 0) //timed out
return false;
PIOS_IRQ_Disable();
if(i2c_adapter->busy)
return false;
if(i2c_adapter->busy) {
PIOS_IRQ_Enable();
return -2;
}
i2c_adapter->busy = 1;
PIOS_IRQ_Enable();
#endif /* USE_FREERTOS */
@ -1023,10 +1020,12 @@ bool PIOS_I2C_Transfer(uint32_t i2c_id, const struct pios_i2c_txn txn_list[], ui
PIOS_IRQ_Enable();
#endif /* USE_FREERTOS */
return (!i2c_adapter->bus_error) && semaphore_success;
return !semaphore_success ? -2 :
i2c_adapter->bus_error ? -1 :
0;
}
bool PIOS_I2C_Transfer_Callback(uint32_t i2c_id, const struct pios_i2c_txn txn_list[], uint32_t num_txns, void *callback)
int32_t PIOS_I2C_Transfer_Callback(uint32_t i2c_id, const struct pios_i2c_txn txn_list[], uint32_t num_txns, void *callback)
{
struct pios_i2c_adapter * i2c_adapter = (struct pios_i2c_adapter *)i2c_id;
@ -1045,16 +1044,10 @@ bool PIOS_I2C_Transfer_Callback(uint32_t i2c_id, const struct pios_i2c_txn txn_l
timeout = i2c_adapter->cfg->transfer_timeout_ms / portTICK_RATE_MS;
semaphore_success &= (xSemaphoreTake(i2c_adapter->sem_busy, timeout) == pdTRUE);
#else
uint32_t timeout = 0xfff;
while(i2c_adapter->busy && --timeout);
if(timeout == 0) //timed out
return false;
PIOS_IRQ_Disable();
if(i2c_adapter->busy)
return false;
i2c_adapter->busy = 2;
if(i2c_adapter->busy) {
PIOS_IRQ_Enable();
return -2;
}
#endif /* USE_FREERTOS */
PIOS_DEBUG_Assert(i2c_adapter->curr_state == I2C_STATE_STOPPED);
@ -1072,7 +1065,7 @@ bool PIOS_I2C_Transfer_Callback(uint32_t i2c_id, const struct pios_i2c_txn txn_l
i2c_adapter->bus_error = false;
i2c_adapter_inject_event(i2c_adapter, I2C_EVENT_START);
return semaphore_success;
return !semaphore_success ? -2 : 0;
}
void PIOS_I2C_EV_IRQ_Handler(uint32_t i2c_id)

View File

@ -168,7 +168,7 @@ int32_t PIOS_IMU3000_ReadFifo(struct pios_imu3000_data * buffer)
* \param[in] len number of bytes which should be read
* \return 0 if operation was successful
* \return -1 if error during I2C transfer
* \return -4 if invalid length
* \return -2 if unable to claim i2c device
*/
static int32_t PIOS_IMU3000_Read(uint8_t address, uint8_t * buffer, uint8_t len)
{
@ -194,7 +194,7 @@ static int32_t PIOS_IMU3000_Read(uint8_t address, uint8_t * buffer, uint8_t len)
}
};
return PIOS_I2C_Transfer(PIOS_I2C_GYRO_ADAPTER, txn_list, NELEMENTS(txn_list)) ? 0 : -1;
return PIOS_I2C_Transfer(PIOS_I2C_GYRO_ADAPTER, txn_list, NELEMENTS(txn_list));
}
// Must allocate on stack to be persistent
@ -227,9 +227,7 @@ static int32_t PIOS_IMU3000_Read_Callback(uint8_t address, uint8_t * buffer, uin
cb_txn_list[1].len = len;
cb_txn_list[1].buf = buffer;
PIOS_I2C_Transfer_Callback(PIOS_I2C_GYRO_ADAPTER, cb_txn_list, NELEMENTS(cb_txn_list), callback);
return 0;
return PIOS_I2C_Transfer_Callback(PIOS_I2C_GYRO_ADAPTER, cb_txn_list, NELEMENTS(cb_txn_list), callback);
}
/**
@ -238,6 +236,7 @@ static int32_t PIOS_IMU3000_Read_Callback(uint8_t address, uint8_t * buffer, uin
* \param[in] buffer source buffer
* \return 0 if operation was successful
* \return -1 if error during I2C transfer
* \return -2 if unable to claim i2c device
*/
static int32_t PIOS_IMU3000_Write(uint8_t address, uint8_t buffer)
{
@ -257,7 +256,7 @@ static int32_t PIOS_IMU3000_Write(uint8_t address, uint8_t buffer)
,
};
return PIOS_I2C_Transfer(PIOS_I2C_GYRO_ADAPTER, txn_list, NELEMENTS(txn_list)) ? 0 : -1;
return PIOS_I2C_Transfer(PIOS_I2C_GYRO_ADAPTER, txn_list, NELEMENTS(txn_list));
}
float PIOS_IMU3000_GetScale()

View File

@ -66,7 +66,7 @@ struct pios_i2c_fault_history {
/* Public Functions */
extern int32_t PIOS_I2C_Transfer(uint32_t i2c_id, const struct pios_i2c_txn txn_list[], uint32_t num_txns);
extern bool PIOS_I2C_Transfer_Callback(uint32_t i2c_id, const struct pios_i2c_txn txn_list[], uint32_t num_txns, void *callback);
extern int32_t PIOS_I2C_Transfer_Callback(uint32_t i2c_id, const struct pios_i2c_txn txn_list[], uint32_t num_txns, void *callback);
extern void PIOS_I2C_EV_IRQ_Handler(uint32_t i2c_id);
extern void PIOS_I2C_ER_IRQ_Handler(uint32_t i2c_id);
extern void PIOS_I2C_GetDiagnostics(struct pios_i2c_fault_history * data, uint8_t * error_counts);