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 /*****************************************************************************/
36 * @addtogroup zdma_v1_0
39 * This file contains interrupt related functions of Xilinx ZDMA core.
40 * Please see xzdma.h for more details of the driver.
43 * MODIFICATION HISTORY:
45 * Ver Who Date Changes
46 * ----- ------ -------- ------------------------------------------------------
47 * 1.0 vns 2/27/15 First release
50 ******************************************************************************/
52 /***************************** Include Files *********************************/
56 /***************** Macros (Inline Functions) Definitions *********************/
59 /**************************** Type Definitions *******************************/
62 /************************** Function Prototypes ******************************/
65 /************************** Variable Definitions *****************************/
68 /************************** Function Definitions *****************************/
71 /*****************************************************************************/
74 * This function is the interrupt handler for the ZDMA core.
76 * This handler reads the pending interrupt from Status register, determines the
77 * source of the interrupts and calls the respective callbacks for the
78 * interrupts that are enabled in IRQ_ENABLE register, and finally clears the
81 * The application is responsible for connecting this function to the interrupt
82 * system. Application beyond this driver is also responsible for providing
83 * callbacks to handle interrupts and installing the callbacks using
84 * XZDma_SetCallBack() during initialization phase. .
86 * @param Instance is a pointer to the XZDma instance to be worked on.
90 * @note To generate interrupt required interrupts should be enabled.
92 ******************************************************************************/
93 void XZDma_IntrHandler(void *Instance)
97 XZDma *InstancePtr = NULL;
98 InstancePtr = (XZDma *)((void *)Instance);
100 /* Verify arguments. */
101 Xil_AssertVoid(InstancePtr != NULL);
103 /* Get pending interrupts */
104 PendingIntr = (u32)(XZDma_IntrGetStatus(InstancePtr));
105 PendingIntr &= (~XZDma_GetIntrMask(InstancePtr));
107 /* ZDMA transfer has completed */
108 ErrorStatus = (PendingIntr) & (XZDMA_IXR_DMA_DONE_MASK);
109 if ((ErrorStatus) != 0U) {
110 XZDma_DisableIntr(InstancePtr, XZDMA_IXR_ALL_INTR_MASK);
111 InstancePtr->ChannelState = XZDMA_IDLE;
112 InstancePtr->DoneHandler(InstancePtr->DoneRef);
115 /* An error has been occurred */
116 ErrorStatus = PendingIntr & (XZDMA_IXR_ERR_MASK);
117 if ((ErrorStatus) != 0U) {
118 if ((ErrorStatus & XZDMA_IXR_DMA_PAUSE_MASK) ==
119 XZDMA_IXR_DMA_PAUSE_MASK) {
120 InstancePtr->ChannelState = XZDMA_PAUSE;
123 if ((ErrorStatus & (XZDMA_IXR_AXI_WR_DATA_MASK |
124 XZDMA_IXR_AXI_RD_DATA_MASK |
125 XZDMA_IXR_AXI_RD_DST_DSCR_MASK |
126 XZDMA_IXR_AXI_RD_SRC_DSCR_MASK)) != 0x00U) {
127 InstancePtr->ChannelState = XZDMA_IDLE;
130 InstancePtr->ErrorHandler(InstancePtr->ErrorRef, ErrorStatus);
133 /* Clear pending interrupt(s) */
134 XZDma_IntrClear(InstancePtr, PendingIntr);
137 /*****************************************************************************/
140 * This routine installs an asynchronous callback function for the given
144 * HandlerType Callback Function Type
145 * ----------------------- --------------------------------------------------
146 * XZDMA_HANDLER_DONE Done handler
147 * XZDMA_HANDLER_ERROR Error handler
151 * @param InstancePtr is a pointer to the XZDma instance to be worked on.
152 * @param HandlerType specifies which callback is to be attached.
153 * @param CallBackFunc is the address of the callback function.
154 * @param CallBackRef is a user data item that will be passed to the
155 * callback function when it is invoked.
158 * - XST_SUCCESS when handler is installed.
159 * - XST_INVALID_PARAM when HandlerType is invalid.
161 * @note Invoking this function for a handler that already has been
162 * installed replaces it with the new handler.
164 ******************************************************************************/
165 s32 XZDma_SetCallBack(XZDma *InstancePtr, XZDma_Handler HandlerType,
166 void *CallBackFunc, void *CallBackRef)
170 /* Verify arguments. */
171 Xil_AssertNonvoid(InstancePtr != NULL);
172 Xil_AssertNonvoid(CallBackFunc != NULL);
173 Xil_AssertNonvoid(CallBackRef != NULL);
174 Xil_AssertNonvoid((HandlerType == XZDMA_HANDLER_DONE) ||
175 (HandlerType == XZDMA_HANDLER_ERROR));
176 Xil_AssertNonvoid(InstancePtr->IsReady ==
177 (u32)(XIL_COMPONENT_IS_READY));
180 * Calls the respective callback function corresponding to
183 switch (HandlerType) {
184 case XZDMA_HANDLER_DONE:
185 InstancePtr->DoneHandler =
186 (XZDma_DoneHandler)((void *)CallBackFunc);
187 InstancePtr->DoneRef = CallBackRef;
188 Status = (XST_SUCCESS);
191 case XZDMA_HANDLER_ERROR:
192 InstancePtr->ErrorHandler =
193 (XZDma_ErrorHandler)((void *)CallBackFunc);
194 InstancePtr->ErrorRef = CallBackRef;
195 Status = (XST_SUCCESS);
199 Status = (XST_INVALID_PARAM);