1 /******************************************************************************
3 * Copyright (C) 2014 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /*****************************************************************************/
37 * This file contains interrupt related functions of Xilinx ZDMA core.
38 * Please see xzdma.h for more details of the driver.
41 * MODIFICATION HISTORY:
43 * Ver Who Date Changes
44 * ----- ------ -------- ------------------------------------------------------
45 * 1.0 vns 2/27/15 First release
48 ******************************************************************************/
50 /***************************** Include Files *********************************/
54 /***************** Macros (Inline Functions) Definitions *********************/
57 /**************************** Type Definitions *******************************/
60 /************************** Function Prototypes ******************************/
63 /************************** Variable Definitions *****************************/
66 /************************** Function Definitions *****************************/
69 /*****************************************************************************/
72 * This function is the interrupt handler for the ZDMA core.
74 * This handler reads the pending interrupt from Status register, determines the
75 * source of the interrupts and calls the respective callbacks for the
76 * interrupts that are enabled in IRQ_ENABLE register, and finally clears the
79 * The application is responsible for connecting this function to the interrupt
80 * system. Application beyond this driver is also responsible for providing
81 * callbacks to handle interrupts and installing the callbacks using
82 * XZDma_SetCallBack() during initialization phase. .
84 * @param Instance is a pointer to the XZDma instance to be worked on.
88 * @note To generate interrupt required interrupts should be enabled.
90 ******************************************************************************/
91 void XZDma_IntrHandler(void *Instance)
95 XZDma *InstancePtr = NULL;
96 InstancePtr = (XZDma *)((void *)Instance);
98 /* Verify arguments. */
99 Xil_AssertVoid(InstancePtr != NULL);
101 /* Get pending interrupts */
102 PendingIntr = (u32)(XZDma_IntrGetStatus(InstancePtr));
103 PendingIntr &= (~XZDma_GetIntrMask(InstancePtr));
105 /* ZDMA transfer has completed */
106 ErrorStatus = (PendingIntr) & (XZDMA_IXR_DMA_DONE_MASK);
107 if ((ErrorStatus) != 0U) {
108 XZDma_DisableIntr(InstancePtr, XZDMA_IXR_ALL_INTR_MASK);
109 InstancePtr->ChannelState = XZDMA_IDLE;
110 InstancePtr->DoneHandler(InstancePtr->DoneRef);
113 /* An error has been occurred */
114 ErrorStatus = PendingIntr & (XZDMA_IXR_ERR_MASK);
115 if ((ErrorStatus) != 0U) {
116 if ((ErrorStatus & XZDMA_IXR_DMA_PAUSE_MASK) ==
117 XZDMA_IXR_DMA_PAUSE_MASK) {
118 InstancePtr->ChannelState = XZDMA_PAUSE;
121 if ((ErrorStatus & (XZDMA_IXR_AXI_WR_DATA_MASK |
122 XZDMA_IXR_AXI_RD_DATA_MASK |
123 XZDMA_IXR_AXI_RD_DST_DSCR_MASK |
124 XZDMA_IXR_AXI_RD_SRC_DSCR_MASK)) != 0x00U) {
125 InstancePtr->ChannelState = XZDMA_IDLE;
128 InstancePtr->ErrorHandler(InstancePtr->ErrorRef, ErrorStatus);
131 /* Clear pending interrupt(s) */
132 XZDma_IntrClear(InstancePtr, PendingIntr);
135 /*****************************************************************************/
138 * This routine installs an asynchronous callback function for the given
142 * HandlerType Callback Function Type
143 * ----------------------- --------------------------------------------------
144 * XZDMA_HANDLER_DONE Done handler
145 * XZDMA_HANDLER_ERROR Error handler
149 * @param InstancePtr is a pointer to the XZDma instance to be worked on.
150 * @param HandlerType specifies which callback is to be attached.
151 * @param CallBackFunc is the address of the callback function.
152 * @param CallBackRef is a user data item that will be passed to the
153 * callback function when it is invoked.
156 * - XST_SUCCESS when handler is installed.
157 * - XST_INVALID_PARAM when HandlerType is invalid.
159 * @note Invoking this function for a handler that already has been
160 * installed replaces it with the new handler.
162 ******************************************************************************/
163 s32 XZDma_SetCallBack(XZDma *InstancePtr, XZDma_Handler HandlerType,
164 void *CallBackFunc, void *CallBackRef)
168 /* Verify arguments. */
169 Xil_AssertNonvoid(InstancePtr != NULL);
170 Xil_AssertNonvoid(CallBackFunc != NULL);
171 Xil_AssertNonvoid(CallBackRef != NULL);
172 Xil_AssertNonvoid((HandlerType == XZDMA_HANDLER_DONE) ||
173 (HandlerType == XZDMA_HANDLER_ERROR));
174 Xil_AssertNonvoid(InstancePtr->IsReady ==
175 (u32)(XIL_COMPONENT_IS_READY));
178 * Calls the respective callback function corresponding to
181 switch (HandlerType) {
182 case XZDMA_HANDLER_DONE:
183 InstancePtr->DoneHandler =
184 (XZDma_DoneHandler)((void *)CallBackFunc);
185 InstancePtr->DoneRef = CallBackRef;
186 Status = (XST_SUCCESS);
189 case XZDMA_HANDLER_ERROR:
190 InstancePtr->ErrorHandler =
191 (XZDma_ErrorHandler)((void *)CallBackFunc);
192 InstancePtr->ErrorRef = CallBackRef;
193 Status = (XST_SUCCESS);
197 Status = (XST_INVALID_PARAM);