aboutsummaryrefslogtreecommitdiff
path: root/apps/systemcmds/i2c/i2c.c
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2013-01-08 01:11:52 -0800
committerpx4dev <px4@purgatory.org>2013-01-13 19:04:59 -0800
commitf12fa7ee060b33194723df983b643b51410ea4f6 (patch)
tree1c4e18c2c56c5c4195923968cd166bd8c404f330 /apps/systemcmds/i2c/i2c.c
parent7c7112a157d863665fe1b8fae2a94fbbb17dc199 (diff)
downloadpx4-firmware-f12fa7ee060b33194723df983b643b51410ea4f6.tar.gz
px4-firmware-f12fa7ee060b33194723df983b643b51410ea4f6.tar.bz2
px4-firmware-f12fa7ee060b33194723df983b643b51410ea4f6.zip
Don't do retries, since it just complicates things.
Diffstat (limited to 'apps/systemcmds/i2c/i2c.c')
-rw-r--r--apps/systemcmds/i2c/i2c.c73
1 files changed, 34 insertions, 39 deletions
diff --git a/apps/systemcmds/i2c/i2c.c b/apps/systemcmds/i2c/i2c.c
index 1124e560d..57c61e824 100644
--- a/apps/systemcmds/i2c/i2c.c
+++ b/apps/systemcmds/i2c/i2c.c
@@ -94,46 +94,41 @@ transfer(uint8_t address, uint8_t *send, unsigned send_len, uint8_t *recv, unsig
struct i2c_msg_s msgv[2];
unsigned msgs;
int ret;
- unsigned tries = 0;
-
- do {
- // debug("transfer out %p/%u in %p/%u", send, send_len, recv, recv_len);
-
- msgs = 0;
-
- if (send_len > 0) {
- msgv[msgs].addr = address;
- msgv[msgs].flags = 0;
- msgv[msgs].buffer = send;
- msgv[msgs].length = send_len;
- msgs++;
- }
-
- if (recv_len > 0) {
- msgv[msgs].addr = address;
- msgv[msgs].flags = I2C_M_READ;
- msgv[msgs].buffer = recv;
- msgv[msgs].length = recv_len;
- msgs++;
- }
-
- if (msgs == 0)
- return -1;
-
- /*
- * 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(i2c, 320000);
- ret = I2C_TRANSFER(i2c, &msgv[0], msgs);
-
- if (ret == OK)
- break;
-
- // reset the I2C bus to unwedge on error
+
+ // debug("transfer out %p/%u in %p/%u", send, send_len, recv, recv_len);
+
+ msgs = 0;
+
+ if (send_len > 0) {
+ msgv[msgs].addr = address;
+ msgv[msgs].flags = 0;
+ msgv[msgs].buffer = send;
+ msgv[msgs].length = send_len;
+ msgs++;
+ }
+
+ if (recv_len > 0) {
+ msgv[msgs].addr = address;
+ msgv[msgs].flags = I2C_M_READ;
+ msgv[msgs].buffer = recv;
+ msgv[msgs].length = recv_len;
+ msgs++;
+ }
+
+ if (msgs == 0)
+ return -1;
+
+ /*
+ * 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(i2c, 320000);
+ ret = I2C_TRANSFER(i2c, &msgv[0], msgs);
+
+ // reset the I2C bus to unwedge on error
+ if (ret != OK)
up_i2creset(i2c);
- } while (tries++ < 5);
return ret;
}