lib/sw_services/xilisf/examples/xilisf_qspips_stm_intr_example.c
int QspiFlashIntrExample(XScuGic *IntcInstancePtr, XQspiPs *QspiInstancePtr,
			 u16 QspiDeviceId, u16 QspiIntrId)
{
	int Status = XST_FAILURE;
	u8 *BufferPtr;
	u8 UniqueValue;
	int Count;
	int Page;
	XQspiPs_Config *ConfigPtr;	/* Pointer to Configuration ROM data */
	u32 Options;

	/*
	* Lookup the device configuration in the temporary CROM table. Use this
	* configuration info down below when initializing this component.
	*/
	ConfigPtr = XQspiPs_LookupConfig(QspiDeviceId);
	if (ConfigPtr == NULL) {
		return XST_DEVICE_NOT_FOUND;
	}

	Status = XQspiPs_CfgInitialize(QspiInstancePtr, ConfigPtr,
			ConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}


	/*
	* Set the QSPI options
	*/
	Options = XQSPIPS_FORCE_SSELECT_OPTION |
			XQSPIPS_MANUAL_START_OPTION |
			XQSPIPS_HOLD_B_DRIVE_OPTION;
	Status = XIsf_SetSpiConfiguration(&Isf, QspiInstancePtr,
			Options, XISF_SPI_PRESCALER);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}


	if(ConfigPtr->ConnectionMode == XQSPIPS_CONNECTION_MODE_STACKED) {
		/*
		 * Enable two flash memories, Shared bus (NOT separate bus),
		 * L_PAGE selected by default
		 */
		XQspiPs_SetLqspiConfigReg(QspiInstancePtr,
						DUAL_STACK_CONFIG_WRITE);
	}

	if(ConfigPtr->ConnectionMode == XQSPIPS_CONNECTION_MODE_PARALLEL) {
		/*
		 * Enable two flash memories on separate buses
		 */
		XQspiPs_SetLqspiConfigReg(QspiInstancePtr,
						DUAL_QSPI_CONFIG_WRITE);
	}


	/* Initialize the XILISF Library */
	XIsf_Initialize(&Isf, QspiInstancePtr, FLASH_QSPI_SELECT,
			IsfWriteBuffer);



	XIsf_SetTransferMode(&Isf, XISF_INTERRUPT_MODE);

	/*
	 * Connect the Qspi device to the interrupt subsystem such that
	 * interrupts can occur. This function is application specific
	 */
	Status = QspiSetupIntrSystem(IntcInstancePtr, QspiInstancePtr,
					QspiIntrId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Setup the handler for the QSPI that will be called from the
	 * interrupt context when an QSPI status occurs, specify a pointer to
	 * the QSPI driver instance as the callback reference so the handler is
	 * able to access the instance data
	 */
	XIsf_SetStatusHandler(&Isf, QspiInstancePtr,
				 (XQspiPs_StatusHandler) XilIsf_Handler);

	/*
	 * Initialize the write buffer for a pattern to write to the FLASH
	 * and the read buffer to zero so it can be verified after the read,
	 * the test value that is added to the unique value allows the value
	 * to be changed in a debug environment to guarantee
	 */
	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < PAGE_SIZE;
	     Count++, UniqueValue++) {
		WriteBuffer[Count] = (u8)(UniqueValue + Test);
	}
	memset(ReadBuffer, 0x00, sizeof(ReadBuffer));

	Status = FlashErase(&Isf, TEST_ADDRESS, MAX_DATA);
	if(Status != XST_SUCCESS){
		return XST_FAILURE;
	}

	/*
	 * Write the data in the write buffer to the serial FLASH a page at a
	 * time, starting from TEST_ADDRESS
	 */
	for (Page = 0; Page < PAGE_COUNT; Page++) {
		FlashWrite(&Isf, (Page * PAGE_SIZE) + TEST_ADDRESS,
			   PAGE_SIZE, XISF_WRITE);
	}

	/*
	 * Read the contents of the FLASH from TEST_ADDRESS, using Normal Read
	 * command
	 */
	FlashRead(&Isf, TEST_ADDRESS, MAX_DATA, XISF_READ);

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

	BufferPtr = ReadBuffer;

	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < MAX_DATA;
		Count++, UniqueValue++) {

		if (BufferPtr[Count] != (u8)(UniqueValue + Test)) {
			return XST_FAILURE;
		}
	}


	/*
	 * Read the contents of the FLASH from TEST_ADDRESS, using Fast Read
	 * command
	 */

	Status = FlashRead(&Isf, TEST_ADDRESS, MAX_DATA, XISF_FAST_READ);
	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
	 */

	BufferPtr = ReadBuffer;

	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < MAX_DATA;
	     Count++, UniqueValue++) {

		if (BufferPtr[Count] != (u8)(UniqueValue + Test)) {
			return XST_FAILURE;
		}
	}


	/*
	 * Read the contents of the FLASH from TEST_ADDRESS, using DUAL IO
	 * Fast Read command
	 */
	Status = FlashRead(&Isf, TEST_ADDRESS, MAX_DATA, XISF_DUAL_OP_FAST_READ);
	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
	 */

	BufferPtr = ReadBuffer;
	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < MAX_DATA;
			Count++, UniqueValue++) {

		if (BufferPtr[Count] != (u8)(UniqueValue + Test)) {
			return XST_FAILURE;
		}
	}


	/*
	 * Read the contents of the FLASH from TEST_ADDRESS, using QUAD OP
	 * Fast Read command
	 */
	Status = FlashRead(&Isf, TEST_ADDRESS, MAX_DATA, XISF_QUAD_OP_FAST_READ);
	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
	 */

	BufferPtr = ReadBuffer;
	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < MAX_DATA;
			Count++, UniqueValue++) {
		if (BufferPtr[Count] != (u8)(UniqueValue + Test)) {
			return XST_FAILURE;
		}
	}

	QspiDisableIntrSystem(IntcInstancePtr, QspiIntrId);

	return XST_SUCCESS;
}
/****************************************************************************/
/**
* The purpose of this function is to illustrate how to use the XQspiPs
* device driver in interrupt mode. This function writes and reads data
* from a serial FLASH.
*
* @param	IntcInstancePtr is the instance of the interrupt
* @param	QspiInstancePtr is the Pointer to the qspi driver instance
* @param	QspiDeviceId is the Device ID of qspi
* @param	QspiIntrId is the interrupt ID for QSPI driver
*
* @return	XST_SUCCESS if successful else XST_FAILURE.
*
* @note
*
* This function calls other functions which contain loops that may be infinite
* if interrupts are not working such that it may not return. If the device
* slave select is not correct and the device is not responding on bus it will
* read a status of 0xFF for the status register as the bus is pulled up.
*
*****************************************************************************/
The purpose of this function is to illustrate how to use the XQspiPs
device driver in interrupt mode. This function writes and reads data
from a serial FLASH.
The purpose of this function is to illustrate how to use the XQspiPs device driver in interrupt mode . This function writes and reads data from a serial FLASH .
int QspiFlashIntrExample(XScuGic *IntcInstancePtr, XQspiPs *QspiInstancePtr,
			 u16 QspiDeviceId, u16 QspiIntrId)
{
	int Status = XST_FAILURE;
	u8 *BufferPtr;
	u8 UniqueValue;
	int Count;
	int Page;
	XQspiPs_Config *ConfigPtr;	
	u32 Options;
	ConfigPtr = XQspiPs_LookupConfig(QspiDeviceId);
	if (ConfigPtr == NULL) {
		return XST_DEVICE_NOT_FOUND;
	}
	Status = XQspiPs_CfgInitialize(QspiInstancePtr, ConfigPtr,
			ConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Options = XQSPIPS_FORCE_SSELECT_OPTION |
			XQSPIPS_MANUAL_START_OPTION |
			XQSPIPS_HOLD_B_DRIVE_OPTION;
	Status = XIsf_SetSpiConfiguration(&Isf, QspiInstancePtr,
			Options, XISF_SPI_PRESCALER);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	if(ConfigPtr->ConnectionMode == XQSPIPS_CONNECTION_MODE_STACKED) {
		XQspiPs_SetLqspiConfigReg(QspiInstancePtr,
						DUAL_STACK_CONFIG_WRITE);
	}
	if(ConfigPtr->ConnectionMode == XQSPIPS_CONNECTION_MODE_PARALLEL) {
		XQspiPs_SetLqspiConfigReg(QspiInstancePtr,
						DUAL_QSPI_CONFIG_WRITE);
	}
	XIsf_Initialize(&Isf, QspiInstancePtr, FLASH_QSPI_SELECT,
			IsfWriteBuffer);
	XIsf_SetTransferMode(&Isf, XISF_INTERRUPT_MODE);
	Status = QspiSetupIntrSystem(IntcInstancePtr, QspiInstancePtr,
					QspiIntrId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XIsf_SetStatusHandler(&Isf, QspiInstancePtr,
				 (XQspiPs_StatusHandler) XilIsf_Handler);
	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < PAGE_SIZE;
	     Count++, UniqueValue++) {
		WriteBuffer[Count] = (u8)(UniqueValue + Test);
	}
	memset(ReadBuffer, 0x00, sizeof(ReadBuffer));
	Status = FlashErase(&Isf, TEST_ADDRESS, MAX_DATA);
	if(Status != XST_SUCCESS){
		return XST_FAILURE;
	}
	for (Page = 0; Page < PAGE_COUNT; Page++) {
		FlashWrite(&Isf, (Page * PAGE_SIZE) + TEST_ADDRESS,
			   PAGE_SIZE, XISF_WRITE);
	}
	FlashRead(&Isf, TEST_ADDRESS, MAX_DATA, XISF_READ);
	BufferPtr = ReadBuffer;
	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < MAX_DATA;
		Count++, UniqueValue++) {
		if (BufferPtr[Count] != (u8)(UniqueValue + Test)) {
			return XST_FAILURE;
		}
	}
	Status = FlashRead(&Isf, TEST_ADDRESS, MAX_DATA, XISF_FAST_READ);
	if(Status != XST_SUCCESS){
		return XST_FAILURE;
	}
	BufferPtr = ReadBuffer;
	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < MAX_DATA;
	     Count++, UniqueValue++) {
		if (BufferPtr[Count] != (u8)(UniqueValue + Test)) {
			return XST_FAILURE;
		}
	}
	Status = FlashRead(&Isf, TEST_ADDRESS, MAX_DATA, XISF_DUAL_OP_FAST_READ);
	if(Status != XST_SUCCESS){
		return XST_FAILURE;
	}
	BufferPtr = ReadBuffer;
	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < MAX_DATA;
			Count++, UniqueValue++) {
		if (BufferPtr[Count] != (u8)(UniqueValue + Test)) {
			return XST_FAILURE;
		}
	}
	Status = FlashRead(&Isf, TEST_ADDRESS, MAX_DATA, XISF_QUAD_OP_FAST_READ);
	if(Status != XST_SUCCESS){
		return XST_FAILURE;
	}
	BufferPtr = ReadBuffer;
	for (UniqueValue = UNIQUE_VALUE, Count = 0; Count < MAX_DATA;
			Count++, UniqueValue++) {
		if (BufferPtr[Count] != (u8)(UniqueValue + Test)) {
			return XST_FAILURE;
		}
	}
	QspiDisableIntrSystem(IntcInstancePtr, QspiIntrId);
	return XST_SUCCESS;
}
int QspiFlashIntrExample ( XScuGic * IntcInstancePtr , XQspiPs * QspiInstancePtr , u16 QspiDeviceId , u16 QspiIntrId ) { int Status = XST_FAILURE ; u8 * BufferPtr ; u8 UniqueValue ; int Count ; int Page ; XQspiPs_Config * ConfigPtr ; u32 Options ; ConfigPtr = XQspiPs_LookupConfig ( QspiDeviceId ) ; if ( ConfigPtr == NULL ) { return XST_DEVICE_NOT_FOUND ; } Status = XQspiPs_CfgInitialize ( QspiInstancePtr , ConfigPtr , ConfigPtr -> BaseAddress ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Options = XQSPIPS_FORCE_SSELECT_OPTION | XQSPIPS_MANUAL_START_OPTION | XQSPIPS_HOLD_B_DRIVE_OPTION ; Status = XIsf_SetSpiConfiguration ( & Isf , QspiInstancePtr , Options , XISF_SPI_PRESCALER ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } if ( ConfigPtr -> ConnectionMode == XQSPIPS_CONNECTION_MODE_STACKED ) { XQspiPs_SetLqspiConfigReg ( QspiInstancePtr , DUAL_STACK_CONFIG_WRITE ) ; } if ( ConfigPtr -> ConnectionMode == XQSPIPS_CONNECTION_MODE_PARALLEL ) { XQspiPs_SetLqspiConfigReg ( QspiInstancePtr , DUAL_QSPI_CONFIG_WRITE ) ; } XIsf_Initialize ( & Isf , QspiInstancePtr , FLASH_QSPI_SELECT , IsfWriteBuffer ) ; XIsf_SetTransferMode ( & Isf , XISF_INTERRUPT_MODE ) ; Status = QspiSetupIntrSystem ( IntcInstancePtr , QspiInstancePtr , QspiIntrId ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XIsf_SetStatusHandler ( & Isf , QspiInstancePtr , ( XQspiPs_StatusHandler ) XilIsf_Handler ) ; for ( UniqueValue = UNIQUE_VALUE , Count = 0 ; Count < PAGE_SIZE ; Count ++ , UniqueValue ++ ) { WriteBuffer [ Count ] = ( u8 ) ( UniqueValue + Test ) ; } memset ( ReadBuffer , 0x00 , sizeof ( ReadBuffer ) ) ; Status = FlashErase ( & Isf , TEST_ADDRESS , MAX_DATA ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } for ( Page = 0 ; Page < PAGE_COUNT ; Page ++ ) { FlashWrite ( & Isf , ( Page * PAGE_SIZE ) + TEST_ADDRESS , PAGE_SIZE , XISF_WRITE ) ; } FlashRead ( & Isf , TEST_ADDRESS , MAX_DATA , XISF_READ ) ; BufferPtr = ReadBuffer ; for ( UniqueValue = UNIQUE_VALUE , Count = 0 ; Count < MAX_DATA ; Count ++ , UniqueValue ++ ) { if ( BufferPtr [ Count ] != ( u8 ) ( UniqueValue + Test ) ) { return XST_FAILURE ; } } Status = FlashRead ( & Isf , TEST_ADDRESS , MAX_DATA , XISF_FAST_READ ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } BufferPtr = ReadBuffer ; for ( UniqueValue = UNIQUE_VALUE , Count = 0 ; Count < MAX_DATA ; Count ++ , UniqueValue ++ ) { if ( BufferPtr [ Count ] != ( u8 ) ( UniqueValue + Test ) ) { return XST_FAILURE ; } } Status = FlashRead ( & Isf , TEST_ADDRESS , MAX_DATA , XISF_DUAL_OP_FAST_READ ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } BufferPtr = ReadBuffer ; for ( UniqueValue = UNIQUE_VALUE , Count = 0 ; Count < MAX_DATA ; Count ++ , UniqueValue ++ ) { if ( BufferPtr [ Count ] != ( u8 ) ( UniqueValue + Test ) ) { return XST_FAILURE ; } } Status = FlashRead ( & Isf , TEST_ADDRESS , MAX_DATA , XISF_QUAD_OP_FAST_READ ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } BufferPtr = ReadBuffer ; for ( UniqueValue = UNIQUE_VALUE , Count = 0 ; Count < MAX_DATA ; Count ++ , UniqueValue ++ ) { if ( BufferPtr [ Count ] != ( u8 ) ( UniqueValue + Test ) ) { return XST_FAILURE ; } } QspiDisableIntrSystem ( IntcInstancePtr , QspiIntrId ) ; return XST_SUCCESS ; }
The purpose of this function is to illustrate how to use the XQspiPs
device driver in interrupt mode.
The purpose of this function is to illustrate how to use the XQspiPs device driver in interrupt mode .
/* Pointer to Configuration ROM data */ /*
	* Lookup the device configuration in the temporary CROM table. Use this
	* configuration info down below when initializing this component.
	*/ /*
	* Set the QSPI options
	*/ /*
		 * Enable two flash memories, Shared bus (NOT separate bus),
		 * L_PAGE selected by default
		 */ /*
		 * Enable two flash memories on separate buses
		 */ /* Initialize the XILISF Library */ /*
	 * Connect the Qspi device to the interrupt subsystem such that
	 * interrupts can occur. This function is application specific
	 */ /*
	 * Setup the handler for the QSPI that will be called from the
	 * interrupt context when an QSPI status occurs, specify a pointer to
	 * the QSPI driver instance as the callback reference so the handler is
	 * able to access the instance data
	 */ /*
	 * Initialize the write buffer for a pattern to write to the FLASH
	 * and the read buffer to zero so it can be verified after the read,
	 * the test value that is added to the unique value allows the value
	 * to be changed in a debug environment to guarantee
	 */ /*
	 * Write the data in the write buffer to the serial FLASH a page at a
	 * time, starting from TEST_ADDRESS
	 */ /*
	 * Read the contents of the FLASH from TEST_ADDRESS, using Normal Read
	 * command
	 */ /*
	 * 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
	 */ /*
	 * Read the contents of the FLASH from TEST_ADDRESS, using Fast Read
	 * command
	 */ /*
	 * 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
	 */ /*
	 * Read the contents of the FLASH from TEST_ADDRESS, using DUAL IO
	 * Fast Read command
	 */ /*
	 * 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
	 */ /*
	 * Read the contents of the FLASH from TEST_ADDRESS, using QUAD OP
	 * Fast Read command
	 */ /*
	 * 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
	 */