📄 usbhubclassinterface.c
字号:
}/* End of if (NULL == pParentHub ) */ /* * If this uPowerRequirement less than HUB_INFO::nPowerPerPort * then return USBHST_SUCCESS. */ if (pParentHub->uPowerPerPort >=uPowerRequirement) { /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubCheckPower: Pass DevH=0x%x PowReq=%d\n", uDeviceHandle, uPowerRequirement, 0, 0); return USBHST_SUCCESS; } /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Exiting usbHubCheckPower() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubCheckPower: FAILED DevH=0x%x PowReq=%d\n", uDeviceHandle, uPowerRequirement, 0, 0); /* Return USBHST_FAILURE */ return USBHST_FAILURE; } /* End of function HUB_CheckPower() *//***************************************************************************** usbHubResetDevice - reset the device.** This function is called by the USB Host Software Stack for resetting a device.** RETURNS: N/A** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbHubResetDevice ( UINT32 uDeviceHandle ) { /* The pointer to the parent hub */ pUSB_HUB_INFO pParentHub = NULL; /* port number of the device */ UINT8 uPortIndex = 0; /* The port Information */ pUSB_HUB_PORT_INFO pPort = NULL; /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Entering usbHubResetDevice() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubResetDevice : Called DevH=0x%x\n", uDeviceHandle, 0, 0, 0); /* * Call HUB_FindParentHubInBuses() to find the parent hub and If this is not * found, then return USBHST_INVALID_PARAMETER. */ pParentHub = usbHubFindParentHubInBuses(uDeviceHandle); /* if not found return USBHST_INVALID_PARAMETER */ if (NULL == pParentHub) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubResetDevice : parent hub not found\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; }/* End of if (NULL == pParentHub ) */ /* * Call HUB_FindPortNumber() to find the port number for this device handle. * If this is not found, then return USBHST_INVALID_PARAMETER. */ uPortIndex = usbHubFindPortNumber(pParentHub,uDeviceHandle); /* Check if the port is found */ if (USB_PORT_NUMBER_NOT_FOUND == uPortIndex) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "HUB_ResetDevice : port number not found\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } /* End of if (PORT_NUM.. */ /* Check if the port number is within limits */ if (uPortIndex > (pParentHub->HubDescriptor.bNbrPorts)) { return USBHST_INVALID_PARAMETER; } /* End of (uPortIndex > (pParentHub->.... */ /* Retrieve the HUB_PORT_INFO structure.*/ pPort = pParentHub->pPortList[uPortIndex]; OS_ASSERT( NULL == pPort->pHub); /* Verify */ /* Set the HUB_PORT_INFO::StateOfPort as HUB_RESET_PENDING.*/ pPort->StateOfPort = USB_HUB_RESET_PENDING; /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB,"Waiting for reset completion\n",0,0,0,0); /* * Loop while HUB_PORT_INFO::StateOfPort is HUB_RESET_PENDING. * Or the parent hub::StateOfHub is not MARKED_FOR_DELETION */ while ( (USB_HUB_RESET_PENDING==pPort->StateOfPort) || (USB_MARKED_FOR_DELETION!=pParentHub->StateOfHub ) ) { /* Do nothing.. */ }/* End of while ( (HUB_RESET_PENDING... */ /* * If the parent hub::StateOfHub is MARKED_FOR_DELETION then return * USBHST_FAILURE. */ if (USB_MARKED_FOR_DELETION == pParentHub->StateOfHub ) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB,"usbHubResetDevice : parent hub marked for delete\n",0,0,0,0); /* * Parent hub got marked for deletion.. implies the reset would fail. */ return USBHST_FAILURE; } /* End of if (MARKED_FOR_DELETION == pParentHub->StateOfHub ) */ /* * If the HUB_PORT_INFO::StateOfPort is MARKED_FOR_DELETION * then return USBHST_FAILURE. */ if (USB_MARKED_FOR_DELETION!=pPort->StateOfPort ) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubResetDevice:port marked for delete DevH=0x%x\n", uDeviceHandle, 0, 0, 0); /* * The port got marked for deletion. we may not be able to complete * reset */ return USBHST_FAILURE; }/* End of (MARKED_FOR_DELETION!=pPort->StateOfPort ) */ /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Exiting usbHubResetDevice() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubResetDevice : marked for resetDevH=0x%x\n", uDeviceHandle, 0, 0, 0); /* Return USBHST_SUCCESS.*/ return USBHST_SUCCESS;} /* End of function HUB_ResetDevice() *//***************************************************************************** usbHubClearTT - submits a request for clear TT** This routine submits a request for clear TT.** RETURNS: USBHST_SUCCESS, USBHST_FAILURE if request submission is unsuccessful** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbHubClearTT ( UINT32 uHubHandle, UINT8 uPortNumber, UINT16 uValue, void * pContext ) { /* This is the URB */ pUSBHST_URB pControlURB =NULL; /* This stores the setup packet */ pUSBHST_SETUP_PACKET pSetupPacket =NULL; /* This is to store the request result */ USBHST_STATUS Result =USBHST_FAILURE; /* Port number to which the TT is attached on the hub */ UINT8 uTTPortNumber =0; /* Allocate memory for the setup packet */ pSetupPacket = OS_MALLOC(sizeof(USBHST_SETUP_PACKET)); /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Entering usbHubClearTT() Function", USB_HUB_WV_FILTER); /* Check the result */ if (NULL == pSetupPacket) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB,"usbHubClearTT:memory insuff - pSetupPacket\n",0,0,0,0); return USBHST_INSUFFICIENT_MEMORY; }/* End of if (NULL== pSetupPacket) */ /*Clear the allocated memory */ OS_MEMSET(pSetupPacket,0,sizeof(USBHST_SETUP_PACKET)); /* * Last bit of uPortNumber specifies if HUB is Single/Multiple TT * 1) If the last bit Of uPortNumber is Zero (single TT Hub), * uTTPortNumber is set One * 2) If the last bit of uPortNumber is One(Multiple TT Hub) ,uTTPortNumber * is uPortNumber with last bit made Zero */ uTTPortNumber = ((uPortNumber & 0x80) == 0 )? 1:(uPortNumber & 0x7F ); /* * Call USBHST_FILL_SETUP_PACKET() to populate an USBHST_SETUP_PACKET * structure by with bmRequest as PORT_TARGET, bRequest as CLEAR_TT_REQUEST, * wValue as the uValue, wIndex as uTTPortNumber and wLength as 0. * */ USBHST_FILL_SETUP_PACKET( pSetupPacket, /* pSetup */ USB_PORT_TARGET_SET, /* uRequestType */ USB_CLEAR_TT_REQUEST,/* uRequest */ uValue, /* uValue */ uTTPortNumber, /* uIndex */ 0); /* uSize */ pControlURB = OS_MALLOC(sizeof(USBHST_URB)); /* Check the result */ if (NULL == pControlURB) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB,"usbHubClearTT:memory insuff - pControlURB\n",0,0,0,0); /* Free the allocated setup packet */ OS_FREE(pSetupPacket); /* Return USBHST_INSUFFICIENT_MEMORY */ return USBHST_INSUFFICIENT_MEMORY; }/* End of if (NULL== pControlURB) */ /*clear the memory allocated */ OS_MEMSET(pControlURB,0,sizeof(USBHST_URB)); /* * Call USBHST_FILL_CONTROL_URB() to populate a URB structure with * pHub::uDeviceHandle, endpoint as the DEFAUL_ENDPOINT, transfer buffer as * NULL, transfer length as 0, USBHST_SETUP_PACKET structure, * usbHubClearTTRequestCallback as the callback and the pHub as the pContext. */ USBHST_FILL_CONTROL_URB( pControlURB, /* Urb */ uHubHandle, /* Device */ USB_HUB_DEFAULT_ENDPOINT, /* EndPointAddress */ NULL, /* TransferBuffer */ 0, /* TransferLength */ USBHST_SHORT_TRANSFER_OK, /* TransferFlags */ pSetupPacket, /* SetupPacket */ usbHubClearTTRequestCallback , /* Callback */ pContext, /* pContext */ USBHST_FAILURE /* Status */ ); Result = usbHstURBSubmit(pControlURB); if (USBHST_SUCCESS !=Result) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB,"usbHubClearTT: submit request failed \n",0,0,0,0); /* Free the allocated memory */ OS_FREE(pSetupPacket); OS_FREE(pControlURB); }/* End of if (USBHST_SUCCESS !=Result) */ /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Exiting usbHubClearTT() Function", USB_HUB_WV_FILTER); /* Return the result */ return Result;}/*end ofHUB_ClearTT *//***************************************************************************** usbHubResetTT - This function submits a request for clear TT** This routine submits a request for clear TT** RETURNS: USBHST_SUCCESS, USBHST_FAILURE if request submission is unsuccessful** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbHubResetTT ( UINT32 uHubHandle, UINT8 uPortNumber, void * pContext ) { /* This is the URB */ pUSBHST_URB pControlURB =NULL; /* This stores the setup packet */ pUSBHST_SETUP_PACKET pSetupPacket =NULL; /* This is to store the request result */ USBHST_STATUS Result =USBHST_FAILURE; /* Port number to which the TT is attached on the hub */ UINT8 uTTPortNumber =0; /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Entering usbHubResetTT() Function", USB_HUB_WV_FILTER); /*Allocate for pSetupPacket */ pSetupPacket = OS_MALLOC(sizeof(USBHST_SETUP_PACKET)); /* Check the result */ if (NULL == pSetupPacket) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB,"usbHubResetTT:memory insuff - pSetupPacket\n",0,0,0,0); /* Return USBHST_INSUFFICIENT_MEMORY */ return USBHST_INSUFFICIENT_MEMORY; }/* End of if (NULL== pSetupPacket) */ /*Clear the allocated memory */ OS_MEMSET(pSetupPacket,0,sizeof(USBHST_SETUP_PACKET)); /* * Last bit of uPortNumber specifies if HUB is Single/Multiple TT * 1) If the last bit Of uPortNumber is Zero (single TT Hub), * uTTPortNumber is set One * 2) If the last bit of uPortNumber is One(Multiple TT Hub) ,uTTPortNumber * is uPortNumber with last bit made Zero */ uTTPortNumber = ((uPortNumber & 0x80) == 0 ) ? 1:(uPortNumber & 0x7F); /* * Call USBHST_FILL_SETUP_PACKET() to populate an USBHST_SETUP_PACKET * structure by with bmRequest as PORT_TARGET, bRequest as RESET_TT, * wValue as zero, wIndex as uPortIndex and wLength as 0. */ USBHST_FILL_SETUP_PACKET( pSetupPacket, /* pSetup */ USB_PORT_TARGET_SET, /* uRequestType */ USB_RESET_TT ,/* uRequest */ 0, /* uValue */ uTTPortNumber, /* uIndex */ 0); /* uSize */ /* Allocate memory for the URB */ pControlURB = OS_MALLOC(sizeof(USBHST_URB)); /* Check the result */ if (NULL == pControlURB) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB,"usbHubResetTT:memory insuff - pControlURB\n",0,0,0,0); /* Free the setup packet */ OS_FREE(pSetupPacket); return USBHST_INSUFFICIENT_MEMORY; }/* End of if (NULL== pControlURB) */ /*clear the memory allocated */ OS_MEMSET(pControlURB,0,sizeof(USBHST_URB)); /* * Call USBHST_FILL_CONTROL_URB() to populate a URB structure with * pHub::uDeviceHandle, endpoint as the DEFAUL_ENDPOINT, transfer buffer as * NULL, transfer length as 0, USBHST_SETUP_PACKET structure, * HUB_ClearTTRequestCallback as the callback and the pHub as the pContext. */ USBHST_FILL_CONTROL_URB( pControlURB, /* Urb */ uHubHandle, /* Device */ USB_HUB_DEFAULT_ENDPOINT, /* EndPointAddress */ NULL, /* TransferBuffer */ 0, /* TransferLength */ USBHST_SHORT_TRANSFER_OK, /* TransferFlags */ pSetupPacket, /* SetupPacket */ usbHubResetTTRequestCallback , /* Callback */ pContext, /* pContext */ USBHST_FAILURE /* Status */ ); /* Submit the request to the USBHST */ Result = usbHstURBSubmit(pControlURB); if (USBHST_SUCCESS !=Result) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB,"usbHubResetTT: submit request failed \n",0,0,0,0); /* Free the memory */ OS_FREE(pSetupPacket); OS_FREE(pControlURB); } /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Exiting usbHubResetTT() Function", USB_HUB_WV_FILTER); /* Return Result*/ return Result; }/*end of HUB_ResetTT*//**************************** End of File HUB_ClassInterface.c ****************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -