XilinxProcessorIPLib/drivers/axiethernet/examples/xaxiethernet_example_polled.c
int AxiEthernetSingleFramePolledExample(void)
{
	u32 FifoFreeBytes;
	int PayloadSize = 100;
	u32 TxFrameLength;
	u32 RxFrameLength;

	/*
	 * Start the Axi Ethernet device
	 */
	XAxiEthernet_Start(&AxiEthernetInstance);

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

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

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

	/*******************/
	/* Send the packet */
	/*******************/

	/*
	 * Wait for enough room in FIFO to become available
	 */
	do {
		FifoFreeBytes = XLlFifo_TxVacancy(&FifoInstance);
	} while (FifoFreeBytes < TxFrameLength);

	/*
	 * Write the frame data to FIFO
	 */
	XLlFifo_Write(&FifoInstance, TxFrame, TxFrameLength);

	/*
	 * Initiate transmit
	 */
	XLlFifo_TxSetLen(&FifoInstance, TxFrameLength);

	/*
	 * Wait for status of the transmitted packet
	 */
	switch (AxiEthernetPollForTxStatus()) {
	case XST_SUCCESS:/* Got a successful transmit status */
		break;

	case XST_NO_DATA:	/* Timed out */
		AxiEthernetUtilErrorTrap("Tx timeout");
		return XST_FAILURE;

	default:		/* Some other error */
		return XST_FAILURE;
	}

	/**********************/
	/* Receive the packet */
	/**********************/

	/*
	 * Wait for packet Rx
	 */
	switch (AxiEthernetPollForRxStatus()) {
	case XST_SUCCESS:/* Got a successful receive status */
		break;

	case XST_NO_DATA:	/* Timed out */
		AxiEthernetUtilErrorTrap("Rx timeout");
		return XST_FAILURE;

	default:		/* Some other error */
		return XST_FAILURE;
	}

	while(XLlFifo_RxOccupancy(&FifoInstance)) {
		/*
		 * A packet as arrived, get its length
		 */
		RxFrameLength = XLlFifo_RxGetLen(&FifoInstance);

		/*
		 * Read the received packet data
		 */
		XLlFifo_Read(&FifoInstance, &RxFrame, RxFrameLength);

		/*
		 * Verify the received frame length
		 */
		if ((RxFrameLength) != TxFrameLength) {
			AxiEthernetUtilErrorTrap("Receive length incorrect");
			return XST_FAILURE;
		}

		/*
		 * Validate frame data
		 */
		if (AxiEthernetUtilFrameVerify(&TxFrame, &RxFrame) != 0) {
			AxiEthernetUtilErrorTrap("Receive Data mismatch");
			return XST_FAILURE;
		}
	}

	/*
	 * Stop device
	 */
	XAxiEthernet_Stop(&AxiEthernetInstance);

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* This function demonstrates the usage of the Axi Ethernet by sending and
* receiving a single frame in polled mode.
*
* @param	None.
*
* @return	-XST_SUCCESS to indicate success
*		-XST_FAILURE to indicate failure
*
* @note		None.
*
******************************************************************************/
This function demonstrates the usage of the Axi Ethernet by sending and
receiving a single frame in polled mode.
This function demonstrates the usage of the Axi Ethernet by sending and receiving a single frame in polled mode .
int AxiEthernetSingleFramePolledExample(void)
{
	u32 FifoFreeBytes;
	int PayloadSize = 100;
	u32 TxFrameLength;
	u32 RxFrameLength;
	XAxiEthernet_Start(&AxiEthernetInstance);
	AxiEthernetUtilFrameHdrFormatMAC(&TxFrame, AxiEthernetMAC);
	AxiEthernetUtilFrameHdrFormatType(&TxFrame, PayloadSize);
	AxiEthernetUtilFrameSetPayloadData(&TxFrame, PayloadSize);
	AxiEthernetUtilFrameMemClear(&RxFrame);
	TxFrameLength = XAE_HDR_SIZE + PayloadSize;
	do {
		FifoFreeBytes = XLlFifo_TxVacancy(&FifoInstance);
	} while (FifoFreeBytes < TxFrameLength);
	XLlFifo_Write(&FifoInstance, TxFrame, TxFrameLength);
	XLlFifo_TxSetLen(&FifoInstance, TxFrameLength);
	switch (AxiEthernetPollForTxStatus()) {
	case XST_SUCCESS:
		break;
	case XST_NO_DATA:	
		AxiEthernetUtilErrorTrap("Tx timeout");
		return XST_FAILURE;
	default:		
		return XST_FAILURE;
	}
	switch (AxiEthernetPollForRxStatus()) {
	case XST_SUCCESS:
		break;
	case XST_NO_DATA:	
		AxiEthernetUtilErrorTrap("Rx timeout");
		return XST_FAILURE;
	default:		
		return XST_FAILURE;
	}
	while(XLlFifo_RxOccupancy(&FifoInstance)) {
		RxFrameLength = XLlFifo_RxGetLen(&FifoInstance);
		XLlFifo_Read(&FifoInstance, &RxFrame, RxFrameLength);
		if ((RxFrameLength) != TxFrameLength) {
			AxiEthernetUtilErrorTrap("Receive length incorrect");
			return XST_FAILURE;
		}
		if (AxiEthernetUtilFrameVerify(&TxFrame, &RxFrame) != 0) {
			AxiEthernetUtilErrorTrap("Receive Data mismatch");
			return XST_FAILURE;
		}
	}
	XAxiEthernet_Stop(&AxiEthernetInstance);
	return XST_SUCCESS;
}
int AxiEthernetSingleFramePolledExample ( void ) { u32 FifoFreeBytes ; int PayloadSize = 100 ; u32 TxFrameLength ; u32 RxFrameLength ; XAxiEthernet_Start ( & AxiEthernetInstance ) ; AxiEthernetUtilFrameHdrFormatMAC ( & TxFrame , AxiEthernetMAC ) ; AxiEthernetUtilFrameHdrFormatType ( & TxFrame , PayloadSize ) ; AxiEthernetUtilFrameSetPayloadData ( & TxFrame , PayloadSize ) ; AxiEthernetUtilFrameMemClear ( & RxFrame ) ; TxFrameLength = XAE_HDR_SIZE + PayloadSize ; do { FifoFreeBytes = XLlFifo_TxVacancy ( & FifoInstance ) ; } while ( FifoFreeBytes < TxFrameLength ) ; XLlFifo_Write ( & FifoInstance , TxFrame , TxFrameLength ) ; XLlFifo_TxSetLen ( & FifoInstance , TxFrameLength ) ; switch ( AxiEthernetPollForTxStatus ( ) ) { case XST_SUCCESS : break ; case XST_NO_DATA : AxiEthernetUtilErrorTrap ( " " ) ; return XST_FAILURE ; default : return XST_FAILURE ; } switch ( AxiEthernetPollForRxStatus ( ) ) { case XST_SUCCESS : break ; case XST_NO_DATA : AxiEthernetUtilErrorTrap ( " " ) ; return XST_FAILURE ; default : return XST_FAILURE ; } while ( XLlFifo_RxOccupancy ( & FifoInstance ) ) { RxFrameLength = XLlFifo_RxGetLen ( & FifoInstance ) ; XLlFifo_Read ( & FifoInstance , & RxFrame , RxFrameLength ) ; if ( ( RxFrameLength ) != TxFrameLength ) { AxiEthernetUtilErrorTrap ( " " ) ; return XST_FAILURE ; } if ( AxiEthernetUtilFrameVerify ( & TxFrame , & RxFrame ) != 0 ) { AxiEthernetUtilErrorTrap ( " " ) ; return XST_FAILURE ; } } XAxiEthernet_Stop ( & AxiEthernetInstance ) ; return XST_SUCCESS ; }
This function demonstrates the usage of the Axi Ethernet by sending and
receiving a single frame in polled mode.
This function demonstrates the usage of the Axi Ethernet by sending and receiving a single frame in polled mode .
/*
	 * Start the Axi Ethernet device
	 */ /*
	 * Setup the packet to be transmitted
	 */ /*
	 * Clear out the receive packet memory area
	 */ /*
	 * Calculate frame length (not including FCS)
	 */ /*******************/ /* Send the packet */ /*******************/ /*
	 * Wait for enough room in FIFO to become available
	 */ /*
	 * Write the frame data to FIFO
	 */ /*
	 * Initiate transmit
	 */ /*
	 * Wait for status of the transmitted packet
	 */ /* Got a successful transmit status */ /* Timed out */ /* Some other error */ /**********************/ /* Receive the packet */ /**********************/ /*
	 * Wait for packet Rx
	 */ /* Got a successful receive status */ /* Timed out */ /* Some other error */ /*
		 * A packet as arrived, get its length
		 */ /*
		 * Read the received packet data
		 */ /*
		 * Verify the received frame length
		 */ /*
		 * Validate frame data
		 */ /*
	 * Stop device
	 */