From ead61c1d18281b025696d8851763d9d8f13997e0 Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Wed, 8 Jun 2005 11:47:16 +0000 Subject: Slightly better error handling in the iRiver I2C driver git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6607 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/i2c-h100.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'firmware') diff --git a/firmware/drivers/i2c-h100.c b/firmware/drivers/i2c-h100.c index e2fbea2573..c50cd7ed0a 100644 --- a/firmware/drivers/i2c-h100.c +++ b/firmware/drivers/i2c-h100.c @@ -70,19 +70,22 @@ void i2c_close(void) int i2c_write(int device, unsigned char *buf, int count) { int i; + int rc; - if (i2c_gen_start(device) == -1) + rc = i2c_gen_start(device); + if (rc < 0) { DEBUGF("i2c: gen_start failed (d=%d)", device); - return -1; + return rc*10 - 1; } for (i=0; i= MAX_LOOP) return -1; + count = 0; + /* Wait for interrupt flag */ while (!(regs[O_MBSR] & IFF) && count < MAX_LOOP) { yield(); - count++; + count++; } if (count >= MAX_LOOP) - return -1; + return -2; regs[O_MBSR] &= ~IFF; /* Clear interrupt flag */ if (!(regs[O_MBSR] & ICF)) /* Check that transfer is complete */ - return -1; + return -3; if (regs[O_MBSR] & RXAK) /* Check that the byte has been ACKed */ - return -1; + return -4; return 0; } @@ -140,14 +145,17 @@ int i2c_gen_start(int device) /* Wait for bus to become free */ while ((regs[O_MBSR] & IBB) && (count < MAX_LOOP)) + { + yield(); count++; + } if (count >= MAX_LOOP) return -1; regs[O_MBCR] |= MSTA | MTX; /* Generate START */ - return 0; + return 0; } void i2c_gen_stop(int device) -- cgit v1.2.3