XilinxProcessorIPLib/drivers/qspipsu/examples/xqspipsu_generic_nand_flash_interrupt_example.c
int FlashCheckIsBadBlock(XQspiPsu *QspiPsuPtr, u32 Address)
{

	u32 RealAddr;
	u8 PageReadCmd;
	u8 WriteBfrPtr[3];
	u8 PageAddr[2];
	int Status;

	RealAddr = Address / PageSize;

	/* Page data read */
	PageAddr[0] = (u8) ((RealAddr & 0xFF00) >> 8);
	PageAddr[1] = (u8) (RealAddr & 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 = 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;
	}

	/* Flash read */
	RealAddr = PageSize;

	WriteBfrPtr[COMMAND_OFFSET] = QUAD_READ_CMD_4B;
	WriteBfrPtr[ADDRESS_1_OFFSET] = (u8) ((RealAddr & 0xFF00) >> 8);
	WriteBfrPtr[ADDRESS_2_OFFSET] = (u8) (RealAddr & 0xFF);

	FlashMsg[0].TxBfrPtr = WriteBfrPtr;
	FlashMsg[0].RxBfrPtr = NULL;
	FlashMsg[0].ByteCount = 3;
	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 = 3 * DUMMY_CLOCKS;
	FlashMsg[1].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[1].Flags = 0;

	FlashMsg[2].TxBfrPtr = NULL;
	FlashMsg[2].RxBfrPtr = ReadSpareBfrPtr;
	FlashMsg[2].ByteCount = ((ParameterPageData[SPARE_1_OFFSET] << 8) |
							 ParameterPageData[SPARE_0_OFFSET]);
	FlashMsg[2].BusWidth = XQSPIPSU_SELECT_MODE_QUADSPI;
	FlashMsg[2].Flags = XQSPIPSU_MSG_FLAG_RX;

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

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
 *
 * This API is to check bad block information.
 *
 * @param	QspiPsuPtr is a pointer to the QSPIPSU driver component to use.
 *
 *
 * @return	XST_SUCCESS if successful, else XST_FAILURE.
 *
 *
 ******************************************************************************/
This API is to check bad block information.
@param       QspiPsuPtr is a pointer to the QSPIPSU driver component to use.


This API is to check bad block information . @param QspiPsuPtr is a pointer to the QSPIPSU driver component to use .
int FlashCheckIsBadBlock(XQspiPsu *QspiPsuPtr, u32 Address)
{
	u32 RealAddr;
	u8 PageReadCmd;
	u8 WriteBfrPtr[3];
	u8 PageAddr[2];
	int Status;
	RealAddr = Address / PageSize;
	PageAddr[0] = (u8) ((RealAddr & 0xFF00) >> 8);
	PageAddr[1] = (u8) (RealAddr & 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 = 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;
	}
	RealAddr = PageSize;
	WriteBfrPtr[COMMAND_OFFSET] = QUAD_READ_CMD_4B;
	WriteBfrPtr[ADDRESS_1_OFFSET] = (u8) ((RealAddr & 0xFF00) >> 8);
	WriteBfrPtr[ADDRESS_2_OFFSET] = (u8) (RealAddr & 0xFF);
	FlashMsg[0].TxBfrPtr = WriteBfrPtr;
	FlashMsg[0].RxBfrPtr = NULL;
	FlashMsg[0].ByteCount = 3;
	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 = 3 * DUMMY_CLOCKS;
	FlashMsg[1].BusWidth = XQSPIPSU_SELECT_MODE_SPI;
	FlashMsg[1].Flags = 0;
	FlashMsg[2].TxBfrPtr = NULL;
	FlashMsg[2].RxBfrPtr = ReadSpareBfrPtr;
	FlashMsg[2].ByteCount = ((ParameterPageData[SPARE_1_OFFSET] << 8) |
							 ParameterPageData[SPARE_0_OFFSET]);
	FlashMsg[2].BusWidth = XQSPIPSU_SELECT_MODE_QUADSPI;
	FlashMsg[2].Flags = XQSPIPSU_MSG_FLAG_RX;
	TransferInProgress = TRUE;
	Status = XQspiPsu_InterruptTransfer(QspiPsuPtr, FlashMsg, 3);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	while (TransferInProgress);
	return XST_SUCCESS;
}
int FlashCheckIsBadBlock ( XQspiPsu * QspiPsuPtr , u32 Address ) { u32 RealAddr ; u8 PageReadCmd ; u8 WriteBfrPtr [ 3 ] ; u8 PageAddr [ 2 ] ; int Status ; RealAddr = Address / PageSize ; PageAddr [ 0 ] = ( u8 ) ( ( RealAddr & 0xFF00 ) >> 8 ) ; PageAddr [ 1 ] = ( u8 ) ( RealAddr & 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 = 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 ; } RealAddr = PageSize ; WriteBfrPtr [ COMMAND_OFFSET ] = QUAD_READ_CMD_4B ; WriteBfrPtr [ ADDRESS_1_OFFSET ] = ( u8 ) ( ( RealAddr & 0xFF00 ) >> 8 ) ; WriteBfrPtr [ ADDRESS_2_OFFSET ] = ( u8 ) ( RealAddr & 0xFF ) ; FlashMsg [ 0 ] . TxBfrPtr = WriteBfrPtr ; FlashMsg [ 0 ] . RxBfrPtr = NULL ; FlashMsg [ 0 ] . ByteCount = 3 ; 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 = 3 * DUMMY_CLOCKS ; FlashMsg [ 1 ] . BusWidth = XQSPIPSU_SELECT_MODE_SPI ; FlashMsg [ 1 ] . Flags = 0 ; FlashMsg [ 2 ] . TxBfrPtr = NULL ; FlashMsg [ 2 ] . RxBfrPtr = ReadSpareBfrPtr ; FlashMsg [ 2 ] . ByteCount = ( ( ParameterPageData [ SPARE_1_OFFSET ] << 8 ) | ParameterPageData [ SPARE_0_OFFSET ] ) ; FlashMsg [ 2 ] . BusWidth = XQSPIPSU_SELECT_MODE_QUADSPI ; FlashMsg [ 2 ] . Flags = XQSPIPSU_MSG_FLAG_RX ; TransferInProgress = TRUE ; Status = XQspiPsu_InterruptTransfer ( QspiPsuPtr , FlashMsg , 3 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } while ( TransferInProgress ) ; return XST_SUCCESS ; }
This API is to check bad block information.
This API is to check bad block information .
/* Page data read */ /* Check flash is busy */ /* Flash read */