📄 xtemac.c
字号:
/* $Id: *//******************************************************************************** XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"* AS A COURTESY TO YOU, SOLELY FOR USE IN DEVELOPING PROGRAMS AND* SOLUTIONS FOR XILINX DEVICES. BY PROVIDING THIS DESIGN, CODE,* OR INFORMATION AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE,* APPLICATION OR STANDARD, XILINX IS MAKING NO REPRESENTATION* THAT THIS IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,* AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE* FOR YOUR IMPLEMENTATION. XILINX EXPRESSLY DISCLAIMS ANY* WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE* IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR* REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF* INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS* FOR A PARTICULAR PURPOSE.** (c) Copyright 2005-2006 Xilinx Inc.* All rights reserved.* This program is free software; you can redistribute it and/or modify it* under the terms of the GNU General Public License as published by the* Free Software Foundation; either version 2 of the License, or (at your* option) any later version.** You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA*******************************************************************************//*****************************************************************************//**** @file xtemac.c** The XTemac driver. Functions in this file are the minimum required functions* for this driver. See xtemac.h for a detailed description of the driver.** <pre>* MODIFICATION HISTORY:** Ver Who Date Changes* ----- ---- -------- -------------------------------------------------------* 1.00a rmm 06/01/05 First release* 2.00a rmm 11/21/05 Switched to local link DMA driver, removed simple* DMA code, relocated XTemac_Initialize(),* XTemac_VmInitialize(), and XTemac_LookupConfig() to* xtemac_init.c, added XTemac_CfgInitialize().* </pre>******************************************************************************//***************************** Include Files *********************************/#include "xtemac.h"#include "xtemac_i.h"/************************** Constant Definitions *****************************//**************************** Type Definitions *******************************//***************** Macros (Inline Functions) Definitions *********************//************************** Function Prototypes ******************************/void XTemac_StubHandler(void); /* Default handler routine */static void InitHw(XTemac *InstancePtr); /* HW reset *//************************** Variable Definitions *****************************//*****************************************************************************//*** Initialize a specific XTemac instance/driver. The initialization entails:* - Initialize fields of the XTemac instance structure* - Reset HW and apply default options* - Configure the packet FIFOs if present* - Configure the DMA channels if present** The PHY is setup independently from the TEMAC. Use the MII or whatever other* interface may be present for setup.** @param InstancePtr is a pointer to the instance to be worked on.* @param CfgPtr is the device configuration structure containing required HW* build data.* @param VirtualAddress is the base address of the device. If address* translation is not utilized, this parameter can be passed in using* CfgPtr->BaseAddress to specify the physical base address.** @return* - XST_SUCCESS if initialization was successful* - XST_FAILURE if initialization of packet FIFOs or DMA channels failed, or* device operating mode cannot be determined*******************************************************************************/XStatus XTemac_CfgInitialize(XTemac *InstancePtr, XTemac_Config *CfgPtr, u32 VirtualAddress){ XStatus Result; /* Verify arguments */ XASSERT_NONVOID(InstancePtr != NULL); /* Clear instance memory and make copy of configuration */ memset(InstancePtr, 0, sizeof(XTemac)); memcpy(&InstancePtr->Config, CfgPtr, sizeof(XTemac_Config)); /* Set device base address */ InstancePtr->BaseAddress = VirtualAddress; /* Set callbacks to an initial stub routine */ InstancePtr->FifoRecvHandler = (XTemac_FifoRecvHandler)XTemac_StubHandler; InstancePtr->FifoSendHandler = (XTemac_FifoSendHandler)XTemac_StubHandler; InstancePtr->ErrorHandler = (XTemac_ErrorHandler)XTemac_StubHandler; InstancePtr->AnegHandler = (XTemac_AnegHandler)XTemac_StubHandler; InstancePtr->SgRecvHandler = (XTemac_SgHandler)XTemac_StubHandler; InstancePtr->SgSendHandler = (XTemac_SgHandler)XTemac_StubHandler; /* FIFO mode */ if (XTemac_mIsFifo(InstancePtr)) { /* Select best processor based transfer method to/from FIFOs */ Result = XTemac_ConfigureFifoAccess(InstancePtr); if (Result != XST_SUCCESS) { return(XST_FAILURE); } } /* SGDMA mode */ else if (XTemac_mIsSgDma(InstancePtr)) { Result = XDmaV3_Initialize(&InstancePtr->RecvDma, InstancePtr->BaseAddress + XTE_DMA_RECV_OFFSET); if (Result != XST_SUCCESS) { return(XST_FAILURE); } Result = XDmaV3_Initialize(&InstancePtr->SendDma, InstancePtr->BaseAddress + XTE_DMA_SEND_OFFSET); if (Result != XST_SUCCESS) { return(XST_FAILURE); } } /* Unknown mode */ else { return(XST_FAILURE); } /* Reset the hardware and set default options */ InstancePtr->IsReady = XCOMPONENT_IS_READY; XTemac_Reset(InstancePtr, XTE_NORESET_HARD); return(XST_SUCCESS);}/*****************************************************************************//*** Start the Ethernet controller as follows:* - Enable transmitter if XTE_TRANSMIT_ENABLE_OPTION is set* - Enable receiver if XTE_RECEIVER_ENABLE_OPTION is set* - If not polled mode, then start the SG DMA send and receive channels (if* configured) and enable the global device interrupt** If starting for the first time after calling XTemac_Initialize() or* XTemac_Reset(), send and receive interrupts will not be generated until* XTemac_IntrFifoEnable() or XTemac_IntrSgEnable() are called. Otherwise,* interrupt settings made by these functions will be restored.** @param InstancePtr is a pointer to the instance to be worked on.** @return* - XST_SUCCESS if the device was started successfully* - XST_DMA_SG_NO_LIST if configured for scatter-gather DMA and a descriptor* list has not yet been created for the send or receive channel** @note* The driver tries to match the hardware configuration. So if the hardware* is configured with scatter-gather DMA, the driver expects to start the* scatter-gather channels and expects that the user has previously set up* the buffer descriptor lists.** This function makes use of internal resources that are shared between the* Start, Stop, and Set/ClearOptions functions. So if one task might be setting* device options while another is trying to start the device, the user is* required to provide protection of this shared data (typically using a* semaphore).** This function must not be preempted by an interrupt that may service the* device.*******************************************************************************/XStatus XTemac_Start(XTemac *InstancePtr){ u32 Reg; XStatus Result; /* Assert bad arguments and conditions */ XASSERT_NONVOID(InstancePtr != NULL); XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY); /* If already started, then there is nothing to do */ if (InstancePtr->IsStarted == XCOMPONENT_IS_STARTED) { return(XST_SUCCESS); } /* Start SG DMA */ if (XTemac_mIsSgDma(InstancePtr)) { /* When starting the DMA channels, both transmit and receive sides * need an initialized BD list. */ Result = XDmaV3_SgStart(&InstancePtr->RecvDma); if (Result == XST_DMA_SG_NO_LIST) { return(Result); } Result = XDmaV3_SgStart(&InstancePtr->SendDma); if (Result == XST_DMA_SG_NO_LIST) { return(Result); } } /* Enable transmitter if not already enabled */ if (InstancePtr->Options & XTE_TRANSMITTER_ENABLE_OPTION) { Reg = XTemac_mGetHostReg(XTE_TXC_OFFSET); if (!(Reg & XTE_TXC_TXEN_MASK)) { XTemac_mSetHostReg(XTE_TXC_OFFSET, Reg | XTE_TXC_TXEN_MASK); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -