SemiDrive SSDK Appication Program Interface PTG3.0
Data Structures | Functions
sdrv_spi_nor.h File Reference
#include <stdbool.h>
#include <types.h>
#include <sdrv_ckgen.h>
#include <sdrv_common.h>

Go to the source code of this file.

Data Structures

struct  flash_xfer_info
 
struct  xspi_config
 
struct  xspi_pdata
 
struct  spi_nor_cmd
 
struct  hyperbus_ca
 
struct  hyperflash_cmd
 
struct  spi_nor_config
 
struct  spi_nor_erase_map
 
struct  spi_nor_erase_cmd
 
struct  flash_info
 
struct  spi_nor_host_ops
 
struct  hyperbus_host_ops
 
struct  spi_nor_host
 
struct  spi_nor
 
struct  flash_ops_t
 

Functions

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_infosdrv_spi_nor_get_info (struct spi_nor *flash_handle)
 

Detailed Description

Macro Definition Documentation

◆ 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

#define SECTOR_TYPE_TO_SIZE (   type)    SECTOR_POST_TO_SIZE(SECTOR_TYPE_TO_POST(type))

◆ SNOR_ADDR_DUAL_LANS

#define SNOR_ADDR_DUAL_LANS   (1u << SNOR_ADDR_LANS_PROTO_LSB)

◆ 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

#define SNOR_ADDR_OCTAL_LANS   (3u << SNOR_ADDR_LANS_PROTO_LSB)

◆ SNOR_ADDR_QUAD_LANS

#define SNOR_ADDR_QUAD_LANS   (2u << SNOR_ADDR_LANS_PROTO_LSB)

◆ SNOR_ADDR_SINGLE_LANS

#define SNOR_ADDR_SINGLE_LANS   (0u << SNOR_ADDR_LANS_PROTO_LSB)

◆ SNOR_DATA_DUAL_LANS

#define SNOR_DATA_DUAL_LANS   (1u << SNOR_DATA_LANS_PROTO_LSB)

◆ 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

#define SNOR_DATA_OCTAL_LANS   (3u << SNOR_DATA_LANS_PROTO_LSB)

◆ SNOR_DATA_QUAD_LANS

#define SNOR_DATA_QUAD_LANS   (2u << SNOR_DATA_LANS_PROTO_LSB)

◆ SNOR_DATA_SINGLE_LANS

#define SNOR_DATA_SINGLE_LANS   (0u << SNOR_DATA_LANS_PROTO_LSB)

◆ SNOR_DTR_PROTO

#define SNOR_DTR_PROTO   BIT(16)

◆ SNOR_INST_DUAL_LANS

#define SNOR_INST_DUAL_LANS   (1u << SNOR_INST_LANS_PROTO_LSB)

◆ 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

#define SNOR_INST_OCTAL_LANS   (3u << SNOR_INST_LANS_PROTO_LSB)

◆ SNOR_INST_QUAD_LANS

#define SNOR_INST_QUAD_LANS   (2u << SNOR_INST_LANS_PROTO_LSB)

◆ SNOR_INST_SINGLE_LANS

#define SNOR_INST_SINGLE_LANS   (0u << SNOR_INST_LANS_PROTO_LSB)

◆ SNOR_OPCODE_PROTO_LSB

#define SNOR_OPCODE_PROTO_LSB   (24u)

◆ SNOR_PROTO

#define SNOR_PROTO (   x)    ((x) & SNOR_PROTO_MASK)

◆ SNOR_PROTO_1_1_1

◆ SNOR_PROTO_1_1_1_DTR

#define SNOR_PROTO_1_1_1_DTR   (SNOR_PROTO_1_1_1 | SNOR_DTR_PROTO)

◆ SNOR_PROTO_1_1_2

#define SNOR_PROTO_1_1_2    (SNOR_INST_SINGLE_LANS | SNOR_ADDR_SINGLE_LANS | SNOR_DATA_DUAL_LANS)

◆ SNOR_PROTO_1_1_4

#define SNOR_PROTO_1_1_4    (SNOR_INST_SINGLE_LANS | SNOR_ADDR_SINGLE_LANS | SNOR_DATA_QUAD_LANS)

◆ SNOR_PROTO_1_1_8

◆ SNOR_PROTO_1_1_8_DTR

