summaryrefslogtreecommitdiff
path: root/nuttx/drivers/mtd/at24xx.c
diff options
context:
space:
mode:
authorSarthak Kaingade <sarthakkaingade@yahoo.com>2014-02-24 18:06:22 +0530
committerSarthak Kaingade <sarthakkaingade@yahoo.com>2014-02-24 18:06:22 +0530
commit8c25e0afe2b179f7b8bd7ca4f49016d98012af6d (patch)
tree49a24a6fde718538160b3ced1bc38fb2a01003a9 /nuttx/drivers/mtd/at24xx.c
parent98f4615853570603a0138fe2ee0706811184f2e8 (diff)
parent454523bebfbaca9a77ba9827ba11454caffaa31d (diff)
downloadpx4-nuttx-8c25e0afe2b179f7b8bd7ca4f49016d98012af6d.tar.gz
px4-nuttx-8c25e0afe2b179f7b8bd7ca4f49016d98012af6d.tar.bz2
px4-nuttx-8c25e0afe2b179f7b8bd7ca4f49016d98012af6d.zip
Merge https://github.com/PX4/NuttX
Diffstat (limited to 'nuttx/drivers/mtd/at24xx.c')
-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;