XilinxProcessorIPLib/drivers/emaclite/examples/xemaclite_intr_example.c
int EmacLiteIntrExample(INTC *IntcInstancePtr,
			XEmacLite *EmacLiteInstPtr,
			u16 EmacLiteDeviceId,
			u16 EmacLiteIntrId)
{
	int Status;
	u32 PhyAddress = 0;
	XEmacLite_Config *ConfigPtr;

	/*
	 * Initialize the EmacLite device.
	 */
	ConfigPtr = XEmacLite_LookupConfig(EmacLiteDeviceId);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}
	Status = XEmacLite_CfgInitialize(EmacLiteInstPtr,
					ConfigPtr,
					ConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Set the MAC address.
	 */
	XEmacLite_SetMacAddress(EmacLiteInstPtr, LocalAddress);

	/*
	 * Empty any existing receive frames.
	 */
	XEmacLite_FlushReceive(EmacLiteInstPtr);


	/*
	 * Check if there is a Tx buffer available, if there isn't it is an
	 * error.
	 */
	if (XEmacLite_TxBufferAvailable(EmacLiteInstPtr) != TRUE) {
		return XST_FAILURE;
	}


	/*
	 * Set up the interrupt infrastructure.
	 */
	Status = EmacLiteSetupIntrSystem(IntcInstancePtr,
					 EmacLiteInstPtr,
					 EmacLiteIntrId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Setup the EmacLite handlers.
	 */
	XEmacLite_SetRecvHandler((EmacLiteInstPtr), (void *)(EmacLiteInstPtr),
				 (XEmacLite_Handler)EmacLiteRecvHandler);
	XEmacLite_SetSendHandler((EmacLiteInstPtr), (void *)(EmacLiteInstPtr),
				 (XEmacLite_Handler)EmacLiteSendHandler);


	/*
	 * Enable the interrupts in the EmacLite controller.
	 */
	XEmacLite_EnableInterrupts(EmacLiteInstPtr);
	RecvFrameLength = 0;

	/*
	 * If the MDIO is configured in the device.
	 */
	if (XEmacLite_IsMdioConfigured(EmacLiteInstPtr)) {
		/*
		 * Detect the PHY device and enable the MAC Loop back
		 * in the PHY.
		 */
		PhyAddress = EmacLitePhyDetect(EmacLiteInstPtr);
		Status = EmacLiteEnablePhyLoopBack(EmacLiteInstPtr,
							 PhyAddress);
		if (Status != XST_SUCCESS) {
			XEmacLite_DisableInterrupts(EmacLiteInstPtr);
			EmacLiteDisableIntrSystem(IntcInstancePtr,
							 EmacLiteIntrId);
			return XST_FAILURE;
		}
	}

	/*
	 * Transmit an Ethernet frame.
	 */
	Status = EmacLiteSendFrame(EmacLiteInstPtr,
				   EMACLITE_TEST_FRAME_SIZE);
	if (Status != XST_SUCCESS) {
		if (XEmacLite_IsMdioConfigured(EmacLiteInstPtr)) {
			/*
			 * Disable the MAC Loop back in the PHY and
			 * disable/disconnect the EmacLite Interrupts.
			 */
			EmacLiteDisablePhyLoopBack(EmacLiteInstPtr,
							 PhyAddress);
			XEmacLite_DisableInterrupts(EmacLiteInstPtr);
			EmacLiteDisableIntrSystem(IntcInstancePtr,
							 EmacLiteIntrId);
			return XST_FAILURE;
		}
	}

	/*
	 * Wait for the frame to be transmitted.
	 */
	while (TransmitComplete == FALSE);

	/*
	 * If the MDIO is not configured in the core then return XST_SUCCESS
	 * as the frame has been transmitted.
	 */
	if (!XEmacLite_IsMdioConfigured(EmacLiteInstPtr)) {

		/*
		 * Disable and disconnect the EmacLite Interrupts.
		 */
		XEmacLite_DisableInterrupts(EmacLiteInstPtr);
		EmacLiteDisableIntrSystem(IntcInstancePtr, EmacLiteIntrId);
		return XST_SUCCESS;
	}

	/*
	 * Wait for the frame to be received.
	 */
	while (RecvFrameLength == 0);

	/*
	 * Check the received frame.
	 */
	Status = EmacLiteRecvFrame(EMACLITE_TEST_FRAME_SIZE);

	/*
	 *  Diasble the Loop Back.
	 */
	if (XEmacLite_IsMdioConfigured(EmacLiteInstPtr)) {
		/*
		 * Disable the MAC Loop back in the PHY.
		 */
		 Status |= EmacLiteDisablePhyLoopBack(EmacLiteInstPtr,
		 PhyAddress);
	}

	/*
	 * Disable and disconnect the EmacLite Interrupts.
	 */
	XEmacLite_DisableInterrupts(EmacLiteInstPtr);
	EmacLiteDisableIntrSystem(IntcInstancePtr, EmacLiteIntrId);
	if ((Status != XST_SUCCESS) && (Status != XST_NO_DATA)) {
		return XST_FAILURE;
	}

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* The main entry point for the EmacLite driver example in interrupt mode.

* This function will transmit/receive the Ethernet frames and verify the
* data in the received frame (if the MDIO interface is configured in the
* EmacLite core).
* This function simply transmits a frame if the MDIO interface is not
* configured in the EmacLite core.
*
* @param	IntcInstancePtr is a pointer to the instance of the Intc.
* @param	EmacLiteInstPtr is a pointer to the instance of the EmacLite.
* @param	EmacLiteDeviceId is device ID of the XEmacLite Device ,
*		typically XPAR_<EMACLITE_instance>_DEVICE_ID value from
*		xparameters.h.
* @param	EmacLiteIntrId is the interrupt ID and is typically
*		XPAR_<INTC_instance>_<EMACLITE_instance>_VEC_ID value from
*		xparameters.h.
*
* @return	XST_SUCCESS if successful, otherwise XST_FAILURE.
*
* @note		None.
*
******************************************************************************/
The main entry point for the EmacLite driver example in interrupt mode.
This function will transmit/receive the Ethernet frames and verify the
data in the received frame (if the MDIO interface is configured in the
EmacLite core).
This function simply transmits a frame if the MDIO interface is not
configured in the EmacLite core.
The main entry point for the EmacLite driver example in interrupt mode . This function will transmit / receive the Ethernet frames and verify the data in the received frame ( if the MDIO interface is configured in the EmacLite core ) . This function simply transmits a frame if the MDIO interface is not configured in the EmacLite core .
int EmacLiteIntrExample(INTC *IntcInstancePtr,
			XEmacLite *EmacLiteInstPtr,
			u16 EmacLiteDeviceId,
			u16 EmacLiteIntrId)
{
	int Status;
	u32 PhyAddress = 0;
	XEmacLite_Config *ConfigPtr;
	ConfigPtr = XEmacLite_LookupConfig(EmacLiteDeviceId);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}
	Status = XEmacLite_CfgInitialize(EmacLiteInstPtr,
					ConfigPtr,
					ConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XEmacLite_SetMacAddress(EmacLiteInstPtr, LocalAddress);
	XEmacLite_FlushReceive(EmacLiteInstPtr);
	if (XEmacLite_TxBufferAvailable(EmacLiteInstPtr) != TRUE) {
		return XST_FAILURE;
	}
	Status = EmacLiteSetupIntrSystem(IntcInstancePtr,
					 EmacLiteInstPtr,
					 EmacLiteIntrId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XEmacLite_SetRecvHandler((EmacLiteInstPtr), (void *)(EmacLiteInstPtr),
				 (XEmacLite_Handler)EmacLiteRecvHandler);
	XEmacLite_SetSendHandler((EmacLiteInstPtr), (void *)(EmacLiteInstPtr),
				 (XEmacLite_Handler)EmacLiteSendHandler);
	XEmacLite_EnableInterrupts(EmacLiteInstPtr);
	RecvFrameLength = 0;
	if (XEmacLite_IsMdioConfigured(EmacLiteInstPtr)) {
		PhyAddress = EmacLitePhyDetect(EmacLiteInstPtr);
		Status = EmacLiteEnablePhyLoopBack(EmacLiteInstPtr,
							 PhyAddress);
		if (Status != XST_SUCCESS) {
			XEmacLite_DisableInterrupts(EmacLiteInstPtr);
			EmacLiteDisableIntrSystem(IntcInstancePtr,
							 EmacLiteIntrId);
			return XST_FAILURE;
		}
	}
	Status = EmacLiteSendFrame(EmacLiteInstPtr,
				   EMACLITE_TEST_FRAME_SIZE);
	if (Status != XST_SUCCESS) {
		if (XEmacLite_IsMdioConfigured(EmacLiteInstPtr)) {
			EmacLiteDisablePhyLoopBack(EmacLiteInstPtr,
							 PhyAddress);
			XEmacLite_DisableInterrupts(EmacLiteInstPtr);
			EmacLiteDisableIntrSystem(IntcInstancePtr,
							 EmacLiteIntrId);
			return XST_FAILURE;
		}
	}
	while (TransmitComplete == FALSE);
	if (!XEmacLite_IsMdioConfigured(EmacLiteInstPtr)) {
		XEmacLite_DisableInterrupts(EmacLiteInstPtr);
		EmacLiteDisableIntrSystem(IntcInstancePtr, EmacLiteIntrId);
		return XST_SUCCESS;
	}
	while (RecvFrameLength == 0);
	Status = EmacLiteRecvFrame(EMACLITE_TEST_FRAME_SIZE);
	if (XEmacLite_IsMdioConfigured(EmacLiteInstPtr)) {
		 Status |= EmacLiteDisablePhyLoopBack(EmacLiteInstPtr,
		 PhyAddress);
	}
	XEmacLite_DisableInterrupts(EmacLiteInstPtr);
	EmacLiteDisableIntrSystem(IntcInstancePtr, EmacLiteIntrId);
	if ((Status != XST_SUCCESS) && (Status != XST_NO_DATA)) {
		return XST_FAILURE;
	}
	return XST_SUCCESS;
}
int EmacLiteIntrExample ( INTC * IntcInstancePtr , XEmacLite * EmacLiteInstPtr , u16 EmacLiteDeviceId , u16 EmacLiteIntrId ) { int Status ; u32 PhyAddress = 0 ; XEmacLite_Config * ConfigPtr ; ConfigPtr = XEmacLite_LookupConfig ( EmacLiteDeviceId ) ; if ( ConfigPtr == NULL ) { return XST_FAILURE ; } Status = XEmacLite_CfgInitialize ( EmacLiteInstPtr , ConfigPtr , ConfigPtr -> BaseAddress ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XEmacLite_SetMacAddress ( EmacLiteInstPtr , LocalAddress ) ; XEmacLite_FlushReceive ( EmacLiteInstPtr ) ; if ( XEmacLite_TxBufferAvailable ( EmacLiteInstPtr ) != TRUE ) { return XST_FAILURE ; } Status = EmacLiteSetupIntrSystem ( IntcInstancePtr , EmacLiteInstPtr , EmacLiteIntrId ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XEmacLite_SetRecvHandler ( ( EmacLiteInstPtr ) , ( void * ) ( EmacLiteInstPtr ) , ( XEmacLite_Handler ) EmacLiteRecvHandler ) ; XEmacLite_SetSendHandler ( ( EmacLiteInstPtr ) , ( void * ) ( EmacLiteInstPtr ) , ( XEmacLite_Handler ) EmacLiteSendHandler ) ; XEmacLite_EnableInterrupts ( EmacLiteInstPtr ) ; RecvFrameLength = 0 ; if ( XEmacLite_IsMdioConfigured ( EmacLiteInstPtr ) ) { PhyAddress = EmacLitePhyDetect ( EmacLiteInstPtr ) ; Status = EmacLiteEnablePhyLoopBack ( EmacLiteInstPtr , PhyAddress ) ; if ( Status != XST_SUCCESS ) { XEmacLite_DisableInterrupts ( EmacLiteInstPtr ) ; EmacLiteDisableIntrSystem ( IntcInstancePtr , EmacLiteIntrId ) ; return XST_FAILURE ; } } Status = EmacLiteSendFrame ( EmacLiteInstPtr , EMACLITE_TEST_FRAME_SIZE ) ; if ( Status != XST_SUCCESS ) { if ( XEmacLite_IsMdioConfigured ( EmacLiteInstPtr ) ) { EmacLiteDisablePhyLoopBack ( EmacLiteInstPtr , PhyAddress ) ; XEmacLite_DisableInterrupts ( EmacLiteInstPtr ) ; EmacLiteDisableIntrSystem ( IntcInstancePtr , EmacLiteIntrId ) ; return XST_FAILURE ; } } while ( TransmitComplete == FALSE ) ; if ( ! XEmacLite_IsMdioConfigured ( EmacLiteInstPtr ) ) { XEmacLite_DisableInterrupts ( EmacLiteInstPtr ) ; EmacLiteDisableIntrSystem ( IntcInstancePtr , EmacLiteIntrId ) ; return XST_SUCCESS ; } while ( RecvFrameLength == 0 ) ; Status = EmacLiteRecvFrame ( EMACLITE_TEST_FRAME_SIZE ) ; if ( XEmacLite_IsMdioConfigured ( EmacLiteInstPtr ) ) { Status |= EmacLiteDisablePhyLoopBack ( EmacLiteInstPtr , PhyAddress ) ; } XEmacLite_DisableInterrupts ( EmacLiteInstPtr ) ; EmacLiteDisableIntrSystem ( IntcInstancePtr , EmacLiteIntrId ) ; if ( ( Status != XST_SUCCESS ) && ( Status != XST_NO_DATA ) ) { return XST_FAILURE ; } return XST_SUCCESS ; }
The main entry point for the EmacLite driver example in interrupt mode.
The main entry point for the EmacLite driver example in interrupt mode .
/*
	 * Initialize the EmacLite device.
	 */ /*
	 * Set the MAC address.
	 */ /*
	 * Empty any existing receive frames.
	 */ /*
	 * Check if there is a Tx buffer available, if there isn't it is an
	 * error.
	 */ /*
	 * Set up the interrupt infrastructure.
	 */ /*
	 * Setup the EmacLite handlers.
	 */ /*
	 * Enable the interrupts in the EmacLite controller.
	 */ /*
	 * If the MDIO is configured in the device.
	 */ /*
		 * Detect the PHY device and enable the MAC Loop back
		 * in the PHY.
		 */ /*
	 * Transmit an Ethernet frame.
	 */ /*
			 * Disable the MAC Loop back in the PHY and
			 * disable/disconnect the EmacLite Interrupts.
			 */ /*
	 * Wait for the frame to be transmitted.
	 */ /*
	 * If the MDIO is not configured in the core then return XST_SUCCESS
	 * as the frame has been transmitted.
	 */ /*
		 * Disable and disconnect the EmacLite Interrupts.
		 */ /*
	 * Wait for the frame to be received.
	 */ /*
	 * Check the received frame.
	 */ /*
	 *  Diasble the Loop Back.
	 */ /*
		 * Disable the MAC Loop back in the PHY.
		 */ /*
	 * Disable and disconnect the EmacLite Interrupts.
	 */