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

📄 usbhubutility.c

📁 vxWorks下usb2.0的usbHUB驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:
            /* Free the memory allocated */            OS_FREE (pStatusData);            /* Free the memory allocated */            OS_FREE (pNewHub);             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);            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)(uStatusOfHub&0xFF))&(0x01))? /* Self powered?*/             250:50 ;                              /* 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);    /* 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 Message */    OS_LOG_MESSAGE_MEDIUM(        HUB,        "usbHubConfigure:pNewHub->StateOfHub=%d\n",        pNewHub->StateOfHub,        0,        0,        0);    /* Debug Message */    OS_LOG_MESSAGE_MEDIUM(        HUB,        "usbHubConfigure:pNewHub->bNbrPorts=%d\n",        pNewHub->HubDescriptor.bNbrPorts,        0,        0,        0);    /* Debug Message */    OS_LOG_MESSAGE_MEDIUM(        HUB,        "usbHubConfigure:pNewHub->wHubCharac=0x%x\n",        pNewHub->HubDescriptor.wHubCharacteristics,        0,        0,        0);    /* Debug Message */    OS_LOG_MESSAGE_MEDIUM(        HUB,        "usbHubConfigure:pNewHub->bPwrOn2PwrGood=0x%x\n",        pNewHub->HubDescriptor.bPwrOn2PwrGood,        0,        0,        0);    /* Debug Message */    OS_LOG_MESSAGE_MEDIUM(        HUB,        "usbHubConfigure:pNewHub->bHubContrCurrent=0x%x\n",        pNewHub->HubDescriptor.bHubContrCurrent,        0,        0,        0);    /* POWER ON PORTS (BEGIN) */    /* for all ports that are enabled,     * i. Call HUB_PowerOnPort() with pHub and port count to re enable the     *    port. If the call fails, then free memory and return failure result.     */    for (uPortCount = 0;         uPortCount < pNewHub->HubDescriptor.bNbrPorts;         uPortCount++)    {        /* power on the port */        Result = usbHubPowerOnPort(pNewHub,uPortCount);        if (USBHST_SUCCESS !=Result)        {            /* Debug Message */            OS_LOG_MESSAGE_HIGH(                HUB,                "usbHubEventHandler:power on port %d failed\n",                uPortCount,                0,                0,                0);            /* Call OS_FREE() to free the configuration buffer.*/            OS_FREE (pDeviceDescriptor);            OS_FREE(pConfigDescriptor);            /* Free the memory allocated */            OS_FREE (pStatusChangeData);            /* Free the memory allocated */            OS_FREE (pStatusData);            /* Free the memory allocated */            OS_FREE(pNewHub);            /* Reset the return value */            *pHub=NULL;            /* return failure result */            return Result;        }/* End of if (USBHST_SUCCESS !=Result) */    } /* End of for (uPortCount.... */    /* POWER ON PORTS (END) */    /*     * Call the USBHST_FILL_INT_URB() to populate the     * HUB_INFO::StatusChangeURB.     * Set the HUB_INFO::StatusChangeURB::pfCallBack as     * HUB_InterruptRequestCallback function.     */     USBHST_FILL_INTERRUPT_URB(                          (&(pNewHub->StatusChangeURB)),/* pointer to URB     */                          uDeviceHandle,                /* Device Handle      */                          pNewHub->uInterruptEndpointNumber,        /* EP no: */                          pStatusChangeData,            /* transfer buffer    */                          uLength,                      /* uTransferBufferLen */                          USBHST_SHORT_TRANSFER_OK,     /* TransferFlags      */                          usbHubInterruptRequestCallback, /* pfCallback         */                          pNewHub,                      /* pContext           */                          USBHST_FAILURE                /* uStatus            */                          );    /* Call OS_FREE() to free the  buffer.*/    OS_FREE (pDeviceDescriptor);    OS_FREE(pConfigDescriptor);    /* Set pHub as HUB_INFO structure.*/    *pHub=pNewHub;    /*     * Set the URB Submitted flag as true - This is being done here coz the     * callback can be called when the SubmitURB is called.     */    pNewHub->bURBSubmitted = TRUE;    /*     * Call USBHSTSubmitURB() to submit the URB. If this fails     * i.    Call OS_FREE() to free the status change buffer.     * ii.   Return USBHST_INSUFFICIENT_MEMORY.     */    Result = usbHstURBSubmit(&(pNewHub->StatusChangeURB));    /* Check the result */    if ( USBHST_SUCCESS != Result)    {        /* Debug Message */        OS_LOG_MESSAGE_MEDIUM(            HUB,            "usbHubConfigure:SubmitURB IN failed 0x%x\n",            Result,            0,            0,            0);        /* Free the memory allocated */        OS_FREE (pStatusChangeData);        /* Free the memory allocated */        OS_FREE (pStatusData);        /* Free the memory allocated */        OS_FREE(pNewHub);        /* Reset the return value */        *pHub=NULL;        return USBHST_FAILURE;    }/* End of if ( USBHST_SUCCESS != Result) */		/* WindView Instrumentation */		USB_HUB_LOG_EVENT(			USB_HUB_WV_DEVICE,			"Exiting usbHubconfigure() Function",			USB_HUB_WV_FILTER);    /* Debug Message */    OS_LOG_MESSAGE_LOW(        HUB,        "usbHubConfigure:Done uDevHndl:0x%x pPHub=0x%x,pBus0x%x\n",        uDeviceHandle,        (UINT32)pParentHub,        (UINT32)pBus,        0);    /* Return  USBHST_SUCCESS.*/    return USBHST_SUCCESS;    }/* End of HUB_ConfigureHub() *//***************************************************************************** usbHubHandleDeviceConnection - Handles the device connection.** This routine handles the device connection.** RETURNS: USBHST_SUCCESS, USBHST_INVALID_PARAMETERS If there are errors in* parameters passed.** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbHubHandleDeviceConnection     (    pUSB_HUB_INFO pHub,    UINT8 uPortIndex    )    {    /* Storage for the port information */    pUSB_HUB_PORT_INFO pPort=NULL;    /* Storage for the result of the requests */    USBHST_STATUS Result;		/* WindView Instrumentation */		USB_HUB_LOG_EVENT(			USB_HUB_WV_DEVICE,			"Entering usbHubHandleDeviceConnection() Function",			USB_HUB_WV_FILTER);    /* Debug Message */    OS_LOG_MESSAGE_LOW(        HUB,        "usbHubHandleDeviceConnection:Called pHub=0x%x,port=%d\n",        (UINT32)pHub,        uPortIndex,        0,        0);            /* If pHub is NULL return USBHST_INVALID_PARAMETER*/    if (NULL==pHub)    {        /* Debug Message */        OS_LOG_MESSAGE_MEDIUM(            HUB,"usbHubHandleDeviceConnection:pHub is NULL\n",0,0,0,0);                    return USBHST_INVALID_PARAMETER;            }/* End of if (NULL ==pHub) */    /*     * If the uPortIndex greater than pHub::HubDescriptor::bNbrPorts then     * return USBHST_INVALID_PARAMETER.     * Note: the actual port number is the port index + 1     */    if (uPortIndex >= pHub->HubDescriptor.bNbrPorts)    {        /* Debug Message */        OS_LOG_MESSAGE_MEDIUM(            HUB,            "usbHubHandleDeviceConnection:port=%d>%d\n",            uPortIndex,            pHub->HubDescriptor.bNbrPorts,            0,            0);        return USBHST_INVALID_PARAMETER;            }/* End of if (uPortIndex >= pHub->HubDescriptor.bNbrPorts) */    /*     * Retrieve the HUB_PORT_INFO structure from pHub::pPortList for     * the uPortIndex.     */    pPort=pHub->pPortList[uPortIndex];    OS_ASSERT(NULL != pPort);                                       /* verify */    /* If pHub::pBus is NULL then return USBHST_INVALID_PARAMETER.*/    if (NULL == pHub->pBus)    {        /* Debug Message */        OS_LOG_MESSAGE_MEDIUM(            HUB,            "usbHubHandleDeviceConnection:pBus is NULL\n",            0,            0,            0,            0);        return USBHST_INVALID_PARAMETER;            }/* End of if (NULL ==... */    /* Update the HUB_PORT_INFO::StateOfPort as HUB_RESET_PENDING.*/    pPort->StateOfPort=USB_HUB_RESET_PENDING;    /*     * If pHub:pBus::bDeviceBeingConfigured is TRUE, then return     *  USBHST_SUCCESS.     */    if (TRUE== pHub->pBus->bDeviceBeingConfigured)    {        /* Debug Message */        OS_LOG_MESSAGE_LOW(            HUB,            "usbHubHandleDeviceConnection:other dev being confd\n",            0,            0,            0,            0);        return USBHST_SUCCESS;            }/* End of if (TRUE... */    /* Update the HUB_PORT_INFO::StateOfPort as HUB_RESET_COMPLETION_PENDING.*/    pPort->StateOfPort=USB_HUB_RESET_COMPLETION_PENDING;    /*     * Call HUB_ResetPort() with pHub, uPortIndex. If the call fails,     * return the result.     */    Result=usbHubResetPort(pHub,uPortIndex);    if (USBHST_SUCCESS != Result)    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubHandleDeviceConnecti

⌨️ 快捷键说明

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