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

📄 usbtargprnlib.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 3 页
字号:
/********************************************************************************* usbTargPrnDataRestart - restarts listening ERP** This function restarts the listening of ERP on Bulk Out Pipe.** RETURNS: OK, or ERROR if unable to re-initiate ERP** ERRNO:*  none*/STATUS usbTargPrnDataRestart (void)    {    return initBulkOutErp ();    }/********************************************************************************* mngmtFunc - invoked by usbTargLib for connection management events** This function handles various management related events. <mngmtCode>* consist of the management event function code that is reported by the* TargLib layer. <pContext> is the argument sent for the management event to* be handled.** RETURNS: OK if able to handle event, or ERROR if unable to handle event** ERRNO:*  none** \NOMANUAL*/LOCAL STATUS mngmtFunc    (    pVOID	param,				/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,		/* target channel */    UINT16	mngmtCode,			/* management code */    pVOID	pContext			/* context value */    )    {    pUSB_APPLN_DEVICE_INFO	pDeviceInfo = NULL;/* USB_APPLN_DEVICE_INFO */    switch (mngmtCode)    	{    	case TARG_MNGMT_ATTACH:            if (pContext == NULL)                return ERROR;            /* Retrieve the pointer to the device info data structure */            pDeviceInfo = (pUSB_APPLN_DEVICE_INFO)pContext;    	    /* Initialize global data */            uDeviceFeature = pDeviceInfo->uDeviceFeature;            uEndpointNumberBitmap = pDeviceInfo->uEndpointNumberBitmap;    	    channel = targChannel;    	    /* Allocate buffer */    	    if ((bulkBfr = OSS_MALLOC (BULK_BFR_LEN)) == NULL)                return ERROR;            /*              * If the device is USB 2.0, initialize the bcdUSB field of             * the device descriptor and the device qualifier descriptor.             */            if ((uDeviceFeature & USB_FEATURE_USB20) != 0)                {                devDescr.bcdUsb = TO_LITTLEW(PRN_USB20_VERSION);                devQualifierDescr.bcdUsb = TO_LITTLEW(PRN_USB20_VERSION);                }            /*             * If the device supports remote wakeup, modify the configuration             * descriptor accordingly.             */            if ((uDeviceFeature & USB_FEATURE_DEVICE_REMOTE_WAKEUP) != 0)                {                configDescr.attributes |= USB_ATTR_REMOTE_WAKEUP;                if ((uDeviceFeature & USB_FEATURE_USB20) != 0)                    otherSpeedConfigDescr.attributes |= USB_ATTR_REMOTE_WAKEUP;                }            /*              * Check if the endpoint number is supported.             * The shift value is directly taken as the endpoint address             * as the application is specifically written for printer and it             * supports only the bulk OUT endpoint.             */            if ((uEndpointNumberBitmap >> epDescr.endpointAddress) == 0)                {                /*                  * Search through the bitmap and arrive at an endpoint address                 */                UINT32 uIndex = 1;                for (uIndex = 1; uIndex < 16; uIndex++)                    {                    if ((uEndpointNumberBitmap >> uIndex) != 0)                        {                        epDescr.endpointAddress = uIndex;                        otherSpeedEpDescr.endpointAddress = uIndex;                        break;                        }                    }                if (uIndex == 16)                    return ERROR;                }    	    break;    	case TARG_MNGMT_DETACH:    	    /* Call the function to delete the bulk pipe created */    	    if (bulkPipeHandle != NULL)    	        {    	        usbTargPipeDestroy(bulkPipeHandle);    	        bulkPipeHandle = NULL;    	        }    	    /* De-allocate buffer */    	    if (bulkBfr != NULL)                {                OSS_FREE (bulkBfr);                bulkBfr = NULL;                }            /* Reset the globals */            channel = 0;            uDeviceFeature = 0;            uEndpointNumberBitmap = 0;            /*              * Reset the device and device qualifier descriptors'             * bcusb field             */            devDescr.bcdUsb = TO_LITTLEW(PRN_USB10_VERSION);            devQualifierDescr.bcdUsb = TO_LITTLEW(PRN_USB10_VERSION);            /*             * Reset the device and device qualifier descriptors'             * max packet size field             */            devDescr.maxPacketSize0 = USB_MIN_CTRL_PACKET_SIZE;            devQualifierDescr.maxPacketSize0 = USB_MIN_CTRL_PACKET_SIZE;            /* Reset the endpoint numbers */            epDescr.endpointAddress = PRN_BULK_OUT_ENDPOINT_NUM;            otherSpeedEpDescr.endpointAddress = PRN_BULK_OUT_ENDPOINT_NUM;    	    break;    	case TARG_MNGMT_BUS_RESET:            /* Copy the operating speed of the device */    	    uSpeed = (UINT32)pContext;    	    curConfiguration = 0;    	    bulkInUse = FALSE;    	    bulkBfrValid = FALSE;    	    uDeviceAddress = 0;            /* Reset the device status to indicate that it is self powered */            uDeviceStatus = 0x01;    	    /* Call the function to delete the bulk pipe created */    	    if (bulkPipeHandle != NULL)    	        {    	        usbTargPipeDestroy(bulkPipeHandle);    	        bulkPipeHandle = NULL;    	        }    	    /* Initialize the descriptor values */    	    if (uSpeed == USB_TCD_HIGH_SPEED)    	        {    	                       /*                  * Initialize the max packet sizes for the default control                 * pipe                 */                devDescr.maxPacketSize0 = PRN_HIGH_SPEED_CONTROL_MAX_PACKET_SIZE;                devQualifierDescr.maxPacketSize0 = USB_MIN_CTRL_PACKET_SIZE;                /* Initialize the max packet size for the bulk pipe */                epDescr.maxPacketSize = TO_LITTLEW(USB_MAX_HIGH_SPEED_BULK_SIZE);		otherSpeedEpDescr.maxPacketSize =                                        TO_LITTLEW(USB_MAX_CTRL_PACKET_SIZE);                /* Update the maximum NAK rate */                epDescr.interval = USB_MAX_BULK_OUT_NAK_RATE;                otherSpeedEpDescr.interval = 0;                }            else    	        {                devDescr.maxPacketSize0 = USB_MIN_CTRL_PACKET_SIZE;        	/*                  * If the device is a USB 2.0 device, then set the device                  * qualifier descriptor's maximum packet size        	 */        	if ((uDeviceFeature & USB_FEATURE_USB20) != 0)        	    {        	    devQualifierDescr.maxPacketSize0 = USB_MIN_CTRL_PACKET_SIZE;        	    otherSpeedEpDescr.maxPacketSize =                                       TO_LITTLEW(USB_MAX_HIGH_SPEED_BULK_SIZE);                    otherSpeedEpDescr.interval = USB_MAX_BULK_OUT_NAK_RATE;        	    }                /* Initialize the max packet size for the bulk pipe */                epDescr.maxPacketSize = TO_LITTLEW(PRN_BULK_OUT_MAX_PACKETSIZE);                /* Update the bInterval field */                epDescr.interval = 0;                }             break;    	case TARG_MNGMT_DISCONNECT:    	    curConfiguration = 0;    	    /* Call the function to delete the bulk pipe created */    	    if (bulkPipeHandle != NULL)    	        {    	        usbTargPipeDestroy(bulkPipeHandle);    	        bulkPipeHandle = NULL;    	        }    	    break;        case TARG_MNGMT_SUSPEND:        case TARG_MNGMT_RESUME:    	default:    	    break;    	}    return OK;    }/******************************************************************************** featureClear - invoked by usbTargLib for CLEAR_FEATURE request** This function is called to clear device or endpoint specific features.** RETURNS: OK, or ERROR if unable to clear the feature** ERRNO:*  none** \NOMANUAL*/LOCAL STATUS featureClear    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,	/* target channel */    UINT8	requestType,		/* standard request type  */    UINT16	feature,		/* feature to be cleared */    UINT16	index			/* 0, interface or endpoint */    )    {    STATUS	status = ERROR;		/* variable to hold error status */    /* This request is not accepted when the device is in the default state */    if (uDeviceAddress == 0)        return ERROR;    /* Switch based on the feature which needs to be cleared */    switch(feature)        {        case USB_FSEL_DEV_REMOTE_WAKEUP:            /*              * If the device supports remote wakeup, call the function             * to clear the remote wakeup feature             */            if ((uDeviceFeature & USB_FEATURE_DEVICE_REMOTE_WAKEUP) != 0)                {                status = usbTargDeviceFeatureClear(targChannel, feature);                /* Clear the global status */                if (status == OK)                    uDeviceStatus &= ~0x02;                }            break;        case USB_FSEL_DEV_ENDPOINT_HALT:            /* Check whether the endpoint address is valid */            if ((index == epDescr.endpointAddress) && (bulkPipeHandle != NULL))                {                /* Call the function to clear the endoint halt feature */                status = usbTargPipeStatusSet(bulkPipeHandle,                                              TCD_ENDPOINT_UNSTALL);                }            break;        default:            break;        }        return status;    }/******************************************************************************** featureSet - invoked by usbTargLib for SET_FEATURE request** This function is used to set device or endpoint specific features.* <feature> consists of the feature to set.** RETURNS: OK, or ERROR if unable to set the feature** ERRNO:*  none** \NOMANUAL*/LOCAL STATUS featureSet    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL targChannel,	/* target channel */    UINT8	requestType,		/* request type */    UINT16	feature,		/* feature to be set */    UINT16	index			/* 0, interface or endpoint */    )    {    STATUS	status = ERROR;		/* variable to hold status */    /*      * This request is not accepted when the the device is in the default state     * and the feature to be set is not TEST_MODE     */    if ((uDeviceAddress == 0) && (feature != USB_FSEL_DEV_TEST_MODE))        return ERROR;    /* Switch based on the feature which needs to be set */    switch(feature)        {        case USB_FSEL_DEV_REMOTE_WAKEUP:                        /*             * If the device supports remote wakeup, call the function             * to set the remote wakeup feature             */            if ((uDeviceFeature & USB_FEATURE_DEVICE_REMOTE_WAKEUP) != 0)                {                status = usbTargDeviceFeatureSet(targChannel, feature, index);                /* Set the global status */                if (status == OK)                    uDeviceStatus |= 0x02;                }            break;        case USB_FSEL_DEV_TEST_MODE:            /*             * If the device supports remote wakeup, call the function             * to set the test mode feature             */            if ((uDeviceFeature & USB_FEATURE_TEST_MODE) != 0)                {                status = usbTargDeviceFeatureSet(targChannel,                                                 feature,                                                 ((index & 0xFF00) << 8));                }            break;        case USB_FSEL_DEV_ENDPOINT_HALT:            /* Check whether the endpoint address is valid */            if ((index == epDescr.endpointAddress) && (bulkPipeHandle != NULL))                {                /* Call the function to stall the endoint */                status = usbTargPipeStatusSet(bulkPipeHandle,                                              TCD_ENDPOINT_STALL);                }            break;        default:            break;        }    return status;    }/********************************************************************************* configurationGet - invoked by usbTargLib for GET_CONFIGURATION request** This function is used to get the current configuration of the device.* <pConfiguration> is set with the current configuration and sent to the* host.** RETURNS: OK, or ERROR if unable to return configuration setting** ERRNO:*   none.** \NOMANUAL

⌨️ 快捷键说明

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