9
0
Fork 0

Use calculations on constants to (slightly) reduce code size

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4077 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2011-11-01 16:48:21 +00:00
parent fe0b118d54
commit 03d2fd4c58
2 changed files with 11 additions and 10 deletions

View File

@ -2190,5 +2190,5 @@
has no value inodes on it. has no value inodes on it.
* drivers/mtd/at24xx.c: Now supports a configurable block size that * drivers/mtd/at24xx.c: Now supports a configurable block size that
supports using "clusters" of AT24 pages as blocks. This allows bigger 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 block sizes and more efficient use of EEPROM when the AT24 is used to
support a file system (such as NXFFS). support a file system (such as NXFFS). (Contributed by Hal Glenn).

View File

@ -204,8 +204,8 @@ static ssize_t at24c_bread(FAR struct mtd_dev_s *dev, off_t startblock,
size_t blocksleft; size_t blocksleft;
#if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE #if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE
startblock *= CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE; startblock *= (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE);
nblocks *= CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE; nblocks *= (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE);
#endif #endif
blocksleft = nblocks; 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]; uint8_t buf[AT24XX_PAGESIZE+2];
#if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE #if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE
startblock *= CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE; startblock *= (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE);
nblocks *= CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE; nblocks *= (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE);
#endif #endif
blocksleft = nblocks; 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 #if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE
return nblocks /(CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE); return nblocks / (CONFIG_AT24XX_MTD_BLOCKSIZE / AT24XX_PAGESIZE);
#else #else
return nblocks; return nblocks;
#endif #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 * It has to be at least as big as the blocksize, bigger serves no
* purpose. * purpose.
* neraseblocks * 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 #if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE
geo->blocksize = CONFIG_AT24XX_MTD_BLOCKSIZE; geo->blocksize = CONFIG_AT24XX_MTD_BLOCKSIZE;
geo->erasesize = geo->blocksize; geo->erasesize = CONFIG_AT24XX_MTD_BLOCKSIZE;
geo->neraseblocks = CONFIG_AT24XX_SIZE * (1024/8) / geo->erasesize; geo->neraseblocks = (CONFIG_AT24XX_SIZE * 1024 / 8) / CONFIG_AT24XX_MTD_BLOCKSIZE;
#else #else
geo->blocksize = priv->pagesize; geo->blocksize = priv->pagesize;
geo->erasesize = priv->pagesize; geo->erasesize = priv->pagesize;