📄 usbohciroothubemulation.c
字号:
} /* End of function usbOhciRootHubEmulationInit () *//***************************************************************************** usbOhciProcessRootHubRequest - Root Hub Request Handler** This function handles the request addressed to the root hub.** PARAMETERS: <nHostControllerIndex (IN)> - Host controller index corresponding * to the host controller for which an interrupt has occurred.** <pURB (IN)> - Pointer to the URB.** RETURNS: USBHST_SUCCESS on success,* USBHST_INVALID_PARAMETER if the parameters are invalid** ERRNO:* None.** \NOMANUAL*/LOCAL USBHST_STATUS usbOhciProcessRootHubRequest ( UINT8 uHostControllerIndex, pUSBHST_URB pUrb ) { /* To hold the status of the operation */ USBHST_STATUS nStatus = USBHST_SUCCESS; /* Debug print */ OS_LOG_MESSAGE_LOW( OHCD, "Entering the function: usbOhciProcessRootHubRequest().\n", 0, 0, 0, 0); /* Check whether the host controller index is valid */ if (uHostControllerIndex >= maxOhciCount) { /* Invalid host controller index */ /* Debug print */ OS_LOG_MESSAGE_LOW( OHCD, "Entering the function: usbOhciProcessRootHubRequest().\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } /* Check whether the URB parameter is valid */ if (pUrb == NULL) { /* Invalid URB parameter */ return USBHST_INVALID_PARAMETER; } /* * Check the endpoint address to determine whether the request * corresponds to a control transfer or interrupt transfer. */ if (pUrb->uEndPointAddress == 0x00) { /* * Call the function to process the control transfer on the * root hub. */ nStatus = usbOhciProcessRootHubControlTransfer (uHostControllerIndex, pUrb); } else if (pUrb->uEndPointAddress == 0x81) { /* * Call the function to process the interrupt transfer on the * root hub. */ nStatus = usbOhciProcessRootHubInterruptTransfer (uHostControllerIndex, pUrb); } else { /* Invalid endpoint number */ nStatus = USBHST_INVALID_PARAMETER; } /* Debug print */ OS_LOG_MESSAGE_LOW( OHCD, "Entering the function: usbOhciProcessRootHubRequest().\n", 0, 0, 0, 0); return nStatus; } /* End of function usbOhciProcessRootHubRequest () *//***************************************************************************** usbOhciProcessRootHubControlTransfer - processes the control transfers** This function processes the control transfers addressed to the root hub** PARAMETERS: <nHostControllerIndex (IN)> - Host controller index corresponding * to the host controller for which an interrupt has occurred.** <pURB (IN)> - Pointer to the URB.** RETURNS: USBHST_SUCCESS on success,* USBHST_INVALID_PARAMETER if the parameters are invalid** ERRNO:* None.** \NOMANUAL*/LOCAL USBHST_STATUS usbOhciProcessRootHubControlTransfer ( UINT8 uHostControllerIndex, pUSBHST_URB pUrb ) { /* To hold the status of the operation */ USBHST_STATUS nStatus = USBHST_SUCCESS; /* To hold the contents of the SETUP packet */ pUSBHST_SETUP_PACKET pSetupPacket = NULL; /* Debug print */ OS_LOG_MESSAGE_LOW( OHCD, "Entering the function: usbOhciProcessRootHubControlTransfer().\n", 0, 0, 0, 0); /* Check whether the SETUP packet is valid */ if (pUrb->pTransferSpecificData == NULL) { /* Invalid setup packet buffer */ /* Debug print */ OS_LOG_MESSAGE_LOW( OHCD, "Exiting the function: usbOhciProcessRootHubControlTransfer().\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } /* Check whether the transfer buffer is valid */ if ((pUrb->uTransferLength != 0) && (pUrb->pTransferBuffer == NULL)) { /* Invalid transfer buffer */ /* Debug print */ OS_LOG_MESSAGE_LOW( OHCD, "Exiting the function: usbOhciProcessRootHubControlTransfer().\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } /* Obtain the pointer to the SETUP packet */ pSetupPacket = (pUSBHST_SETUP_PACKET) pUrb->pTransferSpecificData; /* * Check whether the request is a USB standard request or a * hub class specific request. */ if ((pSetupPacket->bmRequestType & USB_OHCI_CONTROL_TRANSFER_REQUEST_TYPE_MASK) == 0x00) { /* * Call the function to process the standard requests addressed * to the root hub. */ nStatus = usbOhciProcessRootHubStandardRequest (uHostControllerIndex, pUrb); } else if ((pSetupPacket->bmRequestType & USB_OHCI_CONTROL_TRANSFER_REQUEST_TYPE_MASK) == USB_OHCI_CLASS_SPECIFIC_REQUEST) { /* * Call the function to process the hub class specific requests * addressed to the root hub. */ nStatus = usbOhciProcessRootHubClassSpecificRequest (uHostControllerIndex, pUrb); } else { /* Invalid request */ pUrb->nStatus = USBHST_INVALID_REQUEST; } /* Check whether the call back function for the URB is valid */ if (pUrb->pfCallback != NULL) { /* Call the call back function for the URB */ (*(pUrb->pfCallback))(pUrb); } /* Debug print */ OS_LOG_MESSAGE_LOW( OHCD, "Exiting the function: usbOhciProcessRootHubControlTransfer().\n", 0, 0, 0, 0); return nStatus; } /* End of function usbOhciProcessRootHubControlTransfer () *//***************************************************************************** usbOhciProcessRootHubInterruptTransfer - processes the interrupt transfers** This function processes the interrupt transfers addressed to the root hub** PARAMETERS: <nHostControllerIndex (IN)> - Host controller index corresponding * to the host controller for which an interrupt has occurred.** <pURB (IN)> - Pointer to the URB.** RETURNS: USBHST_SUCCESS on success,* USBHST_INVALID_PARAMETER if the parameters are invalid** ERRNO:* None.** \NOMANUAL*/LOCAL USBHST_STATUS usbOhciProcessRootHubInterruptTransfer ( UINT8 uHostControllerIndex, pUSBHST_URB pUrb ) { /* To hold the pointer to the host controller information */ PUSB_OHCI_INFORMATION pOhciControllerInfo = NULL; /* * To hold the critical section ID for checking the status change * on the root hub and the ports on the root hub. */ OS_CRITICAL_SECTION_ID criticalSectionId = 0; /* Debug print */ OS_LOG_MESSAGE_LOW( OHCD, "Entering the function: usbOhciProcessRootHubInterruptTransfer().\n", 0, 0, 0, 0); /* Obtain the pointer to the host controller information */ pOhciControllerInfo = &usbOhciControllerInfo[uHostControllerIndex]; /* Queue the status change interrupt request */ pOhciControllerInfo->pRootHubInterruptRequest = pUrb; /* * Enter the critical section * * NOTE: This is requried because the interrupt handler also checks * for updating the status change request pending on the root * hub. */ criticalSectionId = OS_ENTER_CRITICAL_SECTION(); /* Call the function to process the status change on the root hub */ usbOhciProcessRootHubStatusChange (uHostControllerIndex); /* Leave the critical section */ OS_LEAVE_CRITICAL_SECTION(criticalSectionId); /* Return from the function */ /* Debug print */ OS_LOG_MESSAGE_LOW( OHCD, "Exiting the function: usbOhciProcessRootHubInterruptTransfer().\n", 0, 0, 0, 0); return USBHST_SUCCESS; } /* End of function usbOhciProcessRootHubInterruptTransfer () *//***************************************************************************** usbOhciProcessRootHubStandardRequest - processes the USB standard requests** This function processes the USB standard requests addressed to the root hub** PARAMETERS: <nHostControllerIndex (IN)> - Host controller index corresponding * to the host controller for which an interrupt has occurred.** <pURB (IN)> - Pointer to the URB.** RETURNS: USBHST_SUCCESS on success,* USBHST_INVALID_PARAMETER if the parameters are invalid** ERRNO:* None.* * \NOMANUAL*/LOCAL USBHST_STATUS usbOhciProcessRootHubStandardRequest ( UINT8 uHostControllerIndex, pUSBHST_URB pUrb ) { /* To hold the pointer to the host controller information */ PUSB_OHCI_INFORMATION pOhciControllerInfo = NULL; /* To hold the contents of the SETUP packet */ pUSBHST_SETUP_PACKET pSetupPacket = NULL; /* To hold the base address of the OHCI Controller */ UINT32 uBaseAddress = 0; /* To hold the value read from the registers */ UINT32 uRegisterValue = 0; /* Debug print */ OS_LOG_MESSAGE_LOW( OHCD, "Entering the function: usbOhciProcessRootHubStandardRequest().\n", 0, 0, 0, 0); /* Obtain the pointer to the host controller information */ pOhciControllerInfo = &usbOhciControllerInfo[uHostControllerIndex]; /* Obtain the base address for the OHCI Controller */ uBaseAddress = usbOhciControllerInfo[uHostControllerIndex].uBaseAddress; /* Obtain the pointer to the SETUP packet */ pSetupPacket = (pUSBHST_SETUP_PACKET) pUrb->pTransferSpecificData; /* Swap the contents of the setup data structure which has 16 bits */ pSetupPacket->wValue = OS_UINT16_LE_TO_CPU(pSetupPacket->wValue); pSetupPacket->wIndex = OS_UINT16_LE_TO_CPU(pSetupPacket->wIndex); pSetupPacket->wLength = OS_UINT16_LE_TO_CPU(pSetupPacket->wLength); /* Check the request to be processed */ switch (pSetupPacket->bRequest) { case USBHST_REQ_GET_STATUS: /* USB GET_STATUS request */ /* Check the recipient of the request */ switch (pSetupPacket->bmRequestType & USB_OHCI_CONTROL_TRANSFER_REQUEST_RECIPIENT_MASK) { case USBHST_RECIPIENT_DEVICE: /* Device recipient */ /* Clear the URB transfer buffer */ OS_MEMSET (pUrb->pTransferBuffer, 0, USB_OHCI_GET_STATUS_REQUEST_RESPONSE_SIZE); /* Update the device status - Self powered */ pUrb->pTransferBuffer[0] = USB_OHCI_DEVICE_SELF_POWERED; /* Update the device status - remote wakeup enabled */ if (pOhciControllerInfo->bRemoteWakeupEnabled) { /* Remote wakeup is enabled */ pUrb->pTransferBuffer[0] |= USB_OHCI_DEVICE_REMOTE_WAKEUP_ENABLED;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -