]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/emaclite_v4_0/src/xemaclite_intr.c
Update some more standard demos for use on 64-bit architectures.
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / emaclite_v4_0 / src / xemaclite_intr.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2004 - 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 xemaclite_intr.c
36 *
37 * Functions in this file are for the interrupt driven processing functionality.
38 * See xemaclite.h for a detailed description of the driver.
39 *
40 * <pre>
41 * MODIFICATION HISTORY:
42 *
43 * Ver   Who  Date     Changes
44 * ----- ---- -------- --------------------------------------------------------
45 * 1.01a ecm  03/31/04 First release
46 * 1.11a mta  03/21/07 Updated to new coding style
47 * 2.01a ktn  07/20/09 Modified the XEmacLite_EnableInterrupts and
48 *                     XEmacLite_DisableInterrupts functions to enable/disable
49 *                     the interrupt in the Ping buffer as this is used to enable
50 *                     the interrupts for both Ping and Pong Buffers.
51 *                     The interrupt enable bit in the Pong buffer is not used by
52 *                     the HW.
53 * 3.00a ktn  10/22/09 Updated file to use the HAL Processor APIs/macros.
54 *                     The macros have been renamed to remove _m from the name.
55 *
56 * </pre>
57 ******************************************************************************/
58
59 /***************************** Include Files *********************************/
60
61 #include "xemaclite_i.h"
62 #include "xil_io.h"
63 #include "xemaclite.h"
64
65 /************************** Constant Definitions *****************************/
66
67 /**************************** Type Definitions *******************************/
68
69 /***************** Macros (Inline Functions) Definitions *********************/
70
71 /************************** Function Prototypes ******************************/
72
73 /************************** Variable Definitions *****************************/
74 /*****************************************************************************/
75 /**
76 *
77 * Enable the EmacLite Interrupts.
78 *
79 * This function must be called before other functions to send or receive data
80 * in interrupt driven mode. The user should have connected the
81 * interrupt handler of the driver to an interrupt source such as an interrupt
82 * controller or the processor interrupt prior to this function being called.
83 *
84 * @param        InstancePtr is a pointer to the XEmacLite instance.
85 *
86 * @return
87 *               - XST_SUCCESS if the device interrupts were enabled
88 *                       successfully.
89 *               - XST_NO_CALLBACK if the callbacks were not set.
90 *
91 * @note         None.
92 *
93 ******************************************************************************/
94 int XEmacLite_EnableInterrupts(XEmacLite *InstancePtr)
95 {
96         u32 Register;
97         u32 BaseAddress;
98
99         /*
100          * Verify that each of the inputs are valid.
101          */
102         Xil_AssertNonvoid(InstancePtr != NULL);
103         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
104
105         BaseAddress = InstancePtr->EmacLiteConfig.BaseAddress;
106
107         /*
108          * Verify that the handlers are in place.
109          */
110         if ((InstancePtr->RecvHandler == (XEmacLite_Handler) StubHandler) ||
111             (InstancePtr->SendHandler == (XEmacLite_Handler) StubHandler)) {
112                 return XST_NO_CALLBACK;
113         }
114
115         /*
116          * Enable the TX interrupts for both the buffers, the Interrupt Enable
117          * is common for the both the buffers and is defined in the
118          * Ping buffer.
119          */
120         Register = XEmacLite_GetTxStatus(BaseAddress);
121         Register |= XEL_TSR_XMIT_IE_MASK;
122         XEmacLite_SetTxStatus(BaseAddress, Register);
123
124         /*
125          * Enable the RX interrupts for both the buffers, the Interrupt Enable
126          * is common for the both the buffers and is defined in the
127          * Ping buffer.
128          */
129         Register = XEmacLite_GetRxStatus(BaseAddress);
130         Register |= XEL_RSR_RECV_IE_MASK;
131         XEmacLite_SetRxStatus(BaseAddress, Register);
132
133         /*
134          * Enable the global interrupt output.
135          */
136         XEmacLite_WriteReg(BaseAddress, XEL_GIER_OFFSET, XEL_GIER_GIE_MASK);
137
138         return XST_SUCCESS;
139 }
140
141 /*****************************************************************************/
142 /**
143 *
144 * Disables the interrupts from the device (the higher layer software is
145 * responsible for disabling interrupts at the interrupt controller).
146 *
147 * To start using the device again, _EnableInterrupts must be called.
148 *
149 * @param        InstancePtr is a pointer to the XEmacLite instance .
150 *
151 * @return       None.
152 *
153 * @note         None.
154 *
155 ******************************************************************************/
156 void XEmacLite_DisableInterrupts(XEmacLite *InstancePtr)
157 {
158         u32 Register;
159         u32 BaseAddress;
160
161         /*
162          * Verify that each of the inputs are valid.
163          */
164         Xil_AssertVoid(InstancePtr != NULL);
165         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
166
167
168         BaseAddress = InstancePtr->EmacLiteConfig.BaseAddress;
169
170         /*
171          * Disable the global interrupt output.
172          */
173         XEmacLite_WriteReg(BaseAddress, XEL_GIER_OFFSET, 0);
174
175         /*
176          * Disable the TX interrupts for both the buffers, the Interrupt Enable
177          * is common for the both the buffers and is defined in the
178          * Ping buffer.
179          */
180         Register = XEmacLite_GetTxStatus(BaseAddress);
181         Register &= ~XEL_TSR_XMIT_IE_MASK;
182         XEmacLite_SetTxStatus(BaseAddress, Register);
183
184         /*
185          * Disable the RX interrupts for both the buffers, the Interrupt Enable
186          * is common for the both the buffers and is defined in the
187          * Ping buffer.
188          */
189         Register = XEmacLite_GetRxStatus(BaseAddress);
190         Register &= ~XEL_RSR_RECV_IE_MASK;
191         XEmacLite_SetRxStatus(BaseAddress, Register);
192
193 }
194
195 /*****************************************************************************/
196 /**
197 *
198 * Interrupt handler for the EmacLite driver. It performs the following
199 * processing:
200 *
201 *       - Get the interrupt status from the registers to determine the source
202 *       of the interrupt.
203 *       - Call the appropriate handler based on the source of the interrupt.
204 *
205 * @param        InstancePtr contains a pointer to the EmacLite device instance
206 *               for the interrupt.
207 *
208 * @return       None.
209 *
210 * @note         None.
211 *
212 *
213 ******************************************************************************/
214 void XEmacLite_InterruptHandler(void *InstancePtr)
215 {
216
217         XEmacLite *EmacLitePtr;
218         int TxCompleteIntr = FALSE;
219         u32 BaseAddress;
220         u32 TxStatus;
221
222         /*
223          * Verify that each of the inputs are valid.
224          */
225         Xil_AssertVoid(InstancePtr != NULL);
226
227         /*
228          * Convert the non-typed pointer to an EmacLite instance pointer
229          * such that there is access to the device.
230          */
231         EmacLitePtr = (XEmacLite *) InstancePtr;
232         BaseAddress = EmacLitePtr->EmacLiteConfig.BaseAddress;
233
234         if ((XEmacLite_IsRxEmpty(BaseAddress) != TRUE) ||
235                 (XEmacLite_IsRxEmpty(BaseAddress +
236                         XEL_BUFFER_OFFSET) != TRUE)) {
237                 /*
238                  * Call the RX callback.
239                  */
240                 EmacLitePtr->RecvHandler(EmacLitePtr->RecvRef);
241
242         }
243
244         TxStatus = XEmacLite_GetTxStatus(BaseAddress);
245         if (((TxStatus & XEL_TSR_XMIT_BUSY_MASK) == 0) &&
246                 (TxStatus & XEL_TSR_XMIT_ACTIVE_MASK) != 0) {
247
248                 /*
249                  * Clear the Tx Active bit in the Tx Status Register.
250                  */
251                 TxStatus &= ~XEL_TSR_XMIT_ACTIVE_MASK;
252                 XEmacLite_SetTxStatus(BaseAddress, TxStatus);
253
254                 /*
255                  * Update the flag indicating that there was a Tx Interrupt.
256                  */
257                 TxCompleteIntr = TRUE;
258
259         }
260
261         TxStatus = XEmacLite_GetTxStatus(BaseAddress + XEL_BUFFER_OFFSET);
262         if (((TxStatus & XEL_TSR_XMIT_BUSY_MASK) == 0) &&
263                 (TxStatus & XEL_TSR_XMIT_ACTIVE_MASK) != 0) {
264
265                 /*
266                  * Clear the Tx Active bit in the Tx Status Register.
267                  */
268                 TxStatus &= ~XEL_TSR_XMIT_ACTIVE_MASK;
269                 XEmacLite_SetTxStatus(BaseAddress + XEL_BUFFER_OFFSET,
270                                         TxStatus);
271                 /*
272                  * Update the flag indicating that there was a Tx Interrupt.
273                  */
274                 TxCompleteIntr = TRUE;
275         }
276
277         /*
278          * If there was a TX interrupt, call the callback.
279          */
280         if (TxCompleteIntr == TRUE) {
281
282                 /*
283                  * Call the TX callback.
284                  */
285                 EmacLitePtr->SendHandler(EmacLitePtr->SendRef);
286
287         }
288 }
289
290 /*****************************************************************************/
291 /**
292 *
293 * Sets the callback function for handling received frames in interrupt mode.
294 * The upper layer software should call this function during initialization.
295 * The callback is called when a frame is received. The callback function
296 * should communicate the data to a thread such that the processing is not
297 * performed in an interrupt context.
298 *
299 * The callback is invoked by the driver within interrupt context, so it needs
300 * to do its job quickly. If there are other potentially slow operations
301 * within the callback, these should be done at task-level.
302 *
303 * @param        InstancePtr is a pointer to the XEmacLite instance..
304 * @param        CallBackRef is a reference pointer to be passed back to the
305 *               application in the callback. This helps the application
306 *               correlate the callback to a particular driver.
307 * @param        FuncPtr is the pointer to the callback function.
308 *
309 * @return       None.
310 *
311 * @note         None.
312 *
313 ******************************************************************************/
314 void XEmacLite_SetRecvHandler(XEmacLite *InstancePtr, void *CallBackRef,
315                               XEmacLite_Handler FuncPtr)
316 {
317         Xil_AssertVoid(InstancePtr != NULL);
318         Xil_AssertVoid(FuncPtr != NULL);
319         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
320
321         InstancePtr->RecvHandler = FuncPtr;
322         InstancePtr->RecvRef = CallBackRef;
323 }
324
325
326 /*****************************************************************************/
327 /**
328 *
329 * Sets the callback function for handling transmitted frames in interrupt mode.
330 * The upper layer software should call this function during initialization.
331 * The callback is called when a frame is transmitted. The callback function
332 * should communicate the data to a thread such that the processing is not
333 * performed in an interrupt context.
334 *
335 * The callback is invoked by the driver within interrupt context, so it needs
336 * to do its job quickly. If there are other potentially slow operations
337 * within the callback, these should be done at task-level.
338 *
339 * @param        InstancePtr is a pointer to the XEmacLite instance.
340 * @param        CallBackRef is a reference pointer to be passed back to the
341 *               application in the callback. This helps the application
342 *               correlate the callback to a particular driver.
343 * @param        FuncPtr is the pointer to the callback function.
344 *
345 * @return       None.
346 *
347 * @note         None.
348 *
349 ******************************************************************************/
350 void XEmacLite_SetSendHandler(XEmacLite *InstancePtr, void *CallBackRef,
351                               XEmacLite_Handler FuncPtr)
352 {
353         Xil_AssertVoid(InstancePtr != NULL);
354         Xil_AssertVoid(FuncPtr != NULL);
355         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
356
357         InstancePtr->SendHandler = FuncPtr;
358         InstancePtr->SendRef = CallBackRef;
359 }