#include <stdbool.h>
#include <types.h>
#include <sdrv_ckgen.h>
#include <sdrv_common.h>
Go to the source code of this file.
|
| static int | sdrv_spi_nor_wait_idle (struct spi_nor *nor) |
| |
| static int | sdrv_spi_nor_write_enable (struct spi_nor *nor, bool enable) |
| |
| static int | sdrv_spi_nor_init (struct spi_nor *flash_handle, struct spi_nor_host *host, const struct spi_nor_config *flash_config) |
| |
| static void | sdrv_spi_nor_deinit (struct spi_nor *flash_handle) |
| |
| static int | sdrv_spi_nor_read (struct spi_nor *flash_handle, flash_addr_t addr, uint8_t *buf, flash_size_t size) |
| |
| static int | sdrv_spi_nor_write (struct spi_nor *flash_handle, flash_addr_t addr, const uint8_t *buf, flash_size_t size) |
| |
| static int | sdrv_spi_nor_erase (struct spi_nor *flash_handle, flash_addr_t addr, flash_size_t size) |
| |
| static int | sdrv_spi_nor_cancel (struct spi_nor *flash_handle) |
| |
| static void | sdrv_spi_nor_main_function (struct spi_nor *flash_handle) |
| |
| static void | sdrv_spi_nor_setup_handler (struct spi_nor *flash_handle, flash_notification handler) |
| |
| static enum flash_opt_result | sdrv_spi_nor_get_result (struct spi_nor *flash_handle) |
| |
| static struct flash_info * | sdrv_spi_nor_get_info (struct spi_nor *flash_handle) |
| |
- Copyright
- Copyright (c) 2022 Semidrive Semiconductor. All rights reserved.
◆ BIT
| #define BIT |
( |
|
nr | ) |
(1u << (nr)) |
◆ SECTOR_128K_POST
| #define SECTOR_128K_POST (17) |
◆ SECTOR_256K_POST
| #define SECTOR_256K_POST (18) |
◆ SECTOR_32K_POST
| #define SECTOR_32K_POST (15) |
◆ SECTOR_4K_POST
| #define SECTOR_4K_POST (12) |
◆ SECTOR_64K_POST
| #define SECTOR_64K_POST (16) |
◆ SECTOR_POST_TO_SIZE
| #define SECTOR_POST_TO_SIZE |
( |
|
n | ) |
(1U << (n)) |
◆ SECTOR_TYPE_TO_POST
| #define SECTOR_TYPE_TO_POST |
( |
|
type | ) |
((type) ? (14 + (type)) : 12) |
◆ SECTOR_TYPE_TO_SIZE
◆ SNOR_ADDR_DUAL_LANS
◆ SNOR_ADDR_LANS
| #define SNOR_ADDR_LANS |
( |
|
x | ) |
|
Value:
#define SNOR_ADDR_LANS_PROTO_MASK
Definition: sdrv_spi_nor.h:38
#define SNOR_ADDR_LANS_PROTO_LSB
Definition: sdrv_spi_nor.h:37
◆ SNOR_ADDR_LANS_PROTO_LSB
| #define SNOR_ADDR_LANS_PROTO_LSB (4u) |
◆ SNOR_ADDR_LANS_PROTO_MASK
| #define SNOR_ADDR_LANS_PROTO_MASK (0xFu) |
◆ SNOR_ADDR_OCTAL_LANS
◆ SNOR_ADDR_QUAD_LANS
◆ SNOR_ADDR_SINGLE_LANS
◆ SNOR_DATA_DUAL_LANS
◆ SNOR_DATA_LANS
| #define SNOR_DATA_LANS |
( |
|
x | ) |
|
Value:
#define SNOR_DATA_LANS_PROTO_LSB
Definition: sdrv_spi_nor.h:47
#define SNOR_DATA_LANS_PROTO_MASK
Definition: sdrv_spi_nor.h:48
◆ SNOR_DATA_LANS_PROTO_LSB
| #define SNOR_DATA_LANS_PROTO_LSB (0u) |
◆ SNOR_DATA_LANS_PROTO_MASK
| #define SNOR_DATA_LANS_PROTO_MASK (0xFu) |
◆ SNOR_DATA_OCTAL_LANS
◆ SNOR_DATA_QUAD_LANS
◆ SNOR_DATA_SINGLE_LANS
◆ SNOR_DTR_PROTO
| #define SNOR_DTR_PROTO BIT(16) |
◆ SNOR_INST_DUAL_LANS
◆ SNOR_INST_LANS
| #define SNOR_INST_LANS |
( |
|
x | ) |
|
Value:
#define SNOR_INST_LANS_PROTO_MASK
Definition: sdrv_spi_nor.h:29
#define SNOR_INST_LANS_PROTO_LSB
Definition: sdrv_spi_nor.h:28
◆ SNOR_INST_LANS_PROTO_LSB
| #define SNOR_INST_LANS_PROTO_LSB (8u) |
◆ SNOR_INST_LANS_PROTO_MASK
| #define SNOR_INST_LANS_PROTO_MASK (0xFu) |
◆ SNOR_INST_OCTAL_LANS
◆ SNOR_INST_QUAD_LANS
◆ SNOR_INST_SINGLE_LANS
◆ SNOR_OPCODE_PROTO_LSB
| #define SNOR_OPCODE_PROTO_LSB (24u) |
◆ SNOR_PROTO
◆ SNOR_PROTO_1_1_1
◆ SNOR_PROTO_1_1_1_DTR
◆ SNOR_PROTO_1_1_2
◆ SNOR_PROTO_1_1_4
◆ SNOR_PROTO_1_1_8
◆ SNOR_PROTO_1_1_8_DTR
◆ SNOR_PROTO_1_2_2
◆ SNOR_PROTO_1_2_2_DTR
◆ SNOR_PROTO_1_4_4
◆ SNOR_PROTO_1_4_4_DTR
◆ SNOR_PROTO_1_8_8
◆ SNOR_PROTO_1_8_8_DTR
◆ SNOR_PROTO_2_2_2
◆ SNOR_PROTO_4_4_4
◆ SNOR_PROTO_4_4_4_DTR
◆ SNOR_PROTO_8_8_8
◆ SNOR_PROTO_8_8_8_DTR
◆ SNOR_PROTO_DTR
◆ SNOR_PROTO_DTR_MASK
| #define SNOR_PROTO_DTR_MASK 0x1ffffu |
◆ SNOR_PROTO_MASK
| #define SNOR_PROTO_MASK 0xffffu |
◆ SNOR_READID_DUMMY_LSB
| #define SNOR_READID_DUMMY_LSB (24u) |
◆ SPI_NOR_ERR_CODE
| #define SPI_NOR_ERR_CODE |
( |
|
g, |
|
|
|
c |
|
) |
| (((((g) & 0xF) << 5) | ((c) & 0x1F)) * !!(c)) |
◆ SPI_NOR_ERR_STATUS
◆ SPI_NOR_MAX_ID_LEN
| #define SPI_NOR_MAX_ID_LEN 6 |
◆ SPI_NOR_OK_STATUS
◆ SPINOR_SECTOR_128K_SIZE
| #define SPINOR_SECTOR_128K_SIZE (0x20000) |
◆ SPINOR_SECTOR_256K_SIZE
| #define SPINOR_SECTOR_256K_SIZE (0x40000) |
◆ SPINOR_SECTOR_32K_SIZE
| #define SPINOR_SECTOR_32K_SIZE (0x8000) |
◆ SPINOR_SECTOR_4K_SIZE
| #define SPINOR_SECTOR_4K_SIZE (0x1000) |
◆ SPINOR_SECTOR_64K_SIZE
| #define SPINOR_SECTOR_64K_SIZE (0x10000) |
◆ SWITCH_DEVICE_MAX_NUM
| #define SWITCH_DEVICE_MAX_NUM (4u) |
◆ flash_addr_t
flash addr/size use uint64_t.
◆ flash_dma_config
| typedef void(* flash_dma_config) (struct spi_nor *nor, flash_addr_t addr, uint8_t *buf, uint32_t len, bool is_read_flag, uint32_t burst_len) |
◆ flash_dma_stop
| typedef void(* flash_dma_stop) (void) |
◆ flash_dma_stop_signal
| typedef void(* flash_dma_stop_signal) (struct spi_nor *nor) |
◆ flash_notification
◆ flash_size_t
◆ flash_opt
flash operating collection.
| Enumerator |
|---|
| FLASH_OPT_NONE | flash none opt
|
| FLASH_OPT_READ | flash read opt
|
| FLASH_OPT_WRITE | flash write opt
|
| FLASH_OPT_ERASE | flash erase opt
|
| FLASH_OPT_MAX | |
◆ flash_opt_result
flash operating result collection.
| Enumerator |
|---|
| FLASH_OPT_COMPLETE | last transfer success flag
|
| FLASH_OPT_FAILED | last tansfer failed flag
|
| FLASH_OPT_PENDING | last tansfer not complete flag
|
| FLASH_OPT_INCONSISTENT | last tansfer data error flag
|
| FLASH_OPT_INVALID | last tansfer invalid flag
|
| FLASH_OPT_RESULET_MAX | |
◆ spi_memory_type
spi norflash device type.
| Enumerator |
|---|
| SPI_AUTO_DETECT | |
| SPI_NOR_FLASH | |
| SPI_NAND_FLASH | |
| SPI_HYPERFLASH | |
| SPI_HYPERRAM | |
| SPI_HYPERBUS_MCP | |
◆ spi_nor_common_error_code_t
Common error code:
| Enumerator |
|---|
| SPI_NOR_OK | |
| SPI_NOR_FAIL | |
| SPI_NOR_BUSY | |
| SPI_NOR_TIMEOUT | |
| SPI_NOR_UNSUPPORT | |
| SPI_NOR_UNREACHABLE | |
| SPI_NOR_ADDRESS_INVALID | |
| SPI_NOR_LENGTH_INVALID | |
| SPI_NOR_COMMON_CODE_MAX | |
◆ spi_nor_device_mode
device trans mode.
| Enumerator |
|---|
| SPI_NOR_DEV_SINGLE_MODE | |
| SPI_NOR_DEV_LOCKSTEP_MODE | |
| SPI_NOR_DEV_PARALLEL_MODE | |
◆ spi_nor_error_group_t
sub group
| Enumerator |
|---|
| SPI_NOR_COMMON | |
| SPI_NOR_INIT | |
| SPI_NOR_ERASE | |
| SPI_NOR_WRITE | |
| SPI_NOR_READ | |
| SPI_NOR_CANCEL | |
◆ spi_nor_init_error_code_t
error code for init
| Enumerator |
|---|
| SPI_NOR_INIT_TRAIN_E | |
◆ spi_nor_ops
spi norflash r/w/e ops flags.
| Enumerator |
|---|
| SPI_NOR_OPS_READ | |
| SPI_NOR_OPS_WRITE | |
| SPI_NOR_OPS_ERASE | |
| SPI_NOR_OPS_LOCK | |
| SPI_NOR_OPS_UNLOCK | |
◆ spi_nor_proto_type
spi norflash proto type.
| Enumerator |
|---|
| SPI_NOR_PROTO_TYPE_READ | |
| SPI_NOR_PROTO_TYPE_WRITE | |
| SPI_NOR_PROTO_TYPE_ERASE | |
◆ spi_nor_rw_para
spi norflash indirect/direct(r/w) flags.
| Enumerator |
|---|
| SPI_NOR_DIRECT_READ | |
| SPI_NOR_INDIRECT_READ | |
| SPI_NOR_DIRECT_WRITE | |
| SPI_NOR_INDIRECT_WRITE | |
◆ spi_nor_sector_type
| Enumerator |
|---|
| SPI_NOR_SECTOR_4KB | |
| SPI_NOR_SECTOR_32KB | |
| SPI_NOR_SECTOR_64KB | |
| SPI_NOR_SECTOR_128KB | |
| SPI_NOR_SECTOR_256KB | |
| SPI_NOR_SECTOR_TYPE_MAX | |
◆ spi_nor_xfer_mode
spi norflash trans mode, dma/intterrupt/polling.
| Enumerator |
|---|
| SPI_NOR_XFER_POLLING_MODE | |
| SPI_NOR_XFER_INTERRUPT_MODE | |
| SPI_NOR_XFER_DMA_MODE | |
◆ xspi_bus_event_mode
reserve for osEvent interface.
| Enumerator |
|---|
| SPI_NOR_XFER_CLEAR | |
| SPI_NOR_XFER_COMPLETE | |
| SPI_NOR_XFER_WAIT | |
◆ xspi_xfer_mode
reserve.
| Enumerator |
|---|
| XSPI_XFER_NONE | |
| XSPI_XFER_READ | |
| XSPI_XFER_WRITE | |
◆ sdrv_get_flash_handle()
◆ sdrv_host_erase()
◆ sdrv_host_read()
◆ sdrv_host_write()
◆ sdrv_spi_nor_cancel()
| static int sdrv_spi_nor_cancel |
( |
struct spi_nor * |
flash_handle | ) |
|
|
inlinestatic |
spi norflash async cancel interface.
Used for cancel the last tansfer what like read write or erase.
- Parameters
-
| [in] | flash_handle | spi norflash instance contex handle. |
- Returns
- int
- Return values
-
◆ sdrv_spi_nor_deinit()
| static void sdrv_spi_nor_deinit |
( |
struct spi_nor * |
flash_handle | ) |
|
|
inlinestatic |
spi norflash instance destruction interface.
- Parameters
-
| [in] | flash_handle | spi norflash instance contex handle. |
◆ sdrv_spi_nor_enable_rfd()
| static int sdrv_spi_nor_enable_rfd |
( |
struct spi_nor * |
flash_handle, |
|
|
uint8_t |
mask |
|
) |
| |
|
inlinestatic |
◆ sdrv_spi_nor_erase()
spi norflash erase interface.
- Parameters
-
| [in] | flash_handle | spi norflash instance contex handle. |
| [in] | addr | spi norflash addr. |
| [in] | size | Erase size, need aligned with sector_size what get by sdrv_spi_nor_get_info API. |
- Returns
- int
- Return values
-
◆ sdrv_spi_nor_get_flash_table()
| static const struct flash_info * sdrv_spi_nor_get_flash_table |
( |
bool |
is_hyperbus, |
|
|
uint32_t * |
num |
|
) |
| |
|
inlinestatic |
◆ sdrv_spi_nor_get_info()
Used for get spi norflash info what like sector size, page size, and ect.
- Parameters
-
| [in] | flash_handle | spi norflash instance contex handle. |
- Returns
- struct flash_info* Norflash info data.
◆ sdrv_spi_nor_get_result()
Used for get spi norflash async tansfer result.
- Parameters
-
| [in] | flash_handle | spi norflash instance contex handle. |
- Returns
- enum flash_opt_result
- Return values
-
| FLASH_OPT_COMPLETE | last transfer success |
| FLASH_OPT_FAILED | last tansfer failed |
| FLASH_OPT_PENDING | last tansfer not complete |
| FLASH_OPT_INCONSISTENT | last tansfer data error |
| FLASH_OPT_INVALID | last tansfer invalid |
◆ sdrv_spi_nor_init()
spi norflash host initialize function.
This function used for before any other spi nor APIs.
- Parameters
-
| [in] | host_config | spi norflash host config data, will not used after function return, so this param can be in stack. |
- Returns
- void* The host platform data.
- Return values
-
spi norflash instance initialization interface.
This function must used after spi_nor_host_init and before other APIs.
- Parameters
-
| [in,out] | flash_handle | spi norflash instance contex handle, the data memory need alloc by user. |
| [in] | flash_config | spi norflash device config data, will not used after function return, so this param can be in stack. |
- Returns
- int
- Return values
-
◆ sdrv_spi_nor_main_function()
| static void sdrv_spi_nor_main_function |
( |
struct spi_nor * |
flash_handle | ) |
|
|
inlinestatic |
spi norflash async main function interface.
When use async mode, this function need be called cyclically.
- Parameters
-
| [in] | flash_handle | spi norflash instance contex handle. |
◆ sdrv_spi_nor_read()
spi norflash read interface.
When the buffer and read size aligned with cacheline size will provide best performance.
- Parameters
-
| [in] | flash_handle | spi norflash instance contex handle. |
| [in] | addr | spi norflash addr. |
| [in] | buf | Read buffer, alloc by user. |
| [in] | size | Read size, need aligned with 4bytes for dma limit. |
- Returns
- int
- Return values
-
◆ sdrv_spi_nor_setup_handler()
Used for setup spi norflash async mode notification handler.
When use async mode, user can selet passive notification mode or active query mode.
- Parameters
-
| [in] | flash_handle | spi norflash instance contex handle. |
| [in] | handler | flash notification handler. |
◆ sdrv_spi_nor_wait_idle()
| static int sdrv_spi_nor_wait_idle |
( |
struct spi_nor * |
nor | ) |
|
|
inlinestatic |
spi norflash get status.
- Parameters
-
| [in] | nor | spi norflash instance contex handle. |
- Return values
-
◆ sdrv_spi_nor_write()
spi norflash write interface.
When the buffer and write size aligned with cacheline size will provide best performance.
- Parameters
-
| [in] | flash_handle | spi norflash instance contex handle. |
| [in] | addr | spi norflash addr. |
| [in] | buf | Write buffer, alloc by user. |
| [in] | size | Read size, need aligned with 4bytes for dma limit. |
- Returns
- int
- Return values
-
◆ sdrv_spi_nor_write_enable()
| static int sdrv_spi_nor_write_enable |
( |
struct spi_nor * |
nor, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
spi norflash write enable op.
- Parameters
-
| [in] | nor | spi norflash instance contex handle. |
| [in] | enable | spi norflash write enable or not . |
- Return values
-
◆ hyperbus_ops
◆ spi_nor_ops