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

📄 usbehcdrhemulation.c

📁 usb2 driver for vxwokrs
💻 C
📖 第 1 页 / 共 5 页
字号:
    /* Update the status */    pURB->nStatus = USBHST_SUCCESS;    /* Free memory allocated for the buffer */    OS_FREE(pBuffer);    OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdRhGetHubDescriptor - Exit\n",0,0,0,0);    return Status;    }    /* End of usbEhcdRhGetHubDescriptor() *//***************************************************************************** usbEhcdRhGetPortStatus - get the status of the port** This routine gets the status of the port.** RETURNS: USBHST_SUCCESS - if the URB is submitted successfully.*  USBHST_INVALID_PARAMETER - if the parameters are not valid.** ERRNO:*   None.*/USBHST_STATUS usbEhcdRhGetPortStatus    (    pUSB_EHCD_DATA pHCDData,           /* Ptr to HCD block           */    pUSBHST_URB	   pURB                /* Ptr to User Request Block  */    )    {    /* To hold the request status */    USBHST_STATUS Status = USBHST_SUCCESS;    /* Pointer to the setup packet */    pUSBHST_SETUP_PACKET pSetup = NULL;    /* To hold the status of the hub port */    UINT32 uPortStatus = 0;    /*     * This holds the port status which is available in the     * root hub port status buffer     */    UINT32 uPortStatusAvailable = 0;    UINT32	uBusIndex = 0; /* index of the host controller */    OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdRhGetPortStatus - Entry\n",0,0,0,0);    /* Check the validity of the parameters */    if (NULL == pHCDData ||        NULL == pURB ||        NULL == pURB->pTransferSpecificData ||        NULL == pURB->pTransferBuffer)        {        OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdRhGetPortStatus - \                                           Invalid parameters\n",0,0,0,0);        pURB->nStatus = USBHST_INVALID_PARAMETER;        return USBHST_INVALID_PARAMETER;        }    /* Extract the index of the host controller */    uBusIndex = pHCDData->uBusIndex;    /* Extract the setup packet */    pSetup = (pUSBHST_SETUP_PACKET)pURB->pTransferSpecificData;    /* Check whether the members are valid */    if (pSetup->wIndex >                pHCDData->RHData.uNumDownstreamPorts)        {        OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdRhGetPortStatus - \                                           Invalid port index\n",0,0,0,0);        pURB->nStatus = USBHST_INVALID_PARAMETER;        return USBHST_INVALID_PARAMETER;        }    /*     * The hub's port status contains 4 bytes of information, out of which     * the hub's port status is reported in the byte offsets 0 to 1     * and the hub's port status change in the byte offsets 2 to 3     */    /* Update the port status change bytes - Start */    /*     * Following is the interpretation of the 16 bits of port status change     * Bit 5-15 Reserved     * Bit 4 - Reset change     * Bit 3 - Overcurrent indicator Change     * Bit 2 - Suspend Change     * Bit 1 - Port Enable/Disable change     * Bit 0 - Connect status change     */    /* Update the overcurrent change bit */    uPortStatus |= USB_EHCD_GET_FIELD_PORT(pHCDData,                                       (pSetup->wIndex)- 1,                                       OVER_CURRENT_CHANGE);    uPortStatus <<= 1;    /*     * Update the suspend change bit     * (ie) 0 since there is no suspend-change indication in EHCI     */    uPortStatus |= 0;    uPortStatus <<= 1;    /* Store enable/disable change bit */    uPortStatus |= USB_EHCD_GET_FIELD_PORT(pHCDData,                                  (pSetup->wIndex)- 1,                                  PORT_ENABLE_CHANGE);    uPortStatus <<= 1;    /* Store connect status change */    uPortStatus |= USB_EHCD_GET_FIELD_PORT(pHCDData,                                  (pSetup->wIndex)- 1,                                  CONNECT_STATUS_CHANGE);    uPortStatus <<= 1;    /* Update the port status change bytes - End */    /* Update the port status bytes - Start */    /*     * Following is the interpretation of the 16 bits of port status     * Bit 13-15 Reserved     * Bit 12- Port indicator displays software controller colour     * Bit 11- Port is in Port Test Mode     * Bit 10- High speed device is attached     * Bit 9 - Low speed device is attached     * Bit 8 - Port is powered on     * Bit 5-7 Reserved     * Bit 4 - Reset signalling asserted     * Bit 3 - An overcurrent condition exists on the port     * Bit 2 - Port is suspended     * Bit 1 - Port is enabled     * Bit 0 - Device is present on the port     */    /* fill next 3 bits with 0 */    uPortStatus <<= 3;    /* Check whether the port indicator field is set and update the status */    if (0 != USB_EHCD_GET_FIELD_PORT(pHCDData,                                 (pSetup->wIndex)- 1,                                  PORT_INDICATOR_CONTROL))        {        uPortStatus |= 0x01;        }    uPortStatus <<= 1;    /* Check whether the port test mode field is set and update the status */    if (0 != USB_EHCD_GET_FIELD_PORT(pHCDData,                                (pSetup->wIndex)- 1,                                 PORT_TEST_CONTROL))        {        uPortStatus |= 0x01;        }    uPortStatus <<= 1;    /* Check whether a high speed device is attached and update the status */    uPortStatus |= USB_EHCD_GET_FIELD_PORT(pHCDData,                                  (pSetup->wIndex)- 1,                                  PORT_ENABLED_DISABLED);    uPortStatus <<= 1;    /* This cannot be updated as low/ full speed is not supported in Root hub */    if (USBHST_LOW_SPEED == USB_EHCD_GET_FIELD_PORT(pHCDData,                                                (pSetup->wIndex)- 1,                                                LINE_STATUS))        {        uPortStatus |= 0x01;        }    uPortStatus <<= 1;    /* Check whether the port is powered on and update the status */    uPortStatus |= USB_EHCD_GET_FIELD_PORT(pHCDData,                                  (pSetup->wIndex)- 1,                                  PORT_POWER);    uPortStatus <<= 1;    /* Bits 5 to 7 are reserved */    uPortStatus <<= 3;    /* Read the bit indicating whether a reset is asserted. Update the status */    uPortStatus |= USB_EHCD_GET_FIELD_PORT(pHCDData,                                  (pSetup->wIndex)- 1,                                  PORT_RESET);    uPortStatus <<= 1;    /*     * Check whether a over current is detected     * in the port and update the status     */    uPortStatus |= USB_EHCD_GET_FIELD_PORT(pHCDData,                                  (pSetup->wIndex)- 1,                                  OVER_CURRENT_ACTIVE);    uPortStatus <<= 1;    /* Check whether the port is suspended and update the status */    uPortStatus |= USB_EHCD_GET_FIELD_PORT(pHCDData,                                  (pSetup->wIndex)- 1,                                  SUSPEND);    uPortStatus <<= 1;    /* Check whether the port is enabled and update the status */    uPortStatus |= USB_EHCD_GET_FIELD_PORT(pHCDData,                                  (pSetup->wIndex)- 1,                                  PORT_ENABLED_DISABLED);    uPortStatus <<= 1;    /* Check whether a device is connected and update the status */    uPortStatus |= USB_EHCD_GET_FIELD_PORT(pHCDData,                                  (pSetup->wIndex)- 1,                                  CURRENT_CONNECT_STATUS);    /* Update the port status bytes - End */    /* Copy the data which is available in the port status */    OS_MEMCPY(&uPortStatusAvailable,              (pHCDData->RHData.pPortStatus + (pSetup->wIndex) - 1),              USB_EHCD_RH_PORT_STATUS_SIZE);    /* Swap the data to LE format */    uPortStatusAvailable = USB_EHCD_SWAP_DATA(uBusIndex,                                              uPortStatusAvailable);    /* Update the port status value */    uPortStatus |= uPortStatusAvailable;    /* Swap the data to CPU format */    uPortStatus = USB_EHCD_SWAP_DATA(uBusIndex,uPortStatus);    /* Copy the port status */    OS_MEMCPY(pURB->pTransferBuffer, &uPortStatus, 4);    /* Update the status of URB */    pURB->nStatus = USBHST_SUCCESS;    OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdRhGetPortStatus - Exit\n",0,0,0,0);    return Status;    }    /* End of usbEhcdRhGetPortStatus() *//***************************************************************************** usbEhcdRhSetPortFeature - set the features of the port** This routine sets the features of the port.** RETURNS: USBHST_SUCCESS if the URB is submitted successfully.*  USBHST_INVALID_PARAMETER if the parameters are not valid.** ERRNO:*   None.*/USBHST_STATUS usbEhcdRhSetPortFeature    (    pUSB_EHCD_DATA pHCDData,           /* Ptr to HCD block           */    pUSBHST_URB	   pURB                /* Ptr to User Request Block  */    )    {    /* To hold the request status */    USBHST_STATUS Status = USBHST_SUCCESS;    /* Pointer to the setup packet */    pUSBHST_SETUP_PACKET pSetup = NULL;    /* To hold the count value */    UINT32 uCount = 0;    UINT32	uBusIndex = 0; /* index of the host controller */	/* WindView Instrumentation */	USB_HCD_LOG_EVENT(		USB_EHCI_WV_PORT_ROUTE,		"usbEhcdRhSetPortFeature() starts",		USB_EHCD_WV_FILTER);    OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdRhSetPortFeature - Entry\n",0,0,0,0);    /* Check the validity of the parameters */    if (NULL == pHCDData ||        NULL == pURB ||        NULL == pURB->pTransferSpecificData)        {        OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdRhSetPortFeature - \                                           Invalid parameters\n",0,0,0,0);        pURB->nStatus = USBHST_INVALID_PARAMETER;        return USBHST_INVALID_PARAMETER;        }    /* Extract the index of the host controller */    uBusIndex = pHCDData->uBusIndex;    /* Extract the setup packet */    pSetup = (pUSBHST_SETUP_PACKET)pURB->pTransferSpecificData;    /* Switch on the feature to be selected */    switch(pSetup->wValue)        {        case USB_EHCD_RH_PORT_RESET:/* If port reset */            {            /* Attempt port reset only if HC is not halted */            if(0 == USB_EHCD_GET_FIELD(pHCDData,                                   USBSTS,                                   HCHALTED))                {                /*                 * If a low speed device is detected, change the                 * ownership of the port to the companion host controller                 */                if (USBHST_LOW_SPEED == USB_EHCD_GET_FIELD_PORT(pHCDData,                                                            (pSetup->wIndex)- 1,                                                            LINE_STATUS))                    {					/* WindView Instrumentation */					USB_HCD_LOG_EVENT(						USB_EHCI_WV_PORT_ROUTE, 						"SetPortFeature : Low speed device detected",						USB_EHCD_WV_FILTER);                    OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdRhSetPortFeature - \                                                Port being handed over\n",0,0,0,0);                    /*                     * Release ownership of the port                     * to the companion controller                     */                    USB_EHCD_SET_BIT_PORT(pHCDData,                                      ((pSetup->wIndex) -1),                                      PORT_OWNER);                    }                /* A high/Full speed device is attached */                else                    {                    /*                     * At this point, it is not known whether                     * the connected device is a full/ high speed device.                     * After giving a port reset, if the port is enabled,                     * then a high speed device is connected. If it is                     * not enabled, then a full speed device is                     * connected.                     */                    /*                     * Give a settling time for the mechanical                     * and electrical connections                     * Check whether there is any performance issue with this                     * wait.                     */                    OS_DELAY_MS(100);                    /* Disable the port */                    USB_EHCD_CLR_BIT_PORT(pHCDData,                                      ((pSetup->wIndex)- 1),                                      PORT_ENABLED_DISABLED);                    /* Initiate a reset to the port */                    USB_EHCD_SET_BIT_PORT(pHCDData,                                      ((pSetup->wIndex) -1),                                      PORT_RESET);                    /*                     * The reset signal should be driven atleast for 50ms                     * from the Root hub.                     * Additional 10ms is given here for software delays. 

⌨️ 快捷键说明

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