XilinxProcessorIPLib/drivers/axiethernet/examples/xaxiethernet_mcdma_ping_req_example.c
int AxiEthernetPingReqExample(XAxiEthernet *AxiEthernetInstancePtr,
			      XMcdma *DmaInstancePtr,
			      u16 AxiEthernetDeviceId,
			      u16 AxiMcDmaDeviceId)
{
	int Status;
	int Index;
	int Count;
	int EchoReplyStatus;
	XAxiEthernet_Config *MacCfgPtr;
	XMcdma_Config* DmaConfig;
	SeqNum = 0;
	RecvFrameLength = 0;
	EchoReplyStatus = XST_FAILURE;
	NumOfPingReqPkts = NUM_OF_PING_REQ_PKTS;

	/*
	 *  Get the configuration of AxiEthernet hardware.
	 */
	MacCfgPtr = XAxiEthernet_LookupConfig(AxiEthernetDeviceId);

	/*
	 * Check whether MCDMA is present or not
	 */
	if(MacCfgPtr->AxiDevType != XPAR_AXI_MCDMA) {
		xil_printf
			("Device HW not configured for MCDMA mode\r\n");
		return XST_FAILURE;
	}

	DmaConfig = XMcdma_LookupConfig(AxiMcDmaDeviceId);

	/*
	 * Initialize AXIMCDMA engine. AXIMCDMA engine must be initialized before
	 * AxiEthernet. During AXIMCDMA engine initialization, AXIMCDMA hardware is
	 * reset, and since AXIMCDMA reset line is connected to AxiEthernet, this
	 * would ensure a reset of AxiEthernet.
	 */
	Status = XMcDma_CfgInitialize(DmaInstancePtr, DmaConfig);
	if(Status != XST_SUCCESS) {
		xil_printf("Error initializing DMA\r\n");
		return XST_FAILURE;
	}

	xil_printf("DMA init success\n\r");

	/*
	 * Initialize AxiEthernet hardware.
	 */
	Status = XAxiEthernet_CfgInitialize(AxiEthernetInstancePtr, MacCfgPtr,
					MacCfgPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		xil_printf("Error in initialize");
		return XST_FAILURE;
	}

	if (MacCfgPtr->Enable_1588)
		Padding = 8;

	xil_printf("Cfg init success\n\r");
#if defined(__aarch64__)
        Xil_SetTlbAttributes((UINTPTR)TxBdSpace, NORM_NONCACHE | INNER_SHAREABLE);
        Xil_SetTlbAttributes((UINTPTR)RxBdSpace, NORM_NONCACHE | INNER_SHAREABLE);
#endif

	TxCount = 0;
	RxCount = 0;
	TxBuffPtr = (UINTPTR) &TxFrame;
	RxBuffPtr = (UINTPTR) &RxFrame;

	/* Buffer descriptor Setup for the MCDMA Channels */
	RxBdSetup(DmaInstancePtr, AxiEthernetInstancePtr);
	TxBdSetup(DmaInstancePtr, AxiEthernetInstancePtr);
	RxSetup(DmaInstancePtr, AxiEthernetInstancePtr, Mcdma_ChanId, NUM_OF_PING_REQ_PKTS * 10);

	/*
	 * Set the MAC address
	 */
	Status = XAxiEthernet_SetMacAddress(AxiEthernetInstancePtr,
					LocalMacAddr);
	if (Status != XST_SUCCESS) {
	      xil_printf("Error setting MAC address");
	      return XST_FAILURE;
	}

	PhySetup(AxiEthernetInstancePtr);

	/*
	 * Setting the operating speed of the MAC needs a delay.  There
	 * doesn't seem to be register to poll, so please consider this
	 * during your application design.
	 */
	 sleep(2);

	/*
	 * Make sure Tx and Rx are enabled
	 */
	Status = XAxiEthernet_SetOptions(AxiEthernetInstancePtr,
				         XAE_RECEIVER_ENABLE_OPTION |
					 XAE_TRANSMITTER_ENABLE_OPTION);
	if (Status != XST_SUCCESS) {
		xil_printf("Error setting options");
		return XST_FAILURE;
	}


	/*
	 * Start the Axi Ethernet and enable its ERROR interrupts
	 */
	XAxiEthernet_Start(AxiEthernetInstancePtr);

	/*
	 * Empty any existing receive frames.
	 */
	while (NumOfPingReqPkts--) {

		/*
		 * Introduce delay.
		 */
		Count = DELAY;
		while (Count--) {
		}

		/*
		 * Send an ARP or an ICMP packet based on receive packet.
		 */
		if (SeqNum == 0) {
			SendArpReqFrame(AxiEthernetInstancePtr, DmaInstancePtr, Mcdma_ChanId);
		} else {
			SendEchoReqFrame(AxiEthernetInstancePtr, DmaInstancePtr, Mcdma_ChanId);
		}

		/*
		 * Check next 10 packets for the correct reply.
		 */
		Index = NUM_RX_PACK_CHECK_REQ;
		while (Index--) {

			/*
			 * Wait for a Receive packet.
			 */
			Count = NUM_PACK_CHECK_RX_PACK;
			while (RecvFrameLength == 0) {
				RecvFrameLength = XAxiEnet_Recv(DmaInstancePtr);
				/*
				 * To avoid infinite loop when no packet is
				 * received.
				 */
				if (Count-- == 0) {
					break;
				}
			}

			/*
			 * Process the Receive frame.
			 */
			if (RecvFrameLength != 0) {
				EchoReplyStatus = ProcessRecvFrame(
						AxiEthernetInstancePtr, DmaInstancePtr, Mcdma_ChanId);
			}
			RecvFrameLength = 0;

			/*
			 * Comes out of loop when an echo reply packet is
			 * received.
			 */
			if (EchoReplyStatus == XST_SUCCESS) {
				break;
			}
		}

		/*
		 * If no echo reply packet is received, it reports
		 * request timed out.
		 */
		if (EchoReplyStatus == XST_FAILURE) {
			xil_printf("Packet No: %d",
				NUM_OF_PING_REQ_PKTS - NumOfPingReqPkts);
			xil_printf(" Seq NO %d Request timed out\r\n",
							SeqNum);
		}
	}
	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* The entry point for the AxiEthernet driver to ping request example in polled
* mode. This function will generate specified number of request packets as
* defined in "NUM_OF_PING_REQ_PKTS.
*
* @param	AxiEthernetInstancePtr is a pointer to the instance of the
*		AxiEthernet component.
* @param	DmaInstancePtr is a pointer to the instance of the AXI MCDMA
*		component.
* @param	AxiEthernetDeviceId is Device ID of the Axi Ethernet Device ,
*		typically XPAR_<AXIETHERNET_instance>_DEVICE_ID value from
*		xparameters.h.
* @param	AxiMcDmaDeviceId is Device ID of the Axi DMAA Device ,
*		typically XPAR_<AXIMCDMA_instance>_DEVICE_ID value from
*		xparameters.h.
*
* @return	XST_FAILURE to indicate failure, otherwise it will return
*		XST_SUCCESS.
*
* @note		AxiMcdma hardware must be initialized before initializing
*		AxiEthernet. Since AxiMcdma reset line is connected to the
*		AxiEthernet reset line, a reset of AxiMcdma hardware during its
*		initialization would reset AxiEthernet.
*
******************************************************************************/
The entry point for the AxiEthernet driver to ping request example in polled
mode. This function will generate specified number of request packets as
defined in "NUM_OF_PING_REQ_PKTS.
The entry point for the AxiEthernet driver to ping request example in polled mode . This function will generate specified number of request packets as defined in " NUM_OF_PING_REQ_PKTS .
int AxiEthernetPingReqExample(XAxiEthernet *AxiEthernetInstancePtr,
			      XMcdma *DmaInstancePtr,
			      u16 AxiEthernetDeviceId,
			      u16 AxiMcDmaDeviceId)
{
	int Status;
	int Index;
	int Count;
	int EchoReplyStatus;
	XAxiEthernet_Config *MacCfgPtr;
	XMcdma_Config* DmaConfig;
	SeqNum = 0;
	RecvFrameLength = 0;
	EchoReplyStatus = XST_FAILURE;
	NumOfPingReqPkts = NUM_OF_PING_REQ_PKTS;
	MacCfgPtr = XAxiEthernet_LookupConfig(AxiEthernetDeviceId);
	if(MacCfgPtr->AxiDevType != XPAR_AXI_MCDMA) {
		xil_printf
			("Device HW not configured for MCDMA mode\r\n");
		return XST_FAILURE;
	}
	DmaConfig = XMcdma_LookupConfig(AxiMcDmaDeviceId);
	Status = XMcDma_CfgInitialize(DmaInstancePtr, DmaConfig);
	if(Status != XST_SUCCESS) {
		xil_printf("Error initializing DMA\r\n");
		return XST_FAILURE;
	}
	xil_printf("DMA init success\n\r");
	Status = XAxiEthernet_CfgInitialize(AxiEthernetInstancePtr, MacCfgPtr,
					MacCfgPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		xil_printf("Error in initialize");
		return XST_FAILURE;
	}
	if (MacCfgPtr->Enable_1588)
		Padding = 8;
	xil_printf("Cfg init success\n\r");
#if defined(__aarch64__)
        Xil_SetTlbAttributes((UINTPTR)TxBdSpace, NORM_NONCACHE | INNER_SHAREABLE);
        Xil_SetTlbAttributes((UINTPTR)RxBdSpace, NORM_NONCACHE | INNER_SHAREABLE);
#endif
	TxCount = 0;
	RxCount = 0;
	TxBuffPtr = (UINTPTR) &TxFrame;
	RxBuffPtr = (UINTPTR) &RxFrame;
	RxBdSetup(DmaInstancePtr, AxiEthernetInstancePtr);
	TxBdSetup(DmaInstancePtr, AxiEthernetInstancePtr);
	RxSetup(DmaInstancePtr, AxiEthernetInstancePtr, Mcdma_ChanId, NUM_OF_PING_REQ_PKTS * 10);
	Status = XAxiEthernet_SetMacAddress(AxiEthernetInstancePtr,
					LocalMacAddr);
	if (Status != XST_SUCCESS) {
	      xil_printf("Error setting MAC address");
	      return XST_FAILURE;
	}
	PhySetup(AxiEthernetInstancePtr);
	 sleep(2);
	Status = XAxiEthernet_SetOptions(AxiEthernetInstancePtr,
				         XAE_RECEIVER_ENABLE_OPTION |
					 XAE_TRANSMITTER_ENABLE_OPTION);
	if (Status != XST_SUCCESS) {
		xil_printf("Error setting options");
		return XST_FAILURE;
	}
	XAxiEthernet_Start(AxiEthernetInstancePtr);
	while (NumOfPingReqPkts--) {
		Count = DELAY;
		while (Count--) {
		}
		if (SeqNum == 0) {
			SendArpReqFrame(AxiEthernetInstancePtr, DmaInstancePtr, Mcdma_ChanId);
		} else {
			SendEchoReqFrame(AxiEthernetInstancePtr, DmaInstancePtr, Mcdma_ChanId);
		}
		Index = NUM_RX_PACK_CHECK_REQ;
		while (Index--) {
			Count = NUM_PACK_CHECK_RX_PACK;
			while (RecvFrameLength == 0) {
				RecvFrameLength = XAxiEnet_Recv(DmaInstancePtr);
				if (Count-- == 0) {
					break;
				}
			}
			if (RecvFrameLength != 0) {
				EchoReplyStatus = ProcessRecvFrame(
						AxiEthernetInstancePtr, DmaInstancePtr, Mcdma_ChanId);
			}
			RecvFrameLength = 0;
			if (EchoReplyStatus == XST_SUCCESS) {
				break;
			}
		}
		if (EchoReplyStatus == XST_FAILURE) {
			xil_printf("Packet No: %d",
				NUM_OF_PING_REQ_PKTS - NumOfPingReqPkts);
			xil_printf(" Seq NO %d Request timed out\r\n",
							SeqNum);
		}
	}
	return XST_SUCCESS;
}
int AxiEthernetPingReqExample ( XAxiEthernet * AxiEthernetInstancePtr , XMcdma * DmaInstancePtr , u16 AxiEthernetDeviceId , u16 AxiMcDmaDeviceId ) { int Status ; int Index ; int Count ; int EchoReplyStatus ; XAxiEthernet_Config * MacCfgPtr ; XMcdma_Config * DmaConfig ; SeqNum = 0 ; RecvFrameLength = 0 ; EchoReplyStatus = XST_FAILURE ; NumOfPingReqPkts = NUM_OF_PING_REQ_PKTS ; MacCfgPtr = XAxiEthernet_LookupConfig ( AxiEthernetDeviceId ) ; if ( MacCfgPtr -> AxiDevType != XPAR_AXI_MCDMA ) { xil_printf ( " \r \n " ) ; return XST_FAILURE ; } DmaConfig = XMcdma_LookupConfig ( AxiMcDmaDeviceId ) ; Status = XMcDma_CfgInitialize ( DmaInstancePtr , DmaConfig ) ; if ( Status != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return XST_FAILURE ; } xil_printf ( " \n \r " ) ; Status = XAxiEthernet_CfgInitialize ( AxiEthernetInstancePtr , MacCfgPtr , MacCfgPtr -> BaseAddress ) ; if ( Status != XST_SUCCESS ) { xil_printf ( " " ) ; return XST_FAILURE ; } if ( MacCfgPtr -> Enable_1588 ) Padding = 8 ; xil_printf ( " \n \r " ) ; #if defined ( __aarch64__ ) Xil_SetTlbAttributes ( ( UINTPTR ) TxBdSpace , NORM_NONCACHE | INNER_SHAREABLE ) ; Xil_SetTlbAttributes ( ( UINTPTR ) RxBdSpace , NORM_NONCACHE | INNER_SHAREABLE ) ; #endif TxCount = 0 ; RxCount = 0 ; TxBuffPtr = ( UINTPTR ) & TxFrame ; RxBuffPtr = ( UINTPTR ) & RxFrame ; RxBdSetup ( DmaInstancePtr , AxiEthernetInstancePtr ) ; TxBdSetup ( DmaInstancePtr , AxiEthernetInstancePtr ) ; RxSetup ( DmaInstancePtr , AxiEthernetInstancePtr , Mcdma_ChanId , NUM_OF_PING_REQ_PKTS * 10 ) ; Status = XAxiEthernet_SetMacAddress ( AxiEthernetInstancePtr , LocalMacAddr ) ; if ( Status != XST_SUCCESS ) { xil_printf ( " " ) ; return XST_FAILURE ; } PhySetup ( AxiEthernetInstancePtr ) ; sleep ( 2 ) ; Status = XAxiEthernet_SetOptions ( AxiEthernetInstancePtr , XAE_RECEIVER_ENABLE_OPTION | XAE_TRANSMITTER_ENABLE_OPTION ) ; if ( Status != XST_SUCCESS ) { xil_printf ( " " ) ; return XST_FAILURE ; } XAxiEthernet_Start ( AxiEthernetInstancePtr ) ; while ( NumOfPingReqPkts -- ) { Count = DELAY ; while ( Count -- ) { } if ( SeqNum == 0 ) { SendArpReqFrame ( AxiEthernetInstancePtr , DmaInstancePtr , Mcdma_ChanId ) ; } else { SendEchoReqFrame ( AxiEthernetInstancePtr , DmaInstancePtr , Mcdma_ChanId ) ; } Index = NUM_RX_PACK_CHECK_REQ ; while ( Index -- ) { Count = NUM_PACK_CHECK_RX_PACK ; while ( RecvFrameLength == 0 ) { RecvFrameLength = XAxiEnet_Recv ( DmaInstancePtr ) ; if ( Count -- == 0 ) { break ; } } if ( RecvFrameLength != 0 ) { EchoReplyStatus = ProcessRecvFrame ( AxiEthernetInstancePtr , DmaInstancePtr , Mcdma_ChanId ) ; } RecvFrameLength = 0 ; if ( EchoReplyStatus == XST_SUCCESS ) { break ; } } if ( EchoReplyStatus == XST_FAILURE ) { xil_printf ( " " , NUM_OF_PING_REQ_PKTS - NumOfPingReqPkts ) ; xil_printf ( " \r \n " , SeqNum ) ; } } return XST_SUCCESS ; }
The entry point for the AxiEthernet driver to ping request example in polled
mode.
The entry point for the AxiEthernet driver to ping request example in polled mode .
/*
	 *  Get the configuration of AxiEthernet hardware.
	 */ /*
	 * Check whether MCDMA is present or not
	 */ /*
	 * Initialize AXIMCDMA engine. AXIMCDMA engine must be initialized before
	 * AxiEthernet. During AXIMCDMA engine initialization, AXIMCDMA hardware is
	 * reset, and since AXIMCDMA reset line is connected to AxiEthernet, this
	 * would ensure a reset of AxiEthernet.
	 */ /*
	 * Initialize AxiEthernet hardware.
	 */ /* Buffer descriptor Setup for the MCDMA Channels */ /*
	 * Set the MAC address
	 */ /*
	 * Setting the operating speed of the MAC needs a delay.  There
	 * doesn't seem to be register to poll, so please consider this
	 * during your application design.
	 */ /*
	 * Make sure Tx and Rx are enabled
	 */ /*
	 * Start the Axi Ethernet and enable its ERROR interrupts
	 */ /*
	 * Empty any existing receive frames.
	 */ /*
		 * Introduce delay.
		 */ /*
		 * Send an ARP or an ICMP packet based on receive packet.
		 */ /*
		 * Check next 10 packets for the correct reply.
		 */ /*
			 * Wait for a Receive packet.
			 */ /*
				 * To avoid infinite loop when no packet is
				 * received.
				 */ /*
			 * Process the Receive frame.
			 */ /*
			 * Comes out of loop when an echo reply packet is
			 * received.
			 */ /*
		 * If no echo reply packet is received, it reports
		 * request timed out.
		 */