XilinxProcessorIPLib/drivers/ospipsv/examples/xospipsv_flash_intr_example.c
int FlashRead(XOspiPsv *OspiPsvPtr, u32 Address, u32 ByteCount,
				u8 *WriteBfrPtr, u8 *ReadBfrPtr)
{
	u8 Status;
	u32 RealAddr;
	u32 BytesToRead;
	u32 ByteCnt = ByteCount;

	if ((Address < Flash_Config_Table[FCTIndex].FlashDeviceSize) &&
		((Address + ByteCount) >= Flash_Config_Table[FCTIndex].FlashDeviceSize) &&
		(OspiPsvPtr->Config.ConnectionMode == XOSPIPSV_CONNECTION_MODE_STACKED)) {
		BytesToRead = (Flash_Config_Table[FCTIndex].FlashDeviceSize - Address);
	} else {
		BytesToRead = ByteCount;
	}
	while (ByteCount != 0) {
		/*
		 * Translate address based on type of connection
		 * If stacked assert the slave select based on address
		 */
		RealAddr = GetRealAddr(OspiPsvPtr, Address);

		FlashMsg.Opcode = (u8)Flash_Config_Table[FCTIndex].ReadCmd;
		FlashMsg.Addrsize = 4;
		FlashMsg.Addrvalid = 1;
		FlashMsg.TxBfrPtr = NULL;
		FlashMsg.RxBfrPtr = ReadBfrPtr;
		FlashMsg.ByteCount = BytesToRead;
		FlashMsg.Flags = XOSPIPSV_MSG_FLAG_RX;
		FlashMsg.Addr = RealAddr;
		FlashMsg.Proto = XOspiPsv_Get_Proto(OspiPsvPtr, 1);
		FlashMsg.Dummy = Flash_Config_Table[FCTIndex].DummyCycles +
				OspiPsvPtr->Extra_DummyCycle;
		FlashMsg.IsDDROpCode = 0;
		if (OspiPsvPtr->SdrDdrMode == XOSPIPSV_EDGE_MODE_DDR_PHY) {
			FlashMsg.Proto = XOSPIPSV_READ_8_8_8;
			if (FlashMake == MACRONIX_OCTAL_ID_BYTE0) {
				FlashMsg.Dummy = 20 + OspiPsvPtr->Extra_DummyCycle;
				FlashMsg.Opcode = (u8)(Flash_Config_Table[FCTIndex].ReadCmd >> 8);
			}
		}

		xil_printf("ReadCmd 0x%x\r\n", FlashMsg.Opcode);

		if (OspiPsvPtr->DualByteOpcodeEn != 0U)
			FlashMsg.ExtendedOpcode = (u8)(~FlashMsg.Opcode);

		TransferInProgress = TRUE;
		Error = 0;
		Status = XOspiPsv_IntrTransfer(OspiPsvPtr, &FlashMsg);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
		while(TransferInProgress);
		if (Error) {
			return XST_FAILURE;
		}

		ByteCount -= BytesToRead;
		Address += BytesToRead;
		ReadBfrPtr += BytesToRead;
		BytesToRead = ByteCnt - BytesToRead;
	}

	return 0;
}
/*****************************************************************************/
/**
*
* This function performs read. DMA is the default setting.
*
* @param	OspiPsvPtr is a pointer to the OSPIPSV 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	WriteBfrPtr is Pointer to the write buffer which contains data to be transmitted
* @param	ReadBfrPtr isPointer 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.
This function performs read . DMA is the default setting .
int FlashRead(XOspiPsv *OspiPsvPtr, u32 Address, u32 ByteCount,
				u8 *WriteBfrPtr, u8 *ReadBfrPtr)
{
	u8 Status;
	u32 RealAddr;
	u32 BytesToRead;
	u32 ByteCnt = ByteCount;
	if ((Address < Flash_Config_Table[FCTIndex].FlashDeviceSize) &&
		((Address + ByteCount) >= Flash_Config_Table[FCTIndex].FlashDeviceSize) &&
		(OspiPsvPtr->Config.ConnectionMode == XOSPIPSV_CONNECTION_MODE_STACKED)) {
		BytesToRead = (Flash_Config_Table[FCTIndex].FlashDeviceSize - Address);
	} else {
		BytesToRead = ByteCount;
	}
	while (ByteCount != 0) {
		RealAddr = GetRealAddr(OspiPsvPtr, Address);
		FlashMsg.Opcode = (u8)Flash_Config_Table[FCTIndex].ReadCmd;
		FlashMsg.Addrsize = 4;
		FlashMsg.Addrvalid = 1;
		FlashMsg.TxBfrPtr = NULL;
		FlashMsg.RxBfrPtr = ReadBfrPtr;
		FlashMsg.ByteCount = BytesToRead;
		FlashMsg.Flags = XOSPIPSV_MSG_FLAG_RX;
		FlashMsg.Addr = RealAddr;
		FlashMsg.Proto = XOspiPsv_Get_Proto(OspiPsvPtr, 1);
		FlashMsg.Dummy = Flash_Config_Table[FCTIndex].DummyCycles +
				OspiPsvPtr->Extra_DummyCycle;
		FlashMsg.IsDDROpCode = 0;
		if (OspiPsvPtr->SdrDdrMode == XOSPIPSV_EDGE_MODE_DDR_PHY) {
			FlashMsg.Proto = XOSPIPSV_READ_8_8_8;
			if (FlashMake == MACRONIX_OCTAL_ID_BYTE0) {
				FlashMsg.Dummy = 20 + OspiPsvPtr->Extra_DummyCycle;
				FlashMsg.Opcode = (u8)(Flash_Config_Table[FCTIndex].ReadCmd >> 8);
			}
		}
		xil_printf("ReadCmd 0x%x\r\n", FlashMsg.Opcode);
		if (OspiPsvPtr->DualByteOpcodeEn != 0U)
			FlashMsg.ExtendedOpcode = (u8)(~FlashMsg.Opcode);
		TransferInProgress = TRUE;
		Error = 0;
		Status = XOspiPsv_IntrTransfer(OspiPsvPtr, &FlashMsg);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
		while(TransferInProgress);
		if (Error) {
			return XST_FAILURE;
		}
		ByteCount -= BytesToRead;
		Address += BytesToRead;
		ReadBfrPtr += BytesToRead;
		BytesToRead = ByteCnt - BytesToRead;
	}
	return 0;
}
int FlashRead ( XOspiPsv * OspiPsvPtr , u32 Address , u32 ByteCount , u8 * WriteBfrPtr , u8 * ReadBfrPtr ) { u8 Status ; u32 RealAddr ; u32 BytesToRead ; u32 ByteCnt = ByteCount ; if ( ( Address < Flash_Config_Table [ FCTIndex ] . FlashDeviceSize ) && ( ( Address + ByteCount ) >= Flash_Config_Table [ FCTIndex ] . FlashDeviceSize ) && ( OspiPsvPtr -> Config . ConnectionMode == XOSPIPSV_CONNECTION_MODE_STACKED ) ) { BytesToRead = ( Flash_Config_Table [ FCTIndex ] . FlashDeviceSize - Address ) ; } else { BytesToRead = ByteCount ; } while ( ByteCount != 0 ) { RealAddr = GetRealAddr ( OspiPsvPtr , Address ) ; FlashMsg . Opcode = ( u8 ) Flash_Config_Table [ FCTIndex ] . ReadCmd ; FlashMsg . Addrsize = 4 ; FlashMsg . Addrvalid = 1 ; FlashMsg . TxBfrPtr = NULL ; FlashMsg . RxBfrPtr = ReadBfrPtr ; FlashMsg . ByteCount = BytesToRead ; FlashMsg . Flags = XOSPIPSV_MSG_FLAG_RX ; FlashMsg . Addr = RealAddr ; FlashMsg . Proto = XOspiPsv_Get_Proto ( OspiPsvPtr , 1 ) ; FlashMsg . Dummy = Flash_Config_Table [ FCTIndex ] . DummyCycles + OspiPsvPtr -> Extra_DummyCycle ; FlashMsg . IsDDROpCode = 0 ; if ( OspiPsvPtr -> SdrDdrMode == XOSPIPSV_EDGE_MODE_DDR_PHY ) { FlashMsg . Proto = XOSPIPSV_READ_8_8_8 ; if ( FlashMake == MACRONIX_OCTAL_ID_BYTE0 ) { FlashMsg . Dummy = 20 + OspiPsvPtr -> Extra_DummyCycle ; FlashMsg . Opcode = ( u8 ) ( Flash_Config_Table [ FCTIndex ] . ReadCmd >> 8 ) ; } } xil_printf ( " \r \n " , FlashMsg . Opcode ) ; if ( OspiPsvPtr -> DualByteOpcodeEn != 0U ) FlashMsg . ExtendedOpcode = ( u8 ) ( ~ FlashMsg . Opcode ) ; TransferInProgress = TRUE ; Error = 0 ; Status = XOspiPsv_IntrTransfer ( OspiPsvPtr , & FlashMsg ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } while ( TransferInProgress ) ; if ( Error ) { return XST_FAILURE ; } ByteCount -= BytesToRead ; Address += BytesToRead ; ReadBfrPtr += BytesToRead ; BytesToRead = ByteCnt - BytesToRead ; } return 0 ; }
This function performs read.
This function performs read .
/*
		 * Translate address based on type of connection
		 * If stacked assert the slave select based on address
		 */