arch/sim: Move spiflash simulation to drivers/spi instead

since it's common implementation can be used in other arch too

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2022-01-06 13:48:21 +08:00
committed by Xiang Xiao
parent ee916bdb91
commit d296f9c085
8 changed files with 423 additions and 370 deletions
-106
View File
@@ -381,112 +381,6 @@ config SIM_INT_POLLDELAY
endif # SIM_IOEXPANDER
config SIM_SPIFLASH
bool "Simulated SPI FLASH with SMARTFS"
default n
select FS_SMARTFS
select MTD_SMART
---help---
Adds a simulated SPI FLASH that responds to standard M25 style
commands on the SPI bus.
choice
prompt "Simulated SPI FLASH Size"
default SIM_SPIFLASH_1M
depends on SIM_SPIFLASH
config SIM_SPIFLASH_1M
bool "1 MBit (128K Byte)"
config SIM_SPIFLASH_8M
bool "8 MBit (1M Byte)"
config SIM_SPIFLASH_32M
bool "32 MBit (4M Byte)"
config SIM_SPIFLASH_64M
bool "64 MBit (8M Byte)"
config SIM_SPIFLASH_128M
bool "128 MBit (16M Byte)"
endchoice
config SIM_SPIFLASH_SECTORSIZE
int "FLASH Sector Erase Size"
default 65536
depends on SIM_SPIFLASH
---help---
Sets the large sector erase size that the part simulates.
This driver simulates SPI devices that have both a large
sector erase as well as a "sub-sector" (per the datasheet)
erase size (typically 4K bytes).
config SIM_SPIFLASH_SUBSECTORSIZE
int "FLASH Sub-Sector Erase Size"
default 4096
depends on SIM_SPIFLASH
---help---
Sets the smaller sub-sector erase size supported by the
FLASH emulation
config SIM_SPIFLASH_M25P
bool "Enable M25Pxx FLASH"
depends on MTD_M25P
---help---
Enables simulation of an M25P type FLASH
config SIM_SPIFLASH_SST26
bool "Enable SST26 FLASH"
depends on MTD_SST26
---help---
Enables simulation of an SST26 type FLASH
config SIM_SPIFLASH_W25
bool "Enable W25 FLASH"
depends on MTD_W25
---help---
Enables simulation of a W25 type FLASH
config SIM_SPIFLASH_CUSTOM
bool "Enable Emulation of a Custom Manufacturer / ID FLASH"
depends on SIM_SPIFLASH
---help---
Enables simulation of FLASH with a custom Manufacturer, ID and Capacity
config SIM_SPIFLASH_MANUFACTURER
hex "Hex ID of the FLASH manufacturer code"
default 0x20
depends on SIM_SPIFLASH_CUSTOM
---help---
Allows the simulated FLASH Manufacturer ID to be set.
config SIM_SPIFLASH_MEMORY_TYPE
hex "Hex ID of the FLASH Memory Type code"
default 0x20
depends on SIM_SPIFLASH_CUSTOM
---help---
Allows the simulated FLASH Memory Type code to be set.
config SIM_SPIFLASH_CAPACITY
hex "Hex ID of the FLASH capacity code"
default 0x14
depends on SIM_SPIFLASH_CUSTOM
---help---
Allows the simulated FLASH Memory Capacity code to be set.
config SIM_SPIFLASH_PAGESIZE
int "FLASH Write / Program Page Size"
default 256
depends on SIM_SPIFLASH
---help---
Sets the size of a page program operation. The page size
represents the maximum number of bytes that can be sent
for a program operation. If more bytes than this are
sent on a single Page Program, then the address will
"wrap" causing the initial data sent to be overwritten.
This is consistent with standard SPI FLASH operation.
config SIM_QSPIFLASH
bool "Simulated QSPI FLASH with SMARTFS"
default n
-4
View File
@@ -140,10 +140,6 @@ ifeq ($(CONFIG_SIM_IOEXPANDER),y)
CSRCS += up_ioexpander.c
endif
ifeq ($(CONFIG_SIM_SPIFLASH),y)
CSRCS += up_spiflash.c
endif
ifeq ($(CONFIG_SIM_QSPIFLASH),y)
CSRCS += up_qspiflash.c
endif
+12 -9
View File
@@ -38,6 +38,7 @@
#include <nuttx/note/note_driver.h>
#include <nuttx/syslog/syslog_console.h>
#include <nuttx/serial/pty.h>
#include <nuttx/spi/spi_flash.h>
#include <nuttx/crypto/crypto.h>
#include <nuttx/power/pm.h>
@@ -56,23 +57,24 @@
*
****************************************************************************/
#if defined(CONFIG_FS_SMARTFS) && (defined(CONFIG_SIM_SPIFLASH) || defined(CONFIG_SIM_QSPIFLASH))
#if defined(CONFIG_FS_SMARTFS) && defined(CONFIG_MTD_SMART) && \
(defined(CONFIG_SPI_FLASH) || defined(CONFIG_SIM_QSPIFLASH))
static void up_init_smartfs(void)
{
FAR struct mtd_dev_s *mtd;
int minor = 0;
#if defined(CONFIG_MTD_M25P) || defined(CONFIG_MTD_W25) || defined(CONFIG_MTD_SST26)
FAR struct mtd_dev_s *mtd;
FAR struct spi_dev_s *spi;
int minor = 0;
#endif
#ifdef CONFIG_MTD_N25QXXX
FAR struct qspi_dev_s *qspi;
#endif
#ifdef CONFIG_SIM_SPIFLASH
#ifdef CONFIG_SPI_FLASH
#ifdef CONFIG_MTD_M25P
/* Initialize a simulated SPI FLASH block device m25p MTD driver */
spi = up_spiflashinitialize("m25p");
spi = spi_flash_initialize("m25p");
if (spi != NULL)
{
mtd = m25p_initialize(spi);
@@ -91,7 +93,7 @@ static void up_init_smartfs(void)
#ifdef CONFIG_MTD_SST26
/* Initialize a simulated SPI FLASH block device sst26 MTD driver */
spi = up_spiflashinitialize("sst26");
spi = spi_flash_initialize("sst26");
if (spi != NULL)
{
mtd = sst26_initialize_spi(spi);
@@ -110,7 +112,7 @@ static void up_init_smartfs(void)
#ifdef CONFIG_MTD_W25
/* Initialize a simulated SPI FLASH block device w25 MTD driver */
spi = up_spiflashinitialize("w25");
spi = spi_flash_initialize("w25");
if (spi != NULL)
{
mtd = w25_initialize(spi);
@@ -125,7 +127,7 @@ static void up_init_smartfs(void)
}
}
#endif
#endif /* CONFIG_SIM_SPIFLASH */
#endif /* CONFIG_SPI_FLASH */
#if defined(CONFIG_MTD_N25QXXX) && defined(CONFIG_SIM_QSPIFLASH)
/* Initialize a simulated SPI FLASH block device n25qxxx MTD driver */
@@ -270,7 +272,8 @@ void up_initialize(void)
telnet_initialize();
#endif
#if defined(CONFIG_FS_SMARTFS) && (defined(CONFIG_SIM_SPIFLASH) || defined(CONFIG_SIM_QSPIFLASH))
#if defined(CONFIG_FS_SMARTFS) && defined(CONFIG_MTD_SMART) && \
(defined(CONFIG_SPI_FLASH) || defined(CONFIG_SIM_QSPIFLASH))
up_init_smartfs();
#endif
-5
View File
@@ -92,7 +92,6 @@
struct tcb_s;
struct foc_dev_s;
struct spi_dev_s;
struct qspi_dev_s;
struct ioexpander_dev_s;
struct i2c_master_s;
@@ -331,10 +330,6 @@ int up_rptun_init(const char *shmemname, const char *cpuname, bool master);
void up_rptun_loop(void);
#endif
#ifdef CONFIG_SIM_SPIFLASH
struct spi_dev_s *up_spiflashinitialize(const char *name);
#endif
#ifdef CONFIG_SIM_QSPIFLASH
struct qspi_dev_s *up_qspiflashinitialize(void);
#endif
+101
View File
@@ -218,4 +218,105 @@ config SPI_BITBANG_VARWIDTH
only.
endif # SPI_BITBANG
config SPI_FLASH
bool "Simulated SPI FLASH with SMARTFS"
default n
---help---
Adds a simulated SPI FLASH that responds to standard M25 style
commands on the SPI bus.
if SPI_FLASH
choice
prompt "Simulated SPI FLASH Size"
default SPI_FLASH_1M
config SPI_FLASH_1M
bool "1 MBit (128K Byte)"
config SPI_FLASH_8M
bool "8 MBit (1M Byte)"
config SPI_FLASH_32M
bool "32 MBit (4M Byte)"
config SPI_FLASH_64M
bool "64 MBit (8M Byte)"
config SPI_FLASH_128M
bool "128 MBit (16M Byte)"
endchoice
config SPI_FLASH_SECTORSIZE
int "FLASH Sector Erase Size"
default 65536
---help---
Sets the large sector erase size that the part simulates.
This driver simulates SPI devices that have both a large
sector erase as well as a "sub-sector" (per the datasheet)
erase size (typically 4K bytes).
config SPI_FLASH_SUBSECTORSIZE
int "FLASH Sub-Sector Erase Size"
default 4096
---help---
Sets the smaller sub-sector erase size supported by the
FLASH emulation
config SPI_FLASH_M25P
bool "Enable M25Pxx FLASH"
---help---
Enables simulation of an M25P type FLASH
config SPI_FLASH_SST26
bool "Enable SST26 FLASH"
---help---
Enables simulation of an SST26 type FLASH
config SPI_FLASH_W25
bool "Enable W25 FLASH"
---help---
Enables simulation of a W25 type FLASH
config SPI_FLASH_CUSTOM
bool "Enable Emulation of a Custom Manufacturer / ID FLASH"
---help---
Enables simulation of FLASH with a custom Manufacturer, ID and Capacity
config SPI_FLASH_MANUFACTURER
hex "Hex ID of the FLASH manufacturer code"
default 0x20
depends on SPI_FLASH_CUSTOM
---help---
Allows the simulated FLASH Manufacturer ID to be set.
config SPI_FLASH_MEMORY_TYPE
hex "Hex ID of the FLASH Memory Type code"
default 0x20
depends on SPI_FLASH_CUSTOM
---help---
Allows the simulated FLASH Memory Type code to be set.
config SPI_FLASH_CAPACITY
hex "Hex ID of the FLASH capacity code"
default 0x14
depends on SPI_FLASH_CUSTOM
---help---
Allows the simulated FLASH Memory Capacity code to be set.
config SPI_FLASH_PAGESIZE
int "FLASH Write / Program Page Size"
default 256
---help---
Sets the size of a page program operation. The page size
represents the maximum number of bytes that can be sent
for a program operation. If more bytes than this are
sent on a single Page Program, then the address will
"wrap" causing the initial data sent to be overwritten.
This is consistent with standard SPI FLASH operation.
endif # SPI_FLASH
endif # SPI
+4
View File
@@ -39,6 +39,10 @@ ifeq ($(CONFIG_SPI_BITBANG),y)
CSRCS += spi_bitbang.c
endif
ifeq ($(CONFIG_SPI_FLASH),y)
CSRCS += spi_flash.c
endif
# Include SPI device driver build support
DEPPATH += --dep-path spi
File diff suppressed because it is too large Load Diff
+70
View File
@@ -0,0 +1,70 @@
/****************************************************************************
* include/nuttx/spi/spi_flash.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_SPI_SPI_FLASH_H
#define __INCLUDE_NUTTX_SPI_SPI_FLASH_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/spi/spi.h>
#ifdef CONFIG_SPI_FLASH
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: spi_flash_initialize
*
* Description:
* Create an instance of the SPI flash emulated driver.
*
* Input Parameters:
* name - the flash model to be emulated.
*
* Returned Value:
* On success a non-NULL, initialized SPI driver instance is returned.
*
****************************************************************************/
#ifdef CONFIG_SPI_FLASH
FAR struct spi_dev_s *spi_flash_initialize(FAR const char *name);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* CONFIG_SPI_FLASH */
#endif /* __INCLUDE_NUTTX_SPI_SPI_FLASH_H */