📄 usbhalendpoint.c
字号:
pPipeInfo->uEndpointInterruptStatus = 0; /* Release the mutex */ OSS_MUTEX_RELEASE (pPipeInfo->mutexHandle); /* Update the result of the ERP */ pErp->result = S_usbTcdLib_PID_MISMATCH; /* Call the callback function for the ERP */ if (pErp->targCallback != NULL) (*pErp->targCallback)(pErp); return ERROR; } /*If the data transfer has resulted in an error,complete the request*/ if (((pPipeInfo->uEndpointInterruptStatus & USBTCD_ENDPOINT_TRANSFER_STATUS_MASK) != USBTCD_ENDPOINT_DATA_UNDERRUN) && ((pPipeInfo->uEndpointInterruptStatus & USBTCD_ENDPOINT_TRANSFER_STATUS_MASK) != USBTCD_ENDPOINT_TRANSFER_SUCCESS)) { USBHAL_ERR("usbHalProcessEndpointIN : data transfer error\n", 0,0,0,0,0,0); /* Unlink this element */ usbListUnlink(&pErp->tcdLink); /* * Update the result of the ERP based on the error codes reported in * the endpoint interrupt status */ switch(pPipeInfo->uEndpointInterruptStatus & USBTCD_ENDPOINT_TRANSFER_STATUS_MASK) { case USBTCD_ENDPOINT_DATA_TOGGLE_ERROR: pErp->result = S_usbTcdLib_DATA_TOGGLE_FAULT; break; case USBTCD_ENDPOINT_PID_MISMATCH: pErp->result = S_usbTcdLib_PID_MISMATCH; break; case USBTCD_ENDPOINT_COMMN_FAULT: pErp->result = S_usbTcdLib_COMM_FAULT; break; case USBTCD_ENDPOINT_STALL_ERROR: pErp->result = S_usbTcdLib_STALL_ERROR; break; case USBTCD_ENDPOINT_DATA_OVERRUN: pErp->result = S_usbTcdLib_DATA_OVERRUN; break; default: pErp->result = S_usbTcdLib_GENERAL_FAULT; } /* Reset the endpoint interrupt status */ pPipeInfo->uEndpointInterruptStatus = 0; /* Release the mutex */ OSS_MUTEX_RELEASE (pPipeInfo->mutexHandle); /* Call the callback function for the ERP */ if (pErp->targCallback != NULL) (*pErp->targCallback)(pErp); /* WindView Instrumentation */ USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT, "usbHalProcessEndpointIN exiting: Data Transfer Error...", USB_HAL_WV_FILTER); return ERROR; } } else /* Interrupt is not pending */ { /* Populate the TRB - Start */ trbHeaderInit((pTRB_HEADER)&trbIsBufferEmpty, pHalInfo->pTCDHandle, TCD_FNC_IS_BUFFER_EMPTY, sizeof(TRB_IS_BUFFER_EMPTY)); trbIsBufferEmpty.pipeHandle = pPipeInfo->pipeHandle; trbIsBufferEmpty.bufferEmpty = FALSE; /* Populate the TRB - End */ /* Call the single entry point of the TCD */ status = (*pHalInfo->tcdExecFunc)(&trbIsBufferEmpty); /* * If the status is not OK, call the callback with error * and return ERROR */ if (status != OK) { USBHAL_ERR("usbHalProcessEndpointIN : Error in checking the" "buffer empty status\n",0,0,0,0,0,0); /* Unlink this element */ usbListUnlink (&pErp->tcdLink); /* Release the mutex */ OSS_MUTEX_RELEASE (pPipeInfo->mutexHandle); /* Update the result of the ERP */ pErp->result = S_usbTcdLib_GENERAL_FAULT; /* Call the callback function for the ERP */ if (pErp->targCallback != NULL) (*pErp->targCallback)(pErp); /* WindView Instrumentation */ USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT, "usbHalProcessEndpointIN exiting: TCD Error checking the buffer \ status...", USB_HAL_WV_FILTER); return ERROR; } /* * If the buffer is not empty, the data cannot be * written to the endpoint buffer. It is not an error. * Return OK. */ if (trbIsBufferEmpty.bufferEmpty == FALSE) { USBHAL_DEBUG("usbHalProcessEndpointIN : " "Buffer not empty\n",0,0,0,0,0,0); /* Release the mutex */ OSS_MUTEX_RELEASE (pPipeInfo->mutexHandle); /* WindView Instrumentation */ USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT, "usbHalProcessEndpointIN exiting...", USB_HAL_WV_FILTER); return OK; } } /* Calculate the index into the buffer list */ while((uIndex < pErp->bfrCount) && ((pErp->bfrList[uIndex].actLen) == (pErp->bfrList[uIndex].bfrLen))) uIndex++; /* * This condition can happen when the interrupt is generated for the last * packet in the request */ if (uIndex == pErp->bfrCount) uIndex--; /* * If the entire data has been sent, call the callback function * The 3 conditions are explaines as follows * 1. If it is not a control status transfer and if the entire data has * been sent * 2. If it is a control status transfer and an interrupt has already occured. * 3. If there is a short packet. */ if (((pErp->bfrList[uIndex].actLen == pErp->bfrList[uIndex].bfrLen) && ((uIndex + 1 ) == pErp->bfrCount) && (pPipeInfo->uEndpointInterruptStatus != 0)) || ((trbIsBufferEmpty.bufferEmpty == FALSE) && (pErp->bfrList[uIndex].bfrLen == 0) && (pPipeInfo->uEndpointInterruptStatus != 0)) || ((pPipeInfo->uEndpointInterruptStatus & USBTCD_ENDPOINT_TRANSFER_STATUS_MASK) == USBTCD_ENDPOINT_DATA_UNDERRUN)) { USBHAL_DEBUG("usbHalProcessEndpointIN - Request completed\n",0,0,0,0,0,0); /* * If it is a control pipe, * check whether the amount of data sent was a multiple of max packetsize. * If so, send a 0 length packet. */ if ((pErp->tcdPtr != NULL) && (pErp->bfrList[uIndex].bfrLen != 0) && ((pErp->bfrList[uIndex].bfrLen % pPipeInfo->maxPacketSize) == 0)) { TRB_COPY_DATA_TO_EPBUF trbCopyDataToEpBuf; /* Populate the TRB - start */ trbHeaderInit((pTRB_HEADER)&trbCopyDataToEpBuf, pHalInfo->pTCDHandle, TCD_FNC_COPY_DATA_TO_EPBUF, sizeof(TRB_COPY_DATA_TO_EPBUF)); /* Populate the TRB - end */ trbCopyDataToEpBuf.pipeHandle = pPipeInfo->pipeHandle; trbCopyDataToEpBuf.pBuffer = NULL; /* Set the length to be sent to 0 */ trbCopyDataToEpBuf.uActLength = 0; trbCopyDataToEpBuf.zeroLengthPacket = FALSE; /* Call the single entry point of the TCD */ status = (*pHalInfo->tcdExecFunc)(&trbCopyDataToEpBuf); if (status != OK) { USBHAL_ERR("usbHalProcessEndpointIN : " "Error in copying data to EP buffer\n",0,0,0,0,0,0); /* Unlink this element */ usbListUnlink (&pErp->tcdLink); /* Reset the endpoint interrupt status */ pPipeInfo->uEndpointInterruptStatus = 0; /* Release the mutex */ OSS_MUTEX_RELEASE (pPipeInfo->mutexHandle); /* Update the result of the ERP */ pErp->result = S_usbTcdLib_GENERAL_FAULT; /* Call the callback function for the ERP */ if (pErp->targCallback != NULL) (*pErp->targCallback)(pErp); /* WindView Instrumentation */ USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT, "usbHalProcessEndpointIN exiting: Error in copying data to EP \ buffer...", USB_HAL_WV_FILTER); return ERROR; } } /* Unlink this element */ usbListUnlink (&pErp->tcdLink); /* Reset the endpoint interrupt status */ pPipeInfo->uEndpointInterruptStatus = 0; /* Release the mutex */ OSS_MUTEX_RELEASE(pPipeInfo->mutexHandle); /* Update the ERP result */ pErp->result = 0; /* Call the callback function for the ERP */ if (pErp->targCallback != NULL) (*pErp->targCallback)(pErp); return OK; } else { TRB_COPY_DATA_TO_EPBUF trbCopyDataToEpBuf; /* Populate the TRB - start */ trbHeaderInit((pTRB_HEADER)&trbCopyDataToEpBuf, pHalInfo->pTCDHandle, TCD_FNC_COPY_DATA_TO_EPBUF, sizeof(TRB_COPY_DATA_TO_EPBUF)); trbCopyDataToEpBuf.pipeHandle = pPipeInfo->pipeHandle; trbCopyDataToEpBuf.pBuffer = pErp->bfrList[uIndex].pBfr + pErp->bfrList[uIndex].actLen; trbCopyDataToEpBuf.uActLength = pErp->bfrList[uIndex].bfrLen - pErp->bfrList[uIndex].actLen; if ((pErp->tcdPtr != NULL) && ((pErp->bfrList[uIndex].bfrLen % pPipeInfo->maxPacketSize) == 0)) trbCopyDataToEpBuf.zeroLengthPacket = TRUE; else trbCopyDataToEpBuf.zeroLengthPacket = FALSE; /* Populate the TRB - End */ /* Call the single entry point of the TCD */ status = (*pHalInfo->tcdExecFunc)(&trbCopyDataToEpBuf); /* * If the return status is not OK, call the callback with error * and return ERROR */ if (status != OK) { USBHAL_ERR("usbHalProcessEndpointIN : " "Error in copying data to EP buffer\n",0,0,0,0,0,0); /* Unlink this element */ usbListUnlink (&pErp->tcdLink); /* Reset the endpoint interrupt status */ pPipeInfo->uEndpointInterruptStatus = 0; /* Release the mutex */ OSS_MUTEX_RELEASE (pPipeInfo->mutexHandle); /* Update the result of the ERP */ pErp->result = S_usbTcdLib_GENERAL_FAULT; /* Call the callback function for the ERP */ if (pErp->targCallback != NULL) (*pErp->targCallback)(pErp); /* WindView Instrumentation */ USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT, "usbHalProcessEndpointIN exiting: Error in copying data to EP \ buffer...", USB_HAL_WV_FILTER); return ERROR; } /* Update the buffer list actual length */ pErp->bfrList[uIndex].actLen += trbCopyDataToEpBuf.uActLength; if ((pPipeInfo->uEndpointInterruptStatus != 0) && (pErp->bfrList[uIndex].actLen == trbCopyDataToEpBuf.uActLength)) { pPipeInfo->uEndpointInterruptStatus = 0; if ((pErp->bfrList[uIndex].actLen == pErp->bfrList[uIndex].bfrLen) && ((uIndex + 1 ) == pErp->bfrCount)) { /* Update the result of the ERP */ pErp->result = 0; /* Call the callback function for the ERP */ if (pErp->targCallback != NULL) (*pErp->targCallback)(pErp); } } } /* Release the mutex */ OSS_MUTEX_RELEASE (pPipeInfo->mutexHandle); /* WindView Instrumentation */ USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT, "usbHalProcessEndpointIN exiting...", USB_HAL_WV_FILTER); USBHAL_DEBUG("usbHalProcessEndpointIN - Exiting\n",0,0,0,0,0,0); return OK; }/********************************************************************************* usbHalEndpointRelease - releases the endpoints** Function used by HAL to free the resources allocated for the Pipe info* data structure.** RETURNS: N/A.** ERRNO:* None.** \NOMANUAL*/LOCAL VOID usbHalEndpointRelease ( pUSBHAL_TCD pUsbHal, /* USBHAL_TCD */ pUSBHAL_PIPE_INFO pPipeInfo /* USBHAL_PIPE_INFO */ ) { TRB_ENDPOINT_RELEASE trbEptRelease; /* WindView Instrumentation */ USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT, "usbHalEndpointRelease entered...", USB_HAL_WV_FILTER); USBHAL_DEBUG("usbHalEndpointRelease - Entering\n",0,0,0,0,0,0); /* Check if the parameters are valid */ if ((pUsbHal == NULL) || (pPipeInfo == NULL)) { /* WindView Instrumentation */ USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT, "usbHalEndpointRelease exiting: Bad Paramters Received...", USB_HAL_WV_FILTER); USBHAL_ERR("usbHalEndpointRelease : Invalid parameters\n",0,0,0,0,0,0); return; } /* Populate the TRB - start */ trbHeaderInit((pTRB_HEADER)(&trbEptRelease), pUsbHal->pTCDHandle, TCD_FNC_ENDPOINT_RELEASE, sizeof(TRB_ENDPOINT_RELEASE)); trbEptRelease.pipeHandle = pPipeInfo->pipeHandle; /* Populate the TRB - End */ /* Call the single entry point for the TCD */ (*pUsbHal->tcdExecFunc)(&trbEptRelease); /* If the mutex handle is valid, destroy the mutex */ if (pPipeInfo->mutexHandle != NULL) OSS_MUTEX_DESTROY (pPipeInfo->mutexHandle); /* Free the memory allocated for the Pipe information data structure */ OSS_FREE (pPipeInfo); /* WindView Instrumentation */ USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT, "usbHalEndpointRelease exiting...", USB_HAL_WV_FILTER); USBHAL_DEBUG ("usbHalEndpointRelease - Exiting\n",0,0,0,0,0,0); return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -