XilinxProcessorIPLib/drivers/qspipsu/examples/xqspipsu_generic_nand_flash_interrupt_example.c
s32 XQspiPsu_ReadParamPage(XQspiPsu *QspiPsuPtr)
{
        s32 Status = XST_FAILURE;
        u16 PageAddr;
		u8 PageReadCmd;
		u8 WriteBuf[2];
		u8 Status_Reg;

		/*
		 * To access Parameter page data,
		 * the OTP-E bit in Status Register-2
		 * must be set to “1” first
		 */
		FlashStatusRead(QspiPsuPtr, STATUS_REG_2, &Status_Reg);
		Status_Reg |= 0x01 << OTP_E_BIT;
		FlashStatusWrite(QspiPsuPtr, STATUS_REG_2, Status_Reg);

		PageAddr = PARAMETER_PAGE_ADDRESS;

		/* 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;

		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;
		}

		/* Continuous data read */
		WriteBuf[COMMAND_OFFSET] = QUAD_READ_CMD_4B;

		FlashMsg[0].TxBfrPtr = WriteBuf;
		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 = ParameterPageData;
		FlashMsg[2].ByteCount = 2048;
		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);

		/*
		 * To return to the main memory array operation,
		 * OTP-E bit in Status Register-2 needs to be to
		 * set to "0"
		 */
		FlashStatusRead(QspiPsuPtr, STATUS_REG_2, &Status_Reg);
		Status_Reg &= ~(0x01 << OTP_E_BIT);
		FlashStatusWrite(QspiPsuPtr, STATUS_REG_2, Status_Reg);

		return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* This function reads Parameter Page data from the flash.
*
* @param        QspiPsuPtr is a pointer to the QSPIPSU driver component to use.
* @param        Buf is the parameter page information to return.
*
* @return
*               - XST_SUCCESS if successful.
*               - XST_FAILURE if failed.
*
* @note         None
*
******************************************************************************/
This function reads Parameter Page data from the flash.
This function reads Parameter Page data from the flash .
s32 XQspiPsu_ReadParamPage(XQspiPsu *QspiPsuPtr)
{
        s32 Status = XST_FAILURE;
        u16 PageAddr;
		u8 PageReadCmd;
		u8 WriteBuf[2];
		u8 Status_Reg;
		FlashStatusRead(QspiPsuPtr, STATUS_REG_2, &Status_Reg);
		Status_Reg |= 0x01 << OTP_E_BIT;
		FlashStatusWrite(QspiPsuPtr, STATUS_REG_2, Status_Reg);
		PageAddr = PARAMETER_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;
		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;
		}
		WriteBuf[COMMAND_OFFSET] = QUAD_READ_CMD_4B;
		FlashMsg[0].TxBfrPtr = WriteBuf;
		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 = ParameterPageData;
		FlashMsg[2].ByteCount = 2048;
		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);
		FlashStatusRead(QspiPsuPtr, STATUS_REG_2, &Status_Reg);
		Status_Reg &= ~(0x01 << OTP_E_BIT);
		FlashStatusWrite(QspiPsuPtr, STATUS_REG_2, Status_Reg);
		return XST_SUCCESS;
}
s32 XQspiPsu_ReadParamPage ( XQspiPsu * QspiPsuPtr ) { s32 Status = XST_FAILURE ; u16 PageAddr ; u8 PageReadCmd ; u8 WriteBuf [ 2 ] ; u8 Status_Reg ; FlashStatusRead ( QspiPsuPtr , STATUS_REG_2 , & Status_Reg ) ; Status_Reg |= 0x01 << OTP_E_BIT ; FlashStatusWrite ( QspiPsuPtr , STATUS_REG_2 , Status_Reg ) ; PageAddr = PARAMETER_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 ; 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 ; } WriteBuf [ COMMAND_OFFSET ] = QUAD_READ_CMD_4B ; FlashMsg [ 0 ] . TxBfrPtr = WriteBuf ; 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 = ParameterPageData ; FlashMsg [ 2 ] . ByteCount = 2048 ; 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 ) ; FlashStatusRead ( QspiPsuPtr , STATUS_REG_2 , & Status_Reg ) ; Status_Reg &= ~ ( 0x01 << OTP_E_BIT ) ; FlashStatusWrite ( QspiPsuPtr , STATUS_REG_2 , Status_Reg ) ; return XST_SUCCESS ; }
This function reads Parameter Page data from the flash.
This function reads Parameter Page data from the flash .
/*
		 * To access Parameter page data,
		 * the OTP-E bit in Status Register-2
		 * must be set to “1” first
		 */ /* Set page address */ /* Check flash is busy */ /* Continuous data read */ /*
		 * To return to the main memory array operation,
		 * OTP-E bit in Status Register-2 needs to be to
		 * set to "0"
		 */