XilinxProcessorIPLib/drivers/qspipsu/examples/xqspipsu_generic_nand_flash_interrupt_example.c
int FlashErase(XQspiPsu *QspiPsuPtr, u32 Address)
{
	u8 WriteEnableCmd;
	u8 BlockEraseCmd;
	u32 RealAddr;
	u8 PageAddr[2];
	int Status;

	RealAddr = Address / PageSize;

	/* Enable write enable */
	WriteEnableCmd = WRITE_ENABLE_CMD;

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

	TransferInProgress = TRUE;
	Status = XQspiPsu_InterruptTransfer(QspiPsuPtr, FlashMsg, 1);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	while (TransferInProgress);


	/* Block erase */
	PageAddr[0] = (u8) ((RealAddr & 0xFF00) >> 8);
	PageAddr[1] = (u8) (RealAddr & 0xFF);

	BlockEraseCmd = EraseCmd;

	FlashMsg[0].TxBfrPtr = &BlockEraseCmd;
	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 = PageAddr;
	FlashMsg[2].RxBfrPtr = NULL;
	FlashMsg[2].ByteCount = 2;
	FlashMsg[2].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[2].Flags = XQSPIPSU_MSG_FLAG_TX;

	TransferInProgress = TRUE;
	Status = XQspiPsu_InterruptTransfer(QspiPsuPtr, FlashMsg, 3);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	while (TransferInProgress);

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

	return Status;
}
/*****************************************************************************/
/**
 *
 * This function erases the sectors in the  serial Flash connected to the
 * QSPIPSU interface.
 *
 * @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.
 *
 * @return	XST_SUCCESS if successful, else XST_FAILURE.
 *
 * @note	None.
 *
 ******************************************************************************/
This function erases the sectors in the  serial Flash connected to the
QSPIPSU interface.

@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.



@note        None.
This function erases the sectors in the serial Flash connected to the QSPIPSU interface . @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 . @note None .
int FlashErase(XQspiPsu *QspiPsuPtr, u32 Address)
{
	u8 WriteEnableCmd;
	u8 BlockEraseCmd;
	u32 RealAddr;
	u8 PageAddr[2];
	int Status;
	RealAddr = Address / PageSize;
	WriteEnableCmd = WRITE_ENABLE_CMD;
	FlashMsg[0].TxBfrPtr = &WriteEnableCmd;
	FlashMsg[0].RxBfrPtr = NULL;
	FlashMsg[0].ByteCount = 1;
	FlashMsg[0].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[0].Flags = XQSPIPSU_MSG_FLAG_TX;
	TransferInProgress = TRUE;
	Status = XQspiPsu_InterruptTransfer(QspiPsuPtr, FlashMsg, 1);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	while (TransferInProgress);
	PageAddr[0] = (u8) ((RealAddr & 0xFF00) >> 8);
	PageAddr[1] = (u8) (RealAddr & 0xFF);
	BlockEraseCmd = EraseCmd;
	FlashMsg[0].TxBfrPtr = &BlockEraseCmd;
	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 = PageAddr;
	FlashMsg[2].RxBfrPtr = NULL;
	FlashMsg[2].ByteCount = 2;
	FlashMsg[2].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[2].Flags = XQSPIPSU_MSG_FLAG_TX;
	TransferInProgress = TRUE;
	Status = XQspiPsu_InterruptTransfer(QspiPsuPtr, FlashMsg, 3);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	while (TransferInProgress);
	Status = FlashIsNotBusy(QspiPsuPtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	return Status;
}
int FlashErase ( XQspiPsu * QspiPsuPtr , u32 Address ) { u8 WriteEnableCmd ; u8 BlockEraseCmd ; u32 RealAddr ; u8 PageAddr [ 2 ] ; int Status ; RealAddr = Address / PageSize ; WriteEnableCmd = WRITE_ENABLE_CMD ; FlashMsg [ 0 ] . TxBfrPtr = & WriteEnableCmd ; FlashMsg [ 0 ] . RxBfrPtr = NULL ; FlashMsg [ 0 ] . ByteCount = 1 ; FlashMsg [ 0 ] . BusWidth = XQSPIPSU_SELECT_MODE_SPI ; FlashMsg [ 0 ] . Flags = XQSPIPSU_MSG_FLAG_TX ; TransferInProgress = TRUE ; Status = XQspiPsu_InterruptTransfer ( QspiPsuPtr , FlashMsg , 1 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } while ( TransferInProgress ) ; PageAddr [ 0 ] = ( u8 ) ( ( RealAddr & 0xFF00 ) >> 8 ) ; PageAddr [ 1 ] = ( u8 ) ( RealAddr & 0xFF ) ; BlockEraseCmd = EraseCmd ; FlashMsg [ 0 ] . TxBfrPtr = & BlockEraseCmd ; 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 = PageAddr ; FlashMsg [ 2 ] . RxBfrPtr = NULL ; FlashMsg [ 2 ] . ByteCount = 2 ; FlashMsg [ 2 ] . BusWidth = XQSPIPSU_SELECT_MODE_SPI ; FlashMsg [ 2 ] . Flags = XQSPIPSU_MSG_FLAG_TX ; TransferInProgress = TRUE ; Status = XQspiPsu_InterruptTransfer ( QspiPsuPtr , FlashMsg , 3 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } while ( TransferInProgress ) ; Status = FlashIsNotBusy ( QspiPsuPtr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } return Status ; }
This function erases the sectors in the  serial Flash connected to the
 QSPIPSU interface.
This function erases the sectors in the serial Flash connected to the QSPIPSU interface .
/* Enable write enable */ /* Block erase */ /* Check flash is busy */