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

📄 usbhubutility.c

📁 vxWorks下usb2.0的usbHUB驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:
    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,"usbHubCreateBusStructure:memory insuff -  pBusList\n",0,0,0,0);        return NULL;    }/* End of if (NULL== pBusList) */    /* Clear the allocated structure.*/    OS_MEMSET(pBusList,0,sizeof(USB_HUB_BUS_INFO));    /* set HUB_BUS_INFO::uBusHandle as uBusHandle*/    pBusList->uBusHandle = uBusHandle;    /* set HUB_BUS_INFO::pNextBus as gpGlobalBus*/    pBusList->pNextBus = gpGlobalBus;    /*      * Call the OS_CREATE_THREAD() function to create a thread (the function as     * HUB_BusManager() will be spawned as a thread with HUB_BUS_INFO as the     * parameter) If the thread creation fails:     * i.    Call the OS_FREE() function to free the memory allocated to the     *       HUB_BUS_INFO structure.     * ii.    Return NULL     * Set the HUB_BUS_INFO::BusManagerThreadID as the thread id returned by     * the OS_CREATE_THREAD() function.     */    pBusList->BusManagerThreadID=OS_CREATE_THREAD((char*) pBusManagerName,     /*NAME*/                                                   USB_HUB_THREAD_PRIORITY, /*PRIO*/                                                   usbHubThread,/* ENTRY PNT*/                                                   pBusList           /* ARGS */                                                   );    /* Check for the success  of thread creation */    if (OS_THREAD_FAILURE == pBusList->BusManagerThreadID)    {        /* Free the memory allocated */        OS_FREE(pBusList);                /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubCreateBusStructure:thread create failed=0x%x\n",            pBusList->BusManagerThreadID,            0,            0,            0);        /*return failure */        return NULL;    }/* End of if (NULL==pBusList->BusMan... */   /* Set  gpGlobalBus  as HUB_BUS_INFO*/   gpGlobalBus = pBusList;   /* Debug Message */   OS_LOG_MESSAGE_LOW(       HUB,"usbHubCreateBusStructure:Created ok\n",0,0,0,0);   /* Return HUB_BUS_INFO structure.*/   return pBusList;   }/* End of HUB_CreateBusStructure() *//***************************************************************************** usbHubDeleteBusStructure - deletes the Bus Structure.** This routine deletes the Bus Structure and kills any threadassociated with it.** RETURNS: None** ERRNO: None* * \NOMANUAL*/LOCAL void usbHubDeleteBusStructure     (     UINT8 uBusHandle    )    {    /* Bus List pointer */    pUSB_HUB_BUS_INFO pBusList = gpGlobalBus;    /* Previous bus pointer -to be used for unlinking */    pUSB_HUB_BUS_INFO pPrevBusList = gpGlobalBus;    /* Debug Message */    OS_LOG_MESSAGE_LOW(        HUB,        "usbHubDeleteBusStructure:Called 0x%x\n",        uBusHandle,        0,        0,        0);    /*     * Browse the gpGlobalBus list and check if uBusHandle exists. If it does     * not exists, return.     */    while (NULL != pBusList)    {        /* Check for correct entry */        if (pBusList->uBusHandle == uBusHandle)        {            /* Jump out of the loop */            break;        } /* End of if (pBusList->....*/        /* Set the previous bus list pointer as the current one */        pPrevBusList=pBusList;        /* Go to the next bus list */        pBusList=pBusList->pNextBus;    } /* End of While (NULL != pBusList) */    /* Check if we found the bus */    if (NULL==pBusList)    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubDeleteBusStructure: bus handle 0x%x not found\n",            uBusHandle,            0,            0,            0);        /* nope.. we did nto find the bus, so we return */        return;    } /* End of if (NULL==pBusList) */    /* Unlink the HUB_BUS_INFO from the gpGlobalBus list.(BEGIN) */    /* Check if the previous bus list is the same as the global bus list */    if ( ( pPrevBusList == gpGlobalBus)&& (pPrevBusList==pBusList) )    {        /* This is the first bus */                /* Set the global pointer to this */        gpGlobalBus = pBusList->pNextBus;    }    else    {    	/* This is not the first bus */        /* Reset the pointer to point to the next bus */        pPrevBusList->pNextBus=pBusList->pNextBus;    } /* End of if (pPrevBusList ==.. */    /* Unlink the HUB_BUS_INFO from the gpGlobalBus list.(END) */    /*     * Call OS_DESTROY_THREAD() to kill the thread with thread ID as     * HUB_BUS_INFO:: BusManagerThreadID     */    OS_DESTROY_THREAD(pBusList->BusManagerThreadID);    /* Call OS_FREE() function to free the memory allocated for HUB_BUS_INFO*/    OS_FREE(pBusList);    /* Debug Message */    OS_LOG_MESSAGE_LOW(        HUB,        "usbHubDeleteBusStructure:Done 0x%x\n",        uBusHandle,        0,        0,        0);    /* Return*/    return;}/* End of Hub_DeleteBusStructure() *//***************************************************************************** usbHubRemoveDevice - calls the remove device of the Host stack.** This routine calls the remove device of the Host stack.This also frees the * memory as required.** RETURNS: USBHST_SUCCESS, USBHST_INVALID_PARAMETER if there are invalid params** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbHubRemoveDevice    (    pUSB_HUB_INFO pHub,     UINT8 uPortIndex    )    {    /* To Store the port information */    pUSB_HUB_PORT_INFO pPort = NULL;		/* WindView Instrumentation */		USB_HUB_LOG_EVENT(			USB_HUB_WV_DEVICE,			"Entering usbHubRemoveDevice() Function",			USB_HUB_WV_FILTER);    /* Debug Message */    OS_LOG_MESSAGE_LOW(        HUB,        "usbHubRemoveDevice : Entered pHub= 0x%x, uPortIndex =%d\n",        (UINT32)pHub,        uPortIndex,        0,        0);    /* Verify the Parameters */    if (NULL == pHub)    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,"usbHubRemoveDevice: pHub is NULL\n",0,0,0,0);        /* Return invalid parameter */        return USBHST_INVALID_PARAMETER;    } /* End of if (NULL == pHub) */    /* Verify the Parameters */    if (uPortIndex >= pHub->HubDescriptor.bNbrPorts)    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubRemoveDevice: portIndex = %d NbrPort =%d is Invalid\n",            uPortIndex,            pHub->HubDescriptor.bNbrPorts,            0,            0);        /* Return invalid parameter */        return USBHST_INVALID_PARAMETER;    } /* End of if (uPortIndex >= pHub->HubDescriptor.bNbrPorts) */    /* Copy the pPort value */    pPort= pHub->pPortList[uPortIndex];    /*     * If the port is enabled then Call the     * g_USBHSTFunctionList::USBHST_RemoveDevice() function with     * HUB_PORT_INFO::uDeviceHandle.     */    if (NULL != pPort)    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubRemoveDevice: port present - deleting %d\n",            uPortIndex,            0,            0,            0);        /*         * Check what state this device was in - if this was in being configured,         * then we need to reset the global bus's variable and then mark the         * port for delete         */        USB_MARK_FOR_DELETE_PORT(pHub,pPort);         /* Check if this port is a hub device or not */        if (NULL == pPort->pHub)        {            /* Debug Message */            OS_LOG_MESSAGE_LOW(                HUB,                "usbHubRemoveDevice: non Hub Device\n",                0,                0,                0,                0);            /* disable the port */            pHub->pPortList[uPortIndex]=NULL;            /* Call remove device */            if (0 != pPort->uDeviceHandle)                {                g_usbHstFunctionList.UsbdToHubFunctionList.removeDevice(pPort->uDeviceHandle);                }/* End of if (0 != pPort->uDeviceHandle) */            /* Free the memory */            OS_FREE(pPort);            pPort=NULL;        }        else        /* an Hub device */        {            /* Debug Message */            OS_LOG_MESSAGE_LOW(                HUB,"usbHubRemoveDevice: Hub Device\n",0,0,0,0);            /* Call remove device */        g_usbHstFunctionList.UsbdToHubFunctionList.removeDevice(pPort->uDeviceHandle);        } /* End of if (NULL == pPort->pHub) */    }/* End of if (NULL != pPort ) */		/* WindView Instrumentation */		USB_HUB_LOG_EVENT(			USB_HUB_WV_DEVICE,			"Exiting usbHubRemoveDevice() Function",			USB_HUB_WV_FILTER);    /* Debug Message */    OS_LOG_MESSAGE_LOW(        HUB,        "usbHubRemoveDevice : Done pHub= 0x%x, uPortIndex =%d\n",        (UINT32)pHub,        uPortIndex,        0,        0);    /* Return SUCCESS */    return USBHST_SUCCESS;    } /* End of HUB_RemoveDevice() *//***************************************************************************** usbHubPortDebounceHandler - used for handling de-bounce condition.** This routine handles the de-bounce condition.** RETURNS: USBHST_SUCCESS, USBHST_FAILURE,* USBHST_INVALID_PARAMETER if there are invalid params** ERRNO: None* * \NOMANUAL*/LOCAL USBHST_STATUS usbHubPortDebounceHandler     (    pUSB_HUB_INFO pHub,    UINT8 uPortIndex     )    {    /* Storage for the port informaiton */    pUSB_HUB_PORT_INFO pPort=NULL;    /* Current Frame storage */    UINT16 uCurrentFrame = 0;    /* To store the port status */    USB_HUB_PORT_STATUS PortStatus;    /* To Store the time difference */    UINT16 uTimeDiff = 0;    /* To store the length of the  status */    UINT8 uLength = sizeof(USB_HUB_PORT_STATUS) ;    /* To store the result of the requests */    USBHST_STATUS  Result;    /* To store the max tier possible  */    UINT8 uMaxTier =0;    /* Debug Message */    OS_LOG_MESSAGE_LOW(        HUB,        "usbHubPortDebounceHandler:Called pHub=0x%x port=%d\n",        (UINT32)pHub,        uPortIndex,        0,        0);    /* If the pHub is NULL then return USBHST_INVALID_PARAMETER */    if (NULL==pHub)    {        /* Debug Message */        OS_LOG_MESSAGE_MEDIUM(            HUB,            "usbHubPortDebounceHandler:pHub=0x%x NULL\n",            (UINT32)pHub,            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,            "usbHubPortDebounceHandler:pHub=0x%x port=%d> Max\n",            (UINT32)pHub,            uPortIndex,            pHub->HubDescriptor.bNbrPorts,            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 PORT_INFO::StateOfPort is not HUB_DEBOUNCE_PENDING then     * return USBHST_INVALID_PARAMETER.     */    if (USB_HUB_DEBOUNCE_PENDING != pPort->StateOfPort)    {        /* Debug Message */        OS_LOG_MESSAGE_MEDIUM(            HUB,"usbHubPortDebounceHandler:debounce not pending\n",0,0,0,0);        return USBHST_INVALID_PARAMETER;    }/* End of if (HUB_DEBOUNCE... */    /* Retrieve the current frame by calling the USBHST_GetCurrentFrame()*/    Result=usbHstGetFrameNumber (pHub->uDeviceHandle,&uCurrentFrame);    OS_ASSERT(USBHST_SUCCESS == Result);                            /* verify */    /*     * Call the HUB_TIME_DIFF() function with HUB_PORT_INFO::uConnectFrame and     * current time. If the return value is less than HUB_PORT_DEBOUNCE_TIME,     * return USBHST_SUCCESS.     */    /* Get the time diference */    uTimeDiff = USB_HUB_TIME_DIFF(uCurrentFrame,pPort->uConnectFrame);    /* Check for the time value */    if ( USB_HUB_PORT_DEBOUNCE_TIME > uTimeDiff )    {        /* Debug Message */        OS_LOG_MESSAGE_LOW(            HUB,            "usbHubPortDebounceHandler:pHub=0x%x port=%d WAITING\n",

⌨️ 快捷键说明

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