#include <string.h>
#include "xil_types.h"
#include "xil_assert.h"
#include "xil_io.h"
#include "xstatus.h"
#include "xnandps_hw.h"
#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 |
((XNANDPS_MEMC_CLR_CONFIG_INT_DISABLE1_MASK) | \ (XNANDPS_MEMC_CLR_CONFIG_INT_CLR1_MASK) | \ (XNANDPS_MEMC_CLR_CONFIG_ECC_INT_DISABLE1_MASK))
Interrupt settings
#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 |
((0x80 << XNANDPS_ECC_MEMCOMMAND1_WR_CMD_SHIFT) | \ (0x00 << XNANDPS_ECC_MEMCOMMAND1_RD_CMD_SHIFT) | \ (0x30 << XNANDPS_ECC_MEMCOMMAND1_RD_CMD_END_SHIFT) | \ (0x1 << XNANDPS_ECC_MEMCOMMAND1_RD_CMD_END_VALID_SHIFT))
ECC command 1 settings
#define XNANDPS_ECC_CMD2 |
((0x85 << XNANDPS_ECC_MEMCOMMAND2_WR_COL_CHANGE_SHIFT) | \ (0x05 << XNANDPS_ECC_MEMCOMMAND2_RD_COL_CHANGE_SHIFT) | \ (0xE0 << XNANDPS_ECC_MEMCOMMAND2_RD_COL_CHANGE_END_SHIFT) | \ (0x1 << XNANDPS_ECC_MEMCOMMAND2_RD_COL_CHANGE_END_VALID_SHIFT))
ECC command 2 settings
#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 |
((0x1 << XNANDPS_ECC_MEMCFG_ECC_MODE_SHIFT) | \ (0x1 << XNANDPS_ECC_MEMCFG_ECC_READ_END_SHIFT) | \ (0x0 << XNANDPS_ECC_MEMCFG_ECC_JUMP_SHIFT))
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 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.
enum XNandPs_EccMode |
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.
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. |
int XNandPs_EraseBlock | ( | XNandPs * | InstancePtr, | |
u32 | BlockNum | |||
) |
This function erases a specific block in the NAND device.
InstancePtr | is a pointer to the XNandPs instance. | |
BlockNum | is the block number of the device. |
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.
DeviceId | contains the ID of the device for which the device configuration pointer is to be returned. |
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.
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. |
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.
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. |
int XNandPs_ReadSpareBytes | ( | XNandPs * | InstancePtr, | |
u32 | Page, | |||
u8 * | Buf | |||
) |
This function reads the spare area of a page.
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. |
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.
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. |
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.
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. |
int XNandPs_WriteSpareBytes | ( | XNandPs * | InstancePtr, | |
u32 | Page, | |||
u8 * | Buf | |||
) |
This function write to the spare area of a page.
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. |
Copyright © 1995-2014 Xilinx, Inc. All rights reserved.