1 /******************************************************************************
3 * Copyright (C) 2004 - 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 /*****************************************************************************/
35 * @file xemaclite_intr.c
36 * @addtogroup emaclite_v4_1
39 * Functions in this file are for the interrupt driven processing functionality.
40 * See xemaclite.h for a detailed description of the driver.
43 * MODIFICATION HISTORY:
45 * Ver Who Date Changes
46 * ----- ---- -------- --------------------------------------------------------
47 * 1.01a ecm 03/31/04 First release
48 * 1.11a mta 03/21/07 Updated to new coding style
49 * 2.01a ktn 07/20/09 Modified the XEmacLite_EnableInterrupts and
50 * XEmacLite_DisableInterrupts functions to enable/disable
51 * the interrupt in the Ping buffer as this is used to enable
52 * the interrupts for both Ping and Pong Buffers.
53 * The interrupt enable bit in the Pong buffer is not used by
55 * 3.00a ktn 10/22/09 Updated file to use the HAL Processor APIs/macros.
56 * The macros have been renamed to remove _m from the name.
57 * 4.2 sk 11/10/15 Used UINTPTR instead of u32 for Baseaddress CR# 867425.
60 ******************************************************************************/
62 /***************************** Include Files *********************************/
64 #include "xemaclite_i.h"
66 #include "xemaclite.h"
68 /************************** Constant Definitions *****************************/
70 /**************************** Type Definitions *******************************/
72 /***************** Macros (Inline Functions) Definitions *********************/
74 /************************** Function Prototypes ******************************/
76 /************************** Variable Definitions *****************************/
77 /*****************************************************************************/
80 * Enable the EmacLite Interrupts.
82 * This function must be called before other functions to send or receive data
83 * in interrupt driven mode. The user should have connected the
84 * interrupt handler of the driver to an interrupt source such as an interrupt
85 * controller or the processor interrupt prior to this function being called.
87 * @param InstancePtr is a pointer to the XEmacLite instance.
90 * - XST_SUCCESS if the device interrupts were enabled
92 * - XST_NO_CALLBACK if the callbacks were not set.
96 ******************************************************************************/
97 int XEmacLite_EnableInterrupts(XEmacLite *InstancePtr)
103 * Verify that each of the inputs are valid.
105 Xil_AssertNonvoid(InstancePtr != NULL);
106 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
108 BaseAddress = InstancePtr->EmacLiteConfig.BaseAddress;
111 * Verify that the handlers are in place.
113 if ((InstancePtr->RecvHandler == (XEmacLite_Handler) StubHandler) ||
114 (InstancePtr->SendHandler == (XEmacLite_Handler) StubHandler)) {
115 return XST_NO_CALLBACK;
119 * Enable the TX interrupts for both the buffers, the Interrupt Enable
120 * is common for the both the buffers and is defined in the
123 Register = XEmacLite_GetTxStatus(BaseAddress);
124 Register |= XEL_TSR_XMIT_IE_MASK;
125 XEmacLite_SetTxStatus(BaseAddress, Register);
128 * Enable the RX interrupts for both the buffers, the Interrupt Enable
129 * is common for the both the buffers and is defined in the
132 Register = XEmacLite_GetRxStatus(BaseAddress);
133 Register |= XEL_RSR_RECV_IE_MASK;
134 XEmacLite_SetRxStatus(BaseAddress, Register);
137 * Enable the global interrupt output.
139 XEmacLite_WriteReg(BaseAddress, XEL_GIER_OFFSET, XEL_GIER_GIE_MASK);
144 /*****************************************************************************/
147 * Disables the interrupts from the device (the higher layer software is
148 * responsible for disabling interrupts at the interrupt controller).
150 * To start using the device again, _EnableInterrupts must be called.
152 * @param InstancePtr is a pointer to the XEmacLite instance .
158 ******************************************************************************/
159 void XEmacLite_DisableInterrupts(XEmacLite *InstancePtr)
165 * Verify that each of the inputs are valid.
167 Xil_AssertVoid(InstancePtr != NULL);
168 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
171 BaseAddress = InstancePtr->EmacLiteConfig.BaseAddress;
174 * Disable the global interrupt output.
176 XEmacLite_WriteReg(BaseAddress, XEL_GIER_OFFSET, 0);
179 * Disable the TX interrupts for both the buffers, the Interrupt Enable
180 * is common for the both the buffers and is defined in the
183 Register = XEmacLite_GetTxStatus(BaseAddress);
184 Register &= ~XEL_TSR_XMIT_IE_MASK;
185 XEmacLite_SetTxStatus(BaseAddress, Register);
188 * Disable the RX interrupts for both the buffers, the Interrupt Enable
189 * is common for the both the buffers and is defined in the
192 Register = XEmacLite_GetRxStatus(BaseAddress);
193 Register &= ~XEL_RSR_RECV_IE_MASK;
194 XEmacLite_SetRxStatus(BaseAddress, Register);
198 /*****************************************************************************/
201 * Interrupt handler for the EmacLite driver. It performs the following
204 * - Get the interrupt status from the registers to determine the source
206 * - Call the appropriate handler based on the source of the interrupt.
208 * @param InstancePtr contains a pointer to the EmacLite device instance
216 ******************************************************************************/
217 void XEmacLite_InterruptHandler(void *InstancePtr)
220 XEmacLite *EmacLitePtr;
221 int TxCompleteIntr = FALSE;
226 * Verify that each of the inputs are valid.
228 Xil_AssertVoid(InstancePtr != NULL);
231 * Convert the non-typed pointer to an EmacLite instance pointer
232 * such that there is access to the device.
234 EmacLitePtr = (XEmacLite *) InstancePtr;
235 BaseAddress = EmacLitePtr->EmacLiteConfig.BaseAddress;
237 if ((XEmacLite_IsRxEmpty(BaseAddress) != TRUE) ||
238 (XEmacLite_IsRxEmpty(BaseAddress +
239 XEL_BUFFER_OFFSET) != TRUE)) {
241 * Call the RX callback.
243 EmacLitePtr->RecvHandler(EmacLitePtr->RecvRef);
247 TxStatus = XEmacLite_GetTxStatus(BaseAddress);
248 if (((TxStatus & XEL_TSR_XMIT_BUSY_MASK) == 0) &&
249 (TxStatus & XEL_TSR_XMIT_ACTIVE_MASK) != 0) {
252 * Clear the Tx Active bit in the Tx Status Register.
254 TxStatus &= ~XEL_TSR_XMIT_ACTIVE_MASK;
255 XEmacLite_SetTxStatus(BaseAddress, TxStatus);
258 * Update the flag indicating that there was a Tx Interrupt.
260 TxCompleteIntr = TRUE;
264 TxStatus = XEmacLite_GetTxStatus(BaseAddress + XEL_BUFFER_OFFSET);
265 if (((TxStatus & XEL_TSR_XMIT_BUSY_MASK) == 0) &&
266 (TxStatus & XEL_TSR_XMIT_ACTIVE_MASK) != 0) {
269 * Clear the Tx Active bit in the Tx Status Register.
271 TxStatus &= ~XEL_TSR_XMIT_ACTIVE_MASK;
272 XEmacLite_SetTxStatus(BaseAddress + XEL_BUFFER_OFFSET,
275 * Update the flag indicating that there was a Tx Interrupt.
277 TxCompleteIntr = TRUE;
281 * If there was a TX interrupt, call the callback.
283 if (TxCompleteIntr == TRUE) {
286 * Call the TX callback.
288 EmacLitePtr->SendHandler(EmacLitePtr->SendRef);
293 /*****************************************************************************/
296 * Sets the callback function for handling received frames in interrupt mode.
297 * The upper layer software should call this function during initialization.
298 * The callback is called when a frame is received. The callback function
299 * should communicate the data to a thread such that the processing is not
300 * performed in an interrupt context.
302 * The callback is invoked by the driver within interrupt context, so it needs
303 * to do its job quickly. If there are other potentially slow operations
304 * within the callback, these should be done at task-level.
306 * @param InstancePtr is a pointer to the XEmacLite instance..
307 * @param CallBackRef is a reference pointer to be passed back to the
308 * application in the callback. This helps the application
309 * correlate the callback to a particular driver.
310 * @param FuncPtr is the pointer to the callback function.
316 ******************************************************************************/
317 void XEmacLite_SetRecvHandler(XEmacLite *InstancePtr, void *CallBackRef,
318 XEmacLite_Handler FuncPtr)
320 Xil_AssertVoid(InstancePtr != NULL);
321 Xil_AssertVoid(FuncPtr != NULL);
322 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
324 InstancePtr->RecvHandler = FuncPtr;
325 InstancePtr->RecvRef = CallBackRef;
329 /*****************************************************************************/
332 * Sets the callback function for handling transmitted frames in interrupt mode.
333 * The upper layer software should call this function during initialization.
334 * The callback is called when a frame is transmitted. The callback function
335 * should communicate the data to a thread such that the processing is not
336 * performed in an interrupt context.
338 * The callback is invoked by the driver within interrupt context, so it needs
339 * to do its job quickly. If there are other potentially slow operations
340 * within the callback, these should be done at task-level.
342 * @param InstancePtr is a pointer to the XEmacLite instance.
343 * @param CallBackRef is a reference pointer to be passed back to the
344 * application in the callback. This helps the application
345 * correlate the callback to a particular driver.
346 * @param FuncPtr is the pointer to the callback function.
352 ******************************************************************************/
353 void XEmacLite_SetSendHandler(XEmacLite *InstancePtr, void *CallBackRef,
354 XEmacLite_Handler FuncPtr)
356 Xil_AssertVoid(InstancePtr != NULL);
357 Xil_AssertVoid(FuncPtr != NULL);
358 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
360 InstancePtr->SendHandler = FuncPtr;
361 InstancePtr->SendRef = CallBackRef;