XilinxProcessorIPLib/drivers/axiethernet/examples/xaxiethernet_example_intr_fifo.c
int AxiEthernetMultipleFramesIntrExample(XAxiEthernet *AxiEthernetInstancePtr,
						XLlFifo *FifoInstancePtr)
{
	int FramesToLoopback;
	int PayloadSize;
	u32 TxFrameLength;
	u32 RxFrameLength;
	int Index;

	/*
	 *  Clear variables shared with callbacks
	 */
	FramesRx = 0;
	FramesRxInts = 0;
	FramesTxInts = 0;
	DeviceErrors = 0;
	FrameDataErrors = 0;

	/*
	 * Setup the number of frames to loopback and the size of the frame to
	 * loopback. The default settings should work for every case. Modifying
	 * the settings can cause problems, see discussion below:
	 *
	 * If PayloadSize is set small and FramesToLoopback high, then it is
	 * possible to cause the transmit status FIFO to overflow.
	 *
	 * If PayloadSize is set large and FramesToLoopback high, then it is
	 * possible to cause the transmit packet FIFO to overflow.
	 *
	 * Either of these scenarios may be worth trying out to observe how the
	 * driver reacts. The exact values to cause these types of errors
	 * will vary due to the sizes of the FIFOs selected at hardware build
	 * time. But the following settings should create problems for all
	 * FIFO sizes:
	 *
	 * Transmit status FIFO overflow
	 *    PayloadSize = 1
	 *    FramesToLoopback = 1000
	 *
	 * Transmit packet FIFO overflow
	 *    PayloadSize = 1500
	 *    FramesToLoopback = 16
	 *
	 * These values should always work without error
	 *    PayloadSize = 100
	 *    FramesToLoopback = 5
	 */
	PayloadSize = 100;
	FramesToLoopback = 5;

	/*
	 * Setup the transmit packet
	 */
	AxiEthernetUtilFrameHdrFormatMAC(&TxFrame, AxiEthernetMAC);
	AxiEthernetUtilFrameHdrFormatType(&TxFrame, PayloadSize);
	AxiEthernetUtilFrameSetPayloadData(&TxFrame, PayloadSize);

	/*
	 * Calculate frame length (not including FCS)
	 */
	TxFrameLength = XAE_HDR_SIZE + PayloadSize;

		/****************/
		/* Setup device */
		/****************/

	/*
	 * Start the device
	 */
	XAxiEthernet_Start(AxiEthernetInstancePtr);

	/*
	 * Enable the interrupts
	 */
	XLlFifo_IntEnable(FifoInstancePtr, XLLF_INT_ALL_MASK);


	/****************/
	/* Send packets */
	/****************/

	/*
	 * Since we may be interested to see what happens when FIFOs overflow,
	 * don't check for room in the transmit packet FIFO prior to writing
	 * to it.
	 */

	/*
	 * With the xps_ll_fifo core we can't stuff the fifo with data from
	 * multiple packets and then send them. Instead, the code needs to
	 * write the data, and then immediately send the packet before
	 * writing the data for the next packet.
	 */
	for (Index = 0; Index < FramesToLoopback; Index++) {
		/*
		 * Write frame data to FIFO
		 */
		XLlFifo_Write(FifoInstancePtr, TxFrame, TxFrameLength);
		/*
		 * Initiate the transmission
		 */
		XLlFifo_TxSetLen(FifoInstancePtr, TxFrameLength);
	}

	/*******************/
	/* Receive packets */
	/*******************/

	/*
	 * Now wait for frames to be received. When the callback is executed,
	 * it will disable interrupts and set a shared variable which will
	 * trigger this routine to process received frames
	 */
	for (Index = 0; Index < FramesToLoopback; Index++) {
		/*
		 * Wait
		 */
		while (FramesRxInts == 0);

			/*
		 * Frame has arrived, so get the length
		 */
		RxFrameLength = XLlFifo_RxGetLen(FifoInstancePtr);

		/*
		 * Decision time: We can re-enable receive interrupts here or
		 * after we read the frame out of the FIFO. This is a matter
		 * of preference and goals of an application using the driver.
		 */
		XLlFifo_IntEnable(FifoInstancePtr, XLLF_INT_RC_MASK);

		/*
		 * Frame size as expected?
		 */
		if ((RxFrameLength) != TxFrameLength) {
			AxiEthernetUtilErrorTrap("Receive length incorrect");
		}

		/*
		 * Clear out receive packet memory area
		 */
		AxiEthernetUtilFrameMemClear(&RxFrame);

		/*
		 * Read frame from packet FIFO
		 */
		XLlFifo_Read(FifoInstancePtr, &RxFrame, RxFrameLength);
		/*
		 * Verify the received data
		 */
		if (AxiEthernetUtilFrameVerify(&TxFrame, &RxFrame) != 0) {
			AxiEthernetUtilErrorTrap("Data mismatch");
			return XST_FAILURE;
		}
	}

	/*
	 * Stop the device
	 */
	XAxiEthernet_Stop(AxiEthernetInstancePtr);

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* This example sends and receives a batch of frames. Frame reception is handled
* in this function and not in the callback function.
*
* Use this method of reception when interrupt latency is important.
*
* @param	AxiEthernetInstancePtr is a pointer to the instance of the
*		AxiEthernet component.
* @param	FifoInstancePtr is a pointer to the instance of the Fifo
*		component.
*
* @return
*		- XST_SUCCESS to indicate success.
*		- XST_FAILURE.to indicate failure.
*
* @note		None.
*
******************************************************************************/
This example sends and receives a batch of frames. Frame reception is handled
in this function and not in the callback function.

Use this method of reception when interrupt latency is important.
This example sends and receives a batch of frames . Frame reception is handled in this function and not in the callback function . Use this method of reception when interrupt latency is important .
int AxiEthernetMultipleFramesIntrExample(XAxiEthernet *AxiEthernetInstancePtr,
						XLlFifo *FifoInstancePtr)
{
	int FramesToLoopback;
	int PayloadSize;
	u32 TxFrameLength;
	u32 RxFrameLength;
	int Index;
	FramesRx = 0;
	FramesRxInts = 0;
	FramesTxInts = 0;
	DeviceErrors = 0;
	FrameDataErrors = 0;
	PayloadSize = 100;
	FramesToLoopback = 5;
	AxiEthernetUtilFrameHdrFormatMAC(&TxFrame, AxiEthernetMAC);
	AxiEthernetUtilFrameHdrFormatType(&TxFrame, PayloadSize);
	AxiEthernetUtilFrameSetPayloadData(&TxFrame, PayloadSize);
	TxFrameLength = XAE_HDR_SIZE + PayloadSize;
	XAxiEthernet_Start(AxiEthernetInstancePtr);
	XLlFifo_IntEnable(FifoInstancePtr, XLLF_INT_ALL_MASK);
	for (Index = 0; Index < FramesToLoopback; Index++) {
		XLlFifo_Write(FifoInstancePtr, TxFrame, TxFrameLength);
		XLlFifo_TxSetLen(FifoInstancePtr, TxFrameLength);
	}
	for (Index = 0; Index < FramesToLoopback; Index++) {
		while (FramesRxInts == 0);
		RxFrameLength = XLlFifo_RxGetLen(FifoInstancePtr);
		XLlFifo_IntEnable(FifoInstancePtr, XLLF_INT_RC_MASK);
		if ((RxFrameLength) != TxFrameLength) {
			AxiEthernetUtilErrorTrap("Receive length incorrect");
		}
		AxiEthernetUtilFrameMemClear(&RxFrame);
		XLlFifo_Read(FifoInstancePtr, &RxFrame, RxFrameLength);
		if (AxiEthernetUtilFrameVerify(&TxFrame, &RxFrame) != 0) {
			AxiEthernetUtilErrorTrap("Data mismatch");
			return XST_FAILURE;
		}
	}
	XAxiEthernet_Stop(AxiEthernetInstancePtr);
	return XST_SUCCESS;
}
int AxiEthernetMultipleFramesIntrExample ( XAxiEthernet * AxiEthernetInstancePtr , XLlFifo * FifoInstancePtr ) { int FramesToLoopback ; int PayloadSize ; u32 TxFrameLength ; u32 RxFrameLength ; int Index ; FramesRx = 0 ; FramesRxInts = 0 ; FramesTxInts = 0 ; DeviceErrors = 0 ; FrameDataErrors = 0 ; PayloadSize = 100 ; FramesToLoopback = 5 ; AxiEthernetUtilFrameHdrFormatMAC ( & TxFrame , AxiEthernetMAC ) ; AxiEthernetUtilFrameHdrFormatType ( & TxFrame , PayloadSize ) ; AxiEthernetUtilFrameSetPayloadData ( & TxFrame , PayloadSize ) ; TxFrameLength = XAE_HDR_SIZE + PayloadSize ; XAxiEthernet_Start ( AxiEthernetInstancePtr ) ; XLlFifo_IntEnable ( FifoInstancePtr , XLLF_INT_ALL_MASK ) ; for ( Index = 0 ; Index < FramesToLoopback ; Index ++ ) { XLlFifo_Write ( FifoInstancePtr , TxFrame , TxFrameLength ) ; XLlFifo_TxSetLen ( FifoInstancePtr , TxFrameLength ) ; } for ( Index = 0 ; Index < FramesToLoopback ; Index ++ ) { while ( FramesRxInts == 0 ) ; RxFrameLength = XLlFifo_RxGetLen ( FifoInstancePtr ) ; XLlFifo_IntEnable ( FifoInstancePtr , XLLF_INT_RC_MASK ) ; if ( ( RxFrameLength ) != TxFrameLength ) { AxiEthernetUtilErrorTrap ( " " ) ; } AxiEthernetUtilFrameMemClear ( & RxFrame ) ; XLlFifo_Read ( FifoInstancePtr , & RxFrame , RxFrameLength ) ; if ( AxiEthernetUtilFrameVerify ( & TxFrame , & RxFrame ) != 0 ) { AxiEthernetUtilErrorTrap ( " " ) ; return XST_FAILURE ; } } XAxiEthernet_Stop ( AxiEthernetInstancePtr ) ; return XST_SUCCESS ; }
This example sends and receives a batch of frames.
This example sends and receives a batch of frames .
/*
	 *  Clear variables shared with callbacks
	 */ /*
	 * Setup the number of frames to loopback and the size of the frame to
	 * loopback. The default settings should work for every case. Modifying
	 * the settings can cause problems, see discussion below:
	 *
	 * If PayloadSize is set small and FramesToLoopback high, then it is
	 * possible to cause the transmit status FIFO to overflow.
	 *
	 * If PayloadSize is set large and FramesToLoopback high, then it is
	 * possible to cause the transmit packet FIFO to overflow.
	 *
	 * Either of these scenarios may be worth trying out to observe how the
	 * driver reacts. The exact values to cause these types of errors
	 * will vary due to the sizes of the FIFOs selected at hardware build
	 * time. But the following settings should create problems for all
	 * FIFO sizes:
	 *
	 * Transmit status FIFO overflow
	 *    PayloadSize = 1
	 *    FramesToLoopback = 1000
	 *
	 * Transmit packet FIFO overflow
	 *    PayloadSize = 1500
	 *    FramesToLoopback = 16
	 *
	 * These values should always work without error
	 *    PayloadSize = 100
	 *    FramesToLoopback = 5
	 */ /*
	 * Setup the transmit packet
	 */ /*
	 * Calculate frame length (not including FCS)
	 */ /****************/ /* Setup device */ /****************/ /*
	 * Start the device
	 */ /*
	 * Enable the interrupts
	 */ /****************/ /* Send packets */ /****************/ /*
	 * Since we may be interested to see what happens when FIFOs overflow,
	 * don't check for room in the transmit packet FIFO prior to writing
	 * to it.
	 */ /*
	 * With the xps_ll_fifo core we can't stuff the fifo with data from
	 * multiple packets and then send them. Instead, the code needs to
	 * write the data, and then immediately send the packet before
	 * writing the data for the next packet.
	 */ /*
		 * Write frame data to FIFO
		 */ /*
		 * Initiate the transmission
		 */ /*******************/ /* Receive packets */ /*******************/ /*
	 * Now wait for frames to be received. When the callback is executed,
	 * it will disable interrupts and set a shared variable which will
	 * trigger this routine to process received frames
	 */ /*
		 * Wait
		 */ /*
		 * Frame has arrived, so get the length
		 */ /*
		 * Decision time: We can re-enable receive interrupts here or
		 * after we read the frame out of the FIFO. This is a matter
		 * of preference and goals of an application using the driver.
		 */ /*
		 * Frame size as expected?
		 */ /*
		 * Clear out receive packet memory area
		 */ /*
		 * Read frame from packet FIFO
		 */ /*
		 * Verify the received data
		 */ /*
	 * Stop the device
	 */