/****************************************************************************** * * Copyright (C) 2013 - 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 xllfifo_interrupt_example.c * This file demonstrates how to use the Streaming fifo driver on the xilinx AXI * Streaming FIFO IP.The AXI4-Stream FIFO core allows memory mapped access to a * AXI-Stream interface. The core can be used to interface to AXI Streaming IPs * similar to the LogiCORE IP AXI Ethernet core, without having to use full DMA * solution. * * This is the interrupt example for the FIFO it assumes that at the * h/w level FIFO is connected in loopback.In these we write known amount of * data to the FIFO and wait for interrupts and after compltely receiving the * data compares it with the data transmitted. * * Note: The TDEST Must be enabled in the H/W design inorder to get * correct RDR value. * *
 * MODIFICATION HISTORY:
 *
 * Ver   Who  Date     Changes
 * ----- ---- -------- -------------------------------------------------------
 * 3.00a adk 08/10/2013 initial release CR:727787
 *
 * 
* * *************************************************************************** */ /***************************** Include Files *********************************/ #include "xparameters.h" #include "xil_exception.h" #include "xstreamer.h" #include "xil_cache.h" #include "xllfifo.h" #include "xstatus.h" #ifdef XPAR_UARTNS550_0_BASEADDR #include "xuartns550_l.h" /* to use uartns550 */ #endif #ifdef XPAR_INTC_0_DEVICE_ID #include "xintc.h" #else #include "xscugic.h" #endif /**************************** Type Definitions *******************************/ /***************** Macros (Inline Functions) Definitions *********************/ #define FIFO_DEV_ID XPAR_AXI_FIFO_0_DEVICE_ID #ifdef XPAR_INTC_0_DEVICE_ID #define INTC_DEVICE_ID XPAR_INTC_0_DEVICE_ID #define FIFO_INTR_ID XPAR_INTC_0_LLFIFO_0_VEC_ID #else #define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID #define FIFO_INTR_ID XPAR_FABRIC_LLFIFO_0_VEC_ID #endif #ifdef XPAR_INTC_0_DEVICE_ID #define INTC XIntc #define INTC_HANDLER XIntc_InterruptHandler #else #define INTC XScuGic #define INTC_HANDLER XScuGic_InterruptHandler #endif #define WORD_SIZE 4 /* Size of words in bytes */ #define MAX_PACKET_LEN 4 #define NO_OF_PACKETS 64 #define MAX_DATA_BUFFER_SIZE NO_OF_PACKETS*MAX_PACKET_LEN #undef DEBUG /************************** Function Prototypes ******************************/ #ifdef XPAR_UARTNS550_0_BASEADDR static void Uart550_Setup(void); #endif int XLlFifoInterruptExample(XLlFifo *InstancePtr, u16 DeviceId); int TxSend(XLlFifo *InstancePtr, u32 *SourceAddr); static void FifoHandler(XLlFifo *Fifo); static void FifoRecvHandler(XLlFifo *Fifo); static void FifoSendHandler(XLlFifo *Fifo); static void FifoErrorHandler(XLlFifo *InstancePtr, u32 Pending); int SetupInterruptSystem(INTC *IntcInstancePtr, XLlFifo *InstancePtr, u16 FifoIntrId); static void DisableIntrSystem(INTC *IntcInstancePtr, u16 FifoIntrId); /* * Flags interrupt handlers use to notify the application context the events. */ volatile int Done; volatile int Error; /************************** Variable Definitions *****************************/ /* * Device instance definitions */ XLlFifo FifoInstance; /* * Instance of the Interrupt Controller */ static INTC Intc; u32 SourceBuffer[MAX_DATA_BUFFER_SIZE * WORD_SIZE]; u32 DestinationBuffer[MAX_DATA_BUFFER_SIZE * WORD_SIZE]; /*****************************************************************************/ /** * * Main function * * This function is the main entry of the AXI FIFO interrupt test. * * @param None * * @return - XST_SUCCESS if tests pass * - XST_FAILURE if fails. * * @note None * ******************************************************************************/ int main() { int Status; xil_printf("--- Entering main() ---\n\r"); Status = XLlFifoInterruptExample(&FifoInstance, FIFO_DEV_ID); if (Status != XST_SUCCESS) { xil_printf("Axi Streaming FIFO Interrupt Example Test Failed"); xil_printf("--- Exiting main() ---\n\r"); return XST_FAILURE; } xil_printf("Axi Streaming FIFO Interrupt Example Test passed\n\r"); xil_printf("--- Exiting main() ---\n\r"); return XST_SUCCESS; } /*****************************************************************************/ /** * * This function demonstrates the usage of AXI FIFO * It does the following: * - Set up the output terminal if UART16550 is in the hardware build * - Initialize the Axi FIFO Device. * - Set up the interrupt handler for fifo * - Transmit the data * - Compare the data * - Return the result * * @param InstancePtr is a pointer to the instance of the * XLlFifo instance. * @param DeviceId is Device ID of the Axi Fifo Deive instance, * typically XPAR__DEVICE_ID value from * xparameters.h. * * @return -XST_SUCCESS to indicate success * -XST_FAILURE to indicate failure * ******************************************************************************/ int XLlFifoInterruptExample(XLlFifo *InstancePtr, u16 DeviceId) { XLlFifo_Config *Config; int Status; int i; int err; Status = XST_SUCCESS; /* Initial setup for Uart16550 */ #ifdef XPAR_UARTNS550_0_BASEADDR Uart550_Setup(); #endif /* Initialize the Device Configuration Interface driver */ Config = XLlFfio_LookupConfig(DeviceId); if (!Config) { xil_printf("No config found for %d\r\n", DeviceId); return XST_FAILURE; } /* * This is where the virtual address would be used, this example * uses physical address. */ Status = XLlFifo_CfgInitialize(InstancePtr, Config, Config->BaseAddress); if (Status != XST_SUCCESS) { xil_printf("Initialization failed\n\r"); return Status; } /* Check for the Reset value */ Status = XLlFifo_Status(InstancePtr); XLlFifo_IntClear(InstancePtr,0xffffffff); Status = XLlFifo_Status(InstancePtr); if(Status != 0x0) { xil_printf("\n ERROR : Reset value of ISR0 : 0x%x\t" "Expected : 0x0\n\r", XLlFifo_Status(InstancePtr)); return XST_FAILURE; } /* * Connect the Axi Streaming FIFO to the interrupt subsystem such * that interrupts can occur. This function is application specific. */ Status = SetupInterruptSystem(&Intc, InstancePtr, FIFO_INTR_ID); if (Status != XST_SUCCESS) { xil_printf("Failed intr setup\r\n"); return XST_FAILURE; } XLlFifo_IntEnable(InstancePtr, XLLF_INT_ALL_MASK); Done = 0; /* Transmit the Data Stream */ Status = TxSend(InstancePtr, SourceBuffer); if (Status != XST_SUCCESS){ xil_printf("Transmission of Data failed\n\r"); return XST_FAILURE; } while(!Done); /* Check for errors */ if(Error) { xil_printf("Errors in the FIFO\n\r"); return XST_FAILURE; } err = 0; /* Compare the data sent with the data received */ xil_printf("Comparing data...\n\r"); for( i=0 ; iCpuBaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } XScuGic_SetPriorityTriggerType(IntcInstancePtr, FifoIntrId, 0xA0, 0x3); /* * Connect the device driver handler that will be called when an * interrupt for the device occurs, the handler defined above performs * the specific interrupt processing for the device. */ Status = XScuGic_Connect(IntcInstancePtr, FifoIntrId, (Xil_InterruptHandler)FifoHandler, InstancePtr); if (Status != XST_SUCCESS) { return Status; } XScuGic_Enable(IntcInstancePtr, FifoIntrId); #endif /* * Initialize the exception table. */ Xil_ExceptionInit(); /* * Register the interrupt controller handler with the exception table. */ Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)INTC_HANDLER, (void *)IntcInstancePtr);; /* * Enable exceptions. */ Xil_ExceptionEnable(); return XST_SUCCESS; } /*****************************************************************************/ /** * * This function disables the interrupts for the AXI FIFO device. * * @param IntcInstancePtr is the pointer to the INTC component instance * @param FifoIntrId is interrupt ID associated for the FIFO component * * @return None * * @note None * ******************************************************************************/ static void DisableIntrSystem(INTC *IntcInstancePtr, u16 FifoIntrId) { #ifdef XPAR_INTC_0_DEVICE_ID /* Disconnect the interrupts */ XIntc_Disconnect(IntcInstancePtr, FifoIntrId); #else XScuGic_Disconnect(IntcInstancePtr, FifoIntrId); #endif } #ifdef XPAR_UARTNS550_0_BASEADDR /*****************************************************************************/ /* * * Uart16550 setup routine, need to set baudrate to 9600 and data bits to 8 * * @param None * * @return None * * @note None * ******************************************************************************/ static void Uart550_Setup(void) { XUartNs550_SetBaud(XPAR_UARTNS550_0_BASEADDR, XPAR_XUARTNS550_CLOCK_HZ, 9600); XUartNs550_SetLineControlReg(XPAR_UARTNS550_0_BASEADDR, XUN_LCR_8_DATA_BITS); } #endif