Software Drivers

xnandps.h File Reference

#include <string.h>
#include "xil_types.h"
#include "xil_assert.h"
#include "xil_io.h"
#include "xstatus.h"
#include "xnandps_hw.h"

Classes

struct  XNandPs_Config
struct  XNandPs_Geometry
struct  XNandPs_Features
struct  XNandPs_BbtDesc
struct  XNandPs_BadBlockPattern
struct  XNandPs_EccConfig
struct  XNandPsTag
struct  XNandPs_CommandFormat

Defines

#define XNANDPS_H
#define XNANDPS_MAX_TARGETS   1
#define XNANDPS_MAX_BLOCKS   32768
#define XNANDPS_MAX_PAGE_SIZE   16384
#define XNANDPS_MAX_SPARE_SIZE   512
#define XNANDPS_ECC_BLOCK_SIZE   512
#define XNANDPS_ECC_BYTES   3
#define XNANDPS_PAGE_SIZE_512   512
#define XNANDPS_PAGE_SIZE_1024   1024
#define XNANDPS_PAGE_SIZE_2048   2048
#define XNANDPS_PAGE_SIZE_4096   4096
#define XNANDPS_PAGE_SIZE_8192   8192
#define XNANDPS_SPARE_SIZE_8   8
#define XNANDPS_SPARE_SIZE_16   16
#define XNANDPS_SPARE_SIZE_32   32
#define XNANDPS_SPARE_SIZE_64   64
#define XNANDPS_SPARE_SIZE_128   128
#define XNANDPS_SPARE_SIZE_256   256
#define XNANDPS_FLASH_WIDTH_8   8
#define XNANDPS_FLASH_WIDTH_16   16
#define XNANDPS_END_CMD_NONE   0
#define XNANDPS_END_CMD_INVALID   0
#define XNANDPS_CMD_PHASE   1
#define XNANDPS_DATA_PHASE   2
#define XNANDPS_PAGE_NOT_VALID   -1
#define XNANDPS_COLUMN_NOT_VALID   -1
#define XNANDPS_AXI_DATA_WIDTH   4
#define XNANDPS_START_CMD_SHIFT   3
#define XNANDPS_END_CMD_SHIFT   11
#define XNANDPS_END_CMD_VALID_SHIFT   20
#define XNANDPS_ADDR_CYCLES_SHIFT   21
#define XNANDPS_CHIP_ADDR_SHIFT   24
#define XNANDPS_ECC_LAST_SHIFT   10
#define XNANDPS_CLEAR_CS_SHIFT   21
#define XNANDPS_COMMAND_PHASE_MASK   0x00000000
#define XNANDPS_DATA_PHASE_MASK   0x00080000
#define XNANDPS_ECC_CORRECT_BYTE_MASK   0x1FF
#define XNANDPS_ECC_CORRECT_BIT_MASK   0x7
#define XNANDPS_CLR_CONFIG
#define XNANDPS_ECC_MEMCFG
#define XNANDPS_ECC_CMD1
#define XNANDPS_ECC_CMD2
#define XNANDPS_CLR_CS   (0x1 << XNANDPS_CLEAR_CS_SHIFT)
#define XNANDPS_ECC_LAST   (0x1 << XNANDPS_ECC_LAST_SHIFT)
#define OneHot(Value)   (!((Value) & (Value - 1)))

Typedefs

typedef struct XNandPsTag XNandPs

Enumerations

enum  XNandPs_EccMode { XNANDPS_ECC_NONE = 0, XNANDPS_ECC_SW, XNANDPS_ECC_HW, XNANDPS_ECC_ONDIE }

Functions

XNandPs_ConfigXNandPs_LookupConfig (u16 DeviceId)
int XNandPs_CfgInitialize (XNandPs *InstancePtr, XNandPs_Config *ConfigPtr, u32 SmcBaseAddr, u32 FlashBaseAddr)
int XNandPs_Read (XNandPs *InstancePtr, u64 Offset, u32 Bytes, void *DestPtr, u8 *UserSparePtr)
int XNandPs_ReadCache (XNandPs *InstancePtr, u64 Offset, u32 Bytes, void *SrcPtr, u8 *UserSparePtr)
int XNandPs_Write (XNandPs *InstancePtr, u64 Offset, u32 Bytes, void *SrcPtr, u8 *UserSparePtr)
int XNandPs_WriteCache (XNandPs *InstancePtr, u64 Offset, u32 Length, void *SrcPtr, u8 *UserSparePtr)
int XNandPs_ReadSpareBytes (XNandPs *InstancePtr, u32 Page, u8 *Buf)
int XNandPs_WriteSpareBytes (XNandPs *InstancePtr, u32 Page, u8 *Buf)
int XNandPs_EraseBlock (XNandPs *InstancePtr, u32 BlockNum)

Detailed Description


Define Documentation

#define OneHot ( Value   )     (!((Value) & (Value - 1)))

OneHot is used to check if one and only one bit is set. This Macro returns 1 if the value passed is OneHot.

