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

📄 usbd.c

📁 usb2 driver for vxwokrs
💻 C
📖 第 1 页 / 共 5 页
字号:
                    /* Call the addDevice function for driver */                    nReturnStatus =                    pDeviceDriverInfo->addDevice(                                                pUSBDeviceInfo->hDevice,                                                USBHST_DEFAULT_INTERFACE_VALUE,                                                pUSBDeviceInfo->uDeviceSpeed,                                                &(pUSBDeviceInfo->pDriverData));                    /* Check if calling the addDevice is passed */                    if ( USBHST_SUCCESS == nReturnStatus )                        {                        /* Increment functional device count in the bus */                        USBD_INCREMENT_FUNCTIONAL_DEVICE_COUNT(                                                              pUSBDeviceInfo->uBusIndex);                        /* Store the driver info in the device info*/                        pUSBDeviceInfo->pDriver = pDeviceDriverInfo;                        }/* End of if (USBHST_SUCCESS .....) */                    /* Continue the match with the next device in the list */                    pUSBDeviceInfo = pUSBDeviceInfo->pNextUSBDeviceInfo;                    continue;                    }/* End of else if (0 != pUSBDeviceInfo->uDeviceClass) */                /*                 * Check if the device class is zero. if it is zero, then                 * load the driver based on the interface information                 */                if ( 0 == pUSBDeviceInfo->uDeviceClass )                    {                    pInterfaceInfo = pUSBDeviceInfo->pInterfacesInfo;                    for ( uInterfaceCount = 0;                        uInterfaceCount < pUSBDeviceInfo->uInterfaceCount;                        uInterfaceCount++ )                        {                        /*                         * Check if the any of the interface in the device                         * matches the driver                         */                        if ( (pInterfaceInfo[uInterfaceCount].uInterfaceClass !=                              pDeviceDriverInfo->uVendorIDorClass) ||                             ((pDeviceDriverInfo->uProductIDorSubClass != USBD_NOTIFY_ALL) &&                             (pInterfaceInfo[uInterfaceCount].uInterfaceSubClass !=                              pDeviceDriverInfo->uProductIDorSubClass)) ||                             ((pDeviceDriverInfo->uBCDUSBorProtocol != USBD_NOTIFY_ALL) &&                             (pInterfaceInfo[uInterfaceCount].uInterfaceProtocol !=                              pDeviceDriverInfo->uBCDUSBorProtocol)) )                            {                            /* Continue the match with the next interface */                            continue;                            }                        /* Call the add device function to add the device */                        nReturnStatus =                        pDeviceDriverInfo->addDevice(                                                    pUSBDeviceInfo->hDevice,                                                    pInterfaceInfo[uInterfaceCount].uInterfaceNum,                                                    pUSBDeviceInfo->uDeviceSpeed,                                                    &pInterfaceInfo[uInterfaceCount].pDriverData);                        /* Check for the return status */                        if ( USBHST_SUCCESS == nReturnStatus )                            {                            /* Increment functional device count in the bus */                            USBD_INCREMENT_FUNCTIONAL_DEVICE_COUNT(                                                                  pUSBDeviceInfo->uBusIndex);                            /* Store the driver info in the interface info*/                            pInterfaceInfo[uInterfaceCount].pDriver =                            pDeviceDriverInfo;                            }/* End of if (return status check) */                        } /* End of for (loop for interface info) */                    } /* End of if (device class is zero) */                /* Continue the match with the next device in the list */                pUSBDeviceInfo = pUSBDeviceInfo->pNextUSBDeviceInfo;                }/* End of while (NULL != pUSBDeviceInfo) */            }/* End of for (Loop to check all the buses) */        }/* End of if (Driver is class specific) */    else        {        /* Else case if driver is vendor specific */        /*         * Check if the given driver info matches any of the device info.         * Check for all devices in all the buses.         */        for ( uIndex = 0; uIndex < USBD_MAX_BUS_NUM; uIndex++ )            {            /* Get the device list for the uIndex bus */            pUSBDeviceInfo = gUSBBusInfoList[uIndex].pUSBDeviceInfoList;            while ( NULL != pUSBDeviceInfo )                {                /*                 * If the device is not vendor specific, then check if any                 * of its interfaces are vendor specific                 */                if ( USBHST_VENDOR_SPECIFIC != pUSBDeviceInfo->uDeviceClass )                    {                    /* Obtain the interface information from the device info */                    pInterfaceInfo = pUSBDeviceInfo->pInterfacesInfo;                    for ( uInterfaceCount = 0;                        uInterfaceCount < pUSBDeviceInfo->uInterfaceCount;                        uInterfaceCount++ )                        {                        /* Checking if the interface class is vendor specific */                        if ( USBHST_VENDOR_SPECIFIC == pInterfaceInfo[uInterfaceCount].uInterfaceClass )                            {                            /* Check if the driver suits the current interface */                            if ( (pUSBDeviceInfo->uVendorID !=                                  pDeviceDriverInfo->uVendorIDorClass) ||                                 (pUSBDeviceInfo->uDeviceID !=                                  pDeviceDriverInfo->uProductIDorSubClass) ||                                 (pUSBDeviceInfo->uBCDDevice !=                                  pDeviceDriverInfo->uBCDUSBorProtocol) )                                {                                /* Continue the match with the next interface */                                continue;                                }/* End of if (match the driver) */                            /*                             * The driver matches the device.                             * Call the add device function to add the device                             */                            nReturnStatus =                            pDeviceDriverInfo->addDevice(                                                        pUSBDeviceInfo->hDevice,                                                        pInterfaceInfo[uInterfaceCount].uInterfaceNum,                                                        pUSBDeviceInfo->uDeviceSpeed,                                                        &pInterfaceInfo[uInterfaceCount].pDriverData);                            /* Check for the return status */                            if ( USBHST_SUCCESS == nReturnStatus )                                {                                /* Increment functional device count in the bus */                                USBD_INCREMENT_FUNCTIONAL_DEVICE_COUNT(                                                                      pUSBDeviceInfo->uBusIndex);                                /* Store the driver info in the interface info*/                                pInterfaceInfo[uInterfaceCount].pDriver =                                pDeviceDriverInfo;                                }/* End of if (Check for return status) */                            }/* End of if (Interface is vendor specific) */                        } /* End of for loop for interface info */                    /* Continue the match with the next device in the list */                    pUSBDeviceInfo = pUSBDeviceInfo->pNextUSBDeviceInfo;                    continue;                    }/* End of if (Device class is not vendor specific) */                /* Match the driver for vendor specific device */                if ( (pUSBDeviceInfo->uBCDDevice ==                      pDeviceDriverInfo->uBCDUSBorProtocol) &&                     (pUSBDeviceInfo->uVendorID ==                      pDeviceDriverInfo->uVendorIDorClass) &&                     (pUSBDeviceInfo->uDeviceID ==                      pDeviceDriverInfo->uProductIDorSubClass) )                    {                    /* Call the add device function to add a hub */                    nReturnStatus =                    pDeviceDriverInfo->addDevice(                                                pUSBDeviceInfo->hDevice,                                                0,                                                pUSBDeviceInfo->uDeviceSpeed,                                                &(pUSBDeviceInfo->pDriverData));                    /* Check whether the driver was loaded sucessfully */                    if ( USBHST_SUCCESS == nReturnStatus )                        {                        /* Increment functional device count in the bus */                        USBD_INCREMENT_FUNCTIONAL_DEVICE_COUNT(                                                              pUSBDeviceInfo->uBusIndex);                        /* Store the driver info in the interface info*/                        pUSBDeviceInfo->pDriver = pDeviceDriverInfo;                        }/* End of if (return status check) */                    } /* End of If (vendor Match found)  */                /* Continue to match with the next device in the list */                pUSBDeviceInfo = pUSBDeviceInfo->pNextUSBDeviceInfo;                } /* End of while (NULL != pUSBDeviceInfo) */            } /* End of for (Loop for all the bus) */        } /* End of else if (driver is vendor specific) */    OS_LOG_MESSAGE_LOW(USBD, "Exiting usbdFindDevices() Function.\n",0,0,0,0);    return USBHST_SUCCESS;    } /* End of function usbdFindDevices() *//***************************************************************************** usbdFindDriver - find USB driver** This routine scans the driver list for the driver.** RETURNS: USBHST_INVALID_PARAMETER, USBHST_SUCCESS Drivers for the* specified device is searched and loaded, if found, successfully** ERRNO: None*/LOCAL USBHST_STATUS usbdFindDriver    (    pUSBD_DEVICE_INFO pUSBDeviceInfo    /* Ptr to USB Device info */    )    {    /* To store the driver info */    pUSBHST_DEVICE_DRIVER   pDeviceDriverInfo = NULL;    /* To store interface info */    pUSBD_INTERFACE_INFO    pInterfaceInfo = NULL;    /* Loop count variables */    UINT8                   uInterfaceCount = 0;    /* To store the status */    USBHST_STATUS           nStatus = USBHST_FAILURE;    OS_LOG_MESSAGE_LOW(USBD, "Entering usbdFindDriver() Function.\n",0,0,0,0);    /* Check if the parameter pUSBDeviceInfo is valid */    if (NULL == pUSBDeviceInfo)        {        OS_LOG_MESSAGE_MEDIUM(            USBD,            "usbdFindDriver() Failed: Invalid parameter Device Info.\n",            0,            0,            0,            0);        return USBHST_INVALID_PARAMETER;        }    /*     * Check if the device has multiple configurations and is vendor     * specific. If so, return error     */    if ((1 < pUSBDeviceInfo->uNumConfigurations) &&        (USBHST_VENDOR_SPECIFIC == pUSBDeviceInfo->uDeviceClass))    {        OS_LOG_MESSAGE_HIGH(                            USBD,                            "usbdFindDriver() Failed: Vendor specific \                            device with multiple configurations not \                            supported.\n",                            0,                            0,                            0,                            0);        return USBHST_INVALID_PARAMETER;    }    /*     * Check if the given parameter info matches with any driver in the global     * driver list. If it matches then populate pDriver with the matched driver     * and return USBHST_SUCCESS     */    /* Check if the given device is vendor specific */    if (USBHST_VENDOR_SPECIFIC == pUSBDeviceInfo->uDeviceClass)        {        if ((0 == pUSBDeviceInfo->uVendorID) ||            (0 == pUSBDeviceInfo->uDeviceID))            {            OS_LOG_MESSAGE_MEDIUM(                USBD,                "usbdFindDriver() Failed: Invalid parameter Device Info.\n",                0,                0,                0,                0);            return USBHST_INVALID_PARAMETER;            }        /* Find the matching driver for the device */        nStatus = usbdMatchDriver(TRUE,                                   pUSBDeviceInfo->uVendorID,                                   pUSBDeviceInfo->uDeviceID,                                   pUSBDeviceInfo->uBCDDevice,                                   &pDeviceDriverInfo);        /* Check the status returned */        if (USBHST_FAILURE == nStatus)            {            OS_LOG_MESSAGE_HIGH(                USBD,                "usbdFindDriver() Failed: Matching Driver not found.\n",                0,                0,                0,                0);            return USBHST_FAILURE;            }        /* Check if pDeviceDriverInfo returned is  valid */        if (NULL == pDeviceDriverInfo)            {            OS_LOG_MESSAGE_HIGH(                USBD,                "usbdFindDriver() Failed: Matching Driver \                    returned null driver.\n",                0,                0,                0,                0);            return USBHST_FAILURE;            }        /* Load the driver for the device */        nStatus = pDeviceDriverInfo->addDevice(pUSBDeviceInfo->hDevice,                                               0,                                               pUSBDeviceInfo->uDeviceSpeed,                                               &(pUSBDeviceInfo->pDriverData));        /* Check whether the driver was loaded successfully */        if (USBHST_SUCCESS == nStatus)            {            /* Increment the functional device count in the bus */            USBD_INCREMENT_FUNCTIONAL_DEVICE_COUNT(pUSBDeviceInfo->uBusIndex);            /* Store the driver info in the device info*/            pUSBDeviceInfo->pDriver = pDeviceDriverInfo;            OS_LOG_MESSAGE_LOW(USBD,                               "Exiting usbdFindDriver() Function.\n",                               0,                               0,                               0,                               0);            return USBHST_SUCCESS;            }        else            {            OS_LOG_MESSAGE_HIGH(                USBD,                "USBD_FindDriver() Failed: Add Device failed.\n",                0,                0,                0,

⌨️ 快捷键说明

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