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

📄 usbhubutility.c

📁 vxWorks下usb2.0的usbHUB驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:
            (UINT32)pHub,            uPortIndex,            0,            0);        return  USBHST_SUCCESS;    }/* End of if ( HUB_PORT_DEBOUNCE_TIME.... */    /*     * Call HUB_GET_PORT_STATUS() to get the HUB_PORT_STATUS structure.     * If this fails then return result.     */    Result = USB_HUB_GET_PORT_STATUS(pHub,                                 uPortIndex,                                 (PUINT8)(&PortStatus),                                 &uLength);    if (USBHST_SUCCESS !=Result)    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubPortDebounceHandler:getPortStatus FAIL:0x%x\n",            Result,            0,            0,            0);        return Result;    }/* End of if (USBHST_SUCCESS... */   /* swap the members of the structure */    PortStatus.wPortChange  = OS_UINT16_LE_TO_CPU(PortStatus.wPortChange);    PortStatus.wPortStatus  = OS_UINT16_LE_TO_CPU(PortStatus.wPortStatus);    /*     * If the HUB_PORT_STATUS:;wPortStatus is DISCONNECTED then     * i.    Set the HUB_PORT_INFO::StateOfPort as MARKED_FOR_DELETION     * ii.   Return USBHST_SUCCESS     */    if (0 ==( PortStatus.wPortStatus & USB_PORT_CONNECTION_VALUE) )    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubPortDebounceHandler:DisConnection:0x%x\n",            PortStatus.wPortStatus,            0,            0,            0);        /* Mark the port for deletion */        USB_MARK_FOR_DELETE_PORT(pHub,pPort);        return  USBHST_SUCCESS;    } /* End of if (0==... */    /*     * If the device is connected to a High speed bus,      * The max tiers allowed is as per 2.00 spec     * else     * The max tiers allowed is as per 1.1 spec     */    if (USBHST_HIGH_SPEED != pHub->pBus->uBusSpeed)    {        uMaxTier = HUB_MAX_ALLOWED_DEPTH_USB1_1 ;    }    else    {        uMaxTier = HUB_MAX_ALLOWED_DEPTH_USB2_0;    }    /*      * if pHub::uCurrentTier is HUB_MAX_ALLOWED_DEPTH then     * i.    Set the HUB_PORT_INFO::StateOfPort as MARKED_FOR_DELETION     * ii.   Return USBHST_SUCCESS     */    if (uMaxTier  == pHub->uCurrentTier)    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubPortDebounceHandler:Number of Tiers exceeded Max %d\n",            pHub->uCurrentTier,            0,            0,            0);        /* Mark the port for deletion */        USB_MARK_FOR_DELETE_PORT(pHub,pPort);        return  USBHST_SUCCESS;            }/* End of if (HUB_MAX_ALLO... */    /* Update the StateOfPort as HUB_RESET_PENDING.*/    pPort->StateOfPort=USB_HUB_RESET_PENDING;    /* Debug Message */    OS_LOG_MESSAGE_LOW(        HUB,"usbHubPortDebounceHandler:Done\n",0,0,0,0);    /* Return  USBHST_SUCCESS*/    return  USBHST_SUCCESS;} /* End of HUB_PortDebounceHandler() *//***************************************************************************** usbHubConfigure - Configures a given hub.*** This routine configures a given hub.** RETURNS: USBHST_SUCCESS, USBHST_FAILURE,* USBHST_INSUFFICIENT_MEMORY if the  memory allocation failed.** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbHubConfigure    (    pUSB_HUB_INFO    * pHub,    UINT32             uDeviceHandle,    pUSB_HUB_BUS_INFO  pBus,    pUSB_HUB_INFO      pParentHub     )    {    /* To store the return value */    USBHST_STATUS Result = USBHST_FAILURE;    /* Buffer to store incoming Device descriptor */    UINT8  *      pDeviceDescriptor= NULL;    /* Buffer to store incoming Configuration descriptor */    UINT8  *     pConfigDescriptor= NULL;        /* Pointer to parse Configuration descriptor */    UINT8  *     pParseDesc = NULL ;  	    /* Buffer to store incoming Hub descriptor */    UINT8         pHubDescriptor[6];    /* Buffer for the status change interrupt IN bit map data */    UINT8  *     pStatusChangeData = NULL;    /* Data Store for the status change interrupt IN bit map data */    UINT8  *     pStatusData = NULL;    /* Hub Structure for this hub */    pUSB_HUB_INFO pNewHub    = NULL;    /* Length of descriptor to be stored here */    UINT32         uLength   = 0;    /* Number of ports */    UINT8         uNumPorts  = 0;    /* Counter for the port number */    UINT8         uPortCount = 0;     /* Structure to parse the device descriptor */    pUSBHST_DEVICE_DESCRIPTOR pParseDeviceDesc = NULL;    /* Structure to parse the configuration descriptor */    pUSBHST_CONFIG_DESCRIPTOR pParseConfigDesc = NULL;    /* Structure to parse the interface descriptor */    pUSBHST_INTERFACE_DESCRIPTOR pParseInterfaceDesc = NULL;    /* Structure to parse the interface descriptor */    pUSBHST_INTERFACE_DESCRIPTOR pParseAlternateInterfaceDesc = NULL;    /* Structure to parse the endpoint descriptor */    pUSBHST_ENDPOINT_DESCRIPTOR pParseEndpointDesc = NULL;    /* Variable to store the sequence of descriptors */     UINT32 uDescriptorSequence = 0;    /* Count for number of descriptors which follow config desc */    UINT8  uCount = 0;     /* parsed length of desc to be updated here */     UINT16 uLengthParsed = 0;     /* length of desc to be stored here */     UINT16 uDescLength =0 ;	 /* status of hub */    UINT16 uStatusOfHub = 0;		/* WindView Instrumentation */		USB_HUB_LOG_EVENT(			USB_HUB_WV_DEVICE,			"Entering usbHubconfigure() Function",			USB_HUB_WV_FILTER);    /* Debug Message */    OS_LOG_MESSAGE_LOW(        HUB,        "usbHubconfigure:Called uDevHndl:0x%x pPHub=0x%x, pBus=0x%x\n",        uDeviceHandle,        (UINT32)pParentHub,        (UINT32)pBus,        0);    OS_ASSERT(NULL != pHub);                                        /* Verify */    OS_ASSERT(NULL != pBus);                                        /* Verify */    /*     * Call OS_MALLOC() to allocate Buffer of 18 bytes. If call failed,     * return USBHST_INSUFFICIENT_MEMORY.     */     pDeviceDescriptor = (UINT8 *) OS_MALLOC(18*sizeof(UINT8));     /* Check for call failure */    if (NULL == pDeviceDescriptor)    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,"usbHubConfigure:INSUFF MEMORY-pDeviceDescriptor 18\n",0,0,0,0);        return USBHST_INSUFFICIENT_MEMORY;            }/* End of if (NULL == pDeviceDescriptor ) */    /* Clear the allocated buffer.*/    OS_MEMSET(pDeviceDescriptor,0,sizeof(UINT8)*18);     uLength = 18;    /*    * Call USBHST_GetDescriptor() for uDeviceHandle,    * DEVICE_DESCRIPTOR and for 18 bytes. If call fails,    * i.    Call OS_FREE() to free the Buffer.    * ii.    Return result.    */    Result= usbHstGetDescriptor(    uDeviceHandle, /* Device Handle */                                     USBHST_DEVICE_DESC, /* Desc type */                                     0, /* descriptor index */                                     0, /* language ID */                                     &uLength, /* Size of the descriptor */                                     /* buffer to copy to */                                     (UINT8 *)pDeviceDescriptor );    if (( USBHST_SUCCESS != Result)||(18 != uLength ))    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubConfigure:GetDeviceDesc fail R=0x%x L=%d\n",            Result,            uLength,            0,            0);        /* Free the memory allocated */        OS_FREE (pDeviceDescriptor);        return Result;            }/* End of if ( USBHST_SUCCESS !=Result) */    /* Parse the Device Descriptor buffer */    pParseDeviceDesc = (pUSBHST_DEVICE_DESCRIPTOR) pDeviceDescriptor;        /* Validate the device descriptor */     Result = usbHubValidateDescriptor(pDeviceDescriptor,pParseDeviceDesc->bcdUSB                                    ,USBHST_DEVICE_DESC );    if(USBHST_SUCCESS != Result)	{        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubConfigure:ValidateDeviceDesc fail \n",            0,            0,            0,            0);        /* Free the memory allocated */         OS_FREE (pDeviceDescriptor);        return USBHST_INVALID_PARAMETER;	}    /*     * Call OS_MALLOC() to allocate Buffer of 8 bytes. If call failed,     * return USBHST_INSUFFICIENT_MEMORY.     */    pConfigDescriptor = (UINT8 * ) OS_MALLOC(8*sizeof(UINT8));    /* Set the desc length as 8 */    uLength=8;    /* Check for call failure */    if (NULL == pConfigDescriptor)    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,"usbHubConfigure:INSUFF MEMORY-pConfigdesc 8\n",0,0,0,0);        OS_FREE (pDeviceDescriptor);        return USBHST_INSUFFICIENT_MEMORY;            }/* End of if (NULL == pConfigDescriptor ) */    /* Clear the allocated buffer.*/    OS_MEMSET(pConfigDescriptor,0,sizeof(UINT8)*8);   /*    * Call USBHST_GetDescriptor() for uDeviceHandle,    * CONFIGURATION_DESCRIPTOR and for 8 bytes. If call fails,    * i.    Call OS_FREE() to free the Buffer.    * ii.    Return result.    */    Result= usbHstGetDescriptor(    uDeviceHandle, /* Device Handle */                                     USBHST_CONFIG_DESC, /* Desc type */                                     /* descriptor index */                                     USB_DEF_ACTIVE_HUB_CONFIG_INDEX,                                     0 , /* language ID */                                     &uLength, /* Size of the descriptor */                                     /* buffer to copy to */                                     (UINT8 *)pConfigDescriptor );    if (( USBHST_SUCCESS != Result)||(8 != uLength ))    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubConfigure:getconfdesc fail R=0x%x L=%d\n",            Result,            uLength,            0,            0);        /* Free the memory allocated */        OS_FREE (pDeviceDescriptor);        OS_FREE (pConfigDescriptor);        return Result;            }/* End of if ( USBHST_SUCCESS !=Result) */    /*     * Parse the configuration descriptor and find the complete length of the     * descriptor.     */    uLength=USB_HUB_CONFIG_wTotalLength(pConfigDescriptor);    /* Call OS_FREE to free the Buffer.*/    OS_FREE(pConfigDescriptor);   /*    * Call OS_MALLOC() to allocate configuration buffer for the complete length    * of the descriptor. If call failed, return USBHST_INSUFFICIENT_MEMORY.    */    pConfigDescriptor = (UINT8 *) OS_MALLOC(uLength*sizeof(UINT8));    /* Check for call failure */    if (NULL == pConfigDescriptor)    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubConfigure:INSUFF MEMORY-pConfigdesc %d\n",            uLength*sizeof(UINT8),            0,            0,            0);                        OS_FREE (pDeviceDescriptor);        return USBHST_INSUFFICIENT_MEMORY;    }/* End of if (NULL == pConfigDescriptor ) */    /* Clear the allocated buffer */    OS_MEMSET(pConfigDescriptor,0,sizeof(UINT8)*uLength);    /*      * Call HUB_GetDescriptor() for uDeviceHandle, CONFIGURATION_DESCRIPTOR and     * for complete length. If call fails,     * i.    Call OS_FREE() to free the configuration buffer.     * ii.    Return USBHST_FAILURE.     */    Result= usbHstGetDescriptor(    uDeviceHandle, /* Device Handle */                                     USBHST_CONFIG_DESC, /* Desc type */                                     /* descriptor index */                                     USB_DEF_ACTIVE_HUB_CONFIG_INDEX,                                     0 , /* language ID */                                     &uLength , /* Size of the descriptor */                                     /* buffer to copy to */                                     (UINT8 *)pConfigDescriptor );    /* check  the  result and lenth of descriptor*/    if (( USBHST_SUCCESS != Result)||        (uLength != USB_HUB_CONFIG_wTotalLength(pConfigDescriptor)) )    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubConfigure:getconfdesc fail R=0x%x L=%d\n",            Result,            uLength,            0,            0);/* End of if (( USBHST_SUCCESS != Result.......*/                    /* Free the memory allocated */        OS_FREE (pDeviceDescriptor);        /* Free the memory allocated */        OS_FREE (pConfigDescriptor);        return Result;    }/* End of if ( USBHST_SUCCESS !=Result) */     /* pointer for parsing the desc */     pParseDesc = pConfigDescriptor;     /*     * In this loop we parse the config desc and also keep track of the sequence     * in which the desriptors arrive     * 1) If Default Interface Descriptor then update uDescriptorSequence as     *    value one left shifted by (Four * ucount)     * 2) If Alternate Interface Descriptor then update uDescriptorSequence as     *    value Four left shifted by (Four * ucount)     * 3) If End Point Descriptor then update uDescriptorSequence as     *    value two left shifted by (Four * ucount)     */     while(uCount < 3)	 {        /* this switch  selects the descriptor type  */        switch (pParseDesc[1])		{         /* this is a interface descriptor */         case USBHST_INTERFACE_DESC :           /*validate the endpoint descriptor */           Result = usbHubValidateDescriptor                        (                        pParseDesc,                        pParseDeviceDesc->bcdUSB,                        USBHST_INTERFACE_DESC                        );      	   if(USBHST_SUCCESS != Result)	  	        {                /* Debug Message */                OS_LOG_MESSAGE_HIGH(                  HUB,"usbHubConfigure:ValidateInterfaceDescriptor fail \n",0,0,0,0);

⌨️ 快捷键说明

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