#define XNANDPS_ADDR_CYCLES_SHIFT   21

Address cycles shift

#define XNANDPS_AXI_DATA_WIDTH   4

AXI Data width for last transaction while reading and writing

#define XNANDPS_CHIP_ADDR_SHIFT   24

Chip address shift

#define XNANDPS_CLEAR_CS_SHIFT   21

clear chip select shift

#define XNANDPS_CLR_CONFIG
#define XNANDPS_CLR_CS   (0x1 << XNANDPS_CLEAR_CS_SHIFT)

set Clear chip select

#define XNANDPS_CMD_PHASE   1

End command in command phase

#define XNANDPS_COLUMN_NOT_VALID   -1

Column is not valid in command phase

#define XNANDPS_COMMAND_PHASE_MASK   0x00000000

Command phase mask

#define XNANDPS_DATA_PHASE   2

End command in data phase

#define XNANDPS_DATA_PHASE_MASK   0x00080000

Data phase mask

#define XNANDPS_ECC_BLOCK_SIZE   512

ECC block size

#define XNANDPS_ECC_BYTES   3

ECC bytes per ECC block

#define XNANDPS_ECC_CMD1
#define XNANDPS_ECC_CMD2
#define XNANDPS_ECC_CORRECT_BIT_MASK   0x7

ECC error correction bit position mask, bits[0:2] of error code

#define XNANDPS_ECC_CORRECT_BYTE_MASK   0x1FF

ECC error correction byte position mask, bits[11:3] of error code

#define XNANDPS_ECC_LAST   (0x1 << XNANDPS_ECC_LAST_SHIFT)

set Ecc last

#define XNANDPS_ECC_LAST_SHIFT   10

Ecc last shift

#define XNANDPS_ECC_MEMCFG
Value:

ECC memory configuration settings

#define XNANDPS_END_CMD_INVALID   0

End command invalid

#define XNANDPS_END_CMD_NONE   0

No End command

#define XNANDPS_END_CMD_SHIFT   11

End command shift

#define XNANDPS_END_CMD_VALID_SHIFT   20

End command valid shift

#define XNANDPS_FLASH_WIDTH_16   16

NAND Flash width 16-bit

#define XNANDPS_FLASH_WIDTH_8   8

NAND Flash width 8-bit

#define XNANDPS_H
#define XNANDPS_MAX_BLOCKS   32768

Max number of Blocks

#define XNANDPS_MAX_PAGE_SIZE   16384

Max page size of NAND flash

#define XNANDPS_MAX_SPARE_SIZE   512

Max spare bytes of a NAND flash page

#define XNANDPS_MAX_TARGETS   1

Max number of targets supported

#define XNANDPS_PAGE_NOT_VALID   -1

Page is not valid in command phase

#define XNANDPS_PAGE_SIZE_1024   1024

Page size 1024

#define XNANDPS_PAGE_SIZE_2048   2048

Page size 2048

#define XNANDPS_PAGE_SIZE_4096   4096

Page size 4096

#define XNANDPS_PAGE_SIZE_512   512

Page size 512

#define XNANDPS_PAGE_SIZE_8192   8192

Page size 8192

#define XNANDPS_SPARE_SIZE_128   128

Spare bytes size 128

#define XNANDPS_SPARE_SIZE_16   16

Spare bytes size 16

#define XNANDPS_SPARE_SIZE_256   256

Spare bytes size 256

#define XNANDPS_SPARE_SIZE_32   32

Spare bytes size 32

#define XNANDPS_SPARE_SIZE_64   64

Spare bytes size 64

#define XNANDPS_SPARE_SIZE_8   8

Spare bytes size 8

#define XNANDPS_START_CMD_SHIFT   3

Start command shift


Typedef Documentation

typedef struct XNandPsTag XNandPs

The XNandPs driver instance data. The user is required to allocate a variable of this type for every flash device in the system. A pointer to a variable of this type is then passed to the driver API functions.


Enumeration Type Documentation

Enumerator:
XNANDPS_ECC_NONE 

No ECC

XNANDPS_ECC_SW 

Software ECC

XNANDPS_ECC_HW 

Hardware controller ECC

XNANDPS_ECC_ONDIE 

On-Die ECC


Function Documentation

int XNandPs_CfgInitialize ( XNandPs InstancePtr,
XNandPs_Config ConfigPtr,
u32  SmcBaseAddr,
u32  FlashBaseAddr 
)

This function initializes a specific XNandPs device/instance. This function must be called prior to using the flash device to read or write any data.

Parameters:
InstancePtr is a pointer to the XNandPs instance.
ConfigPtr points to the XNandPs device configuration structure.
SmcBaseAddr is the base address of SMC controller.
FlashBaseAddr is the base address of NAND flash.
Returns:
  • XST_SUCCESS if successful.
  • XST_FAILURE if fail.
