Skip to content

Commit

Permalink
configurable timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
gautierhattenberger committed May 9, 2018
1 parent b1c2dd1 commit ae24eda
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sw/airborne/mcu_periph/i2c.c
Expand Up @@ -287,6 +287,11 @@ bool i2c_transceive(struct i2c_periph *p, struct i2c_transaction *t,
return i2c_submit(p, t);
}

/** Default timeout for blocking I2C transactions */
#ifndef I2C_BLOCKING_TIMEOUT
#define I2C_BLOCKING_TIMEOUT 1.f
#endif

bool i2c_blocking_transmit(struct i2c_periph *p, struct i2c_transaction *t,
uint8_t s_addr, uint8_t len)
{
Expand All @@ -301,7 +306,7 @@ bool i2c_blocking_transmit(struct i2c_periph *p, struct i2c_transaction *t,
// Wait for transaction to complete
float start_t = get_sys_time_float();
while (t->status == I2CTransPending || t->status == I2CTransRunning) {
if (get_sys_time_float() - start_t > 1.f) {
if (get_sys_time_float() - start_t > I2C_BLOCKING_TIMEOUT) {
break; // timeout after 1 second
}
}
Expand All @@ -322,7 +327,7 @@ bool i2c_blocking_receive(struct i2c_periph *p, struct i2c_transaction *t,
// Wait for transaction to complete
float start_t = get_sys_time_float();
while (t->status == I2CTransPending || t->status == I2CTransRunning) {
if (get_sys_time_float() - start_t > 1.f) {
if (get_sys_time_float() - start_t > I2C_BLOCKING_TIMEOUT) {
break; // timeout after 1 second
}
}
Expand All @@ -343,7 +348,7 @@ bool i2c_blocking_transceive(struct i2c_periph *p, struct i2c_transaction *t,
// Wait for transaction to complete
float start_t = get_sys_time_float();
while (t->status == I2CTransPending || t->status == I2CTransRunning) {
if (get_sys_time_float() - start_t > 1.f) {
if (get_sys_time_float() - start_t > I2C_BLOCKING_TIMEOUT) {
break; // timeout after 1 second
}
}
Expand Down

0 comments on commit ae24eda

Please sign in to comment.