XilinxProcessorIPLib/drivers/emacps/examples/xemacps_example_intr_dma.c
static LONG EmacPsResetDevice(XEmacPs * EmacPsInstancePtr)
{
	LONG Status = 0;
	u8 MacSave[6];
	u32 Options;
	XEmacPs_Bd BdTemplate;


	/*
	 * Stop device
	 */
	XEmacPs_Stop(EmacPsInstancePtr);

	/*
	 * Save the device state
	 */
	XEmacPs_GetMacAddress(EmacPsInstancePtr, &MacSave, 1);
	Options = XEmacPs_GetOptions(EmacPsInstancePtr);

	/*
	 * Stop and reset the device
	 */
	XEmacPs_Reset(EmacPsInstancePtr);

	/*
	 * Restore the state
	 */
	XEmacPs_SetMacAddress(EmacPsInstancePtr, &MacSave, 1);
	Status |= XEmacPs_SetOptions(EmacPsInstancePtr, Options);
	Status |= XEmacPs_ClearOptions(EmacPsInstancePtr, ~Options);
	if (Status != XST_SUCCESS) {
		EmacPsUtilErrorTrap("Error restoring state after reset");
		return XST_FAILURE;
	}

	/*
	 * Setup callbacks
	 */
	Status = XEmacPs_SetHandler(EmacPsInstancePtr,
				     XEMACPS_HANDLER_DMASEND,
				     (void *) XEmacPsSendHandler,
				     EmacPsInstancePtr);
	Status |= XEmacPs_SetHandler(EmacPsInstancePtr,
				    XEMACPS_HANDLER_DMARECV,
				    (void *) XEmacPsRecvHandler,
				    EmacPsInstancePtr);
	Status |= XEmacPs_SetHandler(EmacPsInstancePtr, XEMACPS_HANDLER_ERROR,
				    (void *) XEmacPsErrorHandler,
				    EmacPsInstancePtr);
	if (Status != XST_SUCCESS) {
		EmacPsUtilErrorTrap("Error assigning handlers");
		return XST_FAILURE;
	}

	/*
	 * Setup RxBD space.
	 *
	 * We have already defined a properly aligned area of memory to store
	 * RxBDs at the beginning of this source code file so just pass its
	 * address into the function. No MMU is being used so the physical and
	 * virtual addresses are the same.
	 *
	 * Setup a BD template for the Rx channel. This template will be copied
	 * to every RxBD. We will not have to explicitly set these again.
	 */
	XEmacPs_BdClear(&BdTemplate);

	/*
	 * Create the RxBD ring
	 */
	Status = XEmacPs_BdRingCreate(&(XEmacPs_GetRxRing
				      (EmacPsInstancePtr)),
				      (UINTPTR) RxBdSpacePtr,
				      (UINTPTR) RxBdSpacePtr,
				      XEMACPS_BD_ALIGNMENT,
				      RXBD_CNT);
	if (Status != XST_SUCCESS) {
		EmacPsUtilErrorTrap
			("Error setting up RxBD space, BdRingCreate");
		return XST_FAILURE;
	}

	Status = XEmacPs_BdRingClone(&
				      (XEmacPs_GetRxRing(EmacPsInstancePtr)),
				      &BdTemplate, XEMACPS_RECV);
	if (Status != XST_SUCCESS) {
		EmacPsUtilErrorTrap
			("Error setting up RxBD space, BdRingClone");
		return XST_FAILURE;
	}

	/*
	 * Setup TxBD space.
	 *
	 * Like RxBD space, we have already defined a properly aligned area of
	 * memory to use.
	 *
	 * Also like the RxBD space, we create a template. Notice we don't set
	 * the "last" attribute. The examples will be overriding this
	 * attribute so it does no good to set it up here.
	 */
	XEmacPs_BdClear(&BdTemplate);
	XEmacPs_BdSetStatus(&BdTemplate, XEMACPS_TXBUF_USED_MASK);

	/*
	 * Create the TxBD ring
	 */
	Status = XEmacPs_BdRingCreate(&(XEmacPs_GetTxRing
				      (EmacPsInstancePtr)),
				      (UINTPTR) TxBdSpacePtr,
				      (UINTPTR) TxBdSpacePtr,
				      XEMACPS_BD_ALIGNMENT,
				      TXBD_CNT);
	if (Status != XST_SUCCESS) {
		EmacPsUtilErrorTrap
			("Error setting up TxBD space, BdRingCreate");
		return XST_FAILURE;
	}
	Status = XEmacPs_BdRingClone(&
				      (XEmacPs_GetTxRing(EmacPsInstancePtr)),
				      &BdTemplate, XEMACPS_SEND);
	if (Status != XST_SUCCESS) {
		EmacPsUtilErrorTrap
			("Error setting up TxBD space, BdRingClone");
		return XST_FAILURE;
	}

	/*
	 * Restart the device
	 */
	XEmacPs_Start(EmacPsInstancePtr);

	return XST_SUCCESS;
}
/****************************************************************************/
/**
* This function resets the device but preserves the options set by the user.
*
* The descriptor list could be reinitialized with the same calls to
* XEmacPs_BdRingClone() as used in main(). Doing this is a matter of
* preference.
* In many cases, an OS may have resources tied up in the descriptors.
* Reinitializing in this case may bad for the OS since its resources may be
* permamently lost.
*
* @param	EmacPsInstancePtr is a pointer to the instance of the EmacPs
*		driver.
*
* @return	XST_SUCCESS if successful, else XST_FAILURE.
*
* @note		None.
*
*****************************************************************************/
This function resets the device but preserves the options set by the user.
The descriptor list could be reinitialized with the same calls to
XEmacPs_BdRingClone() as used in main(). Doing this is a matter of
preference.
In many cases, an OS may have resources tied up in the descriptors.
Reinitializing in this case may bad for the OS since its resources may be
permamently lost.
This function resets the device but preserves the options set by the user . The descriptor list could be reinitialized with the same calls to XEmacPs_BdRingClone () as used in main () . Doing this is a matter of preference . In many cases an OS may have resources tied up in the descriptors . Reinitializing in this case may bad for the OS since its resources may be permamently lost .
static LONG EmacPsResetDevice(XEmacPs * EmacPsInstancePtr)
{
	LONG Status = 0;
	u8 MacSave[6];
	u32 Options;
	XEmacPs_Bd BdTemplate;
	XEmacPs_Stop(EmacPsInstancePtr);
	XEmacPs_GetMacAddress(EmacPsInstancePtr, &MacSave, 1);
	Options = XEmacPs_GetOptions(EmacPsInstancePtr);
	XEmacPs_Reset(EmacPsInstancePtr);
	XEmacPs_SetMacAddress(EmacPsInstancePtr, &MacSave, 1);
	Status |= XEmacPs_SetOptions(EmacPsInstancePtr, Options);
	Status |= XEmacPs_ClearOptions(EmacPsInstancePtr, ~Options);
	if (Status != XST_SUCCESS) {
		EmacPsUtilErrorTrap("Error restoring state after reset");
		return XST_FAILURE;
	}
	Status = XEmacPs_SetHandler(EmacPsInstancePtr,
				     XEMACPS_HANDLER_DMASEND,
				     (void *) XEmacPsSendHandler,
				     EmacPsInstancePtr);
	Status |= XEmacPs_SetHandler(EmacPsInstancePtr,
				    XEMACPS_HANDLER_DMARECV,
				    (void *) XEmacPsRecvHandler,
				    EmacPsInstancePtr);
	Status |= XEmacPs_SetHandler(EmacPsInstancePtr, XEMACPS_HANDLER_ERROR,
				    (void *) XEmacPsErrorHandler,
				    EmacPsInstancePtr);
	if (Status != XST_SUCCESS) {
		EmacPsUtilErrorTrap("Error assigning handlers");
		return XST_FAILURE;
	}
	XEmacPs_BdClear(&BdTemplate);
	Status = XEmacPs_BdRingCreate(&(XEmacPs_GetRxRing
				      (EmacPsInstancePtr)),
				      (UINTPTR) RxBdSpacePtr,
				      (UINTPTR) RxBdSpacePtr,
				      XEMACPS_BD_ALIGNMENT,
				      RXBD_CNT);
	if (Status != XST_SUCCESS) {
		EmacPsUtilErrorTrap
			("Error setting up RxBD space, BdRingCreate");
		return XST_FAILURE;
	}
	Status = XEmacPs_BdRingClone(&
				      (XEmacPs_GetRxRing(EmacPsInstancePtr)),
				      &BdTemplate, XEMACPS_RECV);
	if (Status != XST_SUCCESS) {
		EmacPsUtilErrorTrap
			("Error setting up RxBD space, BdRingClone");
		return XST_FAILURE;
	}
	XEmacPs_BdClear(&BdTemplate);
	XEmacPs_BdSetStatus(&BdTemplate, XEMACPS_TXBUF_USED_MASK);
	Status = XEmacPs_BdRingCreate(&(XEmacPs_GetTxRing
				      (EmacPsInstancePtr)),
				      (UINTPTR) TxBdSpacePtr,
				      (UINTPTR) TxBdSpacePtr,
				      XEMACPS_BD_ALIGNMENT,
				      TXBD_CNT);
	if (Status != XST_SUCCESS) {
		EmacPsUtilErrorTrap
			("Error setting up TxBD space, BdRingCreate");
		return XST_FAILURE;
	}
	Status = XEmacPs_BdRingClone(&
				      (XEmacPs_GetTxRing(EmacPsInstancePtr)),
				      &BdTemplate, XEMACPS_SEND);
	if (Status != XST_SUCCESS) {
		EmacPsUtilErrorTrap
			("Error setting up TxBD space, BdRingClone");
		return XST_FAILURE;
	}
	XEmacPs_Start(EmacPsInstancePtr);
	return XST_SUCCESS;
}
static LONG EmacPsResetDevice ( XEmacPs * EmacPsInstancePtr ) { LONG Status = 0 ; u8 MacSave [ 6 ] ; u32 Options ; XEmacPs_Bd BdTemplate ; XEmacPs_Stop ( EmacPsInstancePtr ) ; XEmacPs_GetMacAddress ( EmacPsInstancePtr , & MacSave , 1 ) ; Options = XEmacPs_GetOptions ( EmacPsInstancePtr ) ; XEmacPs_Reset ( EmacPsInstancePtr ) ; XEmacPs_SetMacAddress ( EmacPsInstancePtr , & MacSave , 1 ) ; Status |= XEmacPs_SetOptions ( EmacPsInstancePtr , Options ) ; Status |= XEmacPs_ClearOptions ( EmacPsInstancePtr , ~ Options ) ; if ( Status != XST_SUCCESS ) { EmacPsUtilErrorTrap ( " " ) ; return XST_FAILURE ; } Status = XEmacPs_SetHandler ( EmacPsInstancePtr , XEMACPS_HANDLER_DMASEND , ( void * ) XEmacPsSendHandler , EmacPsInstancePtr ) ; Status |= XEmacPs_SetHandler ( EmacPsInstancePtr , XEMACPS_HANDLER_DMARECV , ( void * ) XEmacPsRecvHandler , EmacPsInstancePtr ) ; Status |= XEmacPs_SetHandler ( EmacPsInstancePtr , XEMACPS_HANDLER_ERROR , ( void * ) XEmacPsErrorHandler , EmacPsInstancePtr ) ; if ( Status != XST_SUCCESS ) { EmacPsUtilErrorTrap ( " " ) ; return XST_FAILURE ; } XEmacPs_BdClear ( & BdTemplate ) ; Status = XEmacPs_BdRingCreate ( & ( XEmacPs_GetRxRing ( EmacPsInstancePtr ) ) , ( UINTPTR ) RxBdSpacePtr , ( UINTPTR ) RxBdSpacePtr , XEMACPS_BD_ALIGNMENT , RXBD_CNT ) ; if ( Status != XST_SUCCESS ) { EmacPsUtilErrorTrap ( " " ) ; return XST_FAILURE ; } Status = XEmacPs_BdRingClone ( & ( XEmacPs_GetRxRing ( EmacPsInstancePtr ) ) , & BdTemplate , XEMACPS_RECV ) ; if ( Status != XST_SUCCESS ) { EmacPsUtilErrorTrap ( " " ) ; return XST_FAILURE ; } XEmacPs_BdClear ( & BdTemplate ) ; XEmacPs_BdSetStatus ( & BdTemplate , XEMACPS_TXBUF_USED_MASK ) ; Status = XEmacPs_BdRingCreate ( & ( XEmacPs_GetTxRing ( EmacPsInstancePtr ) ) , ( UINTPTR ) TxBdSpacePtr , ( UINTPTR ) TxBdSpacePtr , XEMACPS_BD_ALIGNMENT , TXBD_CNT ) ; if ( Status != XST_SUCCESS ) { EmacPsUtilErrorTrap ( " " ) ; return XST_FAILURE ; } Status = XEmacPs_BdRingClone ( & ( XEmacPs_GetTxRing ( EmacPsInstancePtr ) ) , & BdTemplate , XEMACPS_SEND ) ; if ( Status != XST_SUCCESS ) { EmacPsUtilErrorTrap ( " " ) ; return XST_FAILURE ; } XEmacPs_Start ( EmacPsInstancePtr ) ; return XST_SUCCESS ; }
This function resets the device but preserves the options set by the user.
This function resets the device but preserves the options set by the user .
/*
	 * Stop device
	 */ /*
	 * Save the device state
	 */ /*
	 * Stop and reset the device
	 */ /*
	 * Restore the state
	 */ /*
	 * Setup callbacks
	 */ /*
	 * Setup RxBD space.
	 *
	 * We have already defined a properly aligned area of memory to store
	 * RxBDs at the beginning of this source code file so just pass its
	 * address into the function. No MMU is being used so the physical and
	 * virtual addresses are the same.
	 *
	 * Setup a BD template for the Rx channel. This template will be copied
	 * to every RxBD. We will not have to explicitly set these again.
	 */ /*
	 * Create the RxBD ring
	 */ /*
	 * Setup TxBD space.
	 *
	 * Like RxBD space, we have already defined a properly aligned area of
	 * memory to use.
	 *
	 * Also like the RxBD space, we create a template. Notice we don't set
	 * the "last" attribute. The examples will be overriding this
	 * attribute so it does no good to set it up here.
	 */ /*
	 * Create the TxBD ring
	 */ /*
	 * Restart the device
	 */