summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-11-01 16:48:21 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-11-01 16:48:21 +0000
commit8c532df444b36d69b78a4195187a78024349427e (patch)
tree1e74351022c984b73e59d1f79a8bada95acd9316
parent53c07074863863faa8209e16c11240d02e0ec745 (diff)
downloadnuttx-8c532df444b36d69b78a4195187a78024349427e.tar.gz
nuttx-8c532df444b36d69b78a4195187a78024349427e.tar.bz2
nuttx-8c532df444b36d69b78a4195187a78024349427e.zip
Use calculations on constants to (slightly) reduce code size
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4077 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/ChangeLog4
-rw-r--r--nuttx/drivers/mtd/at24xx.c17
2 files changed, 11 insertions, 10 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index 9186808f3..0dd5c1f3e 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -2190,5 +2190,5 @@
has no value inodes on it.
* drivers/mtd/at24xx.c: Now supports a configurable block size that
supports using "clusters" of AT24 pages as blocks. This allows bigger
- block sizes and more efficient use of FLASH when the AT24 is used to
- support a file system (such as NXFFS).
+ block sizes and more efficient use of EEPROM when the AT24 is used to
+ support a file system (such as NXFFS). (Contributed by Hal Glenn).
diff --git a/nuttx/drivers/mtd/at24xx.c b/nuttx/drivers/mtd/at24xx.c
index 50a6ab913..67d7f1f52 100644
--- a/nuttx/drivers/mtd/at24xx.c
+++ b/nuttx/drivers/mtd/at24xx.c
@@ -204,8 +204,8 @@ static ssize_t at24c_bread(FAR struct mtd_dev_s *dev, off_t startblock,
size_t blocksleft;
#if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE
- startblock *= CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE;
- nblocks *= CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE;
+ startblock *= (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE);
+ nblocks *= (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE);
#endif
blocksleft = nblocks;
@@ -264,8 +264,8 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t
uint8_t buf[AT24XX_PAGESIZE+2];
#if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE
- startblock *= CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE;
- nblocks *= CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE;
+ startblock *= (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE);
+ nblocks *= (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE);
#endif
blocksleft = nblocks;
@@ -302,7 +302,7 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t
}
#if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE
- return nblocks /(CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE);
+ return nblocks / (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE);
#else
return nblocks;
#endif
@@ -343,13 +343,14 @@ static int at24c_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
* It has to be at least as big as the blocksize, bigger serves no
* purpose.
* neraseblocks
- * Note that the device size is in kb, so * 1024 / 8 for bytes
+ * Note that the device size is in kilobits and must be scaled by
+ * 1024 / 8
*/
#if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE
geo->blocksize = CONFIG_AT24XX_MTD_BLOCKSIZE;
- geo->erasesize = geo->blocksize;
- geo->neraseblocks = CONFIG_AT24XX_SIZE * (1024/8) / geo->erasesize;
+ geo->erasesize = CONFIG_AT24XX_MTD_BLOCKSIZE;
+ geo->neraseblocks = (CONFIG_AT24XX_SIZE * 1024 / 8) / CONFIG_AT24XX_MTD_BLOCKSIZE;
#else
geo->blocksize = priv->pagesize;
geo->erasesize = priv->pagesize;