XilinxProcessorIPLib/drivers/qspipsu/examples/xqspipsu_generic_nand_flash_polled_example.c
int FlashRead(XQspiPsu *QspiPsuPtr, u32 Address, u32 ByteCount, u8 Command,
				u8 *WriteBfrPtr, u8 *ReadBfrPtr)
{
	u16 PageAddr;
	u8 PageReadCmd;
	u8 WriteBuf[2];
	int Status;

	PageAddr = Address / PageSize;

	/* Set page address */
	WriteBuf[0] = (u8) ((PageAddr & 0xFF00) >> 8);
	WriteBuf[1] = (u8) (PageAddr & 0xFF);

	PageReadCmd = PAGE_DATA_READ;

	FlashMsg[0].TxBfrPtr = &PageReadCmd;
	FlashMsg[0].RxBfrPtr = NULL;
	FlashMsg[0].ByteCount = 1;
	FlashMsg[0].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[0].Flags = XQSPIPSU_MSG_FLAG_TX;

	FlashMsg[1].TxBfrPtr = NULL;
	FlashMsg[1].RxBfrPtr = NULL;
	FlashMsg[1].ByteCount = DUMMY_CLOCKS;
	FlashMsg[1].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[1].Flags = 0;

	FlashMsg[2].TxBfrPtr = WriteBuf;
	FlashMsg[2].RxBfrPtr = NULL;
	FlashMsg[2].ByteCount = 2;
	FlashMsg[2].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[2].Flags = XQSPIPSU_MSG_FLAG_TX;

	Status = XQspiPsu_PolledTransfer(QspiPsuPtr, FlashMsg, 3);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/* Check flash is busy */
	Status = FlashIsNotBusy(QspiPsuPtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/* Continuous data read */
	WriteBfrPtr[COMMAND_OFFSET] = Command;

	FlashMsg[0].TxBfrPtr = WriteBfrPtr;
	FlashMsg[0].RxBfrPtr = NULL;
	FlashMsg[0].ByteCount = 1;
	FlashMsg[0].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[0].Flags = XQSPIPSU_MSG_FLAG_TX;

	FlashMsg[1].TxBfrPtr = NULL;
	FlashMsg[1].RxBfrPtr = NULL;
	FlashMsg[1].ByteCount = 5 * DUMMY_CLOCKS;
	FlashMsg[1].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[1].Flags = 0;

	FlashMsg[2].TxBfrPtr = NULL;
	FlashMsg[2].RxBfrPtr = ReadBfrPtr;
	FlashMsg[2].ByteCount = ByteCount;
	FlashMsg[2].BusWidth = XQSPIPSU_SELECT_MODE_QUADSPI;
	FlashMsg[2].Flags = XQSPIPSU_MSG_FLAG_RX;

	Status = XQspiPsu_PolledTransfer(QspiPsuPtr, FlashMsg, 3);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
 *
 * This function performs read. DMA is the default setting.
 *
 * @param	QspiPtr is a pointer to the QSPIPSU driver component to use.
 * @param	Address contains the address of the first sector which needs to
 *			be erased.
 * @param	ByteCount contains the total size to be erased.
 * @param	Command is the command used to read data from the flash.
 *		Supports normal, fast, dual and quad read commands.
 * @param	Pointer to the write buffer which contains data to be
 *		transmitted
 * @param	Pointer to the read buffer to which valid received data
 *		should be written
 *
 * @return	XST_SUCCESS if successful, else XST_FAILURE.
 *
 * @note	None.
 *
 ******************************************************************************/
This function performs read. DMA is the default setting.
@param       QspiPtr is a pointer to the QSPIPSU driver component to use.
@param       Address contains the address of the first sector which needs to
be erased.
@param       ByteCount contains the total size to be erased.
@param       Command is the command used to read data from the flash.
Supports normal, fast, dual and quad read commands.
@param       Pointer to the write buffer which contains data to be
transmitted
@param       Pointer to the read buffer to which valid received data
should be written



@note        None.
This function performs read . DMA is the default setting . @param QspiPtr is a pointer to the QSPIPSU driver component to use . @param Address contains the address of the first sector which needs to be erased . @param ByteCount contains the total size to be erased . @param Command is the command used to read data from the flash . Supports normal fast dual and quad read commands . @param Pointer to the write buffer which contains data to be transmitted @param Pointer to the read buffer to which valid received data should be written @note None .
int FlashRead(XQspiPsu *QspiPsuPtr, u32 Address, u32 ByteCount, u8 Command,
				u8 *WriteBfrPtr, u8 *ReadBfrPtr)
{
	u16 PageAddr;
	u8 PageReadCmd;
	u8 WriteBuf[2];
	int Status;
	PageAddr = Address / PageSize;
	WriteBuf[0] = (u8) ((PageAddr & 0xFF00) >> 8);
	WriteBuf[1] = (u8) (PageAddr & 0xFF);
	PageReadCmd = PAGE_DATA_READ;
	FlashMsg[0].TxBfrPtr = &PageReadCmd;
	FlashMsg[0].RxBfrPtr = NULL;
	FlashMsg[0].ByteCount = 1;
	FlashMsg[0].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[0].Flags = XQSPIPSU_MSG_FLAG_TX;
	FlashMsg[1].TxBfrPtr = NULL;
	FlashMsg[1].RxBfrPtr = NULL;
	FlashMsg[1].ByteCount = DUMMY_CLOCKS;
	FlashMsg[1].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[1].Flags = 0;
	FlashMsg[2].TxBfrPtr = WriteBuf;
	FlashMsg[2].RxBfrPtr = NULL;
	FlashMsg[2].ByteCount = 2;
	FlashMsg[2].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[2].Flags = XQSPIPSU_MSG_FLAG_TX;
	Status = XQspiPsu_PolledTransfer(QspiPsuPtr, FlashMsg, 3);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = FlashIsNotBusy(QspiPsuPtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	WriteBfrPtr[COMMAND_OFFSET] = Command;
	FlashMsg[0].TxBfrPtr = WriteBfrPtr;
	FlashMsg[0].RxBfrPtr = NULL;
	FlashMsg[0].ByteCount = 1;
	FlashMsg[0].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[0].Flags = XQSPIPSU_MSG_FLAG_TX;
	FlashMsg[1].TxBfrPtr = NULL;
	FlashMsg[1].RxBfrPtr = NULL;
	FlashMsg[1].ByteCount = 5 * DUMMY_CLOCKS;
	FlashMsg[1].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[1].Flags = 0;
	FlashMsg[2].TxBfrPtr = NULL;
	FlashMsg[2].RxBfrPtr = ReadBfrPtr;
	FlashMsg[2].ByteCount = ByteCount;
	FlashMsg[2].BusWidth = XQSPIPSU_SELECT_MODE_QUADSPI;
	FlashMsg[2].Flags = XQSPIPSU_MSG_FLAG_RX;
	Status = XQspiPsu_PolledTransfer(QspiPsuPtr, FlashMsg, 3);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	return XST_SUCCESS;
}
int FlashRead ( XQspiPsu * QspiPsuPtr , u32 Address , u32 ByteCount , u8 Command , u8 * WriteBfrPtr , u8 * ReadBfrPtr ) { u16 PageAddr ; u8 PageReadCmd ; u8 WriteBuf [ 2 ] ; int Status ; PageAddr = Address / PageSize ; WriteBuf [ 0 ] = ( u8 ) ( ( PageAddr & 0xFF00 ) >> 8 ) ; WriteBuf [ 1 ] = ( u8 ) ( PageAddr & 0xFF ) ; PageReadCmd = PAGE_DATA_READ ; FlashMsg [ 0 ] . TxBfrPtr = & PageReadCmd ; FlashMsg [ 0 ] . RxBfrPtr = NULL ; FlashMsg [ 0 ] . ByteCount = 1 ; FlashMsg [ 0 ] . BusWidth = XQSPIPSU_SELECT_MODE_SPI ; FlashMsg [ 0 ] . Flags = XQSPIPSU_MSG_FLAG_TX ; FlashMsg [ 1 ] . TxBfrPtr = NULL ; FlashMsg [ 1 ] . RxBfrPtr = NULL ; FlashMsg [ 1 ] . ByteCount = DUMMY_CLOCKS ; FlashMsg [ 1 ] . BusWidth = XQSPIPSU_SELECT_MODE_SPI ; FlashMsg [ 1 ] . Flags = 0 ; FlashMsg [ 2 ] . TxBfrPtr = WriteBuf ; FlashMsg [ 2 ] . RxBfrPtr = NULL ; FlashMsg [ 2 ] . ByteCount = 2 ; FlashMsg [ 2 ] . BusWidth = XQSPIPSU_SELECT_MODE_SPI ; FlashMsg [ 2 ] . Flags = XQSPIPSU_MSG_FLAG_TX ; Status = XQspiPsu_PolledTransfer ( QspiPsuPtr , FlashMsg , 3 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = FlashIsNotBusy ( QspiPsuPtr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } WriteBfrPtr [ COMMAND_OFFSET ] = Command ; FlashMsg [ 0 ] . TxBfrPtr = WriteBfrPtr ; FlashMsg [ 0 ] . RxBfrPtr = NULL ; FlashMsg [ 0 ] . ByteCount = 1 ; FlashMsg [ 0 ] . BusWidth = XQSPIPSU_SELECT_MODE_SPI ; FlashMsg [ 0 ] . Flags = XQSPIPSU_MSG_FLAG_TX ; FlashMsg [ 1 ] . TxBfrPtr = NULL ; FlashMsg [ 1 ] . RxBfrPtr = NULL ; FlashMsg [ 1 ] . ByteCount = 5 * DUMMY_CLOCKS ; FlashMsg [ 1 ] . BusWidth = XQSPIPSU_SELECT_MODE_SPI ; FlashMsg [ 1 ] . Flags = 0 ; FlashMsg [ 2 ] . TxBfrPtr = NULL ; FlashMsg [ 2 ] . RxBfrPtr = ReadBfrPtr ; FlashMsg [ 2 ] . ByteCount = ByteCount ; FlashMsg [ 2 ] . BusWidth = XQSPIPSU_SELECT_MODE_QUADSPI ; FlashMsg [ 2 ] . Flags = XQSPIPSU_MSG_FLAG_RX ; Status = XQspiPsu_PolledTransfer ( QspiPsuPtr , FlashMsg , 3 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } return XST_SUCCESS ; }
This function performs read.
This function performs read .
/* Set page address */ /* Check flash is busy */ /* Continuous data read */