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
37 * Functions in this file are for the interrupt driven processing functionality.
38 * See xemaclite.h for a detailed description of the driver.
41 * MODIFICATION HISTORY:
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
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.
57 ******************************************************************************/
59 /***************************** Include Files *********************************/
61 #include "xemaclite_i.h"
63 #include "xemaclite.h"
65 /************************** Constant Definitions *****************************/
67 /**************************** Type Definitions *******************************/
69 /***************** Macros (Inline Functions) Definitions *********************/
71 /************************** Function Prototypes ******************************/
73 /************************** Variable Definitions *****************************/
74 /*****************************************************************************/
77 * Enable the EmacLite Interrupts.
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.
84 * @param InstancePtr is a pointer to the XEmacLite instance.
87 * - XST_SUCCESS if the device interrupts were enabled
89 * - XST_NO_CALLBACK if the callbacks were not set.
93 ******************************************************************************/
94 int XEmacLite_EnableInterrupts(XEmacLite *InstancePtr)
100 * Verify that each of the inputs are valid.
102 Xil_AssertNonvoid(InstancePtr != NULL);
103 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
105 BaseAddress = InstancePtr->EmacLiteConfig.BaseAddress;
108 * Verify that the handlers are in place.
110 if ((InstancePtr->RecvHandler == (XEmacLite_Handler) StubHandler) ||
111 (InstancePtr->SendHandler == (XEmacLite_Handler) StubHandler)) {
112 return XST_NO_CALLBACK;
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
120 Register = XEmacLite_GetTxStatus(BaseAddress);
121 Register |= XEL_TSR_XMIT_IE_MASK;
122 XEmacLite_SetTxStatus(BaseAddress, Register);
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
129 Register = XEmacLite_GetRxStatus(BaseAddress);
130 Register |= XEL_RSR_RECV_IE_MASK;
131 XEmacLite_SetRxStatus(BaseAddress, Register);
134 * Enable the global interrupt output.
136 XEmacLite_WriteReg(BaseAddress, XEL_GIER_OFFSET, XEL_GIER_GIE_MASK);
141 /*****************************************************************************/
144 * Disables the interrupts from the device (the higher layer software is
145 * responsible for disabling interrupts at the interrupt controller).
147 * To start using the device again, _EnableInterrupts must be called.
149 * @param InstancePtr is a pointer to the XEmacLite instance .
155 ******************************************************************************/
156 void XEmacLite_DisableInterrupts(XEmacLite *InstancePtr)
162 * Verify that each of the inputs are valid.
164 Xil_AssertVoid(InstancePtr != NULL);
165 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
168 BaseAddress = InstancePtr->EmacLiteConfig.BaseAddress;
171 * Disable the global interrupt output.
173 XEmacLite_WriteReg(BaseAddress, XEL_GIER_OFFSET, 0);
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
180 Register = XEmacLite_GetTxStatus(BaseAddress);
181 Register &= ~XEL_TSR_XMIT_IE_MASK;
182 XEmacLite_SetTxStatus(BaseAddress, Register);
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
189 Register = XEmacLite_GetRxStatus(BaseAddress);
190 Register &= ~XEL_RSR_RECV_IE_MASK;
191 XEmacLite_SetRxStatus(BaseAddress, Register);
195 /*****************************************************************************/
198 * Interrupt handler for the EmacLite driver. It performs the following
201 * - Get the interrupt status from the registers to determine the source
203 * - Call the appropriate handler based on the source of the interrupt.
205 * @param InstancePtr contains a pointer to the EmacLite device instance
213 ******************************************************************************/
214 void XEmacLite_InterruptHandler(void *InstancePtr)
217 XEmacLite *EmacLitePtr;
218 int TxCompleteIntr = FALSE;
223 * Verify that each of the inputs are valid.
225 Xil_AssertVoid(InstancePtr != NULL);
228 * Convert the non-typed pointer to an EmacLite instance pointer
229 * such that there is access to the device.
231 EmacLitePtr = (XEmacLite *) InstancePtr;
232 BaseAddress = EmacLitePtr->EmacLiteConfig.BaseAddress;
234 if ((XEmacLite_IsRxEmpty(BaseAddress) != TRUE) ||
235 (XEmacLite_IsRxEmpty(BaseAddress +
236 XEL_BUFFER_OFFSET) != TRUE)) {
238 * Call the RX callback.
240 EmacLitePtr->RecvHandler(EmacLitePtr->RecvRef);
244 TxStatus = XEmacLite_GetTxStatus(BaseAddress);
245 if (((TxStatus & XEL_TSR_XMIT_BUSY_MASK) == 0) &&
246 (TxStatus & XEL_TSR_XMIT_ACTIVE_MASK) != 0) {
249 * Clear the Tx Active bit in the Tx Status Register.
251 TxStatus &= ~XEL_TSR_XMIT_ACTIVE_MASK;
252 XEmacLite_SetTxStatus(BaseAddress, TxStatus);
255 * Update the flag indicating that there was a Tx Interrupt.
257 TxCompleteIntr = TRUE;
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) {
266 * Clear the Tx Active bit in the Tx Status Register.
268 TxStatus &= ~XEL_TSR_XMIT_ACTIVE_MASK;
269 XEmacLite_SetTxStatus(BaseAddress + XEL_BUFFER_OFFSET,
272 * Update the flag indicating that there was a Tx Interrupt.
274 TxCompleteIntr = TRUE;
278 * If there was a TX interrupt, call the callback.
280 if (TxCompleteIntr == TRUE) {
283 * Call the TX callback.
285 EmacLitePtr->SendHandler(EmacLitePtr->SendRef);
290 /*****************************************************************************/
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.
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.
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.
313 ******************************************************************************/
314 void XEmacLite_SetRecvHandler(XEmacLite *InstancePtr, void *CallBackRef,
315 XEmacLite_Handler FuncPtr)
317 Xil_AssertVoid(InstancePtr != NULL);
318 Xil_AssertVoid(FuncPtr != NULL);
319 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
321 InstancePtr->RecvHandler = FuncPtr;
322 InstancePtr->RecvRef = CallBackRef;
326 /*****************************************************************************/
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.
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.
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.
349 ******************************************************************************/
350 void XEmacLite_SetSendHandler(XEmacLite *InstancePtr, void *CallBackRef,
351 XEmacLite_Handler FuncPtr)
353 Xil_AssertVoid(InstancePtr != NULL);
354 Xil_AssertVoid(FuncPtr != NULL);
355 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
357 InstancePtr->SendHandler = FuncPtr;
358 InstancePtr->SendRef = CallBackRef;