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

📄 usbd.c

📁 usb2 driver for vxwokrs
💻 C
📖 第 1 页 / 共 5 页
字号:
        if ((pOldDriverList->pDriver->bFlagVendorSpecific ==             pDeviceDriverInfo->bFlagVendorSpecific) &&            (pOldDriverList->pDriver->uVendorIDorClass ==             pDeviceDriverInfo->uVendorIDorClass) &&            (pOldDriverList->pDriver->uProductIDorSubClass ==             pDeviceDriverInfo->uProductIDorSubClass) &&            (pOldDriverList->pDriver->uBCDUSBorProtocol ==             pDeviceDriverInfo->uBCDUSBorProtocol))            {            OS_LOG_MESSAGE_HIGH(                USBD,                "usbHstRegisterDriver() Failed: Driver is already registered.\n",                0,                0,                0,                0);            return USBHST_FAILURE;            }        /* Get the driver in the list */        pOldDriverList = pOldDriverList->pNextDriver;        }    /* Allocate memory to create a new driverlist */    pNewDriverList =        (pUSBD_DEVICE_DRIVER_LIST)OS_MALLOC(sizeof(USBD_DEVICE_DRIVER_LIST));    /* Check if memory is allocated for the new driverlist */    if (NULL == pNewDriverList)        {        OS_LOG_MESSAGE_HIGH(            USBD,            "usbHstRegisterDriver() Failed: \                Insufficient memory for new driver list.\n",            0,            0,            0,            0);        return USBHST_INSUFFICIENT_MEMORY;        }    /* Fill the new driver list memory area with zero */    OS_MEMSET(pNewDriverList, 0, sizeof(USBD_DEVICE_DRIVER_LIST));    /* Populate the new driver list */    pNewDriverList->pDriver = pDeviceDriverInfo;    /* Initialize the next driver to null */    pNewDriverList->pNextDriver = NULL;    /*     * If the driver is a hub class driver then update gpHubFunctionList     * with the Hub Class Driver function pointers provided in the pContext     * parameter.     */    if ((USBHST_HUB_CLASS == pDeviceDriverInfo->uVendorIDorClass) &&        (NULL == gpHubFunctionList))        {        /* Allocate memory to gpHubFunctionList */        gpHubFunctionList =            (pUSBHST_HUB_FUNCTION_LIST)OS_MALLOC(                sizeof(USBHST_HUB_FUNCTION_LIST));        /* Check if memory is allocated for the gpHubFunctionList */        if (NULL == gpHubFunctionList)            {            /* Free the memory allocated for new driver list */            OS_FREE(pNewDriverList);            OS_LOG_MESSAGE_HIGH(                USBD,                "usbHstRegisterDriver() Failed: Insufficient memory for\                    gpHubFunctionList.\n",                0,                0,                0,                0);            return USBHST_INSUFFICIENT_MEMORY;            }        /* Fill the gpHubFunctionList memory area with zero */        OS_MEMSET(gpHubFunctionList, 0, sizeof(USBHST_HUB_FUNCTION_LIST));        /* Initialize global hub function list with pContext hub functions */        /* Store the addRootHub function pointer */        gpHubFunctionList->addRootHub    =                        pHubFunctionList->addRootHub;        /* Store the RemoveRootHub function pointer */        gpHubFunctionList->removeRootHub =                        pHubFunctionList->removeRootHub;        /* Store the CheckForPower function pointer */        gpHubFunctionList->checkForPower =                        pHubFunctionList->checkForPower;        /* Store the ResetDevice function pointer */        gpHubFunctionList->resetDevice   =                        pHubFunctionList->resetDevice;        /* Store the SelectiveResume function pointer */        gpHubFunctionList->selectiveResumeDevice =                        pHubFunctionList->selectiveResumeDevice;        /* Store the Selective Suspend function pointer */        gpHubFunctionList->selectiveSuspendDevice =                        pHubFunctionList->selectiveSuspendDevice;        /* Store the Clear TT Request function pointer */        gpHubFunctionList->clearTT =                                pHubFunctionList->clearTT;        /* Store the Reset TT Request function pointer */        gpHubFunctionList->resetTT =                                pHubFunctionList->resetTT;        /* Store the usbd functions pointer into pContext to be used by hub */        ((pUSBHST_FUNCTION_LIST)(*pContext))->UsbdToHubFunctionList =                                                            gUsbdFunctionList;        }    /* Wait for the completion of the event */    OS_WAIT_FOR_EVENT(gDeviceDriverListLock, OS_WAIT_INFINITE);    /* Add the new driver list to the global driver list */    pNewDriverList->pNextDriver = gpDeviceDriverList;    /* Assign the new driver to global driver list */    gpDeviceDriverList         = pNewDriverList;    /* Release the event */    OS_RELEASE_EVENT(gDeviceDriverListLock);    /* Find matching devices for the new driver and load */    usbdFindDevices(pDeviceDriverInfo);    OS_LOG_MESSAGE_LOW(USBD,                       "Exiting usbHstRegisterDriver() Function.\n",                       0,                       0,                       0,                       0);    return USBHST_SUCCESS;    } /* End of function usbHstDriverRegister *//***************************************************************************** usbHstDriverDeregister - deregisters USB class driver  ** This routine deregisters the class driver with the USB Stack.** RETURNS: USBHST_INVALID_PARAMETER, USBHST_SUCCESS,* USBHST_FAILURE if Driver is not found or if it is a hub class driver* and there are some functional devices present** ERRNO: None*/USBHST_STATUS  usbHstDriverDeregister    (    pUSBHST_DEVICE_DRIVER pDeviceDriverInfo  /* Ptr to Device Driver info */    )    {    /* To store global driver list */    pUSBD_DEVICE_DRIVER_LIST    pDriverList = NULL;    /* To store the previous element in the driver list */    pUSBD_DEVICE_DRIVER_LIST    pPrevList = NULL;    /* Flag to check if matching driver is found */    BOOLEAN                     bFlagMatch = FALSE;    /* To store the device info */    pUSBD_DEVICE_INFO           pDeviceInfoList = NULL;    /* To store the interfaces info */    pUSBD_INTERFACE_INFO        pInterfaceInfo = NULL;    /* To store the specific interface info */    pUSBD_INTERFACE_INFO        pTempInterfaceInfo = NULL;    /* To store the endpoints info */    pUSBD_ENDPOINT_INFO         pEndpointInfo = NULL;    /* To store bus info */    pUSBD_BUS_INFO               pUsbBusInfo = NULL;    /* To store HC driver info */    pUSBHST_HC_DRIVER            pHCDriverInfo = NULL;    /* Loop count variable */    UINT16                      uIndex = 0;    /* Loop count variable */    UINT16                      uInterfaceCount = 0;    /* Loop count variable */    UINT16                      uEndpointCount = 0;			/* WindView Instrumentation */			USB_USBD_LOG_EVENT(				USB_USBD_WV_REGISTER,				"Entering usbHstDeregisterDriver() Function.",				USB_USBD_WV_FILTER);    OS_LOG_MESSAGE_LOW(USBD,                       "Entering usbHstDeregisterDriver() Function.\n",                       0,                       0,                       0,                       0);    /* Initialize pDriverList with the global driver list */    pDriverList  = gpDeviceDriverList;    /* Check if the device driver info passed is not null */    if (NULL == pDeviceDriverInfo)        {        OS_LOG_MESSAGE_MEDIUM(            USBD,            "usbHstDeregisterDriver() Failed: Invalid parameter Driver info\n",            0,            0,            0,            0);        return USBHST_INVALID_PARAMETER;        }    /* Check if the driver is there in the global driver list */    while (NULL != pDriverList)        {        /*         * Check if the bFlagVendorSpecific, VendorIDorClass,         * uProductIDorSubClass are same.         */        if ((pDriverList->pDriver->bFlagVendorSpecific ==             pDeviceDriverInfo->bFlagVendorSpecific) &&            (pDriverList->pDriver->uVendorIDorClass ==             pDeviceDriverInfo->uVendorIDorClass)&&            (pDriverList->pDriver->uProductIDorSubClass ==             pDeviceDriverInfo->uProductIDorSubClass)&&            (pDriverList->pDriver->uBCDUSBorProtocol ==             pDeviceDriverInfo->uBCDUSBorProtocol)           )            {            bFlagMatch = TRUE;            break;            }        /* If they don't match store the current driver in the previous driver*/        pPrevList = pDriverList;        /* Increment the driver to point to next driver */        pDriverList = pDriverList->pNextDriver;        }    /* If the driver is not found then return USBHST_FAILURE */    if (FALSE == bFlagMatch)        {        OS_LOG_MESSAGE_HIGH(            USBD,            "usbHstDeregisterDriver() Failed: Driver not found.\n",            0,            0,            0,            0);        return USBHST_FAILURE;        }    /* Check if it is hub class driver */    if ((FALSE == pDeviceDriverInfo->bFlagVendorSpecific) &&        (USBHST_HUB_CLASS == pDeviceDriverInfo->uVendorIDorClass))        {        /* Check if any functional device is present */        for (uIndex = 0; uIndex < USBD_MAX_HCD_NUM; uIndex++)            {            /*             * If any functional device present for the bus return             * USBHST_FAILURE             */            if (0 != gHCDriverList[uIndex].uNumberOfBus)                {                OS_LOG_MESSAGE_HIGH(                    USBD,                    "usbHstDeregisterDriver() Failed: Functional count\                        is not zero.\n",                    0,                    0,                    0,                    0);                return USBHST_FAILURE;                }            }        /*         * If gpHubFunctionList is not null then release the memory allocated         * for it.         */        if (NULL != gpHubFunctionList)            {            OS_FREE(gpHubFunctionList);            gpHubFunctionList = NULL;            }        /* Wait for the completion of the event */        OS_WAIT_FOR_EVENT(gDeviceDriverListLock, OS_WAIT_INFINITE);        /*         * If pPrevList is NULL then the first element in the driver list is the         * pDeviceDriverInfo which is to be deregistered. Hence store the next         * pointer of pDeviceDriverInfo into gpDeviceDriverList. Else if         * pPrevListis not NULL then store the next pointer of pDeviceDriverInfo         * into pPrevList next pointer.Unlinking the driver info from the         * driver list         */        if (NULL == pPrevList)            {            gpDeviceDriverList = pDriverList->pNextDriver;            }        else            {            pPrevList->pNextDriver = pDriverList->pNextDriver;            }        /* Release the event */        OS_RELEASE_EVENT(gDeviceDriverListLock);        /* Free the memory allocated for the deregistered driver */        OS_FREE(pDriverList);        OS_LOG_MESSAGE_LOW(USBD,                           "Exiting usbHstDeregisterDriver() Function.\n",                           0,                           0,                           0,                           0);        return USBHST_SUCCESS;        } /* End of if hub class driver */    /*     * Check for all the devices in all the bus that uses the pDeviceDriverInfo     * as its driver.     */    for (uIndex = 0; uIndex < USBD_MAX_BUS_NUM; uIndex++)        {        pDeviceInfoList = gUSBBusInfoList[uIndex].pUSBDeviceInfoList;        /* Check if the Device information is valid */        if (NULL == pDeviceInfoList)            continue;        /* Get the bus information */        pUsbBusInfo   = &gUSBBusInfoList[pDeviceInfoList->uBusIndex];        /* Check if the bus information is valid */        if (NULL == pUsbBusInf

⌨️ 快捷键说明

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