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

📄 usbohciroothubemulation.c

📁 风河的vxworks-6.3 FOR amcc440epx BSP!
💻 C
📖 第 1 页 / 共 5 页
字号:
                 			 */                			/* Clear the port enable status change */                			USB_OHCI_REG_WRITE(uHostControllerIndex, 					(uBaseAddress + 					uRootHubPortStatusRegisterOffset),                          		USB_OHCI_RH_PORT_STATUS_PESC);                			/* Update the URB status */                			pUrb->nStatus = USBHST_SUCCESS;                			break;            			case USB_OHCI_C_PORT_SUSPEND:                			/*                  			 * NOTE: Write 1 to the port suspend status change							 * bit to clear the port suspend status change.                 			 */                			/* Clear the port suspend status change */                			USB_OHCI_REG_WRITE(uHostControllerIndex, 					(uBaseAddress + 					uRootHubPortStatusRegisterOffset),                          		USB_OHCI_RH_PORT_STATUS_PSSC);                			/* Update the URB status */                			pUrb->nStatus = USBHST_SUCCESS;                			break;            			case USB_OHCI_C_PORT_OVER_CURRENT:                			/*                  			 * NOTE: Write 1 to the over current indicator 							 * change (OCIC) bit to clear the port power state.                 			 */                			/* Clear the over current indicator change */                			USB_OHCI_REG_WRITE(uHostControllerIndex, 					(uBaseAddress + 					uRootHubPortStatusRegisterOffset),                          		USB_OHCI_RH_PORT_STATUS_OCIC);                			/* Update the URB status */                			pUrb->nStatus = USBHST_SUCCESS;                			break;            			default:                			/* Invalid request. Update the URB status */                			pUrb->nStatus = USBHST_INVALID_REQUEST;                		break;            			}; /* End of switch (pSetupPacket->wValue) */            		break;        		default:            		/* Invalid request. Update the URB Status */            		pUrb->nStatus = USBHST_INVALID_REQUEST;            		break;        		}; /* End of switch (pSetupPacket->bmRequestType & ... ) */        	break;    	case USBHST_REQ_GET_DESCRIPTOR:           	/*         	 * Check whether the descriptor type and decriptor index is valid.         	 *          	 * NOTE: For the root hub, only one hub descriptor is supported.          	 *       Further, the descriptor type and descriptor index should         	 *       be zero.         	 */        	if (pSetupPacket->wValue != 0x2900)        		{            	/* Invalid descriptor type or index */            	pUrb->nStatus = USBHST_STALL_ERROR;            	break;        		}        	/*          	 * Compute the number of bytes required to hold the          	 * 'DeviceRemovable' and 'PortPwrCtrlMask' information of the device			 * descriptor.         	 *         	 * NOTE: HUB_CLASS_DESCRIPTOR structure can hold the above two         	 *       information for maximum of 8 ports. If the number of ports         	 *       on the root hub is greater than 8, additional memory         	 *       should be allocated for the HUB_CLASS_DESCRIPTOR.         	 */                	/*          	 * Compute the number of bytes to copy based on the number of          	 * ports supported on the root hub.         	 */        	uNumberOfBytes = pOhciControllerInfo->uNumberOfDownStreamPorts / 8;        	/* Check for remainder of the bytes */        	if ((pOhciControllerInfo->uNumberOfDownStreamPorts % 8) != 0)        		{            	/* Increment the number of bytes to be copied */            	uNumberOfBytes++;        		}        	/*          	 * Since the HUB_CLASS_DESCRIPTOR can hold a maximum of 8 ports,        	 * update the number of bytes required for the HUB_CLASS_DESCRIPTOR.        	 */        	uNumberOfBytes--;        	/*         	 * Compute the length of the hub descriptor.        	 *        	 * NOTE: The 'DeviceRemovable' and 'PortPwrCtrlMask' fields are        	 *       of variable length based on the number of ports. Further,        	 *       these fields are rounded off to the byte granularity.        	 */        	uHubDescriptorLength =             	sizeof(USB_OHCI_HUB_CLASS_DESCRIPTOR) + uNumberOfBytes;        	/* Allocate memory for the hub class descriptor */        	pHubDescriptor =             	(PUSB_OHCI_HUB_CLASS_DESCRIPTOR) 				OS_MALLOC(uHubDescriptorLength);        	/* Check whether the memory was successfully allocated */        	if (pHubDescriptor == NULL)        		{            	/* Update the status of the URB */            	pUrb->nStatus = USBHST_STALL_ERROR;            	break;        		}        	/* Populate the hub class descriptor (BEGIN) */        	/* Populate the descriptor length */        	pHubDescriptor->bDescLength = uHubDescriptorLength;        	/* Populate the descriptor type */        	pHubDescriptor->bDescriptorType = 				USB_OHCI_HUB_CLASS_DESCRIPTOR_TYPE;        	/* Populate the number of ports */        	pHubDescriptor->bNbrPorts =             	pOhciControllerInfo->uNumberOfDownStreamPorts;        	/*         	 * Populate the hub characteristics.         	 *        	 * NOTE: The hub characteristics of the OHCI host controller        	 *       can be obtained from bits 8 - 12 of the HcRhDescriptorA        	 *       register.        	 */        	/* Read the contents of the HcRhDescriptorA register */        	uRegisterValue =             	USB_OHCI_REG_READ(uHostControllerIndex, uBaseAddress + 				  USB_OHCI_RH_DESCRIPTOR_A_REGISTER_OFFSET);        	/* Populate the hub characteristics information */        	pHubDescriptor->wHubCharacteristics =             	(UINT16) ((uRegisterValue >> 8) & 0x1F);        	/*         	 * Populate the power on to power good information         	 *        	 * NOTE: The power on to power good information of the OHCI host        	 *       controller can be obtained from bits 24 - 31 of the        	 *       HcRhDescriptorA register.        	 */        	pHubDescriptor->bPwrOn2PwrGood = (UINT8) ((uRegisterValue >> 24) 															& 0xFF);        	/*         	 * Populate the device removable information.        	 *        	 * NOTE: The device removable information of OHCI host controller        	 *       can be obtained from bits 0 - 15 of the HcRhDescriptorB         	 *       register.        	 */                	/* Read the contents of the HcRhDescriptorB register */        	uRegisterValue =             	USB_OHCI_REG_READ(uHostControllerIndex, uBaseAddress + 				  USB_OHCI_RH_DESCRIPTOR_B_REGISTER_OFFSET);        	/* Populate the device removable information */        	pHubDescriptor->deviceRemovable[0] = (UINT8) 												 (uRegisterValue & 0xFF);        	/* Check whether the root hub has more than 8 downstream ports */        	if (pOhciControllerInfo->uNumberOfDownStreamPorts > 8)        		{            	/*             	 * Populate the device removable information for the other             	 * ports.             	 *            	 * NOTE: As per HcRhDescriptorB register definition, root hub            	 *       supports a maximum of 16 ports.            	 */            	pHubDescriptor->deviceRemovable[1] =                 	(UINT8) ((uRegisterValue >> 8) & 0xFF);        		}        	/*          	 * Populate the port power control mask information.         	 *         	 * NOTE: The port power control mask information of the OHCI host          	 *       controller can be obtained from bits 16 - 31 of the          	 *       HcRhDescriptorB register.         	 */                	/* Populate the port power control mask information */        	pHubDescriptor->portPwrCtrlMask[0] =             	(UINT8) ((uRegisterValue >> 16) & 0xFF);        	/* Check whether the root hub has more than 8 downstream ports */        	if (pOhciControllerInfo->uNumberOfDownStreamPorts > 8)        		{            	/*             	 * Populate the port power control mask information for other             	 * ports.             	 *            	 * NOTE: As per HcRhDescriptorB register definition, root hub            	 *       supports a maximum of 16 ports.            	 */            	pHubDescriptor->portPwrCtrlMask[1] =                 	(UINT8) ((uRegisterValue >> 24) & 0xFF);        		}        	/* Check the number of bytes of hub descriptor requested */        	if (pSetupPacket->wLength >= uHubDescriptorLength)        		{            	/* Copy the descriptor to the URB transfer buffer */            	OS_MEMCPY(pUrb->pTransferBuffer,                      	  (PUCHAR) pHubDescriptor,                      	  uHubDescriptorLength);            	/* Update the URB transfer length */            	pUrb->uTransferLength = uHubDescriptorLength;        		}        	else         		{            	/* Copy the descriptor to the URB transfer buffer */            	OS_MEMCPY(pUrb->pTransferBuffer,                      	  (PUCHAR) (pHubDescriptor),                      	  pSetupPacket->wLength);            	/* Update the URB transfer length */            	pUrb->uTransferLength = pSetupPacket->wLength;        		}        	/* Update the URB status */        	pUrb->nStatus = USBHST_SUCCESS;        	/* Release the memory allocated for the hub descriptor */       		OS_FREE(pHubDescriptor);        	pHubDescriptor = NULL;        	break;    	case USBHST_REQ_GET_STATUS:        	/* Check the recipient of the request */        	switch (pSetupPacket->bmRequestType &                 		USB_OHCI_CONTROL_TRANSFER_REQUEST_RECIPIENT_MASK)        		{        		case USBHST_RECIPIENT_DEVICE: /* GetHubStatus() request */            		/* Read the contents of the HcRhStatus register */            		uRegisterValue =               		USB_OHCI_REG_READ(uHostControllerIndex,                                         uBaseAddress +					USB_OHCI_RH_STATUS_REGISTER_OFFSET);                    /* INTEGRATION TESTING CHANGE - start */                    /* Swap the value read from the register */                    uRegisterValue = OS_UINT32_CPU_TO_LE(uRegisterValue);                    /* INTEGRATION TESTING CHANGE - End */            		/* Update the URB transfer buffer */            		OS_MEMCPY(pUrb->pTransferBuffer,                      		  (PUCHAR) (&uRegisterValue),                      		  USB_OHCI_GET_HUB_STATUS_REQUEST_RESPONSE_SIZE);            		/* Update the URB transfer length */            		pUrb->uTransferLength =                 		USB_OHCI_GET_HUB_STATUS_REQUEST_RESPONSE_SIZE;            		/* Update the URB status */            		pUrb->nStatus = USBHST_SUCCESS;		            		break;        		case USBHST_RECIPIENT_OTHER: /* GetPortStatus() request */            		/* Check the port number */            		if (pSetupPacket->wIndex >                 			pOhciControllerInfo->uNumberOfDownStreamPorts)            			{                		/* Invalid port index. Update the URB status. */                		pUrb->nStatus = USBHST_INVALID_REQUEST;                		break;            			}            		/* Obtain the offset of the root hub port status register */            		uRootHubPortStatusRegisterOffset =                 		USB_OHCI_RH_PORT_STATUS_REGISTER_OFFSET(							pSetupPacket->wIndex);            		/* Read the contents of the HcRhPortStatus register */               		uRegisterValue =                		USB_OHCI_REG_READ(uHostControllerIndex,                                                   uBaseAddress + 						  uRootHubPortStatusRegisterOffset);                    /* INTEGRATION TESTING CHANGE - Start */                    /* Swap the port status bytes */                     uRegisterValue = OS_UINT32_CPU_TO_LE(uRegisterValue);                    /* INTEGRATION TESTING CHANGE - End */                                		/* Update the URB transfer buffer */            		OS_MEMCPY(pUrb->pTransferBuffer,                      		  (PUCHAR) (&uRegisterValue),                      		  USB_OHCI_GET_PORT_STATUS_REQUEST_RESPONSE_SIZE);            		/* Update the URB transfer length */            		pUrb->uTransferLength =                 		USB_OHCI_GET_PORT_STATUS_REQUEST_RESPONSE_SIZE;            		/* Update the URB status */            		pUrb->nStatus = USBHST_SUCCESS;            		break;        		default:            		/* Invalid request. Update the URB Status */            		pUrb->nStatus = USBHST_INVALID_REQUEST;            		break;        		}; /* End of switch (pSetupPacket->bmRequestType & ... ) */        	break;    	case USBHST_REQ_SET_DESCRIPTOR:        	/*         	 * SET_DESCRIPTOR request is not support for the root hub.        	 * Update the URB status.        	 */        	pUrb->nStatus = USBHST_INVALID_REQUEST;        	break;    	case USBHST_REQ_SET_FEATURE:        	/* Check the recipient of the request */        	switch (pSetupPacket->bmRequestType &                 	USB_OHCI_CONTROL_TRANSFER_REQUEST_RECIPIENT_MASK)        		{        		case USBHST_RECIPIENT_DEVICE: /* SetHubFeature() request */            		/* Check the feature selector for the request */            		switch (pSetupPacket->wValue)            			{            			case USB_OHCI_C_HUB_LOCAL_POWER:             			case USB_OHCI_C_HUB_OVER_CURRENT:                			/* NOTE: These features are not supported on the 							 * root hub 							 */                

⌨️ 快捷键说明

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