⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbtcdpdiusbd12endpoint.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 4 页
字号:
            if (pTrb->uActLength < pEndpointInfo->dmaXfrLen)                sizeToCopy = pTrb->uActLength;            else                sizeToCopy = pEndpointInfo->dmaXfrLen;            USBPDIUSBD12_DEBUG ("usbTcdPdiusbd12FncCopyDataFromEpBuf : \            Invalidating DMA buffer ...\n",0,0,0,0,0,0);            /* Invalidate DMA buffer */            USB_ISA_MEM_INVALIDATE ((char *) sysFdBuf, sizeToCopy);            /* Copy the data from the DMA buffer */             usbTcdPdiusbd12CopyDMABufferData((char *)pTrb->pBuffer,                                             (char *) sysFdBuf,                                             sizeToCopy,                                             pEndpointInfo->maxPacketSize);            /* update size copied */            USBPDIUSBD12_DEBUG ("usbTcdPdiusbd12FncCopyDataFromEpBuf : \            Size to copy = %d...\n", sizeToCopy ,0,0,0,0,0);            pTrb->uActLength = sizeToCopy;            /* Disable the D12's DMA and re-enable interrupts for endpoint */            USBPDIUSBD12_DEBUG ("usbTcdPdiusbd12FncCopyDataFromEpBuf : \            Disabling the DMA operation...\n",0,0,0,0,0,0);	    pTarget->dmaByte &= ~D12_CMD_SD_DMA_ENABLE;            pTarget->dmaByte |= D12_CMD_SD_ENDPT_2_OUT_INTRPT;	    d12SetDma (pTarget);            /* reset DMA related variables */            pTarget->dmaInUse = FALSE;            pTarget->dmaEndpointId = 0;            pTarget->dmaEot = FALSE;            pEndpointInfo->dmaXfrLen = 0;            }        /* endpoint using DMA and no DMA EOT */        else if ((pTarget->dmaInUse) &&                 (pTarget->dmaEndpointId == pEndpointInfo->endpointIndex) &&                 (pTarget->dmaEot == FALSE))            {            USBPDIUSBD12_ERROR ("usbTcdPdiusbd12FncCopyDataFromEpBuf : \            Returning ok...\n",0,0,0,0,0,0);            /*             * This condition can happen when there is a delay between              * initiating the dma and the next OUT token             * So return an OK.             */                          pTrb->uActLength = 0;            return OK;            }        /* dma channel not used */        else if(pTarget->dmaInUse == FALSE)            {            /* update dmaXfrLen */            if (pTrb->uActLength < sysFdBufSize)                pEndpointInfo->dmaXfrLen =  pTrb->uActLength;            else                pEndpointInfo->dmaXfrLen = sysFdBufSize;            USBPDIUSBD12_DEBUG ("usbTcdPdiusbd12FncCopyDataFromEpBuf : \            Initialize D12 for DMA operation...\n",0,0,0,0,0,0);            /* Initialize D12 for DMA operation */            USB_ISA_DMA_SETUP (DMA_MEM_WRITE, sysFdBuf, pEndpointInfo->dmaXfrLen,                               pTarget->dma);            pTarget->dmaByte &= ~D12_CMD_SD_DMA_DIRECTION_MASK;            pTarget->dmaByte &= ~D12_CMD_SD_ENDPT_2_OUT_INTRPT;	    pTarget->dmaByte |= D12_CMD_SD_DMA_DIRECTION_READ;	    pTarget->dmaByte |= D12_CMD_SD_DMA_ENABLE;	    d12SetDma (pTarget);	    /* initialize DMA related variables */            pTarget->dmaInUse = TRUE;            pTarget->dmaEndpointId = pEndpointInfo->endpointIndex;            pTarget->dmaEot = FALSE;            pTrb->uActLength = 0;            }        }    else        {        char * pBuf = (char *)pTrb->pBuffer;        /* Select the endpoint */        d12SelectEndpoint (pTarget, pEndpointInfo->endpointIndex);        /* Read the number of bytes in the buffer. */        OUT_D12_CMD (pTarget,D12_CMD_READ_BUFFER);                /* throw away first byte */        sizeToCopy = IN_D12_DATA (pTarget);	            sizeToCopy = IN_D12_DATA (pTarget);        if (sizeToCopy > pTrb->uActLength)            sizeToCopy = pTrb->uActLength;        USBPDIUSBD12_DEBUG ("usbTcdPdiusbd12FncCopyDataFromEpBuf : Size to \        copy is %d...\n",sizeToCopy,0,0,0,0,0);        /* update  uActLength */        pTrb->uActLength = sizeToCopy;        /* Read buffer data */        USBPDIUSBD12_DEBUG ("usbTcdPdiusbd12FncCopyDataFromEpBuf : Reading \        buffer data...\n",0,0,0,0,0,0);        while (sizeToCopy > 0 )            {            *pBuf  = IN_D12_DATA (pTarget);            pBuf++;            --sizeToCopy;            }        /* Issue command to flush (clear) buffer */        USBPDIUSBD12_DEBUG ("usbTcdPdiusbd12FncCopyDataFromEpBuf : Clearing \        buffer...\n",0,0,0,0,0,0);        /*         * If a setup ERP is pending for the control OUT endpoint, then         * acknowledge the setup ERP to enable the IN and the OUT buffers         */        if ((pTarget->setupErpPending) &&             (pEndpointInfo->endpointIndex == D12_ENDPOINT_CONTROL_OUT))            {            d12AckSetup ( pTarget , D12_ENDPOINT_CONTROL_IN);            d12AckSetup ( pTarget , D12_ENDPOINT_CONTROL_OUT );            pTarget->setupErpPending = FALSE;            }         /* Clear the buffer */        d12ClearBfr (pTarget);        }        /* WindView Instrumentation */    USB_TCD_LOG_EVENT(USB_TCD_PDIUSBD12_ENDPOINT,    "usbTcdPdiusbd12FncCopyDataFromEpBuf exiting...",    USB_TCD_PDIUSBD12_WV_FILTER);       USBPDIUSBD12_DEBUG ("usbTcdPdiusbd12FncCopyDataFromEpBuf : Exiting \    ...\n",0,0,0,0,0,0);    return OK;	}/******************************************************************************** usbTcdPdiusbd12FncCopyDataToEpBuf - implements TCD_FNC_COPY_DATA_TO _EPBUF** This function copies data from user buffer to endpoint FIFO buffer.** RETURNS: OK  if successfully copied, ERROR otherwise.* * ERRNO:*  None.** \NOMANUAL*/LOCAL STATUS usbTcdPdiusbd12FncCopyDataToEpBuf    (    pTRB_COPY_DATA_TO_EPBUF	pTrb		/* TRB to be executed */    )    {    pTRB_HEADER	pHeader = (pTRB_HEADER) pTrb;	/* TRB_HEADER */    pUSB_TCD_PDIUSBD12_ENDPOINT	pEndpointInfo = NULL;					/* USB_TCD_PDIUSBD12_ENDPOINT */    pUSB_TCD_PDIUSBD12_TARGET	pTarget = NULL;	/* USB_TCD_PDIUSBD12_TARGET */    UINT32	sizeToCopy = 0;			/* size to copy */    UINT16	maxPacketSize = 0;		/* max packet size */    UINT8	i = 0;    /* WindView Instrumentation */    USB_TCD_LOG_EVENT(USB_TCD_PDIUSBD12_ENDPOINT,    "usbTcdPdiusbd12FncCopyDataToEpBuf entered ...",    USB_TCD_PDIUSBD12_WV_FILTER);       USBPDIUSBD12_DEBUG ("usbTcdPdiusbd12FncCopyDataToEpBuf : Entered \    ...\n",0,0,0,0,0,0);    /* Validate parameters */    if ((pHeader == NULL) || (pHeader->trbLength < sizeof (TRB_HEADER)) ||        (pTrb->pipeHandle == 0))                {        /* WindView Instrumentation */        USB_TCD_LOG_EVENT(USB_TCD_PDIUSBD12_ENDPOINT,        "usbTcdPdiusbd12FncCopyDataToEpBuf exiting: Bad Paramter Received ...",        USB_TCD_PDIUSBD12_WV_FILTER);           USBPDIUSBD12_ERROR ("usbTcdPdiusbd12FncCopyDataToEpBuf : Invalid \        Parameters...\n",0,0,0,0,0,0);        return ERROR;        }    pEndpointInfo = (pUSB_TCD_PDIUSBD12_ENDPOINT)pTrb->pipeHandle;    pTarget = (pUSB_TCD_PDIUSBD12_TARGET)pHeader->handle;    /* Check if target pointer is valid */    if ( pTarget == NULL )        {        /* WindView Instrumentation */        USB_TCD_LOG_EVENT(USB_TCD_PDIUSBD12_ENDPOINT,        "usbTcdPdiusbd12FncCopyDataToEpBuf exiting: Error assigning pTarget ...",        USB_TCD_PDIUSBD12_WV_FILTER);           USBPDIUSBD12_ERROR ( "usbTcdPdiusbd12FncCopyDataToEpBuf : Error \        assigning pTarget...\n",0,0,0,0,0,0);        return ERROR;        }    /*     * check if the endpoint number is 2, and the type is not interrupt.     * Then only, DMA can be used     */    if ((pEndpointInfo->endpointNo == D12_ENDPOINT_NO_2) &&        (pEndpointInfo->transferType != USB_ATTR_INTERRUPT))  	{    	/* Endpoint using DMA and DMA EOT */    	if ((pTarget->dmaInUse) &&            (pTarget->dmaEndpointId == pEndpointInfo->endpointIndex) &&                 (pTarget->dmaEot == FALSE))            {            USBPDIUSBD12_ERROR ("usbTcdPdiusbd12FncCopyDataToEpBuf :  \            returns ok...\n",0,0,0,0,0,0);            /*             * This condition can happen when there is a delay between              * initiating the dma and the next IN token             * So return an OK.             */                          pTrb->uActLength = 0;            return OK;            }        /* Endpoint is not using DMA and DMA channel is unused */        else if (pTarget->dmaInUse == FALSE)            {            /* update dmaXferlen */            if (pTrb->uActLength < sysFdBufSize)                pEndpointInfo->dmaXfrLen = pTrb->uActLength;            else                pEndpointInfo->dmaXfrLen = sysFdBufSize;            memcpy ((char *)sysFdBuf , pTrb->pBuffer , pEndpointInfo->dmaXfrLen );            /* Flush the DMA buffer */            USBPDIUSBD12_DEBUG ("usbTcdPdiusbd12FncCopyDataToEpBuf : \            Flushing DMA buffer ...\n",0,0,0,0,0,0);            USB_ISA_MEM_FLUSH ((pVOID)sysFdBuf ,pEndpointInfo->dmaXfrLen );            USBPDIUSBD12_DEBUG ("usbTcdPdiusbd12FncCopyDataToEpBuf : \            Initialize D12 for DMA operation...\n",0,0,0,0,0,0);            /* Initialize D12 for DMA operation */            USB_ISA_DMA_SETUP (DMA_MEM_READ, sysFdBuf, pEndpointInfo->dmaXfrLen,                               pTarget->dma);            pTarget->dmaByte &= ~D12_CMD_SD_DMA_DIRECTION_MASK;            pTarget->dmaByte &= ~D12_CMD_SD_ENDPT_2_IN_INTRPT;            pTarget->dmaByte |= D12_CMD_SD_DMA_DIRECTION_WRITE;            pTarget->dmaByte |= D12_CMD_SD_DMA_ENABLE;	    d12SetDma (pTarget);            /* initialize DMA related variables */            pTarget->dmaInUse = TRUE;            pTarget->dmaEndpointId = pEndpointInfo->endpointIndex;            pTarget->dmaEot = FALSE;            pTrb->uActLength = pEndpointInfo->dmaXfrLen ;            }        }    else        {        /* Give Select command */        d12SelectEndpoint (pTarget, pEndpointInfo->endpointIndex);        /* Determine the max packet size of the endpint */        maxPacketSize = pEndpointInfo->maxPacketSize ;        if (pTrb->uActLength < maxPacketSize )            sizeToCopy = pTrb->uActLength;        else            sizeToCopy = maxPacketSize;        USBPDIUSBD12_DEBUG ("usbTcdPdiusbd12FncCopyDataToEpBuf : Size to \        write is %d...\n", sizeToCopy, 0,0,0,0,0);        /* Give Write Command */        USBPDIUSBD12_DEBUG ("usbTcdPdiusbd12FncCopyDataToEpBuf : Giving \        Write Command ...\n",0,0,0,0,0,0);        OUT_D12_CMD (pTarget,D12_CMD_WRITE_BUFFER);        /* Write the first byte as 0 */        OUT_D12_DATA (pTarget , 0 );        /* Write the second byte as the size of the data to write */        OUT_D12_DATA (pTarget , sizeToCopy );        /* Write Buffer Data */        USBPDIUSBD12_DEBUG ("usbTcdPdiusbd12FncCopyDataToEpBuf : Writing \        Buffer...\n",0,0,0,0,0,0);        for ( i = 0 ; i< sizeToCopy ; i++ )            OUT_D12_DATA ( pTarget , pTrb->pBuffer[i]);	pTrb->uActLength = sizeToCopy ;        /* Validate the endpoint FIFO buffer */        USBPDIUSBD12_DEBUG ("usbTcdPdiusbd12FncCopyDataToEpBuf : \        Validating Buffer...\n",0,0,0,0,0,0);	d12ValidateBfr (pTarget );        }    /* WindView Instrumentation */    USB_TCD_LOG_EVENT(USB_TCD_PDIUSBD12_ENDPOINT,    "usbTcdPdiusbd12FncCopyDataToEpBuf exiting...",    USB_TCD_PDIUSBD12_WV_FILTER);       USBPDIUSBD12_DEBUG ("usbTcdPdiusbd12FncCopyDataToEpBuf: Exiting ...\n",    0,0,0,0,0,0);    return OK;    }    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -