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

📄 usbohcidebug.c

📁 风河的vxworks-6.3 FOR amcc440epx BSP!
💻 C
📖 第 1 页 / 共 3 页
字号:
LOCAL VOID usbOhciPowerOnPorts	(	UINT32   uHostControllerIndex	)	{    /* To hold the base address of the OHCI Controller */    UINT32  uBaseAddress = 0;    /* To hold the value read from the registers */    UINT32  uRegisterValue = 0;    /* To hold the loop index */    UINT32  uIndex = 0;    /* To hold the offset of the port status register */    UINT32  uPortStatusRegisterOffset = 0;    /* To hold the number of downstream ports */    UINT32  uNumberOfDownstreamPorts = 0;    /* To hold the pointer to the host controller information */    PUSB_OHCI_INFORMATION   pOhciControllerInfo = NULL;    /* Obtain the pointer to the host controller information */    pOhciControllerInfo = &usbOhciControllerInfo[uHostControllerIndex];    /* Obtain the base address */    uBaseAddress = pOhciControllerInfo->uBaseAddress;    /*      * NOTE: If the root hub supports ganged power on the down stream ports,      *       power on all the downstream ports. Else power on the specified      *       port.     */    /* Read the contents of the root hub descriptor A register */    uRegisterValue =         USB_OHCI_REG_READ(uHostControllerIndex,                          uBaseAddress +                           USB_OHCI_RH_DESCRIPTOR_A_REGISTER_OFFSET);    /*      * Check whether the root hub supports ganged power on the down     * stream ports.     */    if ((uRegisterValue & USB_OHCI_RH_DESCRIPTOR_A_REGISTER__PSM_MASK) == 0)    	{        /*          * NOTE: Write 1 to the Local Power Status Change (LPSC) bit          *       to set the port power state.         */        /*          * Root hub supports ganged power. Power on all the down          * stream ports          */        USB_OHCI_REG_WRITE(uHostControllerIndex, (uBaseAddress +                            USB_OHCI_RH_STATUS_REGISTER_OFFSET),                            USB_OHCI_RH_STATUS_LPSC);        /* Return from the function */        return;    	}    /* Obtain the number of ports supported by the host controller (BEGIN) */    /* Read the contents of the root hub description register */    uNumberOfDownstreamPorts = USB_OHCI_REG_READ(uHostControllerIndex, 		uBaseAddress + USB_OHCI_RH_DESCRIPTOR_A_REGISTER_OFFSET);    /* Mask the other fields of the root hub description register */    uNumberOfDownstreamPorts = uNumberOfDownstreamPorts & 0x000000FF;    /* Obtain the number of ports supported by the host controller (END) */    /* Power on all the downstream ports */    for (uIndex = 1; uIndex <= uNumberOfDownstreamPorts; uIndex++)    	{        /* Obtain the base address of the port status register */        uPortStatusRegisterOffset =             USB_OHCI_RH_PORT_STATUS_REGISTER_OFFSET(uIndex);        /* Read the contents of the port status register */        uRegisterValue =             USB_OHCI_REG_READ(uHostControllerIndex,                              uBaseAddress + uPortStatusRegisterOffset);        /* Set the port power */        USB_OHCI_REG_WRITE(uHostControllerIndex,                            uBaseAddress + uPortStatusRegisterOffset,                            uRegisterValue | 0x00000100);    	}    return;	} /* End of function usbOhciPowerOnPorts () *//**************************************************************************** usbOhciResetPort - function to reset the port of the OHCI host controller** This function is used to reset the port of the OHCI host controller.** Resets the OHCI host controller ports** RETURNS: FALSE, TRUE if the reset operation was successful. ** ERRNO:  N/A*   None** \NOMANUAL*/LOCAL BOOLEAN usbOhciResetPort    (    UINT32   uHostControllerIndex,    UINT8    uPortNumber    )    {    /* To hold the offset of the port status register */    UINT32  uPortStatusRegisterOffset = 0;    /* To hold the value read from the registers */    UINT32  uRegisterValue = 0;    /* To hold the pointer to the host controller information */    PUSB_OHCI_INFORMATION   pOHCIControllerInfo = NULL;    /* To hold the base address of the OHCI Controller */    UINT32  uBaseAddress = 0;    /* Check whether the OHCI host controller index is valid */    if (USB_OHCD_MAX_HOST_CONTROLLERS <= uHostControllerIndex)    {        return FALSE;    }    /* Obtain the pointer to the host controller information */    pOHCIControllerInfo = &usbOhciControllerInfo[uHostControllerIndex];    /* Obtain the base address */    uBaseAddress = pOHCIControllerInfo->uBaseAddress;    /* Obtain the base address of the port status register */    uPortStatusRegisterOffset = USB_OHCI_RH_PORT_STATUS_REGISTER_OFFSET(uPortNumber);    /* Read the contents of the port status register */    uRegisterValue = USB_OHCI_REG_READ(uHostControllerIndex,                                       uBaseAddress +                                        uPortStatusRegisterOffset);    /* Issue a port reset */    USB_OHCI_REG_WRITE(uHostControllerIndex,                       uBaseAddress + uPortStatusRegisterOffset,                       uRegisterValue | 0x00000010);    /*     * Wait for 100 milli seconds for the reset to complete.     *     * NOTE: As per the specification, the reset completion time is     *       10 ms to 20 ms. However, additional delay is provided to     *       handle some devices which take extra time.     */    OS_DELAY_MS(100);    /* Wait for reset completion */    do    {        /* Read the contents of the port status register */        uRegisterValue = USB_OHCI_REG_READ(uHostControllerIndex,                                           uBaseAddress +                                            uPortStatusRegisterOffset);    }    while (0x00100000 != (uRegisterValue & 0x00100000));    /* Clear the reset status change */    USB_OHCI_REG_WRITE(uHostControllerIndex,                        uBaseAddress + uPortStatusRegisterOffset,                       0x00100000);    /* Read the contents of the port status register */    uRegisterValue = USB_OHCI_REG_READ(uHostControllerIndex,                                       uBaseAddress +                                        uPortStatusRegisterOffset);    /* Check whether the device is enabled */    if (0x00000003 == (uRegisterValue & 0x00000003))    {        return TRUE;    }    /* Failed to reset the port */    return FALSE;} /* End of function usbOhciResetPort() *//***************************************************************************** usbOhciWaitForConnection - wait for a device connection on a port** This function is used to wait for a device connection on a port. This* function also issues a port reset and enables the port on which the device* is connected.** PARAMETERS: <uHostControllerIndex (IN)> - Specifies the host controller on* which the device should be connected.** <uPortNumber (IN)> - Specifies the port on which the device will be connected.** RETURNS: TRUE if the device was connected, otherwise FALSE.** ERRNO:*   None**\NOMANUAL*/LOCAL BOOLEAN usbOhciWaitForConnection	(	UINT32   uHostControllerIndex,	UINT8    uPortNumber	)	{    /* To hold the offset of the port status register */    UINT32  uPortStatusRegisterOffset = 0;    /* To hold the value read from the registers */    UINT32  uRegisterValue = 0;    /* To hold the pointer to the host controller information */    PUSB_OHCI_INFORMATION   pOhciControllerInfo = NULL;    /* To hold the base address of the OHCI Controller */    UINT32  uBaseAddress = 0;    /* Check whether the OHCI host controller index is valid */    if (uHostControllerIndex >= USB_OHCD_MAX_HOST_CONTROLLERS)    	{        return FALSE;    	}    /* Obtain the pointer to the host controller information */    pOhciControllerInfo = &usbOhciControllerInfo[uHostControllerIndex];    /* Obtain the base address */    uBaseAddress = pOhciControllerInfo->uBaseAddress;    /* Obtain the base address of the port status register */    uPortStatusRegisterOffset =		USB_OHCI_RH_PORT_STATUS_REGISTER_OFFSET(uPortNumber);    /* Wait for connect status change */    do    	{        /* Read the contents of the port status register */        uRegisterValue =			USB_OHCI_REG_READ(uHostControllerIndex,                                          uBaseAddress +                                           uPortStatusRegisterOffset);    	}	while ((uRegisterValue & 0x00010000) != 0x00010000);    /* Clear the connection status change */    USB_OHCI_REG_WRITE(uHostControllerIndex,                        uBaseAddress + uPortStatusRegisterOffset,                       0x00010000);    /* Read the contents of the port status register */    uRegisterValue =		USB_OHCI_REG_READ(uHostControllerIndex,                                  uBaseAddress + uPortStatusRegisterOffset);    /* Issue a port reset */    USB_OHCI_REG_WRITE(uHostControllerIndex,                        uBaseAddress + uPortStatusRegisterOffset,                       uRegisterValue | 0x00000010);    /* Wait for 100 milli seconds for the reset to complete */    OS_DELAY_MS(100);    /* Wait for reset completion */    do    	{        /* Read the contents of the port status register */        uRegisterValue =			USB_OHCI_REG_READ(uHostControllerIndex,                                          uBaseAddress +                                           uPortStatusRegisterOffset);    	}    while ((uRegisterValue & 0x00100000) != 0x00100000);    /* Clear the reset status change */    USB_OHCI_REG_WRITE(uHostControllerIndex,                        uBaseAddress + uPortStatusRegisterOffset,                       0x00100000);    /* Read the contents of the port status register */    uRegisterValue =		USB_OHCI_REG_READ(uHostControllerIndex,                                   uBaseAddress +                                   uPortStatusRegisterOffset);    /* Check whether the device is enabled */    if ((uRegisterValue & 0x00000003) == 0x00000003)    	{        return TRUE;    	}    return FALSE;	} /* End of function usbOhciWaitForConnection () *//**************************************************************************** usbOhciGetDeviceSpeed - obtain the speed of the device** Function to obtain the speed of the device connected to the root hub.** RETURNS: USBHST_LOW_SPEED,USBHST_FULL_SPEED if a full speed device is*          connected.** ERRNO:*   None** \NOMANUAL*/LOCAL UINT8 usbOhciGetDeviceSpeed    (    UINT32   uHostControllerIndex,    UINT8    uPortNumber    )    {    /* To hold the offset of the port status register */    UINT32  uPortStatusRegisterOffset = 0;    /* To hold the value read from the registers */    UINT32  uRegisterValue = 0;    /* To hold the pointer to the host controller information */    PUSB_OHCI_INFORMATION   pOHCIControllerInfo = NULL;    /* To hold the base address of the OHCI Controller */    UINT32  uBaseAddress = 0;    /* Check whether the OHCI host controller index is valid */    if (uHostControllerIndex >= USB_OHCI_NUMBER_OF_CONTROLLERS)        {        return USBHST_LOW_SPEED;        }    /* Obtain the pointer to the host controller information */    pOHCIControllerInfo = &usbOhciControllerInfo[uHostControllerIndex];    /* Obtain the base address */    uBaseAddress = pOHCIControllerInfo->uBaseAddress;    /* Obtain the base address of the port status register */    uPortStatusRegisterOffset = USB_OHCI_RH_PORT_STATUS_REGISTER_OFFSET(uPortNumber);    /* Read the contents of the port status register */    uRegisterValue = USB_OHCI_REG_READ(uHostControllerIndex,                                        uBaseAddress +                                        uPortStatusRegisterOffset);    /* Check whether the device connnected is a low speed device */    if (0x00000200 == (uRegisterValue & 0x00000200))        {        /* Device connected is a low speed device */        return USBHST_LOW_SPEED;        }    /* Device connected is a full speed device */    return USBHST_FULL_SPEED;    } /* End of function usbOhciGetDeviceSpeed () *//* End of File usbOhciDebug.c */

⌨️ 快捷键说明

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