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

📄 usbcbiufidevlib.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 5 页
字号:
                /* If Unit attention condition, check the ASC and ASCQ */                  switch (status)                    {                    case USB_UFI_WRITE_PROTECT :                        USB_CBI_UFI_DEBUG ("usbCbiUfiReqSense: Media write "\                                           "protected\n", 0, 0, 0, 0, 0 ,0);                        break;                     case USB_UFI_MEDIA_CHANGE :                          USB_CBI_UFI_DEBUG ("usbCbiUfiReqSense: Media changed\n",                                           0, 0, 0, 0, 0 ,0);                        break;                    case USB_UFI_POWER_ON_RESET :                          USB_CBI_UFI_DEBUG ("usbCbiUfiReqSense: Power on reset"\                                           " Bus device reset\n",0, 0, 0, 0, 0 ,0);                        break;                    case USB_UFI_COMMAND_SUCCESS :                          USB_CBI_UFI_DEBUG ("usbCbiUfiReqSense: No sense"\                                           "Bus device reset\n",0, 0, 0, 0, 0 ,0);                        break;                    }                break;            case USB_UFI_DATA_PROTECT:                  USB_CBI_UFI_DEBUG ("usbCbiUfiReqSense: Write Protect\n",                                   0, 0, 0, 0, 0, 0);                break;            default :                break;            }        }    OSS_FREE (pReqSense);	return status;    }        /***************************************************************************** usbCbiUfiDevDestroy - releases USB_CBI_UFI_DEV structure and its links** Unlinks the indicated USB_CBI_UFI_DEV structure and de-allocates* resources associated with the device.** RETURNS: N/A** ERRNO: none**\NOMANUAL*/LOCAL VOID usbCbiUfiDevDestroy    (    pUSB_CBI_UFI_DEV  pCbiUfiDev     /* pointer to MSC/CBI/UFI device   */    )    {    if (pCbiUfiDev != NULL)        {        /* Unlink the structure. */        usbListUnlink (&pCbiUfiDev->cbiUfiDevLink);        /* Release pipes and wait for IRPs. */        if (pCbiUfiDev->outPipeHandle != NULL)            usbdPipeDestroy (usbdHandle, pCbiUfiDev->outPipeHandle);        if (pCbiUfiDev->inPipeHandle != NULL)            usbdPipeDestroy (usbdHandle, pCbiUfiDev->inPipeHandle);        /* wait for any IRP to complete */        OSS_SEM_TAKE (pCbiUfiDev->cbiUfiIrpSem, OSS_DONT_BLOCK);         OSS_SEM_GIVE (pCbiUfiDev->cbiUfiIrpSem);        if (pCbiUfiDev->cbiUfiIrpSem)            OSS_SEM_DESTROY(pCbiUfiDev->cbiUfiIrpSem);        /* Release structure. */        OSS_FREE (pCbiUfiDev);        }    }/***************************************************************************** usbCbiUfiDevFind - Searches for a USB_CBI_UFI_DEV for indicated node ID** This fucntion searches the pointer to USB_CBI_UFI_DEV structure for * specified <nodeId>** RETURNS: pointer to matching USB_CBI_UFI_DEV or NULL if not found** ERRNO: none**\NOMANUAL*/LOCAL pUSB_CBI_UFI_DEV usbCbiUfiDevFind    (    USBD_NODE_ID nodeId          /* node ID to be looked for */    )    {    pUSB_CBI_UFI_DEV pCbiUfiDev = usbListFirst (&cbiUfiDevList);    /* browse through the list */    while (pCbiUfiDev != NULL)        {        if (pCbiUfiDev->cbiUfiDevId == nodeId)            break;        pCbiUfiDev = usbListNext (&pCbiUfiDev->cbiUfiDevLink);        }    return (pCbiUfiDev);    }/***************************************************************************** findEndpoint - Searches for a BULK endpoint of the indicated direction** This function searches for the Bulk endpoint for specified direction** RETURNS: pointer to matching endpoint descriptor or NULL if not found** ERRNO: none**\NOMANUAL*/LOCAL pUSB_ENDPOINT_DESCR findEndpoint    (    pUINT8 pBfr,    UINT16 bfrLen,    UINT8  attribute,     UINT16 direction    )    {    pUSB_ENDPOINT_DESCR pEp;    while ((pEp = usbDescrParseSkip (&pBfr, &bfrLen, USB_DESCR_ENDPOINT))            != NULL)        {        if ((pEp->attributes & USB_ATTR_EPTYPE_MASK) == attribute &&            (pEp->endpointAddress & USB_ENDPOINT_DIR_MASK) == direction)            break;        }    return (pEp);    }/***************************************************************************** usbCbiUfiPhysDevCreate - create USB_CBI_UFI_DEV Structure for the device * * This function is invoked from the dynamic attach callback routine whenever * a USB_CBI_UFI_DEV device is attached.  It allocates memory for the structure,* sets device configuration, and creates pipe for bulk-in,bulk-out and interrupt* endpoints.  It also sets the device configuration so that it follows UFI* command set.* * RETURNS: pUSB_CBI_UFI_DEV on success, NULL if failed to create device** ERRNO: none**\NOMANUAL*/LOCAL pUSB_CBI_UFI_DEV usbCbiUfiPhysDevCreate    (    USBD_NODE_ID nodeId,         /* USBD Node Id ofthe device  */         UINT16       configuration,  /* Configuration value        */     UINT16       interface       /* Interface Number           */     )    {    UINT16   actLength;    UINT8 * pBfr;           /* store for descriptors      */     UINT8 * pScratchBfr;    /* pointer to the above store */     UINT     ifNo;      USB_CBI_UFI_DEV * pCbiUfiDev;    USB_CONFIG_DESCR * pCfgDescr;    USB_INTERFACE_DESCR * pIfDescr;    USB_ENDPOINT_DESCR * pOutEp;    USB_ENDPOINT_DESCR * pInEp;    USB_ENDPOINT_DESCR * pIntrEp;    /*     * A new device is being attached.	Check if we already      * have a structure for this device.     */    if ((pCbiUfiDev = usbCbiUfiDevFind (nodeId)) != NULL)        return (pCbiUfiDev);    /* Allocate memory for a new structure to represent this device */    if ((pBfr = OSS_MALLOC (USB_MAX_DESCR_LEN)) == NULL)        {        USB_CBI_UFI_ERR ("usbCbiUfiPhysDevCreate: Unable to allocate \				memory:pBfr\n", 0, 0, 0, 0, 0, 0);        goto errorExit;        }    if ((pCbiUfiDev = OSS_CALLOC (sizeof (*pCbiUfiDev))) == NULL)        {        USB_CBI_UFI_ERR ("usbCbiUfiPhysDevCreate: Unable to allocate \				memory:pCbiUfiDev\n", 0, 0, 0, 0, 0, 0);        goto errorExit;        }    pCbiUfiDev->cbiUfiDevId     = nodeId;     pCbiUfiDev->interface       = interface;    pCbiUfiDev->connected       = TRUE;    if (OSS_SEM_CREATE( 1, 1, &pCbiUfiDev->cbiUfiIrpSem) != OK)        {        USB_CBI_UFI_ERR ("usbCbiUfiPhysDevCreate: Unable to create irp semaphore "\                         "descriptor\n", 0, 0, 0, 0, 0, 0);        goto errorExit;        }    /* Check out the device configuration */    /* Configuration index is assumed to be one less than config'n value */    if (usbdDescriptorGet (usbdHandle, 			   pCbiUfiDev->cbiUfiDevId, 			   USB_RT_STANDARD | USB_RT_DEVICE, 			   USB_DESCR_CONFIGURATION, 			   0, 			   0, 			   USB_MAX_DESCR_LEN, 			   pBfr, 			   &actLength) 			!= OK)        {        USB_CBI_UFI_ERR ("usbCbiUfiPhysDevCreate: Unable to read configuration "\                         "descriptor\n", 0, 0, 0, 0, 0, 0);        goto errorExit;        }    if ((pCfgDescr = usbDescrParse (pBfr, 				    actLength, 				    USB_DESCR_CONFIGURATION)) 				  == NULL)        {        USB_CBI_UFI_ERR ("usbCbiUfiPhysDevCreate: Unable to find configuration "\                         "descriptor\n", 0, 0, 0, 0, 0, 0);        goto errorExit;        }    /* Store the configuration value */    pCbiUfiDev->configuration = pCfgDescr->configurationValue;       /* Look for the interface representing the USB_CBI_UFI Device. */    ifNo = 0;    /*     * usbDescrParseSkip() modifies the value of the pointer it recieves     * so we pass it a copy of our buffer pointer     */    pScratchBfr = pBfr;    while ((pIfDescr = usbDescrParseSkip (&pScratchBfr, 					  &actLength, 					  USB_DESCR_INTERFACE)) 					!= NULL)        {        if (ifNo == pCbiUfiDev->interface)            break;        ifNo++;        }    if (pIfDescr == NULL)        goto errorExit;    pCbiUfiDev->altSetting = pIfDescr->alternateSetting;    /*      * Retrieve the endpoint descriptor(s) following the identified interface     * descriptor.     */    if ((pOutEp = findEndpoint (pScratchBfr, 				actLength, 				USB_ATTR_BULK, 				USB_ENDPOINT_OUT)) 			    == NULL)        goto errorExit;    if ((pInEp = findEndpoint (pScratchBfr, 				       actLength, 				       USB_ATTR_BULK, 				       USB_ENDPOINT_IN)) 			   == NULL)        goto errorExit;    if ((pIntrEp = findEndpoint (pScratchBfr, 				 actLength, 				 USB_ATTR_INTERRUPT, 				 USB_ENDPOINT_IN)) 			      == NULL)        goto errorExit;     pCbiUfiDev->outEpAddress = pOutEp->endpointAddress;    pCbiUfiDev->inEpAddress  = pInEp->endpointAddress;    pCbiUfiDev->intrEpAddress  = pIntrEp->endpointAddress;    pCbiUfiDev->inEpAddressMaxPkt = pInEp->maxPacketSize;    pCbiUfiDev->outEpAddressMaxPkt = pOutEp->maxPacketSize;    /* Set the device configuration corresponding to USB_CBI_UFI_DEV */    if ((usbdConfigurationSet (usbdHandle, pCbiUfiDev->cbiUfiDevId,                                pCbiUfiDev->configuration,                                pCfgDescr->maxPower * USB_POWER_MA_PER_UNIT)) 			      != OK )        {        USB_CBI_UFI_ERR ("usbCbiUfiPhysDevCreate: Unable to set device "\                         "configuration \n", 0, 0, 0, 0, 0, 0);        goto errorExit;        }    else        {        USB_CBI_UFI_DEBUG ("usbCbiUfiPhysDevCreate: Configuration set to 0x%x \n",                           pCbiUfiDev->configuration, 0, 0, 0, 0, 0);        }       /* Select interface     *     * NOTE: Some devices may reject this command, and this does not represent    * a fatal error.  Therefore, we ignore the return status.    */    usbdInterfaceSet (usbdHandle, 		      pCbiUfiDev->cbiUfiDevId, 		      pCbiUfiDev->interface, 		      pCbiUfiDev->altSetting);    /* Create a Bulk-out pipe for the USB_CBI_UFI_DEV device */    if (usbdPipeCreate (usbdHandle, 			pCbiUfiDev->cbiUfiDevId, 			pOutEp->endpointAddress, 			pCbiUfiDev->configuration, 			pCbiUfiDev->interface, 			USB_XFRTYPE_BULK, 			USB_DIR_OUT, 			FROM_LITTLEW(pOutEp->maxPacketSize),			0, 			0, 			&(pCbiUfiDev->outPipeHandle)) 		!= OK)        {        USB_CBI_UFI_ERR ("usbCbiUfiPhysDevCreate: Error creating bulk out pipe\n",                         0, 0, 0, 0, 0, 0);        goto errorExit;        }     /* Create a Bulk-in pipe for the USB_CBI_UFI_DEV device */           if (usbdPipeCreate (usbdHandle, pCbiUfiDev->cbiUfiDevId,                         pInEp->endpointAddress, pCbiUfiDev->configuration,                         pCbiUfiDev->interface, USB_XFRTYPE_BULK, USB_DIR_IN,                         FROM_LITTLEW(pInEp->maxPacketSize), 0, 0,                         &(pCbiUfiDev->inPipeHandle)) != OK)        {        USB_CBI_UFI_ERR ("usbCbiUfiPhysDevCreate: Error creating bulk in pipe\n",                         0, 0, 0, 0, 0, 0);        goto errorExit;        }     /* Create a Interrupt pipe for the USB_CBI_UFI_DEV device */    if ((usbdPipeCreate (usbdHandle, pCbiUfiDev->cbiUfiDevId,                         pIntrEp->endpointAddress, 			pCbiUfiDev->configuration,                         pCbiUfiDev->interface, 			USB_XFRTYPE_INTERRUPT, 			USB_DIR_IN,                         2, 

⌨️ 快捷键说明

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