mirror of
https://github.com/apache/nuttx.git
synced 2025-12-11 12:57:57 +08:00
drivers: mtd: fix nxstyle errors
Fix nxstyle errors to pass the CI errors. Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
This commit is contained in:
committed by
Xiang Xiao
parent
95adb15824
commit
2d8b193df4
@@ -1,6 +1,7 @@
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* drivers/mtd/at24xx.c
|
||||
* Driver for I2C-based at24cxx EEPROM(at24c32,at24c64,at24c128,at24c256,at24c512)
|
||||
* Driver for I2C-based at24cxx EEPROM
|
||||
* (at24c32,at24c64,at24c128,at24c256,at24c512)
|
||||
*
|
||||
* Copyright (C) 2011 Li Zhuoyi. All rights reserved.
|
||||
* Author: Li Zhuoyi <lzyy.cn@gmail.com>
|
||||
@@ -40,11 +41,11 @@
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
@@ -66,11 +67,13 @@
|
||||
|
||||
#ifdef CONFIG_MTD_AT24XX
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* As a minimum, the size of the AT24 part and its 7-bit I2C address are required. */
|
||||
/* As a minimum,
|
||||
* the size of the AT24 part and its 7-bit I2C address are required.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_AT24XX_SIZE
|
||||
# warning "Assuming AT24 size 64"
|
||||
@@ -129,11 +132,11 @@
|
||||
# define AT24XX_ADDRSIZE 2
|
||||
#endif
|
||||
|
||||
/* For applications where a file system is used on the AT24, the tiny page sizes
|
||||
* will result in very inefficient FLASH usage. In such cases, it is better if
|
||||
* blocks are comprised of "clusters" of pages so that the file system block
|
||||
* size is, say, 256 or 512 bytes. In any event, the block size *must* be an
|
||||
* even multiple of the pages.
|
||||
/* For applications where a file system is used on the AT24, the tiny page
|
||||
* sizes will result in very inefficient FLASH usage. In such cases, it is
|
||||
* better if blocks are comprised of "clusters" of pages so that the file
|
||||
* system block size is, say, 256 or 512 bytes.
|
||||
* In any event, the block size *must* be an even multiple of the pages.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_AT24XX_MTD_BLOCKSIZE
|
||||
@@ -145,9 +148,9 @@
|
||||
# define CONFIG_AT24XX_TIMEOUT_MS 10
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* This type represents the state of the MTD device. The struct mtd_dev_s
|
||||
* must appear at the beginning of the definition so that you can freely
|
||||
@@ -167,24 +170,33 @@ struct at24c_dev_s
|
||||
uint16_t npages; /* 128, 256, 512, 1024 */
|
||||
};
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* MTD driver methods */
|
||||
|
||||
static int at24c_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks);
|
||||
static ssize_t at24c_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
static int at24c_erase(FAR struct mtd_dev_s *dev,
|
||||
off_t startblock,
|
||||
size_t nblocks);
|
||||
static ssize_t at24c_bread(FAR struct mtd_dev_s *dev,
|
||||
off_t startblock,
|
||||
size_t nblocks, FAR uint8_t *buf);
|
||||
static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
size_t nblocks, FAR const uint8_t *buf);
|
||||
static ssize_t at24c_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes,
|
||||
static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev,
|
||||
off_t startblock,
|
||||
size_t nblocks,
|
||||
FAR const uint8_t *buf);
|
||||
static ssize_t at24c_read(FAR struct mtd_dev_s *dev,
|
||||
off_t offset,
|
||||
size_t nbytes,
|
||||
FAR uint8_t *buffer);
|
||||
static int at24c_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg);
|
||||
static int at24c_ioctl(FAR struct mtd_dev_s *dev,
|
||||
int cmd,
|
||||
unsigned long arg);
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_AT24XX_MULTI
|
||||
/* If only a signal AT24 part is supported then a statically allocated state
|
||||
@@ -194,17 +206,17 @@ static int at24c_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg);
|
||||
static struct at24c_dev_s g_at24c;
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at24c_i2c_write
|
||||
*
|
||||
* Description:
|
||||
* Write to the I2C device.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int at24c_i2c_write(FAR struct at24c_dev_s *priv, uint16_t at24addr,
|
||||
FAR const uint8_t *buffer, int buflen)
|
||||
@@ -224,13 +236,13 @@ static int at24c_i2c_write(FAR struct at24c_dev_s *priv, uint16_t at24addr,
|
||||
return I2C_TRANSFER(priv->dev, &msg, 1);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at24c_i2c_read
|
||||
*
|
||||
* Description:
|
||||
* Read from the I2C device.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int at24c_i2c_read(FAR struct at24c_dev_s *priv, uint16_t at24addr,
|
||||
FAR uint8_t *buffer, int buflen)
|
||||
@@ -250,9 +262,9 @@ static int at24c_i2c_read(FAR struct at24c_dev_s *priv, uint16_t at24addr,
|
||||
return I2C_TRANSFER(priv->dev, &msg, 1);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at24c_eraseall
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int at24c_eraseall(FAR struct at24c_dev_s *priv)
|
||||
{
|
||||
@@ -277,7 +289,10 @@ static int at24c_eraseall(FAR struct at24c_dev_s *priv)
|
||||
#endif
|
||||
|
||||
wait = CONFIG_AT24XX_TIMEOUT_MS;
|
||||
while (at24c_i2c_write(priv, at24addr, buf, AT24XX_ADDRSIZE) < 0)
|
||||
while (at24c_i2c_write(priv,
|
||||
at24addr,
|
||||
buf,
|
||||
AT24XX_ADDRSIZE) < 0)
|
||||
{
|
||||
finfo("wait\n");
|
||||
if (!wait--)
|
||||
@@ -288,29 +303,36 @@ static int at24c_eraseall(FAR struct at24c_dev_s *priv)
|
||||
nxsig_usleep(1000);
|
||||
}
|
||||
|
||||
at24c_i2c_write(priv, at24addr, buf, AT24XX_PAGESIZE + AT24XX_ADDRSIZE);
|
||||
at24c_i2c_write(priv,
|
||||
at24addr,
|
||||
buf,
|
||||
AT24XX_PAGESIZE + AT24XX_ADDRSIZE);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at24c_erase
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int at24c_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks)
|
||||
static int at24c_erase(FAR struct mtd_dev_s *dev,
|
||||
off_t startblock,
|
||||
size_t nblocks)
|
||||
{
|
||||
/* EEprom need not erase */
|
||||
|
||||
return (int)nblocks;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at24c_read_internal
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t at24c_read_internal(FAR struct at24c_dev_s *priv, off_t offset,
|
||||
size_t nbytes, FAR uint8_t *buffer,
|
||||
static ssize_t at24c_read_internal(FAR struct at24c_dev_s *priv,
|
||||
off_t offset,
|
||||
size_t nbytes,
|
||||
FAR uint8_t *buffer,
|
||||
uint8_t address)
|
||||
{
|
||||
uint8_t buf[AT24XX_ADDRSIZE];
|
||||
@@ -363,9 +385,9 @@ static ssize_t at24c_read_internal(FAR struct at24c_dev_s *priv, off_t offset,
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at24c_bread
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t at24c_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
size_t nblocks, FAR uint8_t *buffer)
|
||||
@@ -421,12 +443,12 @@ static ssize_t at24c_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
#endif
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at24c_bwrite
|
||||
*
|
||||
* Operates on MTD block's and translates to FLASH pages
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
size_t nblocks,
|
||||
@@ -495,18 +517,22 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
#endif
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at24c_read
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t at24c_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes,
|
||||
static ssize_t at24c_read(FAR struct mtd_dev_s *dev,
|
||||
off_t offset,
|
||||
size_t nbytes,
|
||||
FAR uint8_t *buffer)
|
||||
{
|
||||
FAR struct at24c_dev_s *priv = (FAR struct at24c_dev_s *)dev;
|
||||
size_t memsize;
|
||||
uint8_t addr;
|
||||
|
||||
finfo("offset: %lu nbytes: %lu\n", (unsigned long)offset, (unsigned long)nbytes);
|
||||
finfo("offset: %lu nbytes: %lu\n",
|
||||
(unsigned long)offset,
|
||||
(unsigned long)nbytes);
|
||||
|
||||
/* Don't permit reads beyond the end of the memory region */
|
||||
|
||||
@@ -543,9 +569,9 @@ static ssize_t at24c_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes
|
||||
return at24c_read_internal(priv, offset, nbytes, buffer, addr);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at24c_ioctl
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int at24c_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
{
|
||||
@@ -562,25 +588,28 @@ static int at24c_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
((uintptr_t)arg);
|
||||
if (geo)
|
||||
{
|
||||
/* Populate the geometry structure with information need to know
|
||||
* the capacity and how to access the device.
|
||||
/* Populate the geometry structure with information need to
|
||||
* know the capacity and how to access the device.
|
||||
*
|
||||
* NOTE: that the device is treated as though it where just an array
|
||||
* of fixed size blocks. That is most likely not true, but the client
|
||||
* will expect the device logic to do whatever is necessary to make it
|
||||
* appear so.
|
||||
* NOTE:
|
||||
* that the device is treated as though it where just an array
|
||||
* of fixed size blocks.
|
||||
* That is most likely not true, but the client will expect the
|
||||
* device logic to do whatever is necessary to make it appear
|
||||
* so.
|
||||
*
|
||||
* blocksize:
|
||||
* May be user defined. The block size for the at24XX devices may be
|
||||
* larger than the page size in order to better support file systems.
|
||||
* The read and write functions translate BLOCKS to pages for the
|
||||
* small flash devices
|
||||
* May be user defined.
|
||||
* The block size for the at24XX devices may be larger than
|
||||
* the page size in order to better support file systems.
|
||||
* The read and write functions translate BLOCKS to pages
|
||||
* for the small flash devices
|
||||
* erasesize:
|
||||
* It has to be at least as big as the blocksize, bigger serves no
|
||||
* purpose.
|
||||
* It has to be at least as big as the blocksize, bigger
|
||||
* serves no purpose.
|
||||
* neraseblocks
|
||||
* Note that the device size is in kilobits and must be scaled by
|
||||
* 1024 / 8
|
||||
* Note that the device size is in kilobits and must be
|
||||
* scaled by 1024 / 8
|
||||
*/
|
||||
|
||||
#if CONFIG_AT24XX_MTD_BLOCKSIZE > AT24XX_PAGESIZE
|
||||
@@ -622,22 +651,24 @@ static int at24c_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at24c_initialize
|
||||
*
|
||||
* Description:
|
||||
* Create an initialized MTD device instance. MTD devices are not registered
|
||||
* in the file system, but are created as instances that can be bound to
|
||||
* other functions (such as a block or character driver front end).
|
||||
* Create an initialized MTD device instance.
|
||||
* MTD devices are not registered in the file system, but are created
|
||||
* as instances that can be bound to other functions
|
||||
* (such as a block or character driver front end).
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_AT24XX_MULTI
|
||||
FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_master_s *dev, uint8_t address)
|
||||
FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_master_s *dev,
|
||||
uint8_t address)
|
||||
#else
|
||||
FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_master_s *dev)
|
||||
#endif
|
||||
@@ -650,8 +681,8 @@ FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_master_s *dev)
|
||||
/* Allocate a state structure (we allocate the structure instead of using
|
||||
* a fixed, static allocation so that we can handle multiple FLASH devices.
|
||||
* The current implementation would handle only one FLASH part per I2C
|
||||
* device (only because of the SPIDEV_FLASH(0) definition) and so would have
|
||||
* to be extended to handle multiple FLASH parts on the same I2C bus.
|
||||
* device (only because of the SPIDEV_FLASH(0) definition) and so would
|
||||
* have to be extended to handle multiple FLASH parts on the same I2C bus.
|
||||
*/
|
||||
|
||||
priv = (FAR struct at24c_dev_s *)kmm_zalloc(sizeof(struct at24c_dev_s));
|
||||
@@ -664,8 +695,8 @@ FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_master_s *dev)
|
||||
#else
|
||||
finfo("dev: %p\n", dev);
|
||||
|
||||
/* If only a signal AT24 part is supported then a statically allocated state
|
||||
* structure is used.
|
||||
/* If only a signal AT24 part is supported then a statically allocated
|
||||
* state structure is used.
|
||||
*/
|
||||
|
||||
priv = &g_at24c;
|
||||
@@ -703,14 +734,15 @@ FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_master_s *dev)
|
||||
return (FAR struct mtd_dev_s *)priv;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at24c_uninitialize
|
||||
*
|
||||
* Description:
|
||||
* Release resources held by an allocated MTD device instance. Resources are only
|
||||
* allocated for the case where multiple AT24xx devices are support.
|
||||
* Release resources held by an allocated MTD device instance.
|
||||
* Resources are only allocated for the case where multiple AT24xx
|
||||
* devices are support.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_AT24XX_MULTI
|
||||
void at24c_uninitialize(FAR struct mtd_dev_s *mtd)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* drivers/mtd/at25.c
|
||||
* Driver for SPI-based AT25DF321 (32Mbit) flash.
|
||||
*
|
||||
@@ -33,11 +33,11 @@
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
@@ -56,11 +56,11 @@
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <nuttx/mtd/mtd.h>
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ********************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#ifndef CONFIG_AT25_SPIMODE
|
||||
# define CONFIG_AT25_SPIMODE SPIDEV_MODE0
|
||||
@@ -70,7 +70,7 @@
|
||||
# define CONFIG_AT25_SPIFREQUENCY 20000000
|
||||
#endif
|
||||
|
||||
/* AT25 Registers *******************************************************************/
|
||||
/* AT25 Registers ***********************************************************/
|
||||
|
||||
/* Identification register values */
|
||||
|
||||
@@ -129,9 +129,9 @@
|
||||
|
||||
#define AT25_DUMMY 0xa5
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* This type represents the state of the MTD device. The struct mtd_dev_s
|
||||
* must appear at the beginning of the definition so that you can freely
|
||||
@@ -148,9 +148,9 @@ struct at25_dev_s
|
||||
uint32_t npages; /* 32,768 or 65,536 */
|
||||
};
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* Helpers */
|
||||
|
||||
@@ -159,29 +159,41 @@ static inline void at25_unlock(FAR struct spi_dev_s *dev);
|
||||
static inline int at25_readid(struct at25_dev_s *priv);
|
||||
static void at25_waitwritecomplete(struct at25_dev_s *priv);
|
||||
static void at25_writeenable(struct at25_dev_s *priv);
|
||||
static inline void at25_sectorerase(struct at25_dev_s *priv, off_t offset);
|
||||
static inline void at25_sectorerase(struct at25_dev_s *priv,
|
||||
off_t offset);
|
||||
static inline int at25_bulkerase(struct at25_dev_s *priv);
|
||||
static inline void at25_pagewrite(struct at25_dev_s *priv, FAR const uint8_t *buffer,
|
||||
static inline void at25_pagewrite(struct at25_dev_s *priv,
|
||||
FAR const uint8_t *buffer,
|
||||
off_t offset);
|
||||
|
||||
/* MTD driver methods */
|
||||
|
||||
static int at25_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks);
|
||||
static ssize_t at25_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
size_t nblocks, FAR uint8_t *buf);
|
||||
static ssize_t at25_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
size_t nblocks, FAR const uint8_t *buf);
|
||||
static ssize_t at25_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes,
|
||||
static int at25_erase(FAR struct mtd_dev_s *dev,
|
||||
off_t startblock,
|
||||
size_t nblocks);
|
||||
static ssize_t at25_bread(FAR struct mtd_dev_s *dev,
|
||||
off_t startblock,
|
||||
size_t nblocks,
|
||||
FAR uint8_t *buf);
|
||||
static ssize_t at25_bwrite(FAR struct mtd_dev_s *dev,
|
||||
off_t startblock,
|
||||
size_t nblocks,
|
||||
FAR const uint8_t *buf);
|
||||
static ssize_t at25_read(FAR struct mtd_dev_s *dev,
|
||||
off_t offset,
|
||||
size_t nbytes,
|
||||
FAR uint8_t *buffer);
|
||||
static int at25_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg);
|
||||
static int at25_ioctl(FAR struct mtd_dev_s *dev,
|
||||
int cmd,
|
||||
unsigned long arg);
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at25_lock
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static void at25_lock(FAR struct spi_dev_s *dev)
|
||||
{
|
||||
@@ -189,16 +201,18 @@ static void at25_lock(FAR struct spi_dev_s *dev)
|
||||
* lock SPI to have exclusive access to the buses for a sequence of
|
||||
* transfers. The bus should be locked before the chip is selected.
|
||||
*
|
||||
* This is a blocking call and will not return until we have exclusive access to
|
||||
* the SPI bus. We will retain that exclusive access until the bus is unlocked.
|
||||
* This is a blocking call and will not return until we have exclusive
|
||||
* access to the SPI bus.
|
||||
* We will retain that exclusive access until the bus is unlocked.
|
||||
*/
|
||||
|
||||
SPI_LOCK(dev, true);
|
||||
|
||||
/* After locking the SPI bus, the we also need call the setfrequency, setbits, and
|
||||
* setmode methods to make sure that the SPI is properly configured for the device.
|
||||
* If the SPI bus is being shared, then it may have been left in an incompatible
|
||||
* state.
|
||||
/* After locking the SPI bus, the we also need call the setfrequency,
|
||||
* setbits, and setmode methods to make sure that the SPI is properly
|
||||
* configured for the device.
|
||||
* If the SPI bus is being shared, then it may have been left in an
|
||||
* incompatible state.
|
||||
*/
|
||||
|
||||
SPI_SETMODE(dev, CONFIG_AT25_SPIMODE);
|
||||
@@ -207,18 +221,18 @@ static void at25_lock(FAR struct spi_dev_s *dev)
|
||||
SPI_SETFREQUENCY(dev, CONFIG_AT25_SPIFREQUENCY);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at25_unlock
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static inline void at25_unlock(FAR struct spi_dev_s *dev)
|
||||
{
|
||||
SPI_LOCK(dev, false);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at25_readid
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static inline int at25_readid(struct at25_dev_s *priv)
|
||||
{
|
||||
@@ -248,7 +262,8 @@ static inline int at25_readid(struct at25_dev_s *priv)
|
||||
|
||||
/* Check for a valid manufacturer and memory type */
|
||||
|
||||
if (manufacturer == AT25_MANUFACTURER && memory == AT25_AT25DF081A_TYPE)
|
||||
if (manufacturer == AT25_MANUFACTURER &&
|
||||
memory == AT25_AT25DF081A_TYPE)
|
||||
{
|
||||
priv->sectorshift = AT25_AT25DF081A_SECTOR_SHIFT;
|
||||
priv->nsectors = AT25_AT25DF081A_NSECTORS;
|
||||
@@ -256,7 +271,8 @@ static inline int at25_readid(struct at25_dev_s *priv)
|
||||
priv->npages = AT25_AT25DF081A_NPAGES;
|
||||
return OK;
|
||||
}
|
||||
else if (manufacturer == AT25_MANUFACTURER && memory == AT25_AT25DF321_TYPE)
|
||||
else if (manufacturer == AT25_MANUFACTURER &&
|
||||
memory == AT25_AT25DF321_TYPE)
|
||||
{
|
||||
priv->sectorshift = AT25_AT25DF321_SECTOR_SHIFT;
|
||||
priv->nsectors = AT25_AT25DF321_NSECTORS;
|
||||
@@ -268,9 +284,9 @@ static inline int at25_readid(struct at25_dev_s *priv)
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at25_waitwritecomplete
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static void at25_waitwritecomplete(struct at25_dev_s *priv)
|
||||
{
|
||||
@@ -288,7 +304,9 @@ static void at25_waitwritecomplete(struct at25_dev_s *priv)
|
||||
|
||||
SPI_SEND(priv->dev, AT25_RDSR);
|
||||
|
||||
/* Send a dummy byte to generate the clock needed to shift out the status */
|
||||
/* Send a dummy byte to generate the clock needed to shift out
|
||||
* the status
|
||||
*/
|
||||
|
||||
status = SPI_SEND(priv->dev, AT25_DUMMY);
|
||||
|
||||
@@ -296,9 +314,10 @@ static void at25_waitwritecomplete(struct at25_dev_s *priv)
|
||||
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), false);
|
||||
|
||||
/* Given that writing could take up to few tens of milliseconds, and erasing
|
||||
* could take more. The following short delay in the "busy" case will allow
|
||||
* other peripherals to access the SPI bus.
|
||||
/* Given that writing could take up to few tens of milliseconds,
|
||||
* and erasing could take more.
|
||||
* The following short delay in the "busy" case will allow other
|
||||
* peripherals to access the SPI bus.
|
||||
*/
|
||||
|
||||
if ((status & AT25_SR_BUSY) != 0)
|
||||
@@ -318,9 +337,9 @@ static void at25_waitwritecomplete(struct at25_dev_s *priv)
|
||||
finfo("Complete, status: 0x%02x\n", status);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at25_writeenable
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static void at25_writeenable(struct at25_dev_s *priv)
|
||||
{
|
||||
@@ -330,9 +349,9 @@ static void at25_writeenable(struct at25_dev_s *priv)
|
||||
finfo("Enabled\n");
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at25_sectorerase
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static inline void at25_sectorerase(struct at25_dev_s *priv, off_t sector)
|
||||
{
|
||||
@@ -375,9 +394,9 @@ static inline void at25_sectorerase(struct at25_dev_s *priv, off_t sector)
|
||||
finfo("Erased\n");
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at25_bulkerase
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static inline int at25_bulkerase(struct at25_dev_s *priv)
|
||||
{
|
||||
@@ -410,11 +429,12 @@ static inline int at25_bulkerase(struct at25_dev_s *priv)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at25_pagewrite
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static inline void at25_pagewrite(struct at25_dev_s *priv, FAR const uint8_t *buffer,
|
||||
static inline void at25_pagewrite(struct at25_dev_s *priv,
|
||||
FAR const uint8_t *buffer,
|
||||
off_t page)
|
||||
{
|
||||
off_t offset = page << 8;
|
||||
@@ -457,11 +477,13 @@ static inline void at25_pagewrite(struct at25_dev_s *priv, FAR const uint8_t *bu
|
||||
finfo("Written\n");
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at25_erase
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int at25_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks)
|
||||
static int at25_erase(FAR struct mtd_dev_s *dev,
|
||||
off_t startblock,
|
||||
size_t nblocks)
|
||||
{
|
||||
FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
|
||||
size_t blocksleft = nblocks;
|
||||
@@ -483,9 +505,9 @@ static int at25_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblock
|
||||
return (int)nblocks;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at25_bread
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t at25_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
size_t nblocks,
|
||||
@@ -496,7 +518,9 @@ static ssize_t at25_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
|
||||
finfo("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
|
||||
|
||||
/* On this device, we can handle the block read just like the byte-oriented read */
|
||||
/* On this device, we can handle the block read just like the byte-oriented
|
||||
* read
|
||||
*/
|
||||
|
||||
nbytes = at25_read(dev, startblock << priv->pageshift,
|
||||
nblocks << priv->pageshift, buffer);
|
||||
@@ -508,9 +532,9 @@ static ssize_t at25_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
return (int)nbytes;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at25_bwrite
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t at25_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
size_t nblocks, FAR const uint8_t *buffer)
|
||||
@@ -535,11 +559,13 @@ static ssize_t at25_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
return nblocks;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at25_read
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t at25_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes,
|
||||
static ssize_t at25_read(FAR struct mtd_dev_s *dev,
|
||||
off_t offset,
|
||||
size_t nbytes,
|
||||
FAR uint8_t *buffer)
|
||||
{
|
||||
FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
|
||||
@@ -587,9 +613,9 @@ static ssize_t at25_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes,
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at25_ioctl
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int at25_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
{
|
||||
@@ -607,13 +633,15 @@ static int at25_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
|
||||
if (geo != NULL)
|
||||
{
|
||||
/* Populate the geometry structure with information need to know
|
||||
* the capacity and how to access the device.
|
||||
/* Populate the geometry structure with information need to
|
||||
* know the capacity and how to access the device.
|
||||
*
|
||||
* NOTE: that the device is treated as though it where just an array
|
||||
* of fixed size blocks. That is most likely not true, but the client
|
||||
* will expect the device logic to do whatever is necessary to make it
|
||||
* appear so.
|
||||
* NOTE:
|
||||
* that the device is treated as though it where just an array
|
||||
* of fixed size blocks.
|
||||
* That is most likely not true, but the client will expect the
|
||||
* device logic to do whatever is necessary to make it appear
|
||||
* so.
|
||||
*/
|
||||
|
||||
geo->blocksize = (1 << priv->pageshift);
|
||||
@@ -648,19 +676,19 @@ static int at25_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: at25_initialize
|
||||
*
|
||||
* Description:
|
||||
* Create an initialize MTD device instance. MTD devices are not registered
|
||||
* Create an initialize MTD device instance. MTD devices are not registered
|
||||
* in the file system, but are created as instances that can be bound to
|
||||
* other functions (such as a block or character driver front end).
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct mtd_dev_s *at25_initialize(FAR struct spi_dev_s *dev)
|
||||
{
|
||||
@@ -672,8 +700,8 @@ FAR struct mtd_dev_s *at25_initialize(FAR struct spi_dev_s *dev)
|
||||
/* Allocate a state structure (we allocate the structure instead of using
|
||||
* a fixed, static allocation so that we can handle multiple FLASH devices.
|
||||
* The current implementation would handle only one FLASH part per SPI
|
||||
* device (only because of the SPIDEV_FLASH(0) definition) and so would have
|
||||
* to be extended to handle multiple FLASH parts on the same SPI bus.
|
||||
* device (only because of the SPIDEV_FLASH(0) definition) and so would
|
||||
* have to be extended to handle multiple FLASH parts on the same SPI bus.
|
||||
*/
|
||||
|
||||
priv = (FAR struct at25_dev_s *)kmm_zalloc(sizeof(struct at25_dev_s));
|
||||
@@ -700,7 +728,9 @@ FAR struct mtd_dev_s *at25_initialize(FAR struct spi_dev_s *dev)
|
||||
ret = at25_readid(priv);
|
||||
if (ret != OK)
|
||||
{
|
||||
/* Unrecognized! Discard all of that work we just did and return NULL */
|
||||
/* Unrecognized!
|
||||
* Discard all of that work we just did and return NULL
|
||||
*/
|
||||
|
||||
ferr("ERROR: Unrecognized\n");
|
||||
kmm_free(priv);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -80,6 +80,7 @@ static unsigned int hamming_bitsinbyte(uint8_t byte)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
byte >>= 1;
|
||||
}
|
||||
|
||||
@@ -194,7 +195,8 @@ static void hamming_compute256(FAR const uint8_t *data, FAR uint8_t *code)
|
||||
colsum >>= 1;
|
||||
}
|
||||
|
||||
/* Now, we must interleave the parity values, to obtain the following layout:
|
||||
/* Now, we must interleave the parity values,
|
||||
* to obtain the following layout:
|
||||
* Code[0] = Line1
|
||||
* Code[1] = Line2
|
||||
* Code[2] = Column
|
||||
@@ -415,7 +417,9 @@ void hamming_compute256x(FAR const uint8_t *data, size_t size, uint8_t *code)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int hamming_verify256x(FAR uint8_t *data, size_t size, FAR const uint8_t *code)
|
||||
int hamming_verify256x(FAR uint8_t *data,
|
||||
size_t size,
|
||||
FAR const uint8_t *code)
|
||||
{
|
||||
ssize_t remaining = (ssize_t)size;
|
||||
int result = HAMMING_SUCCESS;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
/**************************************************************************************************
|
||||
/****************************************************************************
|
||||
* drivers/mtd/mtd_modeltab.c
|
||||
*
|
||||
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
@@ -37,11 +37,11 @@
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/**************************************************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
**************************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/mtd/nand_config.h>
|
||||
@@ -49,122 +49,109 @@
|
||||
#include <nuttx/mtd/nand_scheme.h>
|
||||
#include <nuttx/mtd/nand_model.h>
|
||||
|
||||
/**************************************************************************************************
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
**************************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* List of NandFlash models which can be recognized by the software */
|
||||
|
||||
/****************************************************************************
|
||||
* ID OPTIONS PAGE SPARE DEV BLOCK | SCHEME
|
||||
* SIZE SIZE SIZE SIZE |
|
||||
****************************************************************************/
|
||||
|
||||
const struct nand_model_s g_nandmodels[NAND_NMODELS] =
|
||||
{
|
||||
/*----------|------------------------------+------+-------+------+-------+------------------------
|
||||
* | ID | OPTIONS | PAGE | SPARE | DEV | BLOCK | SCHEME
|
||||
* | | | SIZE | SIZE | SIZE | SIZE |
|
||||
*----------|------------------------------+------+-------+------+-------+------------------------*/
|
||||
|
||||
{0x6e, NANDMODEL_DATAWIDTH8, 256, 0, 1, 4, &g_nand_sparescheme256},
|
||||
{0x64, NANDMODEL_DATAWIDTH8, 256, 0, 2, 4, &g_nand_sparescheme256},
|
||||
{0x68, NANDMODEL_DATAWIDTH8, 4096, 0, 224, 1024, &g_nand_sparescheme4096},
|
||||
{0x6b, NANDMODEL_DATAWIDTH8, 512, 0, 4, 8, &g_nand_sparescheme512},
|
||||
{0xe8, NANDMODEL_DATAWIDTH8, 256, 0, 1, 4, &g_nand_sparescheme256},
|
||||
{0xec, NANDMODEL_DATAWIDTH8, 256, 0, 1, 4, &g_nand_sparescheme256},
|
||||
{0xea, NANDMODEL_DATAWIDTH8, 256, 0, 2, 4, &g_nand_sparescheme256},
|
||||
{0xd5, NANDMODEL_DATAWIDTH8, 512, 0, 4, 8, &g_nand_sparescheme512},
|
||||
{0xe3, NANDMODEL_DATAWIDTH8, 512, 0, 4, 8, &g_nand_sparescheme512},
|
||||
{0xe5, NANDMODEL_DATAWIDTH8, 512, 0, 4, 8, &g_nand_sparescheme512},
|
||||
{0xd6, NANDMODEL_DATAWIDTH8, 512, 0, 8, 8, &g_nand_sparescheme512},
|
||||
|
||||
/*----------|------------------------------+------+-------+------+-------+------------------------*/
|
||||
|
||||
{0x39, NANDMODEL_DATAWIDTH8, 512, 0, 8, 8, &g_nand_sparescheme512},
|
||||
{0xe6, NANDMODEL_DATAWIDTH8, 512, 0, 8, 8, &g_nand_sparescheme512},
|
||||
{0x49, NANDMODEL_DATAWIDTH16, 512, 0, 8, 8, &g_nand_sparescheme512},
|
||||
{0x59, NANDMODEL_DATAWIDTH16, 512, 0, 8, 8, &g_nand_sparescheme512},
|
||||
|
||||
/*----------|------------------------------+------+-------+------+-------+------------------------*/
|
||||
|
||||
{0x33, NANDMODEL_DATAWIDTH8, 512, 0, 16, 16, &g_nand_sparescheme512},
|
||||
{0x73, NANDMODEL_DATAWIDTH8, 512, 0, 16, 16, &g_nand_sparescheme512},
|
||||
{0x43, NANDMODEL_DATAWIDTH16, 512, 0, 16, 16, &g_nand_sparescheme512},
|
||||
{0x53, NANDMODEL_DATAWIDTH16, 512, 0, 16, 16, &g_nand_sparescheme512},
|
||||
|
||||
/*----------|------------------------------+------+-------+------+-------+------------------------*/
|
||||
|
||||
{0x35, NANDMODEL_DATAWIDTH8, 512, 0, 32, 16, &g_nand_sparescheme512},
|
||||
{0x75, NANDMODEL_DATAWIDTH8, 512, 0, 32, 16, &g_nand_sparescheme512},
|
||||
{0x45, NANDMODEL_DATAWIDTH16, 512, 0, 32, 16, &g_nand_sparescheme512},
|
||||
{0x55, NANDMODEL_DATAWIDTH16, 512, 0, 32, 16, &g_nand_sparescheme512},
|
||||
|
||||
/*----------|------------------------------+------+-------+------+-------+------------------------*/
|
||||
|
||||
{0x36, NANDMODEL_DATAWIDTH8, 512, 0, 64, 16, &g_nand_sparescheme512},
|
||||
{0x76, NANDMODEL_DATAWIDTH8, 512, 0, 64, 16, &g_nand_sparescheme512},
|
||||
{0x46, NANDMODEL_DATAWIDTH16, 512, 0, 64, 16, &g_nand_sparescheme512},
|
||||
{0x56, NANDMODEL_DATAWIDTH16, 512, 0, 64, 16, &g_nand_sparescheme512},
|
||||
|
||||
/*----------|------------------------------+------+-------+------+-------+------------------------*/
|
||||
|
||||
{0x78, NANDMODEL_DATAWIDTH8, 512, 0, 128, 16, &g_nand_sparescheme512},
|
||||
{0x39, NANDMODEL_DATAWIDTH8, 512, 0, 128, 16, &g_nand_sparescheme512},
|
||||
{0x79, NANDMODEL_DATAWIDTH8, 512, 0, 128, 16, &g_nand_sparescheme512},
|
||||
{0x72, NANDMODEL_DATAWIDTH16, 512, 0, 128, 16, &g_nand_sparescheme512},
|
||||
{0x49, NANDMODEL_DATAWIDTH16, 512, 0, 128, 16, &g_nand_sparescheme512},
|
||||
{0x74, NANDMODEL_DATAWIDTH16, 512, 0, 128, 16, &g_nand_sparescheme512},
|
||||
{0x59, NANDMODEL_DATAWIDTH16, 512, 0, 128, 16, &g_nand_sparescheme512},
|
||||
|
||||
/*----------|------------------------------+------+-------+------+-------+------------------------*/
|
||||
|
||||
{0x71, NANDMODEL_DATAWIDTH8, 512, 0, 256, 16, &g_nand_sparescheme512},
|
||||
|
||||
/* Large blocks devices. Parameters must be fetched from the extended I */
|
||||
{0x6e, NANDMODEL_DATAWIDTH8, 256, 0, 1, 4, &g_nand_sparescheme256},
|
||||
{0x64, NANDMODEL_DATAWIDTH8, 256, 0, 2, 4, &g_nand_sparescheme256},
|
||||
{0x68, NANDMODEL_DATAWIDTH8, 4096, 0, 224, 1024, &g_nand_sparescheme4096},
|
||||
{0x6b, NANDMODEL_DATAWIDTH8, 512, 0, 4, 8, &g_nand_sparescheme512},
|
||||
{0xe8, NANDMODEL_DATAWIDTH8, 256, 0, 1, 4, &g_nand_sparescheme256},
|
||||
{0xec, NANDMODEL_DATAWIDTH8, 256, 0, 1, 4, &g_nand_sparescheme256},
|
||||
{0xea, NANDMODEL_DATAWIDTH8, 256, 0, 2, 4, &g_nand_sparescheme256},
|
||||
{0xd5, NANDMODEL_DATAWIDTH8, 512, 0, 4, 8, &g_nand_sparescheme512},
|
||||
{0xe3, NANDMODEL_DATAWIDTH8, 512, 0, 4, 8, &g_nand_sparescheme512},
|
||||
{0xe5, NANDMODEL_DATAWIDTH8, 512, 0, 4, 8, &g_nand_sparescheme512},
|
||||
{0xd6, NANDMODEL_DATAWIDTH8, 512, 0, 8, 8, &g_nand_sparescheme512},
|
||||
{0x39, NANDMODEL_DATAWIDTH8, 512, 0, 8, 8, &g_nand_sparescheme512},
|
||||
{0xe6, NANDMODEL_DATAWIDTH8, 512, 0, 8, 8, &g_nand_sparescheme512},
|
||||
{0x49, NANDMODEL_DATAWIDTH16, 512, 0, 8, 8, &g_nand_sparescheme512},
|
||||
{0x59, NANDMODEL_DATAWIDTH16, 512, 0, 8, 8, &g_nand_sparescheme512},
|
||||
{0x33, NANDMODEL_DATAWIDTH8, 512, 0, 16, 16, &g_nand_sparescheme512},
|
||||
{0x73, NANDMODEL_DATAWIDTH8, 512, 0, 16, 16, &g_nand_sparescheme512},
|
||||
{0x43, NANDMODEL_DATAWIDTH16, 512, 0, 16, 16, &g_nand_sparescheme512},
|
||||
{0x53, NANDMODEL_DATAWIDTH16, 512, 0, 16, 16, &g_nand_sparescheme512},
|
||||
{0x35, NANDMODEL_DATAWIDTH8, 512, 0, 32, 16, &g_nand_sparescheme512},
|
||||
{0x75, NANDMODEL_DATAWIDTH8, 512, 0, 32, 16, &g_nand_sparescheme512},
|
||||
{0x45, NANDMODEL_DATAWIDTH16, 512, 0, 32, 16, &g_nand_sparescheme512},
|
||||
{0x55, NANDMODEL_DATAWIDTH16, 512, 0, 32, 16, &g_nand_sparescheme512},
|
||||
{0x36, NANDMODEL_DATAWIDTH8, 512, 0, 64, 16, &g_nand_sparescheme512},
|
||||
{0x76, NANDMODEL_DATAWIDTH8, 512, 0, 64, 16, &g_nand_sparescheme512},
|
||||
{0x46, NANDMODEL_DATAWIDTH16, 512, 0, 64, 16, &g_nand_sparescheme512},
|
||||
{0x56, NANDMODEL_DATAWIDTH16, 512, 0, 64, 16, &g_nand_sparescheme512},
|
||||
{0x78, NANDMODEL_DATAWIDTH8, 512, 0, 128, 16, &g_nand_sparescheme512},
|
||||
{0x39, NANDMODEL_DATAWIDTH8, 512, 0, 128, 16, &g_nand_sparescheme512},
|
||||
{0x79, NANDMODEL_DATAWIDTH8, 512, 0, 128, 16, &g_nand_sparescheme512},
|
||||
{0x72, NANDMODEL_DATAWIDTH16, 512, 0, 128, 16, &g_nand_sparescheme512},
|
||||
{0x49, NANDMODEL_DATAWIDTH16, 512, 0, 128, 16, &g_nand_sparescheme512},
|
||||
{0x74, NANDMODEL_DATAWIDTH16, 512, 0, 128, 16, &g_nand_sparescheme512},
|
||||
{0x59, NANDMODEL_DATAWIDTH16, 512, 0, 128, 16, &g_nand_sparescheme512},
|
||||
{0x71, NANDMODEL_DATAWIDTH8, 512, 0, 256, 16, &g_nand_sparescheme512},
|
||||
/* Large blocks devices. Parameters must be fetched from the extended I */
|
||||
|
||||
#define OPTIONS NANDMODEL_COPYBACK
|
||||
|
||||
/*----------|------------------------------+------+-------+------+-------+------------------------
|
||||
* | ID | OPTIONS | PAGE | SPARE | DEV | BLOCK | SCHEME
|
||||
* | | | SIZE | SIZE | SIZE | SIZE |
|
||||
*----------|------------------------------+------+-------+------+-------+------------------------*/
|
||||
|
||||
{0xA2, NANDMODEL_DATAWIDTH8 | OPTIONS, 0, 0, 64, 0, &g_nand_sparescheme2048},
|
||||
{0xF2, NANDMODEL_DATAWIDTH8 | OPTIONS, 0, 0, 64, 0, &g_nand_sparescheme2048},
|
||||
{0xB2, NANDMODEL_DATAWIDTH16 | OPTIONS, 0, 0, 64, 0, &g_nand_sparescheme2048},
|
||||
{0xC2, NANDMODEL_DATAWIDTH16 | OPTIONS, 0, 0, 64, 0, &g_nand_sparescheme2048},
|
||||
|
||||
/*----------|------------------------------+------+-------+------+-------+------------------------*/
|
||||
|
||||
{0xA1, NANDMODEL_DATAWIDTH8 | OPTIONS, 0, 0, 128, 0, &g_nand_sparescheme2048},
|
||||
{0xF1, NANDMODEL_DATAWIDTH8 | OPTIONS, 0, 0, 128, 0, &g_nand_sparescheme2048},
|
||||
{0xB1, NANDMODEL_DATAWIDTH16 | OPTIONS, 0, 0, 128, 0, &g_nand_sparescheme2048},
|
||||
{0xC1, NANDMODEL_DATAWIDTH16 | OPTIONS, 0, 0, 128, 0, &g_nand_sparescheme2048},
|
||||
|
||||
/*----------|------------------------------+------+-------+------+-------+------------------------*/
|
||||
|
||||
{0xAA, NANDMODEL_DATAWIDTH8 | OPTIONS, 0, 0, 256, 0, &g_nand_sparescheme2048},
|
||||
{0xDA, NANDMODEL_DATAWIDTH8 | OPTIONS, 0, 0, 256, 0, &g_nand_sparescheme2048},
|
||||
{0xBA, NANDMODEL_DATAWIDTH16 | OPTIONS, 0, 0, 256, 0, &g_nand_sparescheme2048},
|
||||
{0xCA, NANDMODEL_DATAWIDTH16 | OPTIONS, 0, 0, 256, 0, &g_nand_sparescheme2048},
|
||||
|
||||
/*----------|------------------------------+------+-------+------+-------+------------------------*/
|
||||
|
||||
{0xAC, NANDMODEL_DATAWIDTH8 | OPTIONS, 0, 0, 512, 0, &g_nand_sparescheme2048},
|
||||
{0xDC, NANDMODEL_DATAWIDTH8 | OPTIONS, 0, 0, 512, 0, &g_nand_sparescheme2048},
|
||||
{0xBC, NANDMODEL_DATAWIDTH16 | OPTIONS, 0, 0, 512, 0, &g_nand_sparescheme2048},
|
||||
{0xCC, NANDMODEL_DATAWIDTH16 | OPTIONS, 0, 0, 512, 0, &g_nand_sparescheme2048},
|
||||
|
||||
/*----------|------------------------------+------+-------+------+-------+------------------------*/
|
||||
|
||||
{0xA3, NANDMODEL_DATAWIDTH8 | OPTIONS, 0, 0, 1024, 0, &g_nand_sparescheme2048},
|
||||
{0xD3, NANDMODEL_DATAWIDTH8 | OPTIONS, 0, 0, 1024, 0, &g_nand_sparescheme2048},
|
||||
{0xB3, NANDMODEL_DATAWIDTH16 | OPTIONS, 0, 0, 1024, 0, &g_nand_sparescheme2048},
|
||||
{0xC3, NANDMODEL_DATAWIDTH16 | OPTIONS, 0, 0, 1024, 0, &g_nand_sparescheme2048},
|
||||
|
||||
/*----------|------------------------------+------+-------+------+-------+------------------------*/
|
||||
|
||||
{0xA5, NANDMODEL_DATAWIDTH8 | OPTIONS, 0, 0, 2048, 0, &g_nand_sparescheme2048},
|
||||
{0xD5, NANDMODEL_DATAWIDTH8 | OPTIONS, 0, 0, 2048, 0, &g_nand_sparescheme2048},
|
||||
{0xB5, NANDMODEL_DATAWIDTH16 | OPTIONS, 0, 0, 2048, 0, &g_nand_sparescheme2048},
|
||||
{0xC5, NANDMODEL_DATAWIDTH16 | OPTIONS, 0, 0, 2048, 0, &g_nand_sparescheme2048},
|
||||
{0x38, NANDMODEL_DATAWIDTH8 | OPTIONS, 0, 0, 1024, 0, &g_nand_sparescheme4096}
|
||||
|
||||
/*----------|------------------------------+------+-------+------+-------+------------------------*/
|
||||
{0xa2, NANDMODEL_DATAWIDTH8 | OPTIONS,
|
||||
0, 0, 64, 0, &g_nand_sparescheme2048},
|
||||
{0xf2, NANDMODEL_DATAWIDTH8 | OPTIONS,
|
||||
0, 0, 64, 0, &g_nand_sparescheme2048},
|
||||
{0xb2, NANDMODEL_DATAWIDTH16 | OPTIONS,
|
||||
0, 0, 64, 0, &g_nand_sparescheme2048},
|
||||
{0xc2, NANDMODEL_DATAWIDTH16 | OPTIONS,
|
||||
0, 0, 64, 0, &g_nand_sparescheme2048},
|
||||
{0xa1, NANDMODEL_DATAWIDTH8 | OPTIONS,
|
||||
0, 0, 128, 0, &g_nand_sparescheme2048},
|
||||
{0xf1, NANDMODEL_DATAWIDTH8 | OPTIONS,
|
||||
0, 0, 128, 0, &g_nand_sparescheme2048},
|
||||
{0xb1, NANDMODEL_DATAWIDTH16 | OPTIONS,
|
||||
0, 0, 128, 0, &g_nand_sparescheme2048},
|
||||
{0xc1, NANDMODEL_DATAWIDTH16 | OPTIONS,
|
||||
0, 0, 128, 0, &g_nand_sparescheme2048},
|
||||
{0xaa, NANDMODEL_DATAWIDTH8 | OPTIONS,
|
||||
0, 0, 256, 0, &g_nand_sparescheme2048},
|
||||
{0xda, NANDMODEL_DATAWIDTH8 | OPTIONS,
|
||||
0, 0, 256, 0, &g_nand_sparescheme2048},
|
||||
{0xba, NANDMODEL_DATAWIDTH16 | OPTIONS,
|
||||
0, 0, 256, 0, &g_nand_sparescheme2048},
|
||||
{0xca, NANDMODEL_DATAWIDTH16 | OPTIONS,
|
||||
0, 0, 256, 0, &g_nand_sparescheme2048},
|
||||
{0xac, NANDMODEL_DATAWIDTH8 | OPTIONS,
|
||||
0, 0, 512, 0, &g_nand_sparescheme2048},
|
||||
{0xdc, NANDMODEL_DATAWIDTH8 | OPTIONS,
|
||||
0, 0, 512, 0, &g_nand_sparescheme2048},
|
||||
{0xbc, NANDMODEL_DATAWIDTH16 | OPTIONS,
|
||||
0, 0, 512, 0, &g_nand_sparescheme2048},
|
||||
{0xcc, NANDMODEL_DATAWIDTH16 | OPTIONS,
|
||||
0, 0, 512, 0, &g_nand_sparescheme2048},
|
||||
{0xa3, NANDMODEL_DATAWIDTH8 | OPTIONS,
|
||||
0, 0, 1024, 0, &g_nand_sparescheme2048},
|
||||
{0xd3, NANDMODEL_DATAWIDTH8 | OPTIONS,
|
||||
0, 0, 1024, 0, &g_nand_sparescheme2048},
|
||||
{0xb3, NANDMODEL_DATAWIDTH16 | OPTIONS,
|
||||
0, 0, 1024, 0, &g_nand_sparescheme2048},
|
||||
{0xd3, NANDMODEL_DATAWIDTH16 | OPTIONS,
|
||||
0, 0, 1024, 0, &g_nand_sparescheme2048},
|
||||
{0xa5, NANDMODEL_DATAWIDTH8 | OPTIONS,
|
||||
0, 0, 2048, 0, &g_nand_sparescheme2048},
|
||||
{0xd5, NANDMODEL_DATAWIDTH8 | OPTIONS,
|
||||
0, 0, 2048, 0, &g_nand_sparescheme2048},
|
||||
{0xb5, NANDMODEL_DATAWIDTH16 | OPTIONS,
|
||||
0, 0, 2048, 0, &g_nand_sparescheme2048},
|
||||
{0xc5, NANDMODEL_DATAWIDTH16 | OPTIONS,
|
||||
0, 0, 2048, 0, &g_nand_sparescheme2048},
|
||||
{0x38, NANDMODEL_DATAWIDTH8 | OPTIONS,
|
||||
0, 0, 1024, 0, &g_nand_sparescheme4096}
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
@@ -97,7 +97,11 @@ int nandecc_readpage(FAR struct nand_dev_s *nand, off_t block,
|
||||
unsigned int sparesize;
|
||||
int ret;
|
||||
|
||||
finfo("block=%d page=%d data=%p spare=%d\n", (int)block, page, data, spare);
|
||||
finfo("block=%d page=%d data=%p spare=%d\n",
|
||||
(int)block,
|
||||
page,
|
||||
data,
|
||||
spare);
|
||||
|
||||
/* Get convenience pointers */
|
||||
|
||||
@@ -189,7 +193,11 @@ int nandecc_writepage(FAR struct nand_dev_s *nand, off_t block,
|
||||
unsigned int sparesize;
|
||||
int ret;
|
||||
|
||||
finfo("block=%d page=%d data=%p spare=%d\n", (int)block, page, data, spare);
|
||||
finfo("block=%d page=%d data=%p spare=%d\n",
|
||||
(int)block,
|
||||
page,
|
||||
data,
|
||||
spare);
|
||||
|
||||
/* Get convenience pointers */
|
||||
|
||||
|
||||
@@ -73,7 +73,8 @@
|
||||
* Input Parameters:
|
||||
* modeltab List of nand_model_s instances.
|
||||
* size Number of models in list.
|
||||
* chipid Identifier returned by the Nand(id1|(id2<<8)|(id3<<16)|(id4<<24)).
|
||||
* chipid Identifier returned by the Nand
|
||||
* (id1|(id2<<8)|(id3<<16)|(id4<<24)).
|
||||
* model nand_model_s instance to update with the model parameters.
|
||||
*
|
||||
* Returned Value:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* drivers/mtd/mtd_rwbuffer.c
|
||||
* MTD driver that contains another MTD driver and provides read-ahead and/or write
|
||||
* buffering.
|
||||
* MTD driver that contains another MTD driver and provides read-ahead
|
||||
* and/or write buffering.
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
@@ -33,11 +33,11 @@
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
@@ -59,9 +59,9 @@
|
||||
|
||||
#if defined(CONFIG_DRVR_WRITEBUFFER) || defined(CONFIG_DRVR_READAHEAD)
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DRVR_INVALIDATE
|
||||
# error This driver requires CONFIG_DRVR_INVALIDATE
|
||||
@@ -79,62 +79,79 @@
|
||||
# define CONFIG_MTD_NRDBLOCKS 4
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* This type represents the state of the MTD device. The struct mtd_dev_s must
|
||||
* appear at the beginning of the definition so that you can freely cast between
|
||||
* pointers to struct mtd_dev_s and struct mtd_rwbuffer_s.
|
||||
/* This type represents the state of the MTD device.
|
||||
* The struct mtd_dev_s must appear at the beginning of the definition so
|
||||
* that you can freely cast between pointers to struct mtd_dev_s and struct
|
||||
* mtd_rwbuffer_s.
|
||||
*/
|
||||
|
||||
struct mtd_rwbuffer_s
|
||||
{
|
||||
struct mtd_dev_s mtd; /* Our exported MTD interface */
|
||||
FAR struct mtd_dev_s *dev; /* Saved lower level MTD interface instance */
|
||||
struct rwbuffer_s rwb; /* The rwbuffer state structure */
|
||||
uint16_t spb; /* Number of sectors per block */
|
||||
struct mtd_dev_s mtd; /* Our exported MTD interface */
|
||||
FAR struct mtd_dev_s *dev; /* Saved lower level MTD interface instance */
|
||||
struct rwbuffer_s rwb; /* The rwbuffer state structure */
|
||||
uint16_t spb; /* Number of sectors per block */
|
||||
};
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* rwbuffer callouts */
|
||||
|
||||
static ssize_t mtd_reload(FAR void *dev, FAR uint8_t *buffer, off_t startblock,
|
||||
static ssize_t mtd_reload(FAR void *dev,
|
||||
FAR uint8_t *buffer,
|
||||
off_t startblock,
|
||||
size_t nblocks);
|
||||
static ssize_t mtd_flush(FAR void *dev, FAR const uint8_t *buffer, off_t startblock,
|
||||
static ssize_t mtd_flush(FAR void *dev,
|
||||
FAR const uint8_t *buffer,
|
||||
off_t startblock,
|
||||
size_t nblocks);
|
||||
|
||||
/* MTD driver methods */
|
||||
|
||||
static int mtd_erase(FAR struct mtd_dev_s *dev, off_t block, size_t nsectors);
|
||||
static ssize_t mtd_bread(FAR struct mtd_dev_s *dev, off_t block,
|
||||
size_t nsectors, FAR uint8_t *buf);
|
||||
static ssize_t mtd_bwrite(FAR struct mtd_dev_s *dev, off_t block,
|
||||
size_t nsectors, FAR const uint8_t *buf);
|
||||
static ssize_t mtd_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes,
|
||||
static int mtd_erase(FAR struct mtd_dev_s *dev,
|
||||
off_t block,
|
||||
size_t nsectors);
|
||||
static ssize_t mtd_bread(FAR struct mtd_dev_s *dev,
|
||||
off_t block,
|
||||
size_t nsectors,
|
||||
FAR uint8_t *buf);
|
||||
static ssize_t mtd_bwrite(FAR struct mtd_dev_s *dev,
|
||||
off_t block,
|
||||
size_t nsectors,
|
||||
FAR const uint8_t *buf);
|
||||
static ssize_t mtd_read(FAR struct mtd_dev_s *dev,
|
||||
off_t offset,
|
||||
size_t nbytes,
|
||||
FAR uint8_t *buffer);
|
||||
static int mtd_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg);
|
||||
static int mtd_ioctl(FAR struct mtd_dev_s *dev,
|
||||
int cmd,
|
||||
unsigned long arg);
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: mtd_reload
|
||||
*
|
||||
* Description:
|
||||
* Reload the read-ahead buffer
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t mtd_reload(FAR void *dev, FAR uint8_t *buffer, off_t startblock,
|
||||
static ssize_t mtd_reload(FAR void *dev,
|
||||
FAR uint8_t *buffer,
|
||||
off_t startblock,
|
||||
size_t nblocks)
|
||||
{
|
||||
FAR struct mtd_rwbuffer_s *priv = (FAR struct mtd_rwbuffer_s *)dev;
|
||||
@@ -145,15 +162,17 @@ static ssize_t mtd_reload(FAR void *dev, FAR uint8_t *buffer, off_t startblock,
|
||||
return priv->dev->bread(priv->dev, startblock, nblocks, buffer);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: mtd_flush
|
||||
*
|
||||
* Description:
|
||||
* Flush the write buffer to hardware
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t mtd_flush(FAR void *dev, FAR const uint8_t *buffer, off_t startblock,
|
||||
static ssize_t mtd_flush(FAR void *dev,
|
||||
FAR const uint8_t *buffer,
|
||||
off_t startblock,
|
||||
size_t nblocks)
|
||||
{
|
||||
FAR struct mtd_rwbuffer_s *priv = (FAR struct mtd_rwbuffer_s *)dev;
|
||||
@@ -164,11 +183,13 @@ static ssize_t mtd_flush(FAR void *dev, FAR const uint8_t *buffer, off_t startbl
|
||||
return priv->dev->bwrite(priv->dev, startblock, nblocks, buffer);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: mtd_erase
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int mtd_erase(FAR struct mtd_dev_s *dev, off_t block, size_t nblocks)
|
||||
static int mtd_erase(FAR struct mtd_dev_s *dev,
|
||||
off_t block,
|
||||
size_t nblocks)
|
||||
{
|
||||
FAR struct mtd_rwbuffer_s *priv = (FAR struct mtd_rwbuffer_s *)dev;
|
||||
off_t sector;
|
||||
@@ -197,57 +218,60 @@ static int mtd_erase(FAR struct mtd_dev_s *dev, off_t block, size_t nblocks)
|
||||
return priv->dev->erase(priv->dev, block, nblocks);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: mtd_bread
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t mtd_bread(FAR struct mtd_dev_s *dev, off_t sector,
|
||||
size_t nsectors, FAR uint8_t *buffer)
|
||||
{
|
||||
FAR struct mtd_rwbuffer_s *priv = (FAR struct mtd_rwbuffer_s *)dev;
|
||||
|
||||
/* Let the rwbuffer logic do it real work. It will call out to mtd_reload if is
|
||||
* needs to read any data.
|
||||
/* Let the rwbuffer logic do it real work.
|
||||
* It will call out to mtd_reload if is needs to read any data.
|
||||
*/
|
||||
|
||||
return rwb_read(&priv->rwb, sector, nsectors, buffer);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: mtd_bwrite
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t mtd_bwrite(FAR struct mtd_dev_s *dev, off_t block, size_t nsectors,
|
||||
FAR const uint8_t *buffer)
|
||||
static ssize_t mtd_bwrite(FAR struct mtd_dev_s *dev, off_t block,
|
||||
size_t nsectors,
|
||||
FAR const uint8_t *buffer)
|
||||
{
|
||||
FAR struct mtd_rwbuffer_s *priv = (FAR struct mtd_rwbuffer_s *)dev;
|
||||
|
||||
/* Let the rwbuffer logic do it real work. It will call out to wrb_reload it is
|
||||
* needs to read any data.
|
||||
/* Let the rwbuffer logic do it real work.
|
||||
* It will call out to wrb_reload it is needs to read any data.
|
||||
*/
|
||||
|
||||
return rwb_write(&priv->rwb, block, nsectors, buffer);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: mtd_read
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t mtd_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes,
|
||||
FAR uint8_t *buffer)
|
||||
static ssize_t mtd_read(FAR struct mtd_dev_s *dev,
|
||||
off_t offset,
|
||||
size_t nbytes,
|
||||
FAR uint8_t *buffer)
|
||||
{
|
||||
FAR struct mtd_rwbuffer_s *priv = (FAR struct mtd_rwbuffer_s *)dev;
|
||||
|
||||
/* Let the rwbuffer logic do it real work. It will call out to mtd_reload it is
|
||||
* needs to read any data.
|
||||
/* Let the rwbuffer logic do it real work.
|
||||
* It will call out to mtd_reload it is needs to read any data.
|
||||
*/
|
||||
|
||||
return rwb_readbytes(&priv->rwb, offset, nbytes, buffer);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: mtd_ioctl
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int mtd_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
{
|
||||
@@ -264,13 +288,14 @@ static int mtd_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
((uintptr_t)arg);
|
||||
if (geo)
|
||||
{
|
||||
/* Populate the geometry structure with information need to know
|
||||
* the capacity and how to access the device.
|
||||
/* Populate the geometry structure with information need to
|
||||
* know the capacity and how to access the device.
|
||||
*
|
||||
* NOTE: that the device is treated as though it where just an array
|
||||
* of fixed size blocks. That is most likely not true, but the client
|
||||
* will expect the device logic to do whatever is necessary to make it
|
||||
* appear so.
|
||||
* NOTE:
|
||||
* that the device is treated as though it where just an array
|
||||
* of fixed size blocks. That is most likely not true, but the
|
||||
* client will expect the device logic to do whatever is
|
||||
* necessary to make it appear so.
|
||||
*/
|
||||
|
||||
geo->blocksize = priv->rwb.blocksize;
|
||||
@@ -315,23 +340,23 @@ static int mtd_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: mtd_rwb_initialize
|
||||
*
|
||||
* Description:
|
||||
* Create an initialized MTD device instance. This MTD driver contains another
|
||||
* MTD driver and converts a larger sector size to a standard 512 byte sector
|
||||
* size.
|
||||
* Create an initialized MTD device instance.
|
||||
* This MTD driver contains another MTD driver and converts a larger
|
||||
* sector size to a standard 512 byte sector size.
|
||||
*
|
||||
* MTD devices are not registered in the file system, but are created as instances
|
||||
* that can be bound to other functions (such as a block or character driver front
|
||||
* end).
|
||||
* MTD devices are not registered in the file system, but are created as
|
||||
* instances that can be bound to other functions (such as a block or
|
||||
* character driver front end).
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct mtd_dev_s *mtd_rwb_initialize(FAR struct mtd_dev_s *mtd)
|
||||
{
|
||||
@@ -354,11 +379,12 @@ FAR struct mtd_dev_s *mtd_rwb_initialize(FAR struct mtd_dev_s *mtd)
|
||||
/* Allocate a state structure (we allocate the structure instead of using
|
||||
* a fixed, static allocation so that we can handle multiple FLASH devices.
|
||||
* The current implementation would handle only one FLASH part per SPI
|
||||
* device (only because of the SPIDEV_FLASH(0) definition) and so would have
|
||||
* to be extended to handle multiple FLASH parts on the same SPI bus.
|
||||
* device (only because of the SPIDEV_FLASH(0) definition) and so would
|
||||
* have to be extended to handle multiple FLASH parts on the same SPI bus.
|
||||
*/
|
||||
|
||||
priv = (FAR struct mtd_rwbuffer_s *)kmm_zalloc(sizeof(struct mtd_rwbuffer_s));
|
||||
priv = (FAR struct mtd_rwbuffer_s *)
|
||||
kmm_zalloc(sizeof(struct mtd_rwbuffer_s));
|
||||
if (!priv)
|
||||
{
|
||||
ferr("ERROR: Failed to allocate mtd_rwbuffer\n");
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* drivers/mtd/mx25rxx.c
|
||||
*
|
||||
* Copyright (C) 201, 2019 Gregory Nutt. All rights reserved.
|
||||
@@ -34,11 +34,11 @@
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <errno.h>
|
||||
@@ -59,9 +59,9 @@
|
||||
#include <nuttx/spi/qspi.h>
|
||||
#include <nuttx/mtd/mtd.h>
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* MX25RXX Commands */
|
||||
|
||||
@@ -146,7 +146,7 @@
|
||||
#define MX25R_CR_TB (1 << 3) /* Bit 3: Top/bottom selected */
|
||||
#define MX25R_CR_DC (1 << 6) /* Bit 6: Dummy cycle */
|
||||
|
||||
/* Cache flags **********************************************************************/
|
||||
/* Cache flags **************************************************************/
|
||||
|
||||
#define MX25RXX_CACHE_VALID (1 << 0) /* 1=Cache has valid data */
|
||||
#define MX25RXX_CACHE_DIRTY (1 << 1) /* 1=Cache is dirty */
|
||||
@@ -164,15 +164,15 @@
|
||||
#define CLR_DIRTY(p) do { (p)->flags &= ~MX25RXX_CACHE_DIRTY; } while (0)
|
||||
#define CLR_ERASED(p) do { (p)->flags &= ~MX25RXX_CACHE_ERASED; } while (0)
|
||||
|
||||
/* 512 byte sector support **********************************************************/
|
||||
/* 512 byte sector support **************************************************/
|
||||
|
||||
#define MX25RXX_SECTOR512_SHIFT 9
|
||||
#define MX25RXX_SECTOR512_SIZE (1 << 9)
|
||||
#define MX25RXX_ERASED_STATE 0xff
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* Internal state of the MTD device */
|
||||
|
||||
@@ -194,9 +194,9 @@ struct mx25rxx_dev_s
|
||||
#endif
|
||||
};
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* MTD driver methods */
|
||||
|
||||
@@ -234,7 +234,9 @@ static void mx25rxx_write_status_config(FAR struct mx25rxx_dev_s *dev,
|
||||
static void mx25rxx_write_enable(FAR struct mx25rxx_dev_s *dev, bool enable);
|
||||
|
||||
static int mx25rxx_write_page(struct mx25rxx_dev_s *priv,
|
||||
FAR const uint8_t *buffer, off_t address, size_t buflen);
|
||||
FAR const uint8_t *buffer,
|
||||
off_t address,
|
||||
size_t buflen);
|
||||
static int mx25rxx_erase_sector(struct mx25rxx_dev_s *priv, off_t sector);
|
||||
#if 0 /* FIXME: Not used */
|
||||
static int mx25rxx_erase_block(struct mx25rxx_dev_s *priv, off_t block);
|
||||
@@ -243,15 +245,16 @@ static int mx25rxx_erase_chip(struct mx25rxx_dev_s *priv);
|
||||
|
||||
#ifdef CONFIG_MX25RXX_SECTOR512
|
||||
static int mx25rxx_flush_cache(struct mx25rxx_dev_s *priv);
|
||||
static FAR uint8_t *mx25rxx_read_cache(struct mx25rxx_dev_s *priv, off_t sector);
|
||||
static FAR uint8_t *mx25rxx_read_cache(struct mx25rxx_dev_s *priv,
|
||||
off_t sector);
|
||||
static void mx25rxx_erase_cache(struct mx25rxx_dev_s *priv, off_t sector);
|
||||
static int mx25rxx_write_cache(FAR struct mx25rxx_dev_s *priv,
|
||||
FAR const uint8_t *buffer, off_t sector, size_t nsectors);
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
void mx25rxx_lock(FAR struct qspi_dev_s *qspi, bool read)
|
||||
{
|
||||
@@ -259,23 +262,24 @@ void mx25rxx_lock(FAR struct qspi_dev_s *qspi, bool read)
|
||||
* lock SPI to have exclusive access to the buses for a sequence of
|
||||
* transfers. The bus should be locked before the chip is selected.
|
||||
*
|
||||
* This is a blocking call and will not return until we have exclusive access
|
||||
* to the SPI bus. We will retain that exclusive access until the bus is
|
||||
* unlocked.
|
||||
* This is a blocking call and will not return until we have exclusive
|
||||
* access to the SPI bus. We will retain that exclusive access until the
|
||||
* bus is unlocked.
|
||||
*/
|
||||
|
||||
QSPI_LOCK(qspi, true);
|
||||
|
||||
/* After locking the SPI bus, the we also need call the setfrequency, setbits
|
||||
* and setmode methods to make sure that the SPI is properly configured for
|
||||
* the device. If the SPI bus is being shared, then it may have been left
|
||||
* in an incompatible state.
|
||||
/* After locking the SPI bus, the we also need call the setfrequency,
|
||||
* setbits and setmode methods to make sure that the SPI is properly
|
||||
* configured for the device. If the SPI bus is being shared, then it
|
||||
* may have been left in an incompatible state.
|
||||
*/
|
||||
|
||||
QSPI_SETMODE(qspi, CONFIG_MX25RXX_QSPIMODE);
|
||||
QSPI_SETBITS(qspi, 8);
|
||||
QSPI_SETFREQUENCY(qspi,
|
||||
read ? CONFIG_MX25RXX_QSPI_READ_FREQUENCY : CONFIG_MX25RXX_QSPI_FREQUENCY);
|
||||
read ? CONFIG_MX25RXX_QSPI_READ_FREQUENCY :
|
||||
CONFIG_MX25RXX_QSPI_FREQUENCY);
|
||||
}
|
||||
|
||||
void mx25rxx_unlock(FAR struct qspi_dev_s *qspi)
|
||||
@@ -538,7 +542,8 @@ int mx25rxx_read_configuration(FAR struct mx25rxx_dev_s *dev)
|
||||
return mx25rxx_command_read(dev->qspi, MX25R_RDCR, dev->cmdbuf, 4);
|
||||
}
|
||||
|
||||
void mx25rxx_write_status_config(FAR struct mx25rxx_dev_s *dev, uint8_t status,
|
||||
void mx25rxx_write_status_config(FAR struct mx25rxx_dev_s *dev,
|
||||
uint8_t status,
|
||||
uint16_t config)
|
||||
{
|
||||
mx25rxx_write_enable(dev, true);
|
||||
@@ -555,7 +560,9 @@ void mx25rxx_write_status_config(FAR struct mx25rxx_dev_s *dev, uint8_t status,
|
||||
mx25rxx_write_enable(dev, false);
|
||||
}
|
||||
|
||||
int mx25rxx_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks)
|
||||
int mx25rxx_erase(FAR struct mtd_dev_s *dev,
|
||||
off_t startblock,
|
||||
size_t nblocks)
|
||||
{
|
||||
FAR struct mx25rxx_dev_s *priv = (FAR struct mx25rxx_dev_s *)dev;
|
||||
size_t blocksleft = nblocks;
|
||||
@@ -636,7 +643,9 @@ ssize_t mx25rxx_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
|
||||
finfo("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
|
||||
|
||||
/* On this device, we can handle the block read just like the byte-oriented read */
|
||||
/* On this device, we can handle the block read just like the
|
||||
* byte-oriented read
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_MX25RXX_SECTOR512
|
||||
nbytes = mx25rxx_read(dev, startblock << MX25RXX_SECTOR512_SHIFT,
|
||||
@@ -730,20 +739,22 @@ int mx25rxx_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
|
||||
if (geo)
|
||||
{
|
||||
/* Populate the geometry structure with information need to know
|
||||
* the capacity and how to access the device.
|
||||
/* Populate the geometry structure with information need to
|
||||
* know the capacity and how to access the device.
|
||||
*
|
||||
* NOTE: that the device is treated as though it where just an array
|
||||
* of fixed size blocks. That is most likely not true, but the client
|
||||
* will expect the device logic to do whatever is necessary to make it
|
||||
* appear so.
|
||||
* NOTE:
|
||||
* that the device is treated as though it where just an
|
||||
* array of fixed size blocks. That is most likely not true,
|
||||
* but the client will expect the device logic to do whatever
|
||||
* is necessary to make it appear so.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_MX25RXX_SECTOR512
|
||||
geo->blocksize = (1 << MX25RXX_SECTOR512_SHIFT);
|
||||
geo->erasesize = (1 << MX25RXX_SECTOR512_SHIFT);
|
||||
geo->neraseblocks = priv->nsectors <<
|
||||
(priv->sectorshift - MX25RXX_SECTOR512_SHIFT);
|
||||
(priv->sectorshift -
|
||||
MX25RXX_SECTOR512_SHIFT);
|
||||
#else
|
||||
geo->blocksize = (1 << priv->pageshift);
|
||||
geo->erasesize = (1 << priv->sectorshift);
|
||||
@@ -823,18 +834,18 @@ int mx25rxx_readid(struct mx25rxx_dev_s *dev)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: mx25rxx_flush_cache
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_MX25RXX_SECTOR512
|
||||
static int mx25rxx_flush_cache(struct mx25rxx_dev_s *priv)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
/* If the cache is dirty (meaning that it no longer matches the old FLASH contents)
|
||||
* or was erased (with the cache containing the correct FLASH contents), then write
|
||||
* the cached erase block to FLASH.
|
||||
/* If the cache is dirty (meaning that it no longer matches the old FLASH
|
||||
* contents) or was erased (with the cache containing the correct FLASH
|
||||
* contents), then write the cached erase block to FLASH.
|
||||
*/
|
||||
|
||||
if (IS_DIRTY(priv) || IS_ERASED(priv))
|
||||
@@ -847,7 +858,10 @@ static int mx25rxx_flush_cache(struct mx25rxx_dev_s *priv)
|
||||
|
||||
/* Write entire erase block to FLASH */
|
||||
|
||||
ret = mx25rxx_write_page(priv, priv->sector, address, 1 << priv->sectorshift);
|
||||
ret = mx25rxx_write_page(priv,
|
||||
priv->sector,
|
||||
address,
|
||||
1 << priv->sectorshift);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: mx25rxx_write_page failed: %d\n", ret);
|
||||
@@ -863,21 +877,23 @@ static int mx25rxx_flush_cache(struct mx25rxx_dev_s *priv)
|
||||
}
|
||||
#endif /* CONFIG_MX25RXX_SECTOR512 */
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: mx25rxx_read_cache
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_MX25RXX_SECTOR512
|
||||
static FAR uint8_t *mx25rxx_read_cache(struct mx25rxx_dev_s *priv, off_t sector)
|
||||
static FAR uint8_t *mx25rxx_read_cache(struct mx25rxx_dev_s *priv,
|
||||
off_t sector)
|
||||
{
|
||||
off_t esectno;
|
||||
int shift;
|
||||
int index;
|
||||
int ret;
|
||||
|
||||
/* Convert from the 512 byte sector to the erase sector size of the device. For
|
||||
* example, if the actual erase sector size is 4Kb (1 << 12), then we first
|
||||
* shift to the right by 3 to get the sector number in 4096 increments.
|
||||
/* Convert from the 512 byte sector to the erase sector size of the device.
|
||||
* For example, if the actual erase sector size is 4Kb (1 << 12), then we
|
||||
* first shift to the right by 3 to get the sector number in 4096
|
||||
* increments.
|
||||
*/
|
||||
|
||||
shift = priv->sectorshift - MX25RXX_SECTOR512_SHIFT;
|
||||
@@ -918,7 +934,9 @@ static FAR uint8_t *mx25rxx_read_cache(struct mx25rxx_dev_s *priv, off_t sector)
|
||||
CLR_ERASED(priv); /* The underlying FLASH has not been erased */
|
||||
}
|
||||
|
||||
/* Get the index to the 512 sector in the erase block that holds the argument */
|
||||
/* Get the index to the 512 sector in the erase block that holds the
|
||||
* argument
|
||||
*/
|
||||
|
||||
index = sector & ((1 << shift) - 1);
|
||||
|
||||
@@ -928,17 +946,17 @@ static FAR uint8_t *mx25rxx_read_cache(struct mx25rxx_dev_s *priv, off_t sector)
|
||||
}
|
||||
#endif /* CONFIG_MX25RXX_SECTOR512 */
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: mx25rxx_erase_cache
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_MX25RXX_SECTOR512
|
||||
static void mx25rxx_erase_cache(struct mx25rxx_dev_s *priv, off_t sector)
|
||||
{
|
||||
FAR uint8_t *dest;
|
||||
|
||||
/* First, make sure that the erase block containing the 512 byte sector is in
|
||||
* the cache.
|
||||
/* First, make sure that the erase block containing the 512 byte sector is
|
||||
* in the cache.
|
||||
*/
|
||||
|
||||
dest = mx25rxx_read_cache(priv, sector);
|
||||
@@ -950,7 +968,8 @@ static void mx25rxx_erase_cache(struct mx25rxx_dev_s *priv, off_t sector)
|
||||
|
||||
if (!IS_ERASED(priv))
|
||||
{
|
||||
off_t esectno = sector >> (priv->sectorshift - MX25RXX_SECTOR512_SHIFT);
|
||||
off_t esectno = sector >>
|
||||
(priv->sectorshift - MX25RXX_SECTOR512_SHIFT);
|
||||
finfo("sector: %jd esectno: %jd\n",
|
||||
(intmax_t)sector, (intmax_t)esectno);
|
||||
|
||||
@@ -958,9 +977,9 @@ static void mx25rxx_erase_cache(struct mx25rxx_dev_s *priv, off_t sector)
|
||||
SET_ERASED(priv);
|
||||
}
|
||||
|
||||
/* Put the cached sector data into the erase state and mark the cache as dirty
|
||||
* (but don't update the FLASH yet. The caller will do that at a more optimal
|
||||
* time).
|
||||
/* Put the cached sector data into the erase state and mark the cache as
|
||||
* dirty (but don't update the FLASH yet. The caller will do that at a
|
||||
* more optimal time).
|
||||
*/
|
||||
|
||||
memset(dest, MX25RXX_ERASED_STATE, MX25RXX_SECTOR512_SIZE);
|
||||
@@ -968,9 +987,9 @@ static void mx25rxx_erase_cache(struct mx25rxx_dev_s *priv, off_t sector)
|
||||
}
|
||||
#endif /* CONFIG_MX25RXX_SECTOR512 */
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: mx25rxx_write_cache
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_MX25RXX_SECTOR512
|
||||
static int mx25rxx_write_cache(FAR struct mx25rxx_dev_s *priv,
|
||||
@@ -982,20 +1001,21 @@ static int mx25rxx_write_cache(FAR struct mx25rxx_dev_s *priv,
|
||||
|
||||
for (; nsectors > 0; nsectors--)
|
||||
{
|
||||
/* First, make sure that the erase block containing 512 byte sector is in
|
||||
* memory.
|
||||
/* First, make sure that the erase block containing 512 byte sector is
|
||||
* in memory.
|
||||
*/
|
||||
|
||||
dest = mx25rxx_read_cache(priv, sector);
|
||||
|
||||
/* Erase the block containing this sector if it is not already erased.
|
||||
* The erased indicated will be cleared when the data from the erase sector
|
||||
* is read into the cache and set here when we erase the sector.
|
||||
* The erased indicated will be cleared when the data from the erase
|
||||
* sector is read into the cache and set here when we erase the sector.
|
||||
*/
|
||||
|
||||
if (!IS_ERASED(priv))
|
||||
{
|
||||
off_t esectno = sector >> (priv->sectorshift - MX25RXX_SECTOR512_SHIFT);
|
||||
off_t esectno = sector >>
|
||||
(priv->sectorshift - MX25RXX_SECTOR512_SHIFT);
|
||||
finfo("sector: %jd esectno: %jd\n",
|
||||
(intmax_t)sector, (intmax_t)esectno);
|
||||
|
||||
@@ -1030,11 +1050,11 @@ static int mx25rxx_write_cache(FAR struct mx25rxx_dev_s *priv,
|
||||
}
|
||||
#endif /* CONFIG_MX25RXX_SECTOR512 */
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: mx25rxx_initialize
|
||||
*
|
||||
* Description:
|
||||
@@ -1044,9 +1064,10 @@ static int mx25rxx_write_cache(FAR struct mx25rxx_dev_s *priv,
|
||||
* instances that can be bound to other functions (such as a block or
|
||||
* character driver front end).
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct mtd_dev_s *mx25rxx_initialize(FAR struct qspi_dev_s *qspi, bool unprotect)
|
||||
FAR struct mtd_dev_s *mx25rxx_initialize(FAR struct qspi_dev_s *qspi,
|
||||
bool unprotect)
|
||||
{
|
||||
FAR struct mx25rxx_dev_s *dev;
|
||||
int ret;
|
||||
@@ -1058,8 +1079,9 @@ FAR struct mtd_dev_s *mx25rxx_initialize(FAR struct qspi_dev_s *qspi, bool unpro
|
||||
/* Allocate a state structure (we allocate the structure instead of using
|
||||
* a fixed, static allocation so that we can handle multiple FLASH devices.
|
||||
* The current implementation would handle only one FLASH part per QuadSPI
|
||||
* device (only because of the QSPIDEV_FLASH(0) definition) and so would have
|
||||
* to be extended to handle multiple FLASH parts on the same QuadSPI bus.
|
||||
* device (only because of the QSPIDEV_FLASH(0) definition) and so would
|
||||
* have to be extended to handle multiple FLASH parts on the same QuadSPI
|
||||
* bus.
|
||||
*/
|
||||
|
||||
dev = (FAR struct mx25rxx_dev_s *)kmm_zalloc(sizeof(*dev));
|
||||
@@ -1104,7 +1126,9 @@ FAR struct mtd_dev_s *mx25rxx_initialize(FAR struct qspi_dev_s *qspi, bool unpro
|
||||
dev->sector = (FAR uint8_t *)QSPI_ALLOC(qspi, 1 << dev->sectorshift);
|
||||
if (dev->sector == NULL)
|
||||
{
|
||||
/* Allocation failed! Discard all of that work we just did and return NULL */
|
||||
/* Allocation failed! Discard all of that work we just did and
|
||||
* return NULL
|
||||
*/
|
||||
|
||||
ferr("ERROR: Sector allocation failed\n");
|
||||
goto exit_free_cmdbuf;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -53,6 +53,7 @@
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#ifndef CONFIG_RAMMTD_BLOCKSIZE
|
||||
@@ -117,18 +118,29 @@ static void *ram_write(FAR void *dest, FAR const void *src, size_t len);
|
||||
|
||||
/* MTD driver methods */
|
||||
|
||||
static int ram_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks);
|
||||
static ssize_t ram_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks,
|
||||
FAR uint8_t *buf);
|
||||
static ssize_t ram_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks,
|
||||
FAR const uint8_t *buf);
|
||||
static ssize_t ram_byteread(FAR struct mtd_dev_s *dev, off_t offset,
|
||||
static int ram_erase(FAR struct mtd_dev_s *dev,
|
||||
off_t startblock,
|
||||
size_t nblocks);
|
||||
static ssize_t ram_bread(FAR struct mtd_dev_s *dev,
|
||||
off_t startblock,
|
||||
size_t nblocks,
|
||||
FAR uint8_t *buf);
|
||||
static ssize_t ram_bwrite(FAR struct mtd_dev_s *dev,
|
||||
off_t startblock,
|
||||
size_t nblocks,
|
||||
FAR const uint8_t *buf);
|
||||
static ssize_t ram_byteread(FAR struct mtd_dev_s *dev,
|
||||
off_t offset,
|
||||
size_t nbytes, FAR uint8_t *buf);
|
||||
#ifdef CONFIG_MTD_BYTE_WRITE
|
||||
static ssize_t ram_bytewrite(FAR struct mtd_dev_s *dev, off_t offset,
|
||||
size_t nbytes, FAR const uint8_t *buf);
|
||||
static ssize_t ram_bytewrite(FAR struct mtd_dev_s *dev,
|
||||
off_t offset,
|
||||
size_t nbytes,
|
||||
FAR const uint8_t *buf);
|
||||
#endif
|
||||
static int ram_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg);
|
||||
static int ram_ioctl(FAR struct mtd_dev_s *dev,
|
||||
int cmd,
|
||||
unsigned long arg);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
@@ -232,8 +244,10 @@ static int ram_erase(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
* Name: ram_bread
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t ram_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks,
|
||||
FAR uint8_t *buf)
|
||||
static ssize_t ram_bread(FAR struct mtd_dev_s *dev,
|
||||
off_t startblock,
|
||||
size_t nblocks,
|
||||
FAR uint8_t *buf)
|
||||
{
|
||||
FAR struct ram_dev_s *priv = (FAR struct ram_dev_s *)dev;
|
||||
off_t offset;
|
||||
@@ -322,9 +336,9 @@ static ssize_t ram_byteread(FAR struct mtd_dev_s *dev, off_t offset,
|
||||
/* Don't let read read past end of buffer */
|
||||
|
||||
if (offset + nbytes > priv->nblocks * CONFIG_RAMMTD_ERASESIZE)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
ram_read(buf, &priv->start[offset], nbytes);
|
||||
return nbytes;
|
||||
@@ -371,11 +385,12 @@ static int ram_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
{
|
||||
case MTDIOC_GEOMETRY:
|
||||
{
|
||||
FAR struct mtd_geometry_s *geo = (FAR struct mtd_geometry_s *)((uintptr_t)arg);
|
||||
FAR struct mtd_geometry_s *geo =
|
||||
(FAR struct mtd_geometry_s *)((uintptr_t)arg);
|
||||
if (geo)
|
||||
{
|
||||
/* Populate the geometry structure with information need to know
|
||||
* the capacity and how to access the device.
|
||||
/* Populate the geometry structure with information need to
|
||||
* know the capacity and how to access the device.
|
||||
*/
|
||||
|
||||
geo->blocksize = CONFIG_RAMMTD_BLOCKSIZE;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* drivers/mtd/sector512.c
|
||||
* MTD driver that contains another MTD driver and converts a larger sector size
|
||||
* to a standard 512 byte sector size.
|
||||
* MTD driver that contains another MTD driver and converts a larger sector
|
||||
* size to a standard 512 byte sector size.
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
@@ -33,11 +33,11 @@
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
@@ -57,9 +57,9 @@
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
#include <nuttx/mtd/mtd.h>
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration */
|
||||
|
||||
@@ -69,35 +69,35 @@
|
||||
|
||||
/* 512-byte sector constants */
|
||||
|
||||
#define SECTOR_512 512
|
||||
#define SHIFT_512 9
|
||||
#define MASK_512 511
|
||||
#define SECTOR_512 512
|
||||
#define SHIFT_512 9
|
||||
#define MASK_512 511
|
||||
|
||||
/* Cache flags */
|
||||
|
||||
#define SST25_CACHE_VALID (1 << 0) /* 1=Cache has valid data */
|
||||
#define SST25_CACHE_DIRTY (1 << 1) /* 1=Cache is dirty */
|
||||
#define SST25_CACHE_ERASED (1 << 2) /* 1=Backing FLASH is erased */
|
||||
#define SST25_CACHE_VALID (1 << 0) /* 1=Cache has valid data */
|
||||
#define SST25_CACHE_DIRTY (1 << 1) /* 1=Cache is dirty */
|
||||
#define SST25_CACHE_ERASED (1 << 2) /* 1=Backing FLASH is erased */
|
||||
|
||||
#define IS_VALID(p) ((((p)->flags) & SST25_CACHE_VALID) != 0)
|
||||
#define IS_DIRTY(p) ((((p)->flags) & SST25_CACHE_DIRTY) != 0)
|
||||
#define IS_ERASED(p) ((((p)->flags) & SST25_CACHE_DIRTY) != 0)
|
||||
#define IS_VALID(p) ((((p)->flags) & SST25_CACHE_VALID) != 0)
|
||||
#define IS_DIRTY(p) ((((p)->flags) & SST25_CACHE_DIRTY) != 0)
|
||||
#define IS_ERASED(p) ((((p)->flags) & SST25_CACHE_DIRTY) != 0)
|
||||
|
||||
#define SET_VALID(p) do { (p)->flags |= SST25_CACHE_VALID; } while (0)
|
||||
#define SET_DIRTY(p) do { (p)->flags |= SST25_CACHE_DIRTY; } while (0)
|
||||
#define SET_ERASED(p) do { (p)->flags |= SST25_CACHE_DIRTY; } while (0)
|
||||
#define SET_VALID(p) do { (p)->flags |= SST25_CACHE_VALID; } while (0)
|
||||
#define SET_DIRTY(p) do { (p)->flags |= SST25_CACHE_DIRTY; } while (0)
|
||||
#define SET_ERASED(p) do { (p)->flags |= SST25_CACHE_DIRTY; } while (0)
|
||||
|
||||
#define CLR_VALID(p) do { (p)->flags &= ~SST25_CACHE_VALID; } while (0)
|
||||
#define CLR_DIRTY(p) do { (p)->flags &= ~SST25_CACHE_DIRTY; } while (0)
|
||||
#define CLR_ERASED(p) do { (p)->flags &= ~SST25_CACHE_DIRTY; } while (0)
|
||||
#define CLR_VALID(p) do { (p)->flags &= ~SST25_CACHE_VALID; } while (0)
|
||||
#define CLR_DIRTY(p) do { (p)->flags &= ~SST25_CACHE_DIRTY; } while (0)
|
||||
#define CLR_ERASED(p) do { (p)->flags &= ~SST25_CACHE_DIRTY; } while (0)
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* This type represents the state of the MTD device. The struct mtd_dev_s must
|
||||
* appear at the beginning of the definition so that you can freely cast between
|
||||
* pointers to struct mtd_dev_s and struct s512_dev_s.
|
||||
/* This type represents the state of the MTD device. The struct mtd_dev_s
|
||||
* must appear at the beginning of the definition so that you can freely
|
||||
* cast between pointers to struct mtd_dev_s and struct s512_dev_s.
|
||||
*/
|
||||
|
||||
struct s512_dev_s
|
||||
@@ -113,9 +113,9 @@ struct s512_dev_s
|
||||
FAR uint8_t *eblock; /* Allocated erase block */
|
||||
};
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* Helpers */
|
||||
|
||||
@@ -126,26 +126,36 @@ static void s512_cacheflush(struct s512_dev_s *priv);
|
||||
|
||||
/* MTD driver methods */
|
||||
|
||||
static int s512_erase(FAR struct mtd_dev_s *dev, off_t sector512, size_t nsectors);
|
||||
static ssize_t s512_bread(FAR struct mtd_dev_s *dev, off_t sector512,
|
||||
size_t nsectors, FAR uint8_t *buf);
|
||||
static ssize_t s512_bwrite(FAR struct mtd_dev_s *dev, off_t sector512,
|
||||
size_t nsectors, FAR const uint8_t *buf);
|
||||
static ssize_t s512_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes,
|
||||
FAR uint8_t *buffer);
|
||||
static int s512_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg);
|
||||
static int s512_erase(FAR struct mtd_dev_s *dev,
|
||||
off_t sector512,
|
||||
size_t nsectors);
|
||||
static ssize_t s512_bread(FAR struct mtd_dev_s *dev,
|
||||
off_t sector512,
|
||||
size_t nsectors,
|
||||
FAR uint8_t *buf);
|
||||
static ssize_t s512_bwrite(FAR struct mtd_dev_s *dev,
|
||||
off_t sector512,
|
||||
size_t nsectors,
|
||||
FAR const uint8_t *buf);
|
||||
static ssize_t s512_read(FAR struct mtd_dev_s *dev,
|
||||
off_t offset,
|
||||
size_t nbytes,
|
||||
FAR uint8_t *buffer);
|
||||
static int s512_ioctl(FAR struct mtd_dev_s *dev,
|
||||
int cmd,
|
||||
unsigned long arg);
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: s512_cacheread
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static FAR uint8_t *s512_cacheread(struct s512_dev_s *priv, off_t sector512)
|
||||
{
|
||||
@@ -191,7 +201,9 @@ static FAR uint8_t *s512_cacheread(struct s512_dev_s *priv, off_t sector512)
|
||||
CLR_ERASED(priv); /* The underlying FLASH has not been erased */
|
||||
}
|
||||
|
||||
/* Get the index to the 512 sector in the erase block that holds the argument */
|
||||
/* Get the index to the 512 sector in the erase block that holds the
|
||||
* argument
|
||||
*/
|
||||
|
||||
index = sector512 % priv->stdperblock;
|
||||
|
||||
@@ -200,9 +212,9 @@ static FAR uint8_t *s512_cacheread(struct s512_dev_s *priv, off_t sector512)
|
||||
return &priv->eblock[index << SHIFT_512];
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: s512_cacheflush
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(CONFIG_MTD_SECT512_READONLY)
|
||||
static void s512_cacheflush(struct s512_dev_s *priv)
|
||||
@@ -239,11 +251,13 @@ static void s512_cacheflush(struct s512_dev_s *priv)
|
||||
}
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: s512_erase
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int s512_erase(FAR struct mtd_dev_s *dev, off_t sector512, size_t nsectors)
|
||||
static int s512_erase(FAR struct mtd_dev_s *dev,
|
||||
off_t sector512,
|
||||
size_t nsectors)
|
||||
{
|
||||
#ifdef CONFIG_MTD_SECT512_READONLY
|
||||
return -EACESS
|
||||
@@ -258,21 +272,22 @@ static int s512_erase(FAR struct mtd_dev_s *dev, off_t sector512, size_t nsector
|
||||
|
||||
while (sectorsleft-- > 0)
|
||||
{
|
||||
/* Erase each sector. First, make sure that the erase block containing the
|
||||
* 512 byte sector is in the cache.
|
||||
/* Erase each sector. First, make sure that the erase block containing
|
||||
* the 512 byte sector is in the cache.
|
||||
*/
|
||||
|
||||
dest = s512_cacheread(priv, sector512);
|
||||
if (!dest)
|
||||
{
|
||||
ferr("ERROR: s512_cacheread(%lu) failed\n", (unsigned long)sector512);
|
||||
ferr("ERROR: s512_cacheread(%lu) failed\n",
|
||||
(unsigned long)sector512);
|
||||
DEBUGPANIC();
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* Erase the block containing this sector if it is not already erased.
|
||||
* The erased indicator will be cleared when the data from the erase sector
|
||||
* is read into the cache and set here when we erase the block.
|
||||
* The erased indicator will be cleared when the data from the erase
|
||||
* sector is read into the cache and set here when we erase the block.
|
||||
*/
|
||||
|
||||
if (!IS_ERASED(priv))
|
||||
@@ -310,9 +325,9 @@ static int s512_erase(FAR struct mtd_dev_s *dev, off_t sector512, size_t nsector
|
||||
#endif
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: s512_bread
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t s512_bread(FAR struct mtd_dev_s *dev, off_t sector512,
|
||||
size_t nsectors, FAR uint8_t *buffer)
|
||||
@@ -333,7 +348,8 @@ static ssize_t s512_bread(FAR struct mtd_dev_s *dev, off_t sector512,
|
||||
src = s512_cacheread(priv, sector512);
|
||||
if (!src)
|
||||
{
|
||||
ferr("ERROR: s512_cacheread(%lu) failed\n", (unsigned long)sector512);
|
||||
ferr("ERROR: s512_cacheread(%lu) failed\n",
|
||||
(unsigned long)sector512);
|
||||
DEBUGPANIC();
|
||||
|
||||
result = (ssize_t)nsectors - remaining;
|
||||
@@ -345,7 +361,9 @@ static ssize_t s512_bread(FAR struct mtd_dev_s *dev, off_t sector512,
|
||||
break;
|
||||
}
|
||||
|
||||
/* Copy the sector data from the erase block cache into the user buffer */
|
||||
/* Copy the sector data from the erase block cache into the user
|
||||
* buffer
|
||||
*/
|
||||
|
||||
memcpy(buffer, src, SECTOR_512);
|
||||
|
||||
@@ -356,9 +374,9 @@ static ssize_t s512_bread(FAR struct mtd_dev_s *dev, off_t sector512,
|
||||
return result;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: s512_bwrite
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t s512_bwrite(FAR struct mtd_dev_s *dev, off_t sector512,
|
||||
size_t nsectors,
|
||||
@@ -378,8 +396,8 @@ static ssize_t s512_bwrite(FAR struct mtd_dev_s *dev, off_t sector512,
|
||||
|
||||
for (remaining = nsectors; remaining > 0; remaining--)
|
||||
{
|
||||
/* First, make sure that the erase block containing 512 byte sector is in
|
||||
* memory.
|
||||
/* First, make sure that the erase block containing 512 byte sector is
|
||||
* in memory.
|
||||
*/
|
||||
|
||||
dest = s512_cacheread(priv, sector512);
|
||||
@@ -395,8 +413,8 @@ static ssize_t s512_bwrite(FAR struct mtd_dev_s *dev, off_t sector512,
|
||||
}
|
||||
|
||||
/* Erase the block containing this sector if it is not already erased.
|
||||
* The erased indicated will be cleared when the data from the erase sector
|
||||
* is read into the cache and set here when we erase the sector.
|
||||
* The erased indicated will be cleared when the data from the erase
|
||||
* sector is read into the cache and set here when we erase the sector.
|
||||
*/
|
||||
|
||||
if (!IS_ERASED(priv))
|
||||
@@ -434,11 +452,13 @@ static ssize_t s512_bwrite(FAR struct mtd_dev_s *dev, off_t sector512,
|
||||
#endif
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: s512_read
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t s512_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes,
|
||||
static ssize_t s512_read(FAR struct mtd_dev_s *dev,
|
||||
off_t offset,
|
||||
size_t nbytes,
|
||||
FAR uint8_t *buffer)
|
||||
{
|
||||
FAR struct s512_dev_s *priv = (FAR struct s512_dev_s *)dev;
|
||||
@@ -495,9 +515,9 @@ static ssize_t s512_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes,
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: s512_ioctl
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int s512_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
{
|
||||
@@ -514,13 +534,14 @@ static int s512_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
((uintptr_t)arg);
|
||||
if (geo)
|
||||
{
|
||||
/* Populate the geometry structure with information need to know
|
||||
* the capacity and how to access the device.
|
||||
/* Populate the geometry structure with information need to
|
||||
* know the capacity and how to access the device.
|
||||
*
|
||||
* NOTE: that the device is treated as though it where just an array
|
||||
* of fixed size blocks. That is most likely not true, but the client
|
||||
* will expect the device logic to do whatever is necessary to make it
|
||||
* appear so.
|
||||
* NOTE:
|
||||
* that the device is treated as though it where just an
|
||||
* array of fixed size blocks. That is most likely not true,
|
||||
* but the client will expect the device logic to do whatever
|
||||
* is necessary to make it appear so.
|
||||
*/
|
||||
|
||||
geo->blocksize = SECTOR_512;
|
||||
@@ -559,23 +580,23 @@ static int s512_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: s512_initialize
|
||||
*
|
||||
* Description:
|
||||
* Create an initialized MTD device instance. This MTD driver contains another
|
||||
* MTD driver and converts a larger sector size to a standard 512 byte sector
|
||||
* size.
|
||||
* Create an initialized MTD device instance. This MTD driver contains
|
||||
* another MTD driver and converts a larger sector size to a standard 512
|
||||
* byte sector size.
|
||||
*
|
||||
* MTD devices are not registered in the file system, but are created as instances
|
||||
* that can be bound to other functions (such as a block or character driver front
|
||||
* end).
|
||||
* MTD devices are not registered in the file system, but are created as
|
||||
* instances that can be bound to other functions (such as a block or
|
||||
* character driver front end).
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct mtd_dev_s *s512_initialize(FAR struct mtd_dev_s *mtd)
|
||||
{
|
||||
@@ -595,7 +616,8 @@ FAR struct mtd_dev_s *s512_initialize(FAR struct mtd_dev_s *mtd)
|
||||
if (ret < 0 || geo.erasesize <= SECTOR_512 ||
|
||||
(geo.erasesize & ~MASK_512) != geo.erasesize)
|
||||
{
|
||||
ferr("ERROR: MTDIOC_GEOMETRY ioctl returned %d, eraseize=%" PRId32 "\n",
|
||||
ferr(
|
||||
"ERROR: MTDIOC_GEOMETRY ioctl returned %d, eraseize=%" PRId32 "\n",
|
||||
ret, geo.erasesize);
|
||||
DEBUGPANIC();
|
||||
return NULL;
|
||||
@@ -604,8 +626,8 @@ FAR struct mtd_dev_s *s512_initialize(FAR struct mtd_dev_s *mtd)
|
||||
/* Allocate a state structure (we allocate the structure instead of using
|
||||
* a fixed, static allocation so that we can handle multiple FLASH devices.
|
||||
* The current implementation would handle only one FLASH part per SPI
|
||||
* device (only because of the SPIDEV_FLASH(0) definition) and so would have
|
||||
* to be extended to handle multiple FLASH parts on the same SPI bus.
|
||||
* device (only because of the SPIDEV_FLASH(0) definition) and so would
|
||||
* have to be extended to handle multiple FLASH parts on the same SPI bus.
|
||||
*/
|
||||
|
||||
priv = (FAR struct s512_dev_s *)kmm_zalloc(sizeof(struct s512_dev_s));
|
||||
|
||||
@@ -90,6 +90,7 @@ static int skel_ioctl(FAR struct mtd_dev_s *dev, int cmd,
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure holds the state of the MTD driver */
|
||||
|
||||
static struct skel_dev_s g_skeldev =
|
||||
@@ -255,13 +256,14 @@ static int skel_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
FAR struct mtd_geometry_s *geo = (FAR struct mtd_geometry_s *)arg;
|
||||
if (geo)
|
||||
{
|
||||
/* Populate the geometry structure with information needed to know
|
||||
* the capacity and how to access the device.
|
||||
/* Populate the geometry structure with information needed to
|
||||
* know the capacity and how to access the device.
|
||||
*
|
||||
* NOTE: that the device is treated as though it where just an array
|
||||
* of fixed size blocks. That is most likely not true, but the client
|
||||
* will expect the device logic to do whatever is necessary to make it
|
||||
* appear so.
|
||||
* NOTE:
|
||||
* that the device is treated as though it where just an array
|
||||
* of fixed size blocks. That is most likely not true, but the
|
||||
* client will expect the device logic to do whatever is
|
||||
* necessary to make it appear so.
|
||||
*/
|
||||
|
||||
geo->blocksize = 512; /* Size of one read/write block */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user