Note:
The user needs to first call the XNandPs_LookupConfig() API which returns the Configuration structure pointer which is passed as a parameter to the XNandPs_CfgInitialize() API.
int XNandPs_EraseBlock ( XNandPs InstancePtr,
u32  BlockNum 
)

This function erases a specific block in the NAND device.

Parameters:
InstancePtr is a pointer to the XNandPs instance.
BlockNum is the block number of the device.
Returns:
  • XST_SUCCESS if successful.
  • XST_FAILURE if fail.
  • XST_NAND_WRITE_PROTECTED if the flash is write protected.
Note:
None
XNandPs_Config* XNandPs_LookupConfig ( u16  DeviceId  ) 

This function looks up the device configuration based on the unique device ID. The table XNandPs_ConfigTable contains the configuration info for each device in the system.

Parameters:
DeviceId contains the ID of the device for which the device configuration pointer is to be returned.
Returns:
  • A pointer to the configuration found.
  • NULL if the specified device ID was not found.
Note:
None.
int XNandPs_Read ( XNandPs InstancePtr,
u64  Offset,
u32  Length,
void *  DestPtr,
u8 *  UserSparePtr 
)

This function reads the data from the Flash device and copies it into the specified user buffer. It doesn't check for the bad blocks while reading the flash pages that cross block boundary. User must take care of handling bad blocks.

Parameters:
InstancePtr is the pointer to the XNandPs instance.
Offset is the flash data address to read from.
Length is number of bytes to read.
DestPtr is the destination address to copy data to.
UserSparePtr is the user buffer to which spare data must be copied.
Returns:
  • XST_SUCCESS if successful.
  • XST_FAILURE if fail.
Note:
This function reads sequential pages from the Flash device.
int XNandPs_ReadCache ( XNandPs InstancePtr,
u64  Offset,
u32  Length,
void *  DestPtr,
u8 *  UserSparePtr 
)

This function reads the data from the Flash device using read page cache command and copies it into the specified user buffer. It doesn't check for the bad blocks while reading the flash pages that cross block boundary. User must take care of handling bad blocks.

Parameters:
InstancePtr is the pointer to the XNandPs instance.
Offset is the flash data address to read from.
Length is number of bytes to read.
DestPtr is the destination address to copy data to.
UserSparePtr is the user buffer to which spare data must be copied.
Returns:
  • XST_SUCCESS if successful.
  • XST_FAILURE if fail.
Note:
This function reads sequential pages from the Flash device.
int XNandPs_ReadSpareBytes ( XNandPs InstancePtr,
u32  Page,
u8 *  Buf 
)

This function reads the spare area of a page.

Parameters:
InstancePtr is the pointer to the XNandPs instance.
Page is the page number from where spare data is read.
Buf is pointer to the buffer where the spare data is filled.
Returns:
  • XST_SUCCESS if successful.
  • XST_FAILURE if fail.
Note:
None.
int XNandPs_Write ( XNandPs InstancePtr,
u64  Offset,
u32  Length,
void *  SrcPtr,
u8 *  UserSparePtr 
)

This function programs the flash device(s) with data specified in the user buffer. The source and destination address must be aligned to the width of the flash's data bus. It doesn't check for the bad blocks while writing to the flash pages that cross block boundary. User must take care of handling bad blocks.

Parameters:
InstancePtr is the pointer to the XNandPs instance.
Offset is the flash data address to write to.
Length is number of bytes to write.
SrcPtr is the source address to write the data from.
UserSparePtr is the user buffer which contains buffer to write into spare data area.
Returns:
  • XST_SUCCESS if successful.
  • XST_FAILURE if fail.
  • XST_NAND_WRITE_PROTECTED if the flash is write protected.
Note:
This function writes number of sequential pages into the Flash device.
int XNandPs_WriteCache ( XNandPs InstancePtr,
u64  Offset,
u32  Length,
void *  SrcPtr,
u8 *  UserSparePtr 
)

This function programs the flash device(s) with data specified in the user buffer using program cache command. The source and destination address must be aligned to the width of the flash's data bus. It doesn't check for the bad blocks while writing to the flash pages that cross block boundary. User must take care of handling bad blocks.

Parameters:
InstancePtr is the pointer to the XNandPs instance.
Offset is the flash data address to write to.
Length is number of bytes to write.
SrcPtr is the source address to write the data from.
UserSparePtr is the user buffer which contains buffer to write into spare data area.
Returns:
  • XST_SUCCESS if successful.
  • XST_FAILURE if fail.
  • XST_NAND_WRITE_PROTECTED if the flash is write protected.
Note:
This function writes number of sequential pages into the Flash device.
int XNandPs_WriteSpareBytes ( XNandPs InstancePtr,
u32  Page,
u8 *  Buf 
)

This function write to the spare area of a page.

Parameters:
InstancePtr is the pointer to the XNandPs instance.
Page is the page number to write.
Buf is pointer to the buffer which holds the data.
Returns:
  • XST_SUCCESS if successful.
  • XST_FAILURE if fail.
Note:
None.