arch/sim/src/up_spiflash.c: Add support for W25 FLASH simulation. From Ken Petit

This commit is contained in:
Ken Pettit 2015-11-18 07:08:06 -06:00 committed by Gregory Nutt
parent a6d6c430d9
commit 992d7d1e85
2 changed files with 34 additions and 1 deletions

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/sim/src/up_initialize.c
*
* Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2011-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -79,6 +79,7 @@ static void up_init_smartfs(void)
FAR struct mtd_dev_s *mtd;
FAR struct spi_dev_s *spi;
#ifdef CONFIG_MTD_M25P
/* Initialize a simulated SPI FLASH block device m25p MTD driver */
spi = up_spiflashinitialize();
@ -87,6 +88,18 @@ static void up_init_smartfs(void)
/* Now initialize a SMART Flash block device and bind it to the MTD device */
smart_initialize(0, mtd, NULL);
#endif
#ifdef CONFIG_MTD_W25
/* Initialize a simulated SPI FLASH block device m25p MTD driver */
spi = up_spiflashinitialize();
mtd = w25_initialize(spi);
/* Now initialize a SMART Flash block device and bind it to the MTD device */
smart_initialize(0, mtd, NULL);
#endif
}
#endif

View File

@ -84,6 +84,11 @@
#ifdef CONFIG_SIM_SPIFLASH_1M
# define CONFIG_SPIFLASH_SIZE (128 * 1024)
# define CONFIG_SPIFLASH_CAPACITY 0x11
#ifndef CONFIG_SIM_SPIFLASH_SECTORSIZE
# define CONFIG_SIM_SPIFLASH_SECTORSIZE 2048
#endif
#endif
#ifdef CONFIG_SIM_SPIFLASH_8M
@ -157,6 +162,7 @@
#define SPIFLASH_STATE_READ2 14
#define SPIFLASH_STATE_READ3 15
#define SPIFLASH_STATE_READ4 16
#define SPIFLASH_STATE_FREAD_WAIT 17
/* Instructions */
/* Command Value N Description Addr Dummy Data */
@ -666,6 +672,7 @@ static void spiflash_writeword(FAR struct sim_spiflashdev_s *priv, uint16_t data
break;
case SPIFLASH_READ:
case SPIFLASH_FAST_READ:
priv->state = SPIFLASH_STATE_READ1;
break;
@ -780,6 +787,18 @@ static void spiflash_writeword(FAR struct sim_spiflashdev_s *priv, uint16_t data
case SPIFLASH_STATE_READ3:
priv->address |= data;
if (priv->last_cmd == SPIFLASH_FAST_READ)
{
priv->state = SPIFLASH_STATE_FREAD_WAIT;
}
else
{
priv->state = SPIFLASH_STATE_READ4;
}
break;
case SPIFLASH_STATE_FREAD_WAIT:
priv->read_data = 0xff;
priv->state = SPIFLASH_STATE_READ4;
break;
@ -850,6 +869,7 @@ FAR struct spi_dev_s *up_spiflashinitialize()
priv->state = SPIFLASH_STATE_IDLE;
priv->read_data = 0xFF;
priv->last_cmd = 0xFF;
memset(&priv->data[0], 0xFF, sizeof(priv->data));
irqrestore(flags);
return (FAR struct spi_dev_s *)priv;