XilinxProcessorIPLib/drivers/ospipsv/examples/xospipsv_flash_intr_example.c
int OspiPsvInterruptFlashExample(XScuGic *IntcInstancePtr,
				XOspiPsv *OspiPsvInstancePtr, u16 OspiPsvDeviceId)
{
	int Status;
	u8 UniqueValue;
	int Count;
	int Page = 0;
	XOspiPsv_Config *OspiPsvConfig;
	int ReadBfrSize;
	ReadBfrSize = (PAGE_COUNT * MAX_PAGE_SIZE);

	Status = XOspiPsv_DeviceReset(XOSPIPSV_HWPIN_RESET);
	if (Status != XST_SUCCESS)
		return XST_FAILURE;

	/*
	 * Initialize the OSPIPSV driver so that it's ready to use
	 */
	OspiPsvConfig = XOspiPsv_LookupConfig(OspiPsvDeviceId);
	if (NULL == OspiPsvConfig) {
		return XST_FAILURE;
	}
	/* To test, change connection mode here if not obtained from HDF */

	Status = XOspiPsv_CfgInitialize(OspiPsvInstancePtr, OspiPsvConfig);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	Status = OspiPsvSetupIntrSystem(IntcInstancePtr, OspiPsvInstancePtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	XOspiPsv_SetStatusHandler(OspiPsvInstancePtr, OspiPsvInstancePtr,
					 (XOspiPsv_StatusHandler) OspiPsvHandler);
	/*
	 * Enable IDAC controller in OSPI
	 */
	XOspiPsv_SetOptions(OspiPsvInstancePtr, XOSPIPSV_IDAC_EN_OPTION);
	/*
	 * Set the prescaler for OSPIPSV clock
	 */
	XOspiPsv_SetClkPrescaler(OspiPsvInstancePtr, XOSPIPSV_CLK_PRESCALE_12);

	Status = XOspiPsv_SelectFlash(OspiPsvInstancePtr, XOSPIPSV_SELECT_FLASH_CS0);
	if (Status != XST_SUCCESS)
		return XST_FAILURE;

	/*
	 * Read flash ID and obtain all flash related information
	 * It is important to call the read id function before
	 * performing proceeding to any operation, including
	 * preparing the WriteBuffer
	 */
	Status = FlashReadID(OspiPsvInstancePtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/* Set Flash device and Controller modes */
	Status = FlashSetSDRDDRMode(OspiPsvInstancePtr, XOSPIPSV_EDGE_MODE_SDR_NON_PHY);
	if (Status != XST_SUCCESS)
		return XST_FAILURE;

	if(Flash_Config_Table[FCTIndex].FlashDeviceSize > SIXTEENMB) {
		Status = FlashEnterExit4BAddMode(OspiPsvInstancePtr, 1);
		if(Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
	}

	if (OspiPsvInstancePtr->Config.ConnectionMode == XOSPIPSV_CONNECTION_MODE_STACKED) {
		Flash_Config_Table[FCTIndex].NumPage *= 2;
		Flash_Config_Table[FCTIndex].NumSect *= 2;

		/* Reset the controller mode to NON-PHY */
		Status = XOspiPsv_SetSdrDdrMode(OspiPsvInstancePtr, XOSPIPSV_EDGE_MODE_SDR_NON_PHY);
		if (Status != XST_SUCCESS)
			return XST_FAILURE;

		Status = XOspiPsv_SelectFlash(OspiPsvInstancePtr, XOSPIPSV_SELECT_FLASH_CS1);
		if (Status != XST_SUCCESS)
			return XST_FAILURE;

		/* Set Flash device and Controller modes */
		Status = FlashSetSDRDDRMode(OspiPsvInstancePtr, XOSPIPSV_EDGE_MODE_SDR_NON_PHY);
		if (Status != XST_SUCCESS)
			return XST_FAILURE;

		if(Flash_Config_Table[FCTIndex].FlashDeviceSize > SIXTEENMB) {
			Status = FlashEnterExit4BAddMode(OspiPsvInstancePtr, 1);
			if(Status != XST_SUCCESS) {
				return XST_FAILURE;
			}
		}
	}

	MaxData = PAGE_COUNT * (Flash_Config_Table[FCTIndex].PageSize);

	for (UniqueValue = UNIQUE_VALUE, Count = 0;
		Count < Flash_Config_Table[FCTIndex].PageSize * PAGE_COUNT;
			Count++, UniqueValue++) {
		WriteBuffer[Count] = (u8)(UniqueValue + Test);

	}

	Status = FlashErase(OspiPsvInstancePtr, TEST_ADDRESS, MaxData, CmdBfr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	xil_printf("WriteCmd: 0x%x\n\r", (u8)Flash_Config_Table[FCTIndex].WriteCmd);
	for (Page = 0; Page < PAGE_COUNT; Page++) {
		Status = FlashIoWrite(OspiPsvInstancePtr,
		(Page * Flash_Config_Table[FCTIndex].PageSize) + TEST_ADDRESS,
		((Flash_Config_Table[FCTIndex].PageSize)), WriteBuffer);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
	}
	for (Count = 0; Count < ReadBfrSize; Count++) {
		ReadBuffer[Count] = 0;
	}

	Status = FlashRead(OspiPsvInstancePtr, TEST_ADDRESS, MaxData,
			CmdBfr, ReadBuffer);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Setup a pointer to the start of the data that was read into the read
	 * buffer and verify the data read is the data that was written
	 */
	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < MaxData;
	     Count++, UniqueValue++) {
		if (ReadBuffer[Count] != (u8)(UniqueValue + Test)) {
			return XST_FAILURE;
		}
	}

	if(Flash_Config_Table[FCTIndex].FlashDeviceSize > SIXTEENMB) {
		Status = FlashEnterExit4BAddMode(OspiPsvInstancePtr, 0);
		if(Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
	}

	OspiPsvDisableIntrSystem(IntcInstancePtr, OSPIPSV_INTR_ID);

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* The purpose of this function is to illustrate how to use the XOspiPsv
* device driver using OSPI flash devices greater than or equal to 128Mb.
* This function reads data in either DMA or DAC mode.
*
* @param        IntcInstancePtr is a pointer to the instance of the Intc device.
* @param        OspiPsvInstancePtr is a pointer to the instance of the Ospi device.
* @param        OspiPsvDeviceId is the Device ID of the Ospi Device and is the
*               XPAR_<OSPI_instance>_DEVICE_ID value from xparameters.h.
*
* @return	XST_SUCCESS if successful, else XST_FAILURE.
*
* @note		None.
*
*****************************************************************************/
The purpose of this function is to illustrate how to use the XOspiPsv
device driver using OSPI flash devices greater than or equal to 128Mb.
This function reads data in either DMA or DAC mode.
The purpose of this function is to illustrate how to use the XOspiPsv device driver using OSPI flash devices greater than or equal to 128Mb . This function reads data in either DMA or DAC mode .
int OspiPsvInterruptFlashExample(XScuGic *IntcInstancePtr,
				XOspiPsv *OspiPsvInstancePtr, u16 OspiPsvDeviceId)
{
	int Status;
	u8 UniqueValue;
	int Count;
	int Page = 0;
	XOspiPsv_Config *OspiPsvConfig;
	int ReadBfrSize;
	ReadBfrSize = (PAGE_COUNT * MAX_PAGE_SIZE);
	Status = XOspiPsv_DeviceReset(XOSPIPSV_HWPIN_RESET);
	if (Status != XST_SUCCESS)
		return XST_FAILURE;
	OspiPsvConfig = XOspiPsv_LookupConfig(OspiPsvDeviceId);
	if (NULL == OspiPsvConfig) {
		return XST_FAILURE;
	}
	Status = XOspiPsv_CfgInitialize(OspiPsvInstancePtr, OspiPsvConfig);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = OspiPsvSetupIntrSystem(IntcInstancePtr, OspiPsvInstancePtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XOspiPsv_SetStatusHandler(OspiPsvInstancePtr, OspiPsvInstancePtr,
					 (XOspiPsv_StatusHandler) OspiPsvHandler);
	XOspiPsv_SetOptions(OspiPsvInstancePtr, XOSPIPSV_IDAC_EN_OPTION);
	XOspiPsv_SetClkPrescaler(OspiPsvInstancePtr, XOSPIPSV_CLK_PRESCALE_12);
	Status = XOspiPsv_SelectFlash(OspiPsvInstancePtr, XOSPIPSV_SELECT_FLASH_CS0);
	if (Status != XST_SUCCESS)
		return XST_FAILURE;
	Status = FlashReadID(OspiPsvInstancePtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = FlashSetSDRDDRMode(OspiPsvInstancePtr, XOSPIPSV_EDGE_MODE_SDR_NON_PHY);
	if (Status != XST_SUCCESS)
		return XST_FAILURE;
	if(Flash_Config_Table[FCTIndex].FlashDeviceSize > SIXTEENMB) {
		Status = FlashEnterExit4BAddMode(OspiPsvInstancePtr, 1);
		if(Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
	}
	if (OspiPsvInstancePtr->Config.ConnectionMode == XOSPIPSV_CONNECTION_MODE_STACKED) {
		Flash_Config_Table[FCTIndex].NumPage *= 2;
		Flash_Config_Table[FCTIndex].NumSect *= 2;
		Status = XOspiPsv_SetSdrDdrMode(OspiPsvInstancePtr, XOSPIPSV_EDGE_MODE_SDR_NON_PHY);
		if (Status != XST_SUCCESS)
			return XST_FAILURE;
		Status = XOspiPsv_SelectFlash(OspiPsvInstancePtr, XOSPIPSV_SELECT_FLASH_CS1);
		if (Status != XST_SUCCESS)
			return XST_FAILURE;
		Status = FlashSetSDRDDRMode(OspiPsvInstancePtr, XOSPIPSV_EDGE_MODE_SDR_NON_PHY);
		if (Status != XST_SUCCESS)
			return XST_FAILURE;
		if(Flash_Config_Table[FCTIndex].FlashDeviceSize > SIXTEENMB) {
			Status = FlashEnterExit4BAddMode(OspiPsvInstancePtr, 1);
			if(Status != XST_SUCCESS) {
				return XST_FAILURE;
			}
		}
	}
	MaxData = PAGE_COUNT * (Flash_Config_Table[FCTIndex].PageSize);
	for (UniqueValue = UNIQUE_VALUE, Count = 0;
		Count < Flash_Config_Table[FCTIndex].PageSize * PAGE_COUNT;
			Count++, UniqueValue++) {
		WriteBuffer[Count] = (u8)(UniqueValue + Test);
	}
	Status = FlashErase(OspiPsvInstancePtr, TEST_ADDRESS, MaxData, CmdBfr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	xil_printf("WriteCmd: 0x%x\n\r", (u8)Flash_Config_Table[FCTIndex].WriteCmd);
	for (Page = 0; Page < PAGE_COUNT; Page++) {
		Status = FlashIoWrite(OspiPsvInstancePtr,
		(Page * Flash_Config_Table[FCTIndex].PageSize) + TEST_ADDRESS,
		((Flash_Config_Table[FCTIndex].PageSize)), WriteBuffer);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
	}
	for (Count = 0; Count < ReadBfrSize; Count++) {
		ReadBuffer[Count] = 0;
	}
	Status = FlashRead(OspiPsvInstancePtr, TEST_ADDRESS, MaxData,
			CmdBfr, ReadBuffer);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < MaxData;
	     Count++, UniqueValue++) {
		if (ReadBuffer[Count] != (u8)(UniqueValue + Test)) {
			return XST_FAILURE;
		}
	}
	if(Flash_Config_Table[FCTIndex].FlashDeviceSize > SIXTEENMB) {
		Status = FlashEnterExit4BAddMode(OspiPsvInstancePtr, 0);
		if(Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
	}
	OspiPsvDisableIntrSystem(IntcInstancePtr, OSPIPSV_INTR_ID);
	return XST_SUCCESS;
}
int OspiPsvInterruptFlashExample ( XScuGic * IntcInstancePtr , XOspiPsv * OspiPsvInstancePtr , u16 OspiPsvDeviceId ) { int Status ; u8 UniqueValue ; int Count ; int Page = 0 ; XOspiPsv_Config * OspiPsvConfig ; int ReadBfrSize ; ReadBfrSize = ( PAGE_COUNT * MAX_PAGE_SIZE ) ; Status = XOspiPsv_DeviceReset ( XOSPIPSV_HWPIN_RESET ) ; if ( Status != XST_SUCCESS ) return XST_FAILURE ; OspiPsvConfig = XOspiPsv_LookupConfig ( OspiPsvDeviceId ) ; if ( NULL == OspiPsvConfig ) { return XST_FAILURE ; } Status = XOspiPsv_CfgInitialize ( OspiPsvInstancePtr , OspiPsvConfig ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = OspiPsvSetupIntrSystem ( IntcInstancePtr , OspiPsvInstancePtr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XOspiPsv_SetStatusHandler ( OspiPsvInstancePtr , OspiPsvInstancePtr , ( XOspiPsv_StatusHandler ) OspiPsvHandler ) ; XOspiPsv_SetOptions ( OspiPsvInstancePtr , XOSPIPSV_IDAC_EN_OPTION ) ; XOspiPsv_SetClkPrescaler ( OspiPsvInstancePtr , XOSPIPSV_CLK_PRESCALE_12 ) ; Status = XOspiPsv_SelectFlash ( OspiPsvInstancePtr , XOSPIPSV_SELECT_FLASH_CS0 ) ; if ( Status != XST_SUCCESS ) return XST_FAILURE ; Status = FlashReadID ( OspiPsvInstancePtr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = FlashSetSDRDDRMode ( OspiPsvInstancePtr , XOSPIPSV_EDGE_MODE_SDR_NON_PHY ) ; if ( Status != XST_SUCCESS ) return XST_FAILURE ; if ( Flash_Config_Table [ FCTIndex ] . FlashDeviceSize > SIXTEENMB ) { Status = FlashEnterExit4BAddMode ( OspiPsvInstancePtr , 1 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } } if ( OspiPsvInstancePtr -> Config . ConnectionMode == XOSPIPSV_CONNECTION_MODE_STACKED ) { Flash_Config_Table [ FCTIndex ] . NumPage *= 2 ; Flash_Config_Table [ FCTIndex ] . NumSect *= 2 ; Status = XOspiPsv_SetSdrDdrMode ( OspiPsvInstancePtr , XOSPIPSV_EDGE_MODE_SDR_NON_PHY ) ; if ( Status != XST_SUCCESS ) return XST_FAILURE ; Status = XOspiPsv_SelectFlash ( OspiPsvInstancePtr , XOSPIPSV_SELECT_FLASH_CS1 ) ; if ( Status != XST_SUCCESS ) return XST_FAILURE ; Status = FlashSetSDRDDRMode ( OspiPsvInstancePtr , XOSPIPSV_EDGE_MODE_SDR_NON_PHY ) ; if ( Status != XST_SUCCESS ) return XST_FAILURE ; if ( Flash_Config_Table [ FCTIndex ] . FlashDeviceSize > SIXTEENMB ) { Status = FlashEnterExit4BAddMode ( OspiPsvInstancePtr , 1 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } } } MaxData = PAGE_COUNT * ( Flash_Config_Table [ FCTIndex ] . PageSize ) ; for ( UniqueValue = UNIQUE_VALUE , Count = 0 ; Count < Flash_Config_Table [ FCTIndex ] . PageSize * PAGE_COUNT ; Count ++ , UniqueValue ++ ) { WriteBuffer [ Count ] = ( u8 ) ( UniqueValue + Test ) ; } Status = FlashErase ( OspiPsvInstancePtr , TEST_ADDRESS , MaxData , CmdBfr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } xil_printf ( " \n \r " , ( u8 ) Flash_Config_Table [ FCTIndex ] . WriteCmd ) ; for ( Page = 0 ; Page < PAGE_COUNT ; Page ++ ) { Status = FlashIoWrite ( OspiPsvInstancePtr , ( Page * Flash_Config_Table [ FCTIndex ] . PageSize ) + TEST_ADDRESS , ( ( Flash_Config_Table [ FCTIndex ] . PageSize ) ) , WriteBuffer ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } } for ( Count = 0 ; Count < ReadBfrSize ; Count ++ ) { ReadBuffer [ Count ] = 0 ; } Status = FlashRead ( OspiPsvInstancePtr , TEST_ADDRESS , MaxData , CmdBfr , ReadBuffer ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } for ( UniqueValue = UNIQUE_VALUE , Count = 0 ; Count < MaxData ; Count ++ , UniqueValue ++ ) { if ( ReadBuffer [ Count ] != ( u8 ) ( UniqueValue + Test ) ) { return XST_FAILURE ; } } if ( Flash_Config_Table [ FCTIndex ] . FlashDeviceSize > SIXTEENMB ) { Status = FlashEnterExit4BAddMode ( OspiPsvInstancePtr , 0 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } } OspiPsvDisableIntrSystem ( IntcInstancePtr , OSPIPSV_INTR_ID ) ; return XST_SUCCESS ; }
The purpose of this function is to illustrate how to use the XOspiPsv
device driver using OSPI flash devices greater than or equal to 128Mb.
The purpose of this function is to illustrate how to use the XOspiPsv device driver using OSPI flash devices greater than or equal to 128Mb .
/*
	 * Initialize the OSPIPSV driver so that it's ready to use
	 */ /* To test, change connection mode here if not obtained from HDF */ /*
	 * Enable IDAC controller in OSPI
	 */ /*
	 * Set the prescaler for OSPIPSV clock
	 */ /*
	 * Read flash ID and obtain all flash related information
	 * It is important to call the read id function before
	 * performing proceeding to any operation, including
	 * preparing the WriteBuffer
	 */ /* Set Flash device and Controller modes */ /* Reset the controller mode to NON-PHY */ /* Set Flash device and Controller modes */ /*
	 * Setup a pointer to the start of the data that was read into the read
	 * buffer and verify the data read is the data that was written
	 */