diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-11-01 16:48:21 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-11-01 16:48:21 +0000 |
commit | 8c532df444b36d69b78a4195187a78024349427e (patch) | |
tree | 1e74351022c984b73e59d1f79a8bada95acd9316 /nuttx/drivers/mtd | |
parent | 53c07074863863faa8209e16c11240d02e0ec745 (diff) | |
download | px4-nuttx-8c532df444b36d69b78a4195187a78024349427e.tar.gz px4-nuttx-8c532df444b36d69b78a4195187a78024349427e.tar.bz2 px4-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
Diffstat (limited to 'nuttx/drivers/mtd')
-rw-r--r-- | nuttx/drivers/mtd/at24xx.c | 17 |
1 files changed, 9 insertions, 8 deletions
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; |