]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5_bsp/psu_cortexr5_0/libsrc/zdma_v1_1/src/xzdma_intr.c
Update some more standard demos for use on 64-bit architectures.
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5_bsp / psu_cortexr5_0 / libsrc / zdma_v1_1 / src / xzdma_intr.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2014 Xilinx, Inc.  All rights reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
18 *
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
25 * SOFTWARE.
26 *
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.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 *
35 * @file xzdma_intr.c
36 * @addtogroup zdma_v1_0
37 * @{
38 *
39 * This file contains interrupt related functions of Xilinx ZDMA core.
40 * Please see xzdma.h for more details of the driver.
41 *
42 * <pre>
43 * MODIFICATION HISTORY:
44 *
45 * Ver   Who     Date     Changes
46 * ----- ------  -------- ------------------------------------------------------
47 * 1.0   vns     2/27/15  First release
48 * </pre>
49 *
50 ******************************************************************************/
51
52 /***************************** Include Files *********************************/
53
54 #include "xzdma.h"
55
56 /***************** Macros (Inline Functions) Definitions *********************/
57
58
59 /**************************** Type Definitions *******************************/
60
61
62 /************************** Function Prototypes ******************************/
63
64
65 /************************** Variable Definitions *****************************/
66
67
68 /************************** Function Definitions *****************************/
69
70
71 /*****************************************************************************/
72 /**
73 *
74 * This function is the interrupt handler for the ZDMA core.
75 *
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
79 * interrupts.
80 *
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. .
85 *
86 * @param        Instance is a pointer to the XZDma instance to be worked on.
87 *
88 * @return       None.
89 *
90 * @note         To generate interrupt required interrupts should be enabled.
91 *
92 ******************************************************************************/
93 void XZDma_IntrHandler(void *Instance)
94 {
95         u32 PendingIntr;
96         u32 ErrorStatus;
97         XZDma *InstancePtr = NULL;
98         InstancePtr = (XZDma *)((void *)Instance);
99
100         /* Verify arguments. */
101         Xil_AssertVoid(InstancePtr != NULL);
102
103         /* Get pending interrupts */
104         PendingIntr = (u32)(XZDma_IntrGetStatus(InstancePtr));
105         PendingIntr &= (~XZDma_GetIntrMask(InstancePtr));
106
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);
113         }
114
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;
121                 }
122                 else {
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;
128                         }
129                 }
130                 InstancePtr->ErrorHandler(InstancePtr->ErrorRef, ErrorStatus);
131         }
132
133         /* Clear pending interrupt(s) */
134         XZDma_IntrClear(InstancePtr, PendingIntr);
135 }
136
137 /*****************************************************************************/
138 /**
139 *
140 * This routine installs an asynchronous callback function for the given
141 * HandlerType.
142 *
143 * <pre>
144 * HandlerType              Callback Function Type
145 * -----------------------  --------------------------------------------------
146 * XZDMA_HANDLER_DONE       Done handler
147 * XZDMA_HANDLER_ERROR      Error handler
148 *
149 * </pre>
150 *
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.
156 *
157 * @return
158 *               - XST_SUCCESS when handler is installed.
159 *               - XST_INVALID_PARAM when HandlerType is invalid.
160 *
161 * @note         Invoking this function for a handler that already has been
162 *               installed replaces it with the new handler.
163 *
164 ******************************************************************************/
165 s32 XZDma_SetCallBack(XZDma *InstancePtr, XZDma_Handler HandlerType,
166         void *CallBackFunc, void *CallBackRef)
167 {
168         s32 Status;
169
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));
178
179         /*
180          * Calls the respective callback function corresponding to
181          * the handler type
182          */
183         switch (HandlerType) {
184                 case XZDMA_HANDLER_DONE:
185                         InstancePtr->DoneHandler =
186                                 (XZDma_DoneHandler)((void *)CallBackFunc);
187                         InstancePtr->DoneRef = CallBackRef;
188                         Status = (XST_SUCCESS);
189                         break;
190
191                 case XZDMA_HANDLER_ERROR:
192                         InstancePtr->ErrorHandler =
193                                 (XZDma_ErrorHandler)((void *)CallBackFunc);
194                         InstancePtr->ErrorRef = CallBackRef;
195                         Status = (XST_SUCCESS);
196                         break;
197
198                 default:
199                         Status = (XST_INVALID_PARAM);
200                         break;
201         }
202
203         return Status;
204 }
205 /** @} */