diff options
author | px4dev <px4@purgatory.org> | 2013-01-26 16:15:23 -0800 |
---|---|---|
committer | px4dev <px4@purgatory.org> | 2013-01-26 16:15:23 -0800 |
commit | fd28217e5982cbb848a2ddf2d118ffa3d69a4746 (patch) | |
tree | 86a3ab3a657f4752615379e3bce20d3f8e8cffc4 /apps/drivers/device/i2c.cpp | |
parent | 6bd662cfb2d90628eb03c0bec1ebac54e47a7090 (diff) | |
download | px4-firmware-fd28217e5982cbb848a2ddf2d118ffa3d69a4746.tar.gz px4-firmware-fd28217e5982cbb848a2ddf2d118ffa3d69a4746.tar.bz2 px4-firmware-fd28217e5982cbb848a2ddf2d118ffa3d69a4746.zip |
Implement the retry counter for message-vector based transfers.
Diffstat (limited to 'apps/drivers/device/i2c.cpp')
-rw-r--r-- | apps/drivers/device/i2c.cpp | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/apps/drivers/device/i2c.cpp b/apps/drivers/device/i2c.cpp index a5b2fab7e..d2cd5f19b 100644 --- a/apps/drivers/device/i2c.cpp +++ b/apps/drivers/device/i2c.cpp @@ -169,19 +169,31 @@ I2C::transfer(const uint8_t *send, unsigned send_len, uint8_t *recv, unsigned re int I2C::transfer(i2c_msg_s *msgv, unsigned msgs) { + int ret; + + /* force the device address into the message vector */ for (unsigned i = 0; i < msgs; i++) msgv[i].addr = _address; - /* - * I2C architecture means there is an unavoidable race here - * if there are any devices on the bus with a different frequency - * preference. Really, this is pointless. - */ - I2C_SETFREQUENCY(_dev, _frequency); - int ret = I2C_TRANSFER(_dev, msgv, msgs); + unsigned tries = 0; - if (ret != OK) - up_i2creset(_dev); + do { + + /* + * I2C architecture means there is an unavoidable race here + * if there are any devices on the bus with a different frequency + * preference. Really, this is pointless. + */ + I2C_SETFREQUENCY(_dev, _frequency); + ret = I2C_TRANSFER(_dev, msgv, msgs); + + if (ret == OK) + break; + + if (ret != OK) + up_i2creset(_dev); + + } while (tries++ < _retries); return ret; } |