XilinxProcessorIPLib/drivers/usbps/src/xusbps_endpoint.c
void XUsbPs_EpGetData(XUsbPs *InstancePtr, u8 EpNum, u32 BufferLen)
{
	XUsbPs_EpOut	*Ep;
	XUsbPs_EpSetup	*EpSetup;
	u8 *DataBuff;
	u32 Handle;
	u32 length = 0;
	u32 InavalidateLen = 0;

	/* The buffer is not active which means that it has been processed by
	 * the DMA engine and contains valid data.
	 */
	Ep = &InstancePtr->DeviceConfig.Ep[EpNum].Out;
	EpSetup = &InstancePtr->DeviceConfig.EpCfg[EpNum].Out;

	/* Use the buffer pointer stored in the "user data" field of the
	 * Transfer Descriptor.
	*/

	do {
		XUsbPs_dTDInvalidateCache(Ep->dTDCurr);

		DataBuff = (u8 *) XUsbPs_ReaddTD(Ep->dTDCurr,
				XUSBPS_dTDUSERDATA);

		length = EpSetup->BufSize -
				XUsbPs_dTDGetTransferLen(Ep->dTDCurr);

		if (length > 0) {
			BufferLen = length;
		} else {
			BufferLen = 0;
		}

		/* Invalidate the Buffer Pointer */
		InavalidateLen =  BufferLen;
		if (BufferLen % 32) {
			InavalidateLen = (BufferLen/32) * 32 + 32;
		}

		Xil_DCacheInvalidateRange((unsigned int)DataBuff,
				InavalidateLen);

		memcpy(Ep->BufferPtr, DataBuff,  BufferLen);

		Ep->BytesTxed += BufferLen;
		Ep->BufferPtr += BufferLen;

		Handle	= (u32) Ep->dTDCurr;

		/* Reset the descriptor's BufferPointer0 and Transfer Length
		 * fields to their original value. Note that we can not yet
		 * re-activate the descriptor as the caller will be using the
		 * attached buffer. Once the caller releases the buffer by
		 * calling XUsbPs_EpBufferRelease(),
		 * we can re-activate the descriptor.
		 */
		XUsbPs_WritedTD(Ep->dTDCurr, XUSBPS_dTDBPTR0, DataBuff);
		XUsbPs_dTDSetTransferLen(Ep->dTDCurr, EpSetup->BufSize);

		XUsbPs_dTDFlushCache(Ep->dTDCurr);

		XUsbPs_EpBufferRelease(Handle);

		Ep->dTDCurr = XUsbPs_dTDGetNLP(Ep->dTDCurr);
		XUsbPs_dTDInvalidateCache(Ep->dTDCurr);

		/* Either Host sent exact requested length or more than that
		 * or lesser data.
		 */
		if ((Ep->RequestedBytes <= Ep->BytesTxed) ||
				(Ep->BytesTxed % EpSetup->MaxPacketSize)) {
			Ep->MemAlloted  = 0;
			if (Ep->HandlerIsoFunc) {
				Ep->HandlerIsoFunc(Ep->HandlerRef,
						Ep->RequestedBytes,
						Ep->BytesTxed);
			}

			break;
		}
	} while (!XUsbPs_dTDIsActive(Ep->dTDCurr));

}
/*****************************************************************************/
/**
 * This function receives a data buffer from the endpoint of the given endpoint
 * number and pass it to the application.
 *
 * @param	InstancePtr is a pointer to the XUsbPs instance of the
 *		controller.
 * @param	EpNum is the number of the endpoint to receive data from.
 * @param	BufferLen is holding the buffer length.
 *
 * @return	None.
 *
 * @note	None.
 *
 ******************************************************************************/
This function receives a data buffer from the endpoint of the given endpoint
number and pass it to the application.

@param       InstancePtr is a pointer to the XUsbPs instance of the
controller.
@param       EpNum is the number of the endpoint to receive data from.
@param       BufferLen is holding the buffer length.

@return      None.

