📄 xemac.c
字号:
* - XST_SUCCESS if successful initialization of DMA** @note** None.*******************************************************************************/static XStatus ConfigureDma(XEmac *InstancePtr){ XStatus Result; /* * Initialize the DMA channels with their base addresses. We assume * scatter-gather DMA is the only possible configuration. Descriptor space * will need to be set later by the upper layer. */ Result = XDmaChannel_Initialize(&InstancePtr->RecvChannel, InstancePtr->BaseAddress + XEM_DMA_RECV_OFFSET); if (Result != XST_SUCCESS) { return Result; } Result = XDmaChannel_Initialize(&InstancePtr->SendChannel, InstancePtr->BaseAddress + XEM_DMA_SEND_OFFSET); return Result;}/******************************************************************************//**** Configure the send and receive FIFO components with their base addresses* and interrupt masks. Currently the base addresses are defined constants.** @param InstancePtr is a pointer to the XEmac instance to be worked on.** @return** XST_SUCCESS if successful initialization of the packet FIFOs** @note** None.*******************************************************************************/static XStatus ConfigureFifo(XEmac *InstancePtr){ XStatus Result; /* * Return status from the packet FIFOs initialization is ignored since * they always return success. */ Result = XPacketFifoV200a_Initialize(&InstancePtr->RecvFifo, InstancePtr->BaseAddress + XEM_PFIFO_RXREG_OFFSET, InstancePtr->BaseAddress + XEM_PFIFO_RXDATA_OFFSET); if (Result != XST_SUCCESS) { return Result; } Result = XPacketFifoV200a_Initialize(&InstancePtr->SendFifo, InstancePtr->BaseAddress + XEM_PFIFO_TXREG_OFFSET, InstancePtr->BaseAddress + XEM_PFIFO_TXDATA_OFFSET); return Result;}/******************************************************************************//**** This is a stub for the scatter-gather send and recv callbacks. The stub* is here in case the upper layers forget to set the handlers.** @param CallBackRef is a pointer to the upper layer callback reference* @param BdPtr is a pointer to the first buffer descriptor in a list* @param NumBds is the number of descriptors in the list.** @return** None.** @note** None.*******************************************************************************/static void StubSgHandler(void *CallBackRef, XBufDescriptor *BdPtr, Xuint32 NumBds){ XASSERT_VOID_ALWAYS();}/******************************************************************************//**** This is a stub for the non-DMA send and recv callbacks. The stub is here in* case the upper layers forget to set the handlers.** @param CallBackRef is a pointer to the upper layer callback reference** @return** None.** @note** None.*******************************************************************************/static void StubFifoHandler(void *CallBackRef){ XASSERT_VOID_ALWAYS();}/******************************************************************************//**** This is a stub for the asynchronous error callback. The stub is here in* case the upper layers forget to set the handler.** @param CallBackRef is a pointer to the upper layer callback reference* @param ErrorCode is the Xilinx error code, indicating the cause of the error** @return** None.** @note** None.*******************************************************************************/static void StubErrorHandler(void *CallBackRef, XStatus ErrorCode){ XASSERT_VOID_ALWAYS();}/*****************************************************************************//**** Initialize a specific XEmac instance/driver. The initialization entails:* - Initialize fields of the XEmac structure* - Clear the Ethernet statistics for this device* - Initialize the IPIF component with its register base address* - Configure the FIFO components with their register base addresses.* - If the device is configured with DMA, configure the DMA channel components* with their register base addresses. At some later time, memory pools for* the scatter-gather descriptor lists may be passed to the driver.* - Reset the Ethernet MAC** @param InstancePtr is a pointer to the XEmac instance to be worked on.* @param ConfigPtr is a pointer to a config table for the particular device this* this driver is associated with.** @return** - XST_SUCCESS if initialization was successful* - XST_DEVICE_NOT_FOUND if device configuration information was not found for* a device with the supplied device ID.** @note** None.*******************************************************************************/XStatus Initialize(XEmac *InstancePtr, XEmac_Config *ConfigPtr){ XStatus Result; XASSERT_NONVOID(InstancePtr != XNULL); /* * Lookup the device configuration in the temporary CROM table. Use this * configuration info down below when initializing this component. */ InstancePtr->ConfigPtr = ConfigPtr; /* * Set some default values */ InstancePtr->IsReady = 0; InstancePtr->IsStarted = 0; /* Always default polled to false, let user configure this mode */ InstancePtr->IsPolled = XFALSE; InstancePtr->FifoRecvHandler = StubFifoHandler; InstancePtr->FifoSendHandler = StubFifoHandler; InstancePtr->ErrorHandler = StubErrorHandler; InstancePtr->SgRecvHandler = StubSgHandler; InstancePtr->SgSendHandler = StubSgHandler; /* * Configure the send and receive FIFOs in the MAC */ Result = ConfigureFifo(InstancePtr); if (Result != XST_SUCCESS) { return Result; } /* * If the device is configured for DMA, configure the send and receive DMA * channels in the MAC. */ if (XEmac_mIsDma(InstancePtr)) { Result = ConfigureDma(InstancePtr); if (Result != XST_SUCCESS) { return Result; } if (XEmac_mIsTxDre(InstancePtr) == XTRUE) { InstancePtr->TxDmaControlWord = XEM_DFT_SEND_BD_MASK | XDC_DMACR_DRE_MODE_MASK; } else { InstancePtr->TxDmaControlWord = XEM_DFT_SEND_BD_MASK; } if (XEmac_mIsRxDre(InstancePtr) == XTRUE) { InstancePtr->RxDmaControlWord = XEM_DFT_RECV_BD_MASK | XDC_DMACR_DRE_MODE_MASK; } else { InstancePtr->RxDmaControlWord = XEM_DFT_RECV_BD_MASK; } /* * TX Checksum offload is dynamic and needs to be set for every * BD that uses it. It is not applicable to all data types so the * adapter needs to handle each call individually */ if (XEmac_mIsRxHwCsum(InstancePtr) == XTRUE) { InstancePtr->RxDmaControlWord |= XDC_DMACR_CS_OFFLOAD_MASK; } } /* * Indicate the component is now ready to use. Note that this is done before * we reset the device and the PHY below, which may seem a bit odd. The * choice was made to move it here rather than remove the asserts in various * functions (e.g., Reset() and all functions that it calls). Applications * that use multiple threads, one to initialize the XEmac driver and one * waiting on the IsReady condition could have a problem with this sequence. */ InstancePtr->IsReady = XCOMPONENT_IS_READY; /* * Reset the MAC to get it into its initial state. It is expected that * device configuration by the user will take place after this * initialization is done, but before the device is started. */ XEmac_Reset(InstancePtr); return XST_SUCCESS;}/*****************************************************************************//**** Lookup the device configuration based on the unique device ID. The table* EmacConfigTable contains the configuration info for each device in the system.** @param DeviceId is the unique device ID of the device being looked up.** @return** A pointer to the configuration table entry corresponding to the given* device ID, or XNULL if no match is found.** @note** None.*******************************************************************************/XEmac_Config *XEmac_LookupConfig(Xuint16 DeviceId){ XEmac_Config *CfgPtr = XNULL; int i; for (i=0; i < XPAR_XEMAC_NUM_INSTANCES; i++) { if (XEmac_ConfigTable[i].DeviceId == DeviceId) { CfgPtr = &XEmac_ConfigTable[i]; break; } } return CfgPtr;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -