Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Commit

Permalink
mtd: added timeouts to at24xx eeprom driver
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Tridgell committed Jan 16, 2014
1 parent 400d33a commit f78c521
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions nuttx/drivers/mtd/at24xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f78c521

Please sign in to comment.