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

📄 usbhubutility.c

📁 风河的vxworks-6.3 FOR amcc440epx BSP!
💻 C
📖 第 1 页 / 共 5 页
字号:

       /* hub operating in bus powered mode */

       /* check whether the parent hub is a root hub or not */

       if ( pParentHub != NULL )
          {
          /* As per USB Specs -
           * "another bus powered hub cannot be connected to bus powered hub"
           *
           * check is the parent hub is bus-powered or self-powered.
           * This can be done by comparing the  parent_hub::uPowerPerPort with
           * values USB_HUB_PPORT_POWER_SELF_POWERED(250) or
           * USB_HUB_PPORT_POWER_BUS_POWERED (50)
           */

          if ( pParentHub->uPowerPerPort == USB_HUB_PPORT_POWER_BUS_POWERED )
             {
              /* Free the memory allocated */
             OS_FREE (pDeviceDescriptor);

             /* Free the memory allocated */
             OS_FREE (pConfigDescriptor);

             /* Free memory allocated for hub descriptor */
             OS_FREE (pHubDescriptor);

             /* Free memory allocated for hub status */
             OS_FREE (pStatusOfHub);

             /*
              * cannot configure the new hub cause the parent hub is bus powered
              * and the new hub is also bus powered.
              */

             return USBHST_FAILURE;
             }
         }
     }
    /* Parse the number of ports from the hub descriptor.*/
    uNumPorts=USB_HUB_DESC_bNbrPorts(pHubDescriptor);

    /*
     * Call OS_MALLOC() to allocate HUB_BYTE_GRANURALITY(number of ports + 1)
     * bytes of status change data buffer. If failed,
     * i.    Call OS_FREE() to free the configuration buffer.
     * ii.    Return USBHST_INSUFFICIENT_MEMORY.
     */
    uLength= USB_HUB_BYTE_GRANULARITY(uNumPorts + 1);

    /* allocate the memory */
    pStatusChangeData= OS_MALLOC(uLength);

    /* Check the result */
    if (NULL == pStatusChangeData)
    {
        /* Debug Message */
        OS_LOG_MESSAGE_HIGH(
            HUB,
            "usbHubConfigure:INSUFF MEMORY-pStatusChngData %d\n",uLength,0,0,0);
            
        /* Free the memory allocated */
        OS_FREE (pDeviceDescriptor);

       /* Free the memory allocated */
        OS_FREE (pConfigDescriptor);

        /* Free memory allocated for hub descriptor */
        OS_FREE (pHubDescriptor);

        /* Free memory allocated for hub status */
        OS_FREE (pStatusOfHub);

        return USBHST_INSUFFICIENT_MEMORY;

    } /* End of (USBHST_SUCCESS !=Result ) */

    /* allocate the memory */
    pStatusData= OS_MALLOC(uLength);

    /* Check the result */
     if (NULL == pStatusData)
    {
        /* Debug Message */
        OS_LOG_MESSAGE_HIGH(
            HUB,"usbHubConfigure:INSUFF MEMORY-pStatusData %d\n",uLength,0,0,0);

        /* Free the memory allocated */
        OS_FREE (pDeviceDescriptor);

        OS_FREE (pConfigDescriptor);

        /* Free the memory allocated */
        OS_FREE (pStatusChangeData);

        /* Free memory allocated for hub descriptor */
        OS_FREE (pHubDescriptor);

        /* Free memory allocated for hub status */
        OS_FREE (pStatusOfHub);

        return USBHST_INSUFFICIENT_MEMORY;

    } /* End of (USBHST_SUCCESS !=Result ) */

    /* Clear the allocated buffer for status change data. */
    OS_MEMSET(pStatusChangeData,0,uLength);

    /* Clear the allocated buffer for the status data. */
    OS_MEMSET(pStatusData,0,uLength);

    /*
     * Call OS_MALLOC() to allocate memory for HUB_INFO as
     * sizeof(USB_HUB_INFO)+ ((number of ports-1)*sizeof(PHUB_PORT_INFO)) bytes.
     * If Failed,
     * i.    Call OS_FREE() to free the configuration buffer.
     * ii.    Call OS_FREE() to free the status change buffer.
     * iii.    Return USBHST_INSUFFICIENT_MEMORY.
     */

    /*
     * This is an over allocation of the HUB_INFO structure.
     * this allows us to access pPortList[n] count for all the ports.
     * [<------------->y][y][y][y]...
     * [<------------->y] is the normal size of HUB_INFO with pPortList[1]
     * If there are two ports then it should be pPortList[2]. or:
     * [<------------->yy]
     * and so on.. we shud be still be able to access pPortList[uPortIndex].
     * hence we allocate
     * [<------------->y] bytes + (number of ports-1) * sizeof(y)
     * thus for 5 ports we get automatically get
     * [<------------->y]followed by[y][y][y][y] in one single memory chunk.
     */
    pNewHub=OS_MALLOC( sizeof(USB_HUB_INFO)+
                       ((uNumPorts-1)* sizeof(pUSB_HUB_PORT_INFO)));

    /* Check the result */
    if (NULL == pNewHub)
    {
        /* Free the memory allocated */
        OS_FREE (pDeviceDescriptor);

        /* Free the memory allocated */
        OS_FREE (pConfigDescriptor);

        /* Free the memory allocated */
        OS_FREE (pStatusChangeData);

        /* Free the memory allocated */
        OS_FREE (pStatusData);

        /* Free memory allocated for hub descriptor */
        OS_FREE (pHubDescriptor);

        /* Free memory allocated for hub status */
        OS_FREE (pStatusOfHub);

        /* Debug Message */
        OS_LOG_MESSAGE_HIGH(
            HUB,
            "usbHubConfigure:INSUFF MEMORY-pNewHub: %d\n",
            sizeof(USB_HUB_INFO)+((uNumPorts-1)* sizeof(pUSB_HUB_PORT_INFO)),
            0,
            0,
            0);

        return USBHST_INSUFFICIENT_MEMORY;

    } /* End of (USBHST_SUCCESS !=Result ) */

    /* Clear the allocated structure.*/
    OS_MEMSET(pNewHub,0,
        sizeof(USB_HUB_INFO)+((uNumPorts-1)* sizeof(pUSB_HUB_PORT_INFO)) );



    /*Here we find the TT Organization  */

    /* this switch checks the bDeviceProtocol field in device descriptor */
    switch(pParseDeviceDesc->bDeviceProtocol)
	{

    case 0 :
        /* this hub does not support TT */
        pNewHub->uHubTTInfo = 0;
        break;

    case 1 :
        /* this is a single TT Hub */
        if(pParseInterfaceDesc->bInterfaceProtocol == 0)
		{
            pNewHub->uHubTTInfo = 1;
		}/* end of if(pParseInterfaceDesc ....*/

        /* invalid parameters in descriptor */
        else
		{
            /* Debug Message */
            OS_LOG_MESSAGE_HIGH(
            HUB,"usbHubConfigure:InvalidInterfaceDesc fail \n",0,0,0,0);

            /* Free the memory allocated */
             OS_FREE (pDeviceDescriptor);

            /* Free the memory allocated */
             OS_FREE (pConfigDescriptor);

            /* Free the memory allocated */
            OS_FREE (pStatusChangeData);

            /* Free the memory allocated */
            OS_FREE (pStatusData);

            /* Free the memory allocated */
             OS_FREE (pNewHub);

            /* Free memory allocated for hub descriptor */
            OS_FREE (pHubDescriptor);

            /* Free memory allocated for hub status */
            OS_FREE (pStatusOfHub);

             return USBHST_INVALID_PARAMETER ;
		}/* end of else  */
        break;

     case 2 : 
        /* check if we have recieved default i/f and alternate i/f descriptor*/
        if(uDescriptorSequence == 0x24210)
		{ 
            /* this is a multiple TT hub */
            if(pParseAlternateInterfaceDesc->bInterfaceProtocol == 2)
			{
                pNewHub->uHubTTInfo = 2;

			}  /*  if != 2 then .....*/

		}/* end of if(uDescriptorSequence == 0x24210) */

        /* invalid descriptor */
        else
		{
             /* Debug Message */
             OS_LOG_MESSAGE_HIGH(
                 HUB,"usbHubConfigure:InvalidAltInterfaceDesc fail \n",0,0,0,0);

             /* Free the memory allocated */
             OS_FREE (pDeviceDescriptor);

             /* Free the memory allocated */
             OS_FREE (pConfigDescriptor);

             /* Free the memory allocated */
             OS_FREE (pStatusChangeData);

             /* Free the memory allocated */
             OS_FREE (pStatusData);

             /* Free the memory allocated */
             OS_FREE (pNewHub);

            /* Free memory allocated for hub descriptor */
            OS_FREE (pHubDescriptor);

            /* Free memory allocated for hub status */
            OS_FREE (pStatusOfHub);

             return USBHST_INVALID_PARAMETER ;
		} /* end of else */
        break ;

     default :
          /* Debug Message */
          OS_LOG_MESSAGE_HIGH(
            HUB,"usbHubConfigure:UnknownInterfaceDesc fail \n",0,0,0,0);

            /* Free the memory allocated */
            OS_FREE (pDeviceDescriptor);

            /* Free the memory allocated */
             OS_FREE (pConfigDescriptor);

            /* Free the memory allocated */
            OS_FREE (pStatusChangeData);

            /* Free the memory allocated */
            OS_FREE (pStatusData);

            /* Free the memory allocated */
            OS_FREE (pNewHub);

            /* Free memory allocated for hub descriptor */
            OS_FREE (pHubDescriptor);

            /* Free memory allocated for hub status */
            OS_FREE (pStatusOfHub);

             return USBHST_INVALID_PARAMETER;
	}/* end of switch(pParseDeviceDesc.......)*/

     /* check if Hub is a Multiple TT hub */
    if(pNewHub->uHubTTInfo == 2) 
	{
        Result = usbHstSetInterface (uDeviceHandle,
                            0, /* interface number */
                            1); /* alternate interface Setting*/
         
        /* Check the result */
        if ( USBHST_SUCCESS != Result)
		{
            /* Debug Message */
            OS_LOG_MESSAGE_HIGH(
                HUB,"usbHubConfigure:getStatusOfDevice fail R=0x%x \n",Result,0,0,0);

            /* Free the memory allocated */
            OS_FREE (pDeviceDescriptor);

            /* Free the memory allocated */
             OS_FREE (pConfigDescriptor);

            /* Free the memory allocated */
             OS_FREE (pStatusChangeData);

            /* Free the memory allocated */
             OS_FREE (pStatusData);

            /* Free the memory allocated */
            OS_FREE (pNewHub);

            /* Free memory allocated for hub descriptor */
            OS_FREE (pHubDescriptor);

            /* Free memory allocated for hub status */
            OS_FREE (pStatusOfHub);

            return Result;

		} /* End of (USBHST_SUCCESS !=Result ) */

	}/*end of if(pNewHub->uHubTTInfo ...*/



    /*
     * Populate the HUB_INFO structure, HUB_INFO::HubDescriptor structure by
     * taking the necessary values including parsing the hub descriptor and
     * the configuration descriptor.
     */

    /* the device handle */
    pNewHub->uDeviceHandle=uDeviceHandle;

    /*The pointer to the status change bit map */
    pNewHub->pStatus = pStatusData;

    /* store the parent bus */
    pNewHub->pBus=pBus;

    /*
     * how much power can this device provide to each port? 
     * if this is a self powered config, then we can support 500 mA.
     * if this is a bus powered, we can support a max of 100 mA.
     */
    pNewHub->uPowerPerPort =
            (((UINT8)(*pStatusOfHub&0xFF))&(0x01))? /* Self powered?*/
            USB_HUB_PPORT_POWER_SELF_POWERED:USB_HUB_PPORT_POWER_BUS_POWERED ;
                                          /* multiply by 2 to get mA */
    /* The interrupt endpoint for the Hub */
    pNewHub->uInterruptEndpointNumber = pParseEndpointDesc->bEndpointAddress;

    /*
     * check if the parent of the given hub is NULL or not
     * NULL parent implies root hub. set the tier as 1.
     */
    if (NULL==pParentHub)
    {
       /* root hub, the tier is 1 */
       pNewHub->uCurrentTier = 1;
    }
    else
    {
        /* The current Tier is 1 more than the parent hub */
        pNewHub->uCurrentTier = pParentHub->uCurrentTier + 1;
        
    }/* End of if (NULL == pParentHub) */

    /* Set the Hub state as default no state */
    pNewHub->StateOfHub = USB_HUB_NO_STATE;

    /* Init the Hub descriptor params */

    /* number of ports */
    pNewHub->HubDescriptor.bNbrPorts =
                                USB_HUB_DESC_bNbrPorts(pHubDescriptor);
    /* Hub characteristics */
    pNewHub->HubDescriptor.wHubCharacteristics =
                                USB_HUB_DESC_wHubCharacteristics(pHubDescriptor);

    /* Time for the power to stabilize on power on */
    pNewHub->HubDescriptor.bPwrOn2PwrGood =
                                USB_HUB_DESC_bPwrOn2PwrGood(pHubDescriptor);

    /* hub electronics power requirements */
    pNewHub->HubDescriptor.bHubContrCurrent =
                                USB_HUB_DESC_bHubContrCurrent(pHubDescriptor);

    /* Free the memory allocated for hub descriptor */
    OS_FREE(pHubDescriptor);

    /* Debug Message */
    OS_LOG_MESSAGE_MEDIUM(
        HUB,
        "usbHubConfigure:pNewHub->uDeviceHandle=%d\n",
        pNewHub->uDeviceHandle,
        0,
        0,
        0);

    /* Debug Message */
    OS_LOG_MESSAGE_MEDIUM(
        HUB,
        "usbHubConfigure:pNewHub->uPowerPerPort=%d\n",
        pNewHub->uPowerPerPort,
        0,
        0,
        0);

    /* Debug Message */
    OS_LOG_MESSAGE_MEDIUM(
        HUB,
        "usbHubConfigure:pNewHub->uInterruptEpNumber=%d\n",
        pNewHub->uInterruptEndpointNumber,
        0,
        0,
        0);

    /* Debug Message */
    OS_LOG_MESSAGE_MEDIUM(
        HUB,
        "usbHubConfigure:pNewHub->uCurrentTier=%d\n",
        pNewHub->uCurrentTier,
        0,
        0,
        0);

    /* Debug M

⌨️ 快捷键说明

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