#define SNOR_PROTO_1_1_8_DTR   (SNOR_PROTO_1_1_8 | SNOR_DTR_PROTO)

◆ SNOR_PROTO_1_2_2

#define SNOR_PROTO_1_2_2    (SNOR_INST_SINGLE_LANS | SNOR_ADDR_DUAL_LANS | SNOR_DATA_DUAL_LANS)

◆ SNOR_PROTO_1_2_2_DTR

#define SNOR_PROTO_1_2_2_DTR   (SNOR_PROTO_1_2_2 | SNOR_DTR_PROTO)

◆ SNOR_PROTO_1_4_4

#define SNOR_PROTO_1_4_4    (SNOR_INST_SINGLE_LANS | SNOR_ADDR_QUAD_LANS | SNOR_DATA_QUAD_LANS)

◆ SNOR_PROTO_1_4_4_DTR

#define SNOR_PROTO_1_4_4_DTR   (SNOR_PROTO_1_4_4 | SNOR_DTR_PROTO)

◆ SNOR_PROTO_1_8_8

#define SNOR_PROTO_1_8_8    (SNOR_INST_SINGLE_LANS | SNOR_ADDR_OCTAL_LANS | SNOR_DATA_OCTAL_LANS)

◆ SNOR_PROTO_1_8_8_DTR

#define SNOR_PROTO_1_8_8_DTR   (SNOR_PROTO_1_8_8 | SNOR_DTR_PROTO)

◆ SNOR_PROTO_2_2_2

#define SNOR_PROTO_2_2_2    (SNOR_INST_DUAL_LANS | SNOR_ADDR_DUAL_LANS | SNOR_DATA_DUAL_LANS)

◆ SNOR_PROTO_4_4_4

#define SNOR_PROTO_4_4_4    (SNOR_INST_QUAD_LANS | SNOR_ADDR_QUAD_LANS | SNOR_DATA_QUAD_LANS)

◆ SNOR_PROTO_4_4_4_DTR

#define SNOR_PROTO_4_4_4_DTR   (SNOR_PROTO_4_4_4 | SNOR_DTR_PROTO)

◆ SNOR_PROTO_8_8_8

#define SNOR_PROTO_8_8_8    (SNOR_INST_OCTAL_LANS | SNOR_ADDR_OCTAL_LANS | SNOR_DATA_OCTAL_LANS)

◆ SNOR_PROTO_8_8_8_DTR

#define SNOR_PROTO_8_8_8_DTR   (SNOR_PROTO_8_8_8 | SNOR_DTR_PROTO)

◆ SNOR_PROTO_DTR

#define SNOR_PROTO_DTR (   x)    ((x) & SNOR_PROTO_DTR_MASK)

◆ 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,
 
)    (((((g) & 0xF) << 5) | ((c) & 0x1F)) * !!(c))

◆ SPI_NOR_ERR_STATUS

#define SPI_NOR_ERR_STATUS (   g,
 
)    (int)(SDRV_ERROR_STATUS(SDRV_STATUS_GROUP_XSPI, SPI_NOR_ERR_CODE((g), (c))) * !!(c))

◆ SPI_NOR_MAX_ID_LEN

#define SPI_NOR_MAX_ID_LEN   6

◆ SPI_NOR_OK_STATUS

#define SPI_NOR_OK_STATUS   SDRV_STATUS_OK

◆ 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)

Typedef Documentation

◆ flash_addr_t

typedef uint64_t 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)

dma operation for xspi.

◆ 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

typedef void(* flash_notification) (enum flash_opt type, enum flash_opt_result result)

event callback.

◆ flash_size_t

typedef uint64_t flash_size_t

Enumeration Type Documentation

◆ flash_opt

enum 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 

Function Documentation

◆ sdrv_get_flash_handle()

static struct spi_nor * sdrv_get_flash_handle ( struct spi_nor_host host,
flash_addr_t  addr,
flash_size_t  size 
)
inlinestatic

◆ sdrv_host_erase()

static int sdrv_host_erase ( struct spi_nor_host host,
flash_addr_t  addr,
flash_size_t  size 
)
inlinestatic

◆ sdrv_host_read()

static int sdrv_host_read ( struct spi_nor_host host,
flash_addr_t  addr,
uint8_t *  buf,
flash_size_t  size 
)
inlinestatic

◆ sdrv_host_write()

