urb.c

来自「usb2 driver for vxwokrs」· C语言 代码 · 共 2,135 行 · 第 1/5 页

C
2,135
字号
        return USBHST_INVALID_PARAMETER;    }    /* Obtain the device info of the device handle */    usbdTranslateDeviceHandle(hDevice, &pDeviceInfo);    /* Check if the device info obtained is valid */    if (NULL == pDeviceInfo)    {        OS_LOG_MESSAGE_MEDIUM(            USBD,            "usbHstGetConfiguration() Failed:Invalid parameter.\n",            0,            0,            0,            0);        return USBHST_INVALID_PARAMETER;    }     /* Return the status returned from HCD submit call */    uSize = 1;    nReturnStatus =  usbdSubmitRequest(pDeviceInfo,                                        128,                                        USBHST_REQ_GET_CONFIGURATION,                                        0,                                        0,                                        &uSize,                                        pBuffer);    /* Return the status returned from submit request call */    return nReturnStatus;    } /* End of function usbHstGetConfiguration() *//**************************************************************************** usbHstGetInterface - get interface USB request** This function is used by the class driver layer to issue GetInterface* USB Standard Request** RETURNS: USBHST_SUCCESS, USBHST_INVALID_PARAMETERS,* USBHST_INSUFFICIENT_MEMORY, USBHST_TIMEOUT if request submitted* to Host controller Driver is timed out** ERRNO: None*/USBHST_STATUS usbHstGetInterface    (    UINT32    hDevice,             /* USB device handle          */    UINT16    uInterfaceNumber,    /* Interface number           */    UCHAR    *pBuffer              /* Ptr to fetched data buffer */    )    {     /* To store the device info */    pUSBD_DEVICE_INFO       pDeviceInfo = NULL;    /* To store the usb status returned on submission of request */    USBHST_STATUS           nReturnStatus = USBHST_FAILURE;    /* size of the data to be fetched */    UINT32                  uSize = 0;		/* WindView Instrumentation */		USB_USBD_LOG_EVENT(			USB_USBD_WV_REQUEST,			"Entering usbHstGetInterface() Function.",			USB_USBD_WV_FILTER);    OS_LOG_MESSAGE_LOW(USBD,                       "Entering USBHST_GetInterface() Function.\n",                       0,                       0,                       0,                       0);    /* Check if buffer are valid */    if (NULL == pBuffer)    {        OS_LOG_MESSAGE_MEDIUM(            USBD,            "USBHST_GetInterface() Failed:Invalid parameter.\n",            0,            0,            0,            0);        return USBHST_INVALID_PARAMETER;    }    /* Obtain the device info of the device handle */    usbdTranslateDeviceHandle(hDevice, &pDeviceInfo);    /* Check if the device info obtained is valid */    if (NULL == pDeviceInfo)    {        OS_LOG_MESSAGE_MEDIUM(            USBD,            "USBHST_GetInterface() Failed:Invalid parameter.\n",            0,            0,            0,            0);        return USBHST_INVALID_PARAMETER;    }    /* Check if the uInterfaceNumber is a valid intercace info index */    if (uInterfaceNumber >= pDeviceInfo->uInterfaceCount)    {        OS_LOG_MESSAGE_MEDIUM(            USBD,            "USBHST_GetInterface() Failed:Invalid parameter.\n",            0,            0,            0,            0);        return USBHST_INVALID_PARAMETER;    }    uSize = 1;    nReturnStatus =  usbdSubmitRequest(pDeviceInfo,                                        129,                                        USBHST_REQ_GET_INTERFACE,                                        0,                                        uInterfaceNumber,                                        &uSize,                                        pBuffer);    /* Return the status returned from submit request call */    return nReturnStatus;    } /* End of function usbHstGetInterface() *//**************************************************************************** usbdSetAddress - set address USB request** This function is called by the class driver layer to issue SetAddress * USB Standard Request** RETURNS: USBHST_SUCCESS, USBHST_INVALID_PARAMETERS,* USBHST_INSUFFICIENT_MEMORY, USBHST_TIMEOUT if request submitted* to Host controller Driver is timed out** ERRNO: None*/LOCAL USBHST_STATUS usbdSetAddress    (    pUSBD_DEVICE_INFO pDeviceInfo      /* Pointer to device info */    )    {     /* To store the usb status returned on submission of request */    USBHST_STATUS           nReturnStatus = USBHST_FAILURE;    /* size of the data to be fetched */    UINT32                  uSize = 0;		/* WindView Instrumentation */		USB_USBD_LOG_EVENT(			USB_USBD_WV_REQUEST,			"Entering usbdSetAddress() Function.",			USB_USBD_WV_FILTER);    OS_LOG_MESSAGE_LOW(USBD,                       "Entering USBD_SetAddress() Function.\n",                       0,                       0,                       0,                       0);    /* Check if the device info is valid */    if (NULL == pDeviceInfo)    {        OS_LOG_MESSAGE_MEDIUM(            USBD,            "USBD_SetAddress() Failed:Invalid parameter.\n",            0,            0,            0,            0);        return USBHST_INVALID_PARAMETER;    }    /* Check if the device address is valid */    if ((0 >= pDeviceInfo->uDeviceAddress) ||        (127 < pDeviceInfo->uDeviceAddress))    {        OS_LOG_MESSAGE_MEDIUM(            USBD,            "USBD_SetAddress() Failed:Invalid parameter.\n",            0,            0,            0,            0);        return USBHST_INVALID_PARAMETER;    }    uSize = 0;    nReturnStatus =  usbdSubmitRequest(pDeviceInfo,                                        0,                                        USBHST_REQ_SET_ADDRESS,                                        pDeviceInfo->uDeviceAddress,                                        0,                                        &uSize,                                        NULL);    /* Return the status returned from submit request call */    return nReturnStatus;    } /* End of function usbdSetAddress() *//**************************************************************************** usbHstSetConfiguration - set configuration USB request** This function is called from the class driver layer to issue the* SetConfiguration USB Standard Request** RETURNS: USBHST_SUCCESS, USBHST_INVALID_PARAMETERS,* USBHST_INSUFFICIENT_MEMORY, USBHST_TIMEOUT if request submitted* to Host controller Driver is timed out** ERRNO: None*/USBHST_STATUS usbHstSetConfiguration    (    UINT32    hDevice,   /* USB Device handle   */    UINT16    uIndex     /* Configuration index */    )    {    /* To store the device info */    pUSBD_DEVICE_INFO       pDeviceInfo = NULL;    /* To store bus info */    pUSBD_BUS_INFO           pUsbBusInfo = NULL;    /* To store HC driver info */    pUSBHST_HC_DRIVER        pHCDriverInfo = NULL;    /* To store the setup packet */    pUSBHST_SETUP_PACKET    pSetup = NULL;    /* To store the interface information */    pUSBD_INTERFACE_INFO    pTempInterfaceInfo = NULL;   /* To store the endpoint information */    pUSBD_ENDPOINT_INFO     pEndpointInfo = NULL;   /* To store the endpoint information */    pUSBD_ENDPOINT_INFO     pTempEndpointInfo = NULL;    /* To store the USB request block */    pUSBHST_URB             pUrb = NULL;    /* To store the Event created*/    OS_EVENT_ID             EventId = OS_INVALID_EVENT_ID;    /* To store the usb status returned on submission of request */    USBHST_STATUS           nReturnStatus = USBHST_FAILURE;    /* Count used for iterating over interface information */    UINT8                   uInterfaceCount = 0;    /* Count used for iterating over endpoint information */    UINT8                   uEndpointCount = 0;    /* To store the first 9 bytes of the configuration descriptor */    USBHST_CONFIG_DESCRIPTOR ConfigDesc;    /* To store the whole configuration descriptor */    PUCHAR                  pConfigBuffer = NULL;    /* To be used while getting descriptor */    UINT32                  uSize = 0;    /* To be used to store the 16-bit CRC value */    UINT16                  uNewConfigCRCValue = 0;		/* WindView Instrumentation */		USB_USBD_LOG_EVENT(			USB_USBD_WV_REQUEST,			"Entering usbHstSetConfiguration() Function.",			USB_USBD_WV_FILTER);    OS_LOG_MESSAGE_LOW(USBD,                       "Entering usbHstSetConfiguration() Function.\n",                       0,                       0,                       0,                       0);    /* Obtain the device info of the device handle */    usbdTranslateDeviceHandle(hDevice, &pDeviceInfo);    /* Check if the device info obtained is valid */    if (NULL == pDeviceInfo)    {        OS_LOG_MESSAGE_MEDIUM(            USBD,            "usbHstSetConfiguration() Failed:Invalid parameter.\n",            0,            0,            0,            0);        return USBHST_INVALID_PARAMETER;    }    /* Check if the uIndex is a valid configuration index */    if ((uIndex >= pDeviceInfo->uNumConfigurations) &&        (uIndex != USBHST_DEFAULT_CONFIGURATION_INDEX))    {        OS_LOG_MESSAGE_MEDIUM(            USBD,            "usbHstSetConfiguration() Failed:Invalid parameter.\n",            0,            0,            0,            0);        return USBHST_INVALID_PARAMETER;    }    /* Get the bus information for this request */    pUsbBusInfo   = &gUSBBusInfoList[pDeviceInfo->uBusIndex];    /* Get the HC driver information for this request */    pHCDriverInfo = &gHCDriverList[pUsbBusInfo->hcdIndex];    /* Check for pending requests on all endpoints */    if (NULL != pDeviceInfo->pInterfacesInfo)    {        /*         * Check if there are any requests pending on any of the pipe in         * the current configuration of the device         */        for (uInterfaceCount = 0;             uInterfaceCount < pDeviceInfo->uInterfaceCount;             uInterfaceCount++)        {            /* Get the interface info for the uIntefaceCount */            pTempInterfaceInfo = &pDeviceInfo->pInterfacesInfo[uInterfaceCount];            /* Get the endpoint info */            pEndpointInfo  = pTempInterfaceInfo->pEndpointInformation;            /* If the endpoint info is not NULL */            if (NULL != pEndpointInfo)            {                /* Check if any request is pending */                for (uEndpointCount = 0;                     uEndpointCount < pTempInterfaceInfo->uNumEndpoints;                     uEndpointCount++)                {                    /* Check if the pipe is not zero */                    if (0 != pEndpointInfo[uEndpointCount].hPipe)                    {                        /* Check if any request is pending */                        nReturnStatus =                            pHCDriverInfo->isRequestPending(                                pUsbBusInfo->uRelativeBusIndex,                                pEndpointInfo[uEndpointCount].hPipe);                        /* Check the status returned */                        if (USBHST_SUCCESS == nReturnStatus)                        {                            OS_LOG_MESSAGE_HIGH(                                USBD,                                "UusbHstSetConfiguration() Failed:Some \                                    requests are still pending.\n",                                0,                                0,                                0,                                0);                            return USBHST_FAILURE;                        } /* End of IF IsRequestPending*/                    } /* End of IF pipe is not zero */                } /* End of FOR loop for Endpoints */            } /* End if end point info is not NULL */        } /* End of FOR loop for Interface */    } /* END if the interface info is not NULL */    /* Allocate memory for USBHST_SETUP_PACKET */    pSetup = (pUSBHST_SETUP_PACKET)OS_MALLOC(sizeof(USBHST_SETUP_PACKET));    /* Check if memory is allocated for pSetup */    if (NULL == pSetup)    {        OS_LOG_MESSAGE_HIGH(            USBD,            "usbHstSetConfiguration() Failed: INSUFFICIENT_RESOURCE.\n",            0,            0,            0,            0);        return USBHST_INSUFFICIENT_RESOURCE;    }    /* Fill the setup packet memory area with zero */    OS_MEMSET(pSetup, 0, sizeof(USBHST_SETUP_PACKET));    /* Allocate memory for USB Request block */    pUrb = (pUSBHST_URB)OS_MALLOC(sizeof(USBHST_URB));    /* Check if memory is allocated for USB request block */    if (NULL == pUrb)    {

⌨️ 快捷键说明

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