📄 usbtcdisp1582endpoint.c
字号:
* RETURNS: OK or ERROR, it not able to get the status of the buffer.** ERRNO:* \is* \i S_usbTcdLib_BAD_PARAM.* Bad Parameter is passed.* \ie** \NOMANUAL*/LOCAL STATUS usbTcdIsp1582FncIsBufferEmpty ( pTRB_IS_BUFFER_EMPTY pTrb /* Trb to be executed */ ) { pTRB_HEADER pHeader = (pTRB_HEADER) pTrb; /* TRB_HEADER */ pUSB_TCD_ISP1582_ENDPOINT pEndpointInfo = NULL;/*USB_TCD_ISP1582_ENDPOINT*/ pUSB_TCD_ISP1582_TARGET pTarget = NULL; /* USB_TCD_ISP1582_TARGET */ UINT8 endpointIndex = 0; /* endpoint index */ /* WindView Instrumentation */ USB_TCD_LOG_EVENT(USB_TCD_ISP1582_ENDPOINT, "usbTcdIsp1582FncIsBufferEmpty entering...", USB_TCD_ISP582_WV_FILTER); USBISP1582_DEBUG ("usbTcdIsp1582FncIsBufferEmpty : Entered...\n", 0,0,0,0,0,0); /* Validate parameters */ if ((pHeader == NULL) || (pHeader->trbLength < sizeof (TRB_HEADER)) || (pHeader->handle == NULL) || (pTrb->pipeHandle == 0)) { /* WindView Instrumentation */ USB_TCD_LOG_EVENT(USB_TCD_ISP1582_ENDPOINT, "usbTcdIsp1582FncIsBufferEmpty: Bad Parameter Received", USB_TCD_ISP582_WV_FILTER); USBISP1582_ERROR ("usbTcdIsp1582FncIsBufferEmpty : Bad Parameters \ ...\n",0,0,0,0,0,0); return ossStatus(S_usbTcdLib_BAD_PARAM); } pEndpointInfo = (pUSB_TCD_ISP1582_ENDPOINT)pTrb->pipeHandle; pTarget = (pUSB_TCD_ISP1582_TARGET)pHeader->handle; endpointIndex = pEndpointInfo->endpointIndex; /* Set the Endpoint Index Register */ isp1582Write8 (pTarget , ISP1582_ENDPT_INDEX_REG , endpointIndex); /* Read the buffer register */ if ((isp1582Read8 (pTarget ,ISP1582_BUF_STATUS_REG) & ISP1582_BUF_STATUS_REG_MASK) == ISP1582_BUF_STATUS_REG_BOTH_EMPT) { USBISP1582_DEBUG ("usbTcdIsp1582FncIsBufferEmpty : Both Buffers are \ Empty...\n",0,0,0,0,0,0); /* WindView Instrumentation */ USB_TCD_LOG_EVENT(USB_TCD_ISP1582_ENDPOINT, "usbTcdIsp1582FncIsBufferEmpty: Both buffers are empty...", USB_TCD_ISP582_WV_FILTER); /* Both the buffers are empty */ pTrb->bufferEmpty = TRUE; } else { USBISP1582_DEBUG ("usbTcdIsp1582FncIsBufferEmpty : Either of the \ Buffers is Filles...\n",0,0,0,0,0,0); /* WindView Instrumentation */ USB_TCD_LOG_EVENT(USB_TCD_ISP1582_ENDPOINT, "usbTcdIsp1582FncIsBufferEmpty: Either of buffer is filled...", USB_TCD_ISP582_WV_FILTER); /* Atleast one of the buffer is filled */ pTrb->bufferEmpty = FALSE; } /* WindView Instrumentation */ USB_TCD_LOG_EVENT(USB_TCD_ISP1582_ENDPOINT, "usbTcdIsp1582FncIsBufferEmpty exiting...", USB_TCD_ISP582_WV_FILTER); USBISP1582_DEBUG ("usbTcdIsp1582FncIsBufferEmpty : Exiting...\n", 0,0,0,0,0,0); return OK; }/******************************************************************************** usbTcdIsp1582FncCopyDataFromEpBuf - implements TCD_FNC_COPY_DATA_FROM_EPBUF** This function copies the data from the endpoint FIFO buffer into the * buffer that is passed. If transfer types are BULK or ISOCHRONOUS and DMA * is not being used by any other endpoint, DMA channel is used to carry out * the transfer.* Otherwise we read from the DataPort Register, 16 bits at a time.** RETURNS: OK or ERROR if not able to read data from the enpoint FIFO.** ERRNO:* \is* \i S_usbTcdLib_BAD_PARAM.* Bad Parameter is passed.* \ie** \NOMANUAL*/LOCAL STATUS usbTcdIsp1582FncCopyDataFromEpBuf ( pTRB_COPY_DATA_FROM_EPBUF pTrb /* TRB to be executed */ ) { pTRB_HEADER pHeader = (pTRB_HEADER) pTrb; /* TRB_HEADER */ pUSB_TCD_ISP1582_ENDPOINT pEndpointInfo = NULL;/*USB_TCD_ISP1582_ENDPOINT*/ pUSB_TCD_ISP1582_TARGET pTarget = NULL; /* USB_TCD_ISP1582_TARGET */ UINT8 endpointIndex = 0; /* endpoint index */ UINT8 transferType = 0; /* transfer type */#ifdef DMA_SUPPORTED UINT16 data16 = 0;#endif UINT32 sizeToCopy = 0; /* size to data to copy */ STATUS status = ERROR; /* variable to hold status */ unsigned char * pBuf = pTrb->pBuffer; /* pointer to buffer */ UINT16 data = 0; BOOL bStatusNext = FALSE; /* WindView Instrumentation */ USB_TCD_LOG_EVENT(USB_TCD_ISP1582_ENDPOINT, "usbTcdIsp1582FncCopyDataFromEpBuf entered...", USB_TCD_ISP582_WV_FILTER); USBISP1582_DEBUG ("usbTcdIsp1582FncCopyDataFromEpBuf : Entered...\n", 0,0,0,0,0,0); /* Validate parameters */ if ((pHeader == NULL) || (pHeader->trbLength < sizeof (TRB_HEADER)) || (pHeader->handle == NULL) || (pTrb->pipeHandle == 0) || (pTrb->pBuffer == NULL)) { /* WindView Instrumentation */ USB_TCD_LOG_EVENT(USB_TCD_ISP1582_ENDPOINT, "usbTcdIsp1582FncCopyDataFromEpBuf exiting: Bad Parameter Received", USB_TCD_ISP582_WV_FILTER); USBISP1582_ERROR ("usbTcdIsp1582FncCopyDataFromEpBuf : Bad Parameters \ ...\n",0,0,0,0,0,0); return ossStatus(S_usbTcdLib_BAD_PARAM); } pEndpointInfo = (pUSB_TCD_ISP1582_ENDPOINT)pTrb->pipeHandle; pTarget = (pUSB_TCD_ISP1582_TARGET)pHeader->handle; endpointIndex = pEndpointInfo->endpointIndex; transferType = pEndpointInfo->transferType;#ifdef DMA_SUPPORTED /* * Check if the endpoint supports DMA, i.e. the transfer types are * bulk or isochronous. */ if ((transferType == USB_ATTR_ISOCH || transferType == USB_ATTR_BULK)) { /* * Check whether DMA Channel is in use and whether DMA transfer has * completed succesfully. */ if ((pTarget->dmaEndpointId == endpointIndex) && (pTarget->dmaInUse) && (pTarget->dmaEot)) { USBISP1582_DEBUG ("usbTcdIsp1582FncCopyDataFromEpBuf : DMA EOT has \ happened...\n",0,0,0,0,0,0); data16 = isp1582Read16 (pTarget,ISP1582_DMA_INT_RESN_REG) & isp1582Read16 (pTarget , ISP1582_DMA_INT_ENBL_REG); if (( data16 & ISP1582_DMA_INT_RESN_REG_DMA_XFER_OK) != 0) { /* DMA Transfer is completed succesfully */ /* Determine the size to copy */ if (pTrb->uActLength < pTarget->dmaXferLen) sizeToCopy = pTrb->uActLength; else sizeToCopy = pTarget->dmaXferLen; /* Invalidate DMA buffer */ USB_PCI_MEM_INVALIDATE ((char *) sysFdBuf, sizeToCopy); /* copy data to user suppiled buffer */ memcpy (pTrb->pBuffer,(char *) sysFdBuf, sizeToCopy); /* update uActLength with the size copied */ pTrb->uActLength = sizeToCopy; status = OK; } else { /* DMA has not completed normally. */ status = ERROR; } /* Clear DMA Interrupt Reason Register */ isp1582Write16 (pTarget , ISP1582_DMA_INT_RESN_REG , ISP1582_DMA_INT_RESN_MASK); /* Disable the DMA controller */ USBISP1582_DEBUG ("usbTcdIsp1582FncCopyDataFromEpBuf : Disabling \ the DMA...\n",0,0,0,0,0,0); disableDma (pTarget , endpointIndex); USBISP1582_DEBUG ("usbTcdIsp1582FncCopyDataFromEpBuf :Exiting...\n", 0,0,0,0,0,0); return status; } else if ((pTarget->dmaEndpointId == endpointIndex) && (pTarget->dmaInUse) && (pTarget->dmaEot != TRUE)) return ERROR; else if (pTarget->dmaInUse == FALSE) { /* * If the dma channel is unused. initialize the DMA Controller * to carry out the DMA operation. */ /* Update dmaXferLen */ if (pTrb->uActLength < sysFdBufSize) pTarget->dmaXferLen = pTrb->uActLength; else pTarget->dmaXferLen = sysFdBufSize; USBISP1582_DEBUG ("usbTcdIsp1582FncCopyDataFromEpBuf :Initializing \ the DMA...\n",0,0,0,0,0,0); /* Initialize the DMA Controller */ initializeDma (pTarget , endpointIndex , ISP1582_DMA_COMMAND_REG_GDMA_WRITE); /* Update uActLength */ pTrb->uActLength = 0; USBISP1582_DEBUG ("usbTcdIsp1582FncCopyDataFromEpBuf :Exiting...\n", 0,0,0,0,0,0); return OK; } } /* Endpoint does not support DMA or the dma channel is already in use */#endif USBISP1582_DEBUG ("usbTcdIsp1582FncCopyDataFromEpBuf : Working in PIO Mode \ ...\n",0,0,0,0,0,0); /* Initialize the endpoint index register */ if ((endpointIndex == ISP1582_ENDPT_0_RX) && (pTarget->setupIntPending)) { pTarget->controlOUTStatusPending = FALSE; pTarget->controlINStatusPending = FALSE; isp1582Write8 (pTarget , ISP1582_ENDPT_INDEX_REG , ISP1582_ENDPT_INDEX_REG_EP0SETUP); } else isp1582Write8 (pTarget , ISP1582_ENDPT_INDEX_REG , endpointIndex); /* * If it is a control endpoint and uActLength is 0, then set bit STATUS of * Control Function Register. */ /* Read the buffer length register */ sizeToCopy = isp1582Read16 (pTarget , ISP1582_BUF_LEN_REG); /* * If the trbLength is the same as the size to copy, * then the status stage follows next */ if ((endpointIndex == ISP1582_ENDPT_0_RX) && (pTrb->uActLength == sizeToCopy) && (!pTarget->setupIntPending)) bStatusNext = TRUE; /* Update uActLength to size to copy */ pTrb->uActLength = sizeToCopy; /* * Read Data Port Regsiter. It is a 16 bit access, hence sizeToCopy * should be decremented by 2 and pBuf should be incremented by 2 */ while (sizeToCopy > 0) { data = isp1582Read16( pTarget , ISP1582_DATA_PORT_REG); *pBuf = (char)(data & 0xFF); data >>= 0x08; sizeToCopy--; if (sizeToCopy > 0) { pBuf += 1; *pBuf = (char)(data); sizeToCopy--; if (sizeToCopy > 0) pBuf += 1; } } /* * Set DSEN bit if its a control endpoint and there is a data phase * after the setup phase. */ if (endpointIndex == ISP1582_ENDPT_0_RX) { if (pTarget->setupIntPending) { /* Reuse sizeToCopy to retrieve the size of the data stage */ sizeToCopy = pTrb->pBuffer[6] | (pTrb->pBuffer[7] << 8); /* If there is a data stage followed by setup stage */ if (sizeToCopy != 0) { /* * If this is an IN data stage change endpoint index * to Control IN. */ if ((pTrb->pBuffer[0] & USB_ENDPOINT_DIR_MASK) != 0) isp1582Write8 (pTarget , ISP1582_ENDPT_INDEX_REG , ISP1582_ENDPT_0_TX); else isp1582Write8 (pTarget , ISP1582_ENDPT_INDEX_REG , ISP1582_ENDPT_0_RX); /* Initiate the data stage */ data = isp1582Read8 (pTarget , ISP1582_CNTL_FUNC_REG); isp1582Write8 (pTarget , ISP1582_CNTL_FUNC_REG , data | ISP1582_CNTL_FUNC_REG_DSEN); } else { pTarget->controlINStatusPending = TRUE; } } else { /* If the status stage is pending, set the flag */ if (bStatusNext) { pTarget->controlINStatusPending = TRUE; } } } status = OK; /* WindView Instrumentation */ USB_TCD_LOG_EVENT(USB_TCD_ISP1582_ENDPOINT, "usbTcdIsp1582FncCopyDataFromEpBuf exiting...", USB_TCD_ISP582_WV_FILTER); USBISP1582_DEBUG ("usbTcdIsp1582FncCopyDataFromEpBuf : Exiting...\n", 0,0,0,0,0,0); return status; }/********************************************************************************* usbTcdIsp1582FncCopyDataToEpBuf - implements TCD_FNC_COPY_DATA_TO_EPBUF** This function copies the data into the endpoint FIFO buffer from the buffer* that is passed.** RETURNS: OK or ERROR if not able to read data from the enpoint fifo.** ERRNO:* \is* \i S_usbTcdLib_BAD_PARAM.* Bad Parameter is passed.* \ie** \NOMANUAL*/LOCAL STATUS usbTcdIsp1582FncCopyDataToEpBuf (
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -