/****************************************************************************** * * Copyright (C) 2008 - 2014 Xilinx, Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * Use of the Software is limited solely to applications: * (a) running on a Xilinx device, or * (b) that interact with a Xilinx device through a bus or interconnect. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Except as contained in this notice, the name of the Xilinx shall not be used * in advertising or otherwise to promote the sale, use or other dealings in * this Software without prior written authorization from Xilinx. * ******************************************************************************/ /*****************************************************************************/ /** * @file xspi_polled_example.c * * * This file contains a design example using the Spi driver (XSpi) and the Spi * device using the polled mode. * * To put the driver in polled mode the Global Interrupt must be disabled after * the Spi is Initialized and Spi driver is started. * * This example works with a PPC/MicroBlaze processor. * * @note * * None. * *
* MODIFICATION HISTORY: * * Ver Who Date Changes * ----- ---- -------- --------------------------------------------------------- * 1.00a sdm 03/03/08 First Release * 3.00a ktn 10/28/09 Converted all register accesses to 32 bit access. * Updated to use the HAL APIs/macros. Replaced call to * XSpi_Initialize API with XSpi_LookupConfig and * XSpi_CfgInitialize. * 3.02a sdm 05/04/11 Updated to run the loopback test only in standard spi * mode. *******************************************************************************/ /***************************** Include Files *********************************/ #include "xparameters.h" /* XPAR parameters */ #include "xspi.h" /* SPI device driver */ #include "xspi_l.h" /************************** Constant Definitions *****************************/ /* * The following constants map to the XPAR parameters created in the * xparameters.h file. They are defined here such that a user can easily * change all the needed parameters in one place. */ #define SPI_DEVICE_ID XPAR_SPI_0_DEVICE_ID /* * This is the size of the buffer to be transmitted/received in this example. */ #define BUFFER_SIZE 12 /**************************** Type Definitions *******************************/ /* * The following data type is used to send and receive data on the SPI * interface. */ typedef u8 DataBuffer[BUFFER_SIZE]; /***************** Macros (Inline Functions) Definitions *********************/ /************************** Function Prototypes ******************************/ int SpiPolledExample(XSpi *SpiInstancePtr, u16 SpiDeviceId); /************************** Variable Definitions *****************************/ /* * The instances to support the device drivers are global such that the * are initialized to zero each time the program runs. */ static XSpi SpiInstance; /* The instance of the SPI device */ /* * The following variables are used to read and write to the Spi device, they * are global to avoid having large buffers on the stack. */ u8 ReadBuffer[BUFFER_SIZE]; u8 WriteBuffer[BUFFER_SIZE]; /*****************************************************************************/ /** * * Main function to call the Spi Polled example. * * @param None * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note None * ******************************************************************************/ int main(void) { int Status; /* * Run the Spi Polled example. */ Status = SpiPolledExample(&SpiInstance, SPI_DEVICE_ID); if (Status != XST_SUCCESS) { 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_