@note        None.
This function receives a data buffer from the endpoint of the given endpoint number and pass it to the application . @param InstancePtr is a pointer to the XUsbPs instance of the controller . @param EpNum is the number of the endpoint to receive data from . @param BufferLen is holding the buffer length . @return None . @note None .
void XUsbPs_EpGetData(XUsbPs *InstancePtr, u8 EpNum, u32 BufferLen)
{
	XUsbPs_EpOut	*Ep;
	XUsbPs_EpSetup	*EpSetup;
	u8 *DataBuff;
	u32 Handle;
	u32 length = 0;
	u32 InavalidateLen = 0;
	Ep = &InstancePtr->DeviceConfig.Ep[EpNum].Out;
	EpSetup = &InstancePtr->DeviceConfig.EpCfg[EpNum].Out;
	do {
		XUsbPs_dTDInvalidateCache(Ep->dTDCurr);
		DataBuff = (u8 *) XUsbPs_ReaddTD(Ep->dTDCurr,
				XUSBPS_dTDUSERDATA);
		length = EpSetup->BufSize -
				XUsbPs_dTDGetTransferLen(Ep->dTDCurr);
		if (length > 0) {
			BufferLen = length;
		} else {
			BufferLen = 0;
		}
		InavalidateLen =  BufferLen;
		if (BufferLen % 32) {
			InavalidateLen = (BufferLen/32) * 32 + 32;
		}
		Xil_DCacheInvalidateRange((unsigned int)DataBuff,
				InavalidateLen);
		memcpy(Ep->BufferPtr, DataBuff,  BufferLen);
		Ep->BytesTxed += BufferLen;
		Ep->BufferPtr += BufferLen;
		Handle	= (u32) Ep->dTDCurr;
		XUsbPs_WritedTD(Ep->dTDCurr, XUSBPS_dTDBPTR0, DataBuff);
		XUsbPs_dTDSetTransferLen(Ep->dTDCurr, EpSetup->BufSize);
		XUsbPs_dTDFlushCache(Ep->dTDCurr);
		XUsbPs_EpBufferRelease(Handle);
		Ep->dTDCurr = XUsbPs_dTDGetNLP(Ep->dTDCurr);
		XUsbPs_dTDInvalidateCache(Ep->dTDCurr);
		if ((Ep->RequestedBytes <= Ep->BytesTxed) ||
				(Ep->BytesTxed % EpSetup->MaxPacketSize)) {
			Ep->MemAlloted  = 0;
			if (Ep->HandlerIsoFunc) {
				Ep->HandlerIsoFunc(Ep->HandlerRef,
						Ep->RequestedBytes,
						Ep->BytesTxed);
			}
			break;
		}
	} while (!XUsbPs_dTDIsActive(Ep->dTDCurr));
}
void XUsbPs_EpGetData ( XUsbPs * InstancePtr , u8 EpNum , u32 BufferLen ) { XUsbPs_EpOut * Ep ; XUsbPs_EpSetup * EpSetup ; u8 * DataBuff ; u32 Handle ; u32 length = 0 ; u32 InavalidateLen = 0 ; Ep = & InstancePtr -> DeviceConfig . Ep [ EpNum ] . Out ; EpSetup = & InstancePtr -> DeviceConfig . EpCfg [ EpNum ] . Out ; do { XUsbPs_dTDInvalidateCache ( Ep -> dTDCurr ) ; DataBuff = ( u8 * ) XUsbPs_ReaddTD ( Ep -> dTDCurr , XUSBPS_dTDUSERDATA ) ; length = EpSetup -> BufSize - XUsbPs_dTDGetTransferLen ( Ep -> dTDCurr ) ; if ( length > 0 ) { BufferLen = length ; } else { BufferLen = 0 ; } InavalidateLen = BufferLen ; if ( BufferLen % 32 ) { InavalidateLen = ( BufferLen / 32 ) * 32 + 32 ; } Xil_DCacheInvalidateRange ( ( unsigned int ) DataBuff , InavalidateLen ) ; memcpy ( Ep -> BufferPtr , DataBuff , BufferLen ) ; Ep -> BytesTxed += BufferLen ; Ep -> BufferPtr += BufferLen ; Handle = ( u32 ) Ep -> dTDCurr ; XUsbPs_WritedTD ( Ep -> dTDCurr , XUSBPS_dTDBPTR0 , DataBuff ) ; XUsbPs_dTDSetTransferLen ( Ep -> dTDCurr , EpSetup -> BufSize ) ; XUsbPs_dTDFlushCache ( Ep -> dTDCurr ) ; XUsbPs_EpBufferRelease ( Handle ) ; Ep -> dTDCurr = XUsbPs_dTDGetNLP ( Ep -> dTDCurr ) ; XUsbPs_dTDInvalidateCache ( Ep -> dTDCurr ) ; if ( ( Ep -> RequestedBytes <= Ep -> BytesTxed ) || ( Ep -> BytesTxed % EpSetup -> MaxPacketSize ) ) { Ep -> MemAlloted = 0 ; if ( Ep -> HandlerIsoFunc ) { Ep -> HandlerIsoFunc ( Ep -> HandlerRef , Ep -> RequestedBytes , Ep -> BytesTxed ) ; } break ; } } while ( ! XUsbPs_dTDIsActive ( Ep -> dTDCurr ) ) ; }
This function receives a data buffer from the endpoint of the given endpoint
 number and pass it to the application.
This function receives a data buffer from the endpoint of the given endpoint number and pass it to the application .
/* The buffer is not active which means that it has been processed by
	 * the DMA engine and contains valid data.
	 */ /* Use the buffer pointer stored in the "user data" field of the
	 * Transfer Descriptor.
	*/ /* Invalidate the Buffer Pointer */ /* Reset the descriptor's BufferPointer0 and Transfer Length
		 * fields to their original value. Note that we can not yet
		 * re-activate the descriptor as the caller will be using the
		 * attached buffer. Once the caller releases the buffer by
		 * calling XUsbPs_EpBufferRelease(),
		 * we can re-activate the descriptor.
		 */ /* Either Host sent exact requested length or more than that
		 * or lesser data.
		 */