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

📄 usbcbiufidevlib.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 5 页
字号:
			2, 			0x10,                         &(pCbiUfiDev->intrPipeHandle))) 			!= OK)        {        USB_CBI_UFI_ERR ("usbCbiUfiPhysDevCreate: Error creating interrupt pipe %x\n",                         0, 0, 0, 0, 0, 0);        goto errorExit;        }     /* Clear HALT feauture on the endpoints */    if ((usbdFeatureClear (usbdHandle, 			   pCbiUfiDev->cbiUfiDevId, 			   USB_RT_ENDPOINT,                            USB_FSEL_DEV_ENDPOINT_HALT,                            (pOutEp->endpointAddress & 0xFF))) 			   != OK)        {        USB_CBI_UFI_ERR ("usbCbiUfiPhysDevCreate: Failed to clear HALT feauture "\                         "on bulk out Endpoint %x\n", 0, 0, 0, 0, 0, 0);        }      if ((usbdFeatureClear (usbdHandle, 			   pCbiUfiDev->cbiUfiDevId, 			   USB_RT_ENDPOINT,                            USB_FSEL_DEV_ENDPOINT_HALT,                            (pOutEp->endpointAddress & 0xFF))) 			   != OK)        {        USB_CBI_UFI_ERR ("usbCbiUfiPhysDevCreate: Failed to clear HALT feauture "\                         "on bulk in Endpoint %x\n", 0, 0, 0, 0, 0, 0);        }     /* Link the newly created structure. */    usbListLink (&cbiUfiDevList, pCbiUfiDev,                  &pCbiUfiDev->cbiUfiDevLink, LINK_TAIL);    OSS_FREE (pBfr);    return (pCbiUfiDev);errorExit:    /* Error in creating CBI UFI Device */    usbCbiUfiDevDestroy (pCbiUfiDev);    OSS_FREE (pBfr);    return (NULL);    }/***************************************************************************** usbCbiUfiBlkDevCreate - create a block device** This routine  initializes a BLK_DEV structure, which describes a * logical partition on a USB_CBI_UFI_DEV device.  A logical partition is * an array of contiguously addressed blocks; it can be completely described * by the number of blocks and the address of the first block in the partition.  ** RETURNS: A pointer to the BLK_DEV, or NULL if no CBI/UFI device exists.** ERRNO: none*/BLK_DEV * usbCbiUfiBlkDevCreate     (    USBD_NODE_ID nodeId        /* Node Id of the CBI_UFI device */     )    {    UINT8 * pInquiry;    /* store for INQUIRY data  */      UINT16 senseStatus = 0xffff;     pUSB_CBI_UFI_DEV pCbiUfiDev = usbCbiUfiDevFind (nodeId);    OSS_MUTEX_TAKE (cbiUfiDevMutex, OSS_BLOCK); 	if ((pInquiry = OSS_MALLOC (UFI_STD_INQUIRY_LEN)) == NULL)	{	  USB_CBI_UFI_ERR ("usbCbiUfiBlkDevCreate: Error allocating memory\n",                        0, 0, 0, 0, 0, 0);        OSS_MUTEX_RELEASE (cbiUfiDevMutex);        return NULL;	}    if (pCbiUfiDev == NULL)        {        USB_CBI_UFI_ERR ("usbCbiUfiBlkDevCreate: No MSC/CBI/UFI found\n",                         0, 0, 0, 0, 0, 0);		OSS_FREE (pInquiry);        OSS_MUTEX_RELEASE (cbiUfiDevMutex);        return (NULL);        }    /*      * Initialize the standard block device structure for use with file      * systems.     */    pCbiUfiDev->blkDev.bd_blkRd        = (FUNCPTR) usbCbiUfiDevBlkRd;    pCbiUfiDev->blkDev.bd_blkWrt       = (FUNCPTR) usbCbiUfiDevBlkWrt;    pCbiUfiDev->blkDev.bd_ioctl        = (FUNCPTR) usbCbiUfiDevIoctl;    pCbiUfiDev->blkDev.bd_reset        = (FUNCPTR) NULL;     pCbiUfiDev->blkDev.bd_statusChk    = (FUNCPTR) usbCbiUfiDevStChk;    pCbiUfiDev->blkDev.bd_retry        = 1;    pCbiUfiDev->blkDev.bd_mode         = O_RDWR;    pCbiUfiDev->blkDev.bd_readyChanged = TRUE;    pCbiUfiDev->blkDev.bd_nBlocks =  (UINT32) 0;    pCbiUfiDev->blkDev.bd_bytesPerBlk = (UINT32)  2;   /*      * Read out the standard INQUIRY information from the device, mainly to     * check whether the media is removable or not.     */    pCbiUfiDev->bulkInData  = pInquiry;    if ( usbCbiUfiFormCmd (pCbiUfiDev, USB_UFI_INQUIRY, 0, 0) != OK )        {        USB_CBI_UFI_ERR ("usbCbiUfiBlkDevCreate: Error forming command\n",                         0, 0, 0, 0, 0, 0);			OSS_FREE (pInquiry);		    OSS_MUTEX_RELEASE (cbiUfiDevMutex);	        return (NULL);         }     if ( usbCbiUfiCmdExecute (pCbiUfiDev) != USB_COMMAND_SUCCESS)        {        USB_CBI_UFI_ERR ("usbCbiUfiBlkDevCreate: Error executing "\                         "USB_UFI_INQUIRY command\n", 0, 0, 0, 0, 0, 0);        			OSS_FREE (pInquiry);    	    OSS_MUTEX_RELEASE (cbiUfiDevMutex);	    senseStatus = usbCbiUfiReqSense (pCbiUfiDev);            return (NULL);          }    /* Check the media type bit  */    if (*(pInquiry + 1) & USB_UFI_INQUIRY_RMB_BIT)        {        pCbiUfiDev->blkDev.bd_removable = TRUE;        }    else        {        pCbiUfiDev->blkDev.bd_removable = FALSE;              }    if (usbCbiUfiDevStChk(&pCbiUfiDev->blkDev) == ERROR)         {         OSS_FREE (pInquiry);         OSS_MUTEX_RELEASE (cbiUfiDevMutex);         pCbiUfiDev->connected = FALSE;         return NULL;         }         OSS_FREE (pInquiry);    OSS_MUTEX_RELEASE (cbiUfiDevMutex);    return (&pCbiUfiDev->blkDev);   	}        /***************************************************************************** usbCbiUfiDevBlkRd - routine to read one or more blocks from the device.** This routine reads the specified physical sector(s) from a specified* physical device.  Typically called by file system when data is to be* read from a particular device.** RETURNS: OK on success, or ERROR if failed to read from device** ERRNO: None**\NOMANUAL*/LOCAL STATUS usbCbiUfiDevBlkRd    (    BLK_DEV * pBlkDev,           /* pointer to UFI  device   */     UINT32       blkNum,            /* logical block number     */    UINT32       numBlks,           /* number of blocks to read */    char *    pBuf               /* store for data           */     )    {    USB_COMMAND_STATUS s;    pUSB_CBI_UFI_DEV  pCbiUfiDev = (USB_CBI_UFI_DEV *)pBlkDev;       USB_CBI_UFI_DEBUG ("usbCbiUfiDevBlkRd: Reading from block number: %x\n",                       blkNum, 0, 0, 0, 0, 0);     OSS_MUTEX_TAKE (cbiUfiDevMutex, OSS_BLOCK);     /* initialise the pointer to fetch bulk out data */    pCbiUfiDev->bulkInData = (UINT8 *)pBuf;    if ( usbCbiUfiFormCmd (pCbiUfiDev, USB_UFI_READ10,                            blkNum, numBlks) != OK )        {        OSS_MUTEX_RELEASE (cbiUfiDevMutex);        return (ERROR);          }      s = usbCbiUfiCmdExecute (pCbiUfiDev);       if ( s != USB_COMMAND_SUCCESS )        {        if ( s == USB_COMMAND_FAILED)            usbCbiUfiDevReset (pBlkDev);                usbCbiUfiReqSense (pCbiUfiDev);        OSS_MUTEX_RELEASE (cbiUfiDevMutex);        return (ERROR);         }    OSS_MUTEX_RELEASE (cbiUfiDevMutex);     return (OK);    }/***************************************************************************** usbCbiUfiDevBlkWrt - routine to write one or more blocks to the device.** This routine writes the specified physical sector(s) to a specified physical* device.** RETURNS: OK on success, or ERROR if failed to write to device** ERRNO: None**\NOMANUAL*/LOCAL STATUS usbCbiUfiDevBlkWrt    (    BLK_DEV * pBlkDev,           /* pointer to UFI device     */      UINT32       blkNum,            /* logical block number      */    UINT32       numBlks,           /* number of blocks to write */     char *    pBuf               /* data to be written        */     )    {    USB_COMMAND_STATUS s;    pUSB_CBI_UFI_DEV  pCbiUfiDev = (USB_CBI_UFI_DEV *)pBlkDev;       USB_CBI_UFI_DEBUG ("usbCbiUfiDevBlkWrt: Writing from block number: %x\n",                        blkNum, 0, 0, 0, 0, 0);    OSS_MUTEX_TAKE (cbiUfiDevMutex, OSS_BLOCK);     /* initialise the pointer to fetch bulk out data */    pCbiUfiDev->bulkOutData = (UINT8 *)pBuf;    if ( usbCbiUfiFormCmd (pCbiUfiDev, USB_UFI_WRITE10, blkNum,                            numBlks) != OK )        {        OSS_MUTEX_RELEASE (cbiUfiDevMutex);        return (ERROR);         }    s = usbCbiUfiCmdExecute (pCbiUfiDev);    /*     * check for the status of the write operation. If failed while     * transferring ADSC or any FATAL error, do a block reset.     */       if ( s != USB_COMMAND_SUCCESS )        {        if ( s == USB_COMMAND_FAILED)            {            usbCbiUfiDevReset (pBlkDev);             }        usbCbiUfiReqSense (pCbiUfiDev);           OSS_MUTEX_RELEASE (cbiUfiDevMutex);        return (ERROR);         }    OSS_MUTEX_RELEASE (cbiUfiDevMutex);     return (OK);    }/***************************************************************************** usbCbiUfiIrpCallback - Invoked upon IRP completion** Examines the status of the IRP submitted.  ** RETURNS: N/A** ERRNO: none**\NOMANUAL*/LOCAL VOID usbCbiUfiIrpCallback    (    pVOID p                      /* pointer to the IRP submitted */    )    {    pUSB_IRP      pIrp     = (pUSB_IRP) p;    pUSB_CBI_UFI_DEV pCbiUfiDev = pIrp->userPtr;    /* check whether the IRP was for bulk out/ bulk in / status transport */    if (pIrp == &(pCbiUfiDev->outIrp))        {          if (pIrp->result == OK)     /* check the result of IRP */            {            USB_CBI_UFI_DEBUG ("usbCbiUfiIrpCallback: Num of Bytes transferred on "\                               "out pipe %d\n", pIrp->bfrList[0].actLen,                                0, 0, 0, 0, 0);             }        else            {            USB_CBI_UFI_ERR ("usbCbiUfiIrpCallback: Irp failed on Bulk Out %x \n",                            pIrp->result, 0, 0, 0, 0, 0);             /* Clear HALT Feature on Bulk out Endpoint */             if ((usbdFeatureClear (usbdHandle, pCbiUfiDev->cbiUfiDevId,                            USB_RT_ENDPOINT, USB_FSEL_DEV_ENDPOINT_HALT,                            (pCbiUfiDev->outEpAddress & 0xFF))) != OK)                {                USB_CBI_UFI_ERR ("usbCbiUfiIrpCallback: Failed to clear HALT "\                                 "feature on bulk out Endpoint %x\n", 0, 0, 0,                                  0, 0, 0);                }            }        }      else  if (pIrp == &(pCbiUfiDev->inIrp))   /* IRP for bulk_in data */        {        if (pIrp->result == OK)            {            USB_CBI_UFI_DEBUG ("usbCbiUfiIrpCallback: Num of Bytes read from Bulk "\                               "In =%d\n", pIrp->bfrList[0].actLen, 0, 0, 0, 0, 0);             }        else   /* IRP on BULK IN failed */            {            USB_CBI_UFI_ERR ("usbCbiUfiIrpCallback : Irp failed on Bulk in ,%x\n",                           pIrp->result, 0, 0, 0, 0, 0);            /* Clear HALT Feature on Bulk in Endpoint */            if ((usbdFeatureClear (usbdHandle, 				   pCbiUfiDev->cbiUfiDevId, 				   USB_RT_ENDPOINT,                                    USB_FSEL_DEV_ENDPOINT_HALT,                                    (pCbiUfiDev->inEpAddress & 0xFF))) 				  != OK)                {                USB_CBI_UFI_ERR ("usbCbiUfiIrpCallback: Failed to clear HALT "\                        "feature on bulk in Endpoint %x\n", 0, 0, 0, 0, 0, 0);                }             }        }     else  if (pIrp == &(pCbiUfiDev->statusIrp))   /* IRP for bulk_in data */        {        if (pIrp->result == OK)            {            USB_CBI_UFI_DEBUG ("usbCbiUfiIrpCallback: Num of Bytes read from "\                               "status pipe =%d, %d, %d\n", pIrp->bfrList[0].actLen,                                 pCbiUfiDev->intrStatus[0],                                 pCbiUfiDev->intrStatus[1], 0, 0, 0);             }        else   /* IRP on BULK IN failed */            {            USB_CBI_UFI_ERR ("usbCbiUfiIrpCallback : Irp failed on interrupt pipe ,%x\n",                           pIrp->result, 0, 0, 0, 0, 0);            /* Clear HALT Feature on Bulk in Endpoint */            if ((usbdFeatureClear (usbdHandle, 				   pCbiUfiDev->cbiUfiDevId, 				   USB_RT_ENDPOINT,                                    USB_FSEL_DEV_ENDPOINT_HALT,                                   (pCbiUfiDev->intrEpAddress & 0xFF))) 				   != OK)                {      

⌨️ 快捷键说明

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