summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2014-01-16 16:57:52 +1100
committerLorenz Meier <lm@inf.ethz.ch>2014-01-16 08:05:16 +0100
commitf84093e66b0280af575ecadc5625092ab4d7146d (patch)
treead2c0dc20bbfeb131fbda0e2754492bda9b30f69
parent353eaa23ed92943caa85ed051943b84c825216a2 (diff)
downloadnuttx-f84093e66b0280af575ecadc5625092ab4d7146d.tar.gz
nuttx-f84093e66b0280af575ecadc5625092ab4d7146d.tar.bz2
nuttx-f84093e66b0280af575ecadc5625092ab4d7146d.zip
mtd: added timeouts to at24xx eeprom driver
-rw-r--r--nuttx/drivers/mtd/at24xx.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/nuttx/drivers/mtd/at24xx.c b/nuttx/drivers/mtd/at24xx.c
index 2eb7c9af0..8d89f9bd2 100644
--- a/nuttx/drivers/mtd/at24xx.c
+++ b/nuttx/drivers/mtd/at24xx.c
@@ -230,12 +230,17 @@ static ssize_t at24c_bread(FAR struct mtd_dev_s *dev, off_t startblock,
uint8_t buf[2];
buf[1] = offset & 0xff;
buf[0] = (offset >> 8) & 0xff;
+ uint8_t tries = 100;
- while (I2C_WRITE(priv->dev, buf, 2) < 0)
+ while (I2C_WRITE(priv->dev, buf, 2) < 0 && tries-- > 0)
{
fvdbg("wait\n");
usleep(1000);
}
+ if (tries == 0) {
+ fdbg("timed out reading at offset %u\n", (unsigned)offset);
+ return 0;
+ }
I2C_READ(priv->dev, buffer, priv->pagesize);
startblock++;
@@ -286,11 +291,17 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t
while (blocksleft-- > 0)
{
uint16_t offset = startblock * priv->pagesize;
- while (I2C_WRITE(priv->dev, (uint8_t *)&offset, 2) < 0)
+ uint8_t tries = 100;
+
+ while (I2C_WRITE(priv->dev, (uint8_t *)&offset, 2) < 0 && tries-- > 0)
{
fvdbg("wait\n");
usleep(1000);
}
+ if (tries == 0) {
+ fdbg("timed out writing at offset %u\n", (unsigned)offset);
+ return 0;
+ }
buf[1] = offset & 0xff;
buf[0] = (offset >> 8) & 0xff;