XilinxProcessorIPLib/drivers/spi/examples/xspi_polled_example.c
int SpiPolledExample(XSpi *SpiInstancePtr, u16 SpiDeviceId)
{
	int Status;
	u32 Count;
	u8 Test;
	XSpi_Config *ConfigPtr;	/* Pointer to Configuration data */

	/*
	 * Initialize the SPI driver so that it is  ready to use.
	 */
	ConfigPtr = XSpi_LookupConfig(SpiDeviceId);
	if (ConfigPtr == NULL) {
		return XST_DEVICE_NOT_FOUND;
	}

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

	/*
	 * Perform a self-test to ensure that the hardware was built correctly.
	 */
	Status = XSpi_SelfTest(SpiInstancePtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Run loopback test only in case of standard SPI mode.
	 */
	if (SpiInstancePtr->SpiMode != XSP_STANDARD_MODE) {
		return XST_SUCCESS;
	}

	/*
	 * Set the Spi device as a master and in loopback mode.
	 */
	Status = XSpi_SetOptions(SpiInstancePtr, XSP_MASTER_OPTION |
 					XSP_LOOPBACK_OPTION);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}


	/*
	 * Start the SPI driver so that the device is enabled.
	 */
	XSpi_Start(SpiInstancePtr);

	/*
	 * Disable Global interrupt to use polled mode operation
	 */
	XSpi_IntrGlobalDisable(SpiInstancePtr);

	/*
	 * Initialize the write buffer with pattern to write, initialize 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.
	 */
	Test = 0x10;
	for (Count = 0; Count < BUFFER_SIZE; Count++) {
		WriteBuffer[Count] = (u8)(Count + Test);
		ReadBuffer[Count] = 0;
	}


	/*
	 * Transmit the data.
	 */
	XSpi_Transfer(SpiInstancePtr, WriteBuffer, ReadBuffer, BUFFER_SIZE);

	/*
	 * Compare the data received with the data that was transmitted.
	 */
	for (Count = 0; Count < BUFFER_SIZE; Count++) {
		if (WriteBuffer[Count] != ReadBuffer[Count]) {
			return XST_FAILURE;
		}
	}

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* This function does a minimal test on the Spi device and driver as a
* design example. The purpose of this function is to illustrate how to use
* the XSpi component using the polled mode.
*
* This function sends data and expects to receive the same data.
*
*
* @param	SpiInstancePtr is a pointer to the instance of Spi component.
* @param	SpiDeviceId is the Device ID of the Spi Device and is the
*		XPAR_<SPI_instance>_DEVICE_ID value from xparameters.h.
*
* @return	XST_SUCCESS if successful, otherwise XST_FAILURE.
*
* @note
*
* This function contains an infinite loop such that if the Spi device is not
* working it may never return.
*
******************************************************************************/
This function does a minimal test on the Spi device and driver as a
design example. The purpose of this function is to illustrate how to use
the XSpi component using the polled mode.

This function sends data and expects to receive the same data.
This function does a minimal test on the Spi device and driver as a design example . The purpose of this function is to illustrate how to use the XSpi component using the polled mode . This function sends data and expects to receive the same data .
int SpiPolledExample(XSpi *SpiInstancePtr, u16 SpiDeviceId)
{
	int Status;
	u32 Count;
	u8 Test;
	XSpi_Config *ConfigPtr;	
	ConfigPtr = XSpi_LookupConfig(SpiDeviceId);
	if (ConfigPtr == NULL) {
		return XST_DEVICE_NOT_FOUND;
	}
	Status = XSpi_CfgInitialize(SpiInstancePtr, ConfigPtr,
				  ConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = XSpi_SelfTest(SpiInstancePtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	if (SpiInstancePtr->SpiMode != XSP_STANDARD_MODE) {
		return XST_SUCCESS;
	}
	Status = XSpi_SetOptions(SpiInstancePtr, XSP_MASTER_OPTION |
 					XSP_LOOPBACK_OPTION);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XSpi_Start(SpiInstancePtr);
	XSpi_IntrGlobalDisable(SpiInstancePtr);
	Test = 0x10;
	for (Count = 0; Count < BUFFER_SIZE; Count++) {
		WriteBuffer[Count] = (u8)(Count + Test);
		ReadBuffer[Count] = 0;
	}
	XSpi_Transfer(SpiInstancePtr, WriteBuffer, ReadBuffer, BUFFER_SIZE);
	for (Count = 0; Count < BUFFER_SIZE; Count++) {
		if (WriteBuffer[Count] != ReadBuffer[Count]) {
			return XST_FAILURE;
		}
	}
	return XST_SUCCESS;
}
int SpiPolledExample ( XSpi * SpiInstancePtr , u16 SpiDeviceId ) { int Status ; u32 Count ; u8 Test ; XSpi_Config * ConfigPtr ; ConfigPtr = XSpi_LookupConfig ( SpiDeviceId ) ; if ( ConfigPtr == NULL ) { return XST_DEVICE_NOT_FOUND ; } Status = XSpi_CfgInitialize ( SpiInstancePtr , ConfigPtr , ConfigPtr -> BaseAddress ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XSpi_SelfTest ( SpiInstancePtr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } if ( SpiInstancePtr -> SpiMode != XSP_STANDARD_MODE ) { return XST_SUCCESS ; } Status = XSpi_SetOptions ( SpiInstancePtr , XSP_MASTER_OPTION | XSP_LOOPBACK_OPTION ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XSpi_Start ( SpiInstancePtr ) ; XSpi_IntrGlobalDisable ( SpiInstancePtr ) ; Test = 0x10 ; for ( Count = 0 ; Count < BUFFER_SIZE ; Count ++ ) { WriteBuffer [ Count ] = ( u8 ) ( Count + Test ) ; ReadBuffer [ Count ] = 0 ; } XSpi_Transfer ( SpiInstancePtr , WriteBuffer , ReadBuffer , BUFFER_SIZE ) ; for ( Count = 0 ; Count < BUFFER_SIZE ; Count ++ ) { if ( WriteBuffer [ Count ] != ReadBuffer [ Count ] ) { return XST_FAILURE ; } } return XST_SUCCESS ; }
This function does a minimal test on the Spi device and driver as a
design example.
This function does a minimal test on the Spi device and driver as a design example .
/* Pointer to Configuration data */ /*
	 * Initialize the SPI driver so that it is  ready to use.
	 */ /*
	 * Perform a self-test to ensure that the hardware was built correctly.
	 */ /*
	 * Run loopback test only in case of standard SPI mode.
	 */ /*
	 * Set the Spi device as a master and in loopback mode.
	 */ /*
	 * Start the SPI driver so that the device is enabled.
	 */ /*
	 * Disable Global interrupt to use polled mode operation
	 */ /*
	 * Initialize the write buffer with pattern to write, initialize 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.
	 */ /*
	 * Transmit the data.
	 */ /*
	 * Compare the data received with the data that was transmitted.
	 */