static int sdrv_host_write ( struct spi_nor_host host,
flash_addr_t  addr,
const uint8_t *  buf,
flash_size_t  size 
)
inlinestatic

◆ 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_handlespi norflash instance contex handle.
Returns
int
Return values
0success
otherfailed

◆ sdrv_spi_nor_deinit()

static void sdrv_spi_nor_deinit ( struct spi_nor flash_handle)
inlinestatic

spi norflash instance destruction interface.

Parameters
[in]flash_handlespi 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()

static int sdrv_spi_nor_erase ( struct spi_nor flash_handle,
flash_addr_t  addr,
flash_size_t  size 
)
inlinestatic

spi norflash erase interface.

Parameters
[in]flash_handlespi norflash instance contex handle.
[in]addrspi norflash addr.
[in]sizeErase size, need aligned with sector_size what get by sdrv_spi_nor_get_info API.
Returns
int
Return values
0success
otherfailed

◆ 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()

static struct flash_info * sdrv_spi_nor_get_info ( struct spi_nor flash_handle)
inlinestatic

Used for get spi norflash info what like sector size, page size, and ect.

Parameters
[in]flash_handlespi norflash instance contex handle.
Returns
struct flash_info* Norflash info data.

◆ sdrv_spi_nor_get_result()

static enum flash_opt_result sdrv_spi_nor_get_result ( struct spi_nor flash_handle)
inlinestatic

Used for get spi norflash async tansfer result.

Parameters
[in]flash_handlespi norflash instance contex handle.
Returns
enum flash_opt_result
Return values
FLASH_OPT_COMPLETElast transfer success
FLASH_OPT_FAILEDlast tansfer failed
FLASH_OPT_PENDINGlast tansfer not complete
FLASH_OPT_INCONSISTENTlast tansfer data error
FLASH_OPT_INVALIDlast tansfer invalid

◆ sdrv_spi_nor_init()

static int sdrv_spi_nor_init ( struct spi_nor flash_handle,
struct spi_nor_host host,
const struct spi_nor_config flash_config 
)
inlinestatic

spi norflash host initialize function.

This function used for before any other spi nor APIs.

Parameters
[in]host_configspi 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
Nullfailed
othersuccess.

spi norflash instance initialization interface.

This function must used after spi_nor_host_init and before other APIs.

Parameters
[in,out]flash_handlespi norflash instance contex handle, the data memory need alloc by user.
[in]flash_configspi norflash device config data, will not used after function return, so this param can be in stack.
Returns
int
Return values
0success
otherfailed

◆ 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_handlespi norflash instance contex handle.

◆ sdrv_spi_nor_read()

static int sdrv_spi_nor_read ( struct spi_nor flash_handle,
flash_addr_t  addr,
uint8_t *  buf,
flash_size_t  size 
)
inlinestatic

spi norflash read interface.

When the buffer and read size aligned with cacheline size will provide best performance.

Parameters
[in]flash_handlespi norflash instance contex handle.
[in]addrspi norflash addr.
[in]bufRead buffer, alloc by user.
[in]sizeRead size, need aligned with 4bytes for dma limit.
Returns
int
Return values
0success
otherfailed

◆ sdrv_spi_nor_setup_handler()

static void sdrv_spi_nor_setup_handler ( struct spi_nor flash_handle,
flash_notification  handler 
)
inlinestatic

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_handlespi norflash instance contex handle.
[in]handlerflash 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]norspi norflash instance contex handle.
Return values
0success
otherfailed

◆ sdrv_spi_nor_write()

static int sdrv_spi_nor_write ( struct spi_nor flash_handle,
flash_addr_t  addr,
const uint8_t *  buf,
flash_size_t  size 
)
inlinestatic

spi norflash write interface.

When the buffer and write size aligned with cacheline size will provide best performance.

Parameters
[in]flash_handlespi norflash instance contex handle.
[in]addrspi norflash addr.
[in]bufWrite buffer, alloc by user.
[in]sizeRead size, need aligned with 4bytes for dma limit.
Returns
int
Return values
0success
otherfailed

◆ 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]norspi norflash instance contex handle.
[in]enablespi norflash write enable or not .
Return values
0success
otherfailed

Variable Documentation

◆ hyperbus_ops

flash_ops_t hyperbus_ops
extern

◆ spi_nor_ops