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

📄 usbtargprnlib.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 3 页
字号:
/* usbTargPrnLib.c - USB printer target exerciser/demonstration *//* Copyright 1999-2004 Wind River Systems, Inc. *//*Modification history--------------------02e,02aug04,mta  Modification History Changes02d,23jul04,ami  Apigen Changes02c,12jul04,ami  Coding Convention Changes02b,04may04,pdg  Support for performance calculation02a,02apr04,pdg  modifications for USB 2.0 stack.01b,23nov99,rcb  Change #include ../xxx references to lower case.01a,30aug99,rcb  First.*//*DESCRIPTIONThis module contains code to exercise the usbTargLib by emulating a rudimentaryUSB printer.  This module will generally be invoked by usbTool or a similar USBtest/exerciser application.It is the caller's responsibility to initialize usbTargLib and attach a USB TCD to it.	When attaching a TCD to usbTargLib, the caller must pass a pointer to atable of callbacks required by usbTargLib.  The address of this table and the"callback parameter" required by these callbacks may be obtained by callingusbTargPrnCallbackInfo().  It is not necessary to initialize the usbTartPrnLib or to shut it down.  It performs all of its operations in response to callbacks from usbTargLib.This module also exports a function, usbTargPrnBfrInfo(), which allows a testapplication to retrieve the current status of the bulk output buffer.INCLUDE FILES: usb/usbPlatform.h, string.h, usb/usb.h, usb/usbPrinter.h,               usb/usbDescrCopyLib.h, usb/target/usbTargLib.h,               drv/usb/target/usbTargPrnLib.h, usb/target/usbHalCommon.h*//* includes */#include "usb/usbPlatform.h"                #include "string.h"                         #include "usb/usb.h"                        #include "usb/usbPrinter.h"		            #include "usb/usbDescrCopyLib.h"#include "usb/target/usbTargLib.h"#include "drv/usb/target/usbTargPrnLib.h"#include "usb/target/usbHalCommon.h"        /* defines *//* Define USE_DMA_ENDPOINT to direct printer data to the Philips PDIUSBD12 * "main" endpoint (#2) which uses DMA.  Un-define USE_DMA_ENDPOINT to direct * printer data to the generic endpoint (#1) which uses programmed-IO. */#if 0#define USE_DMA_ENDPOINT#endif/* string identifiers */#define UNICODE_ENGLISH		0x409                  /* unicode coding */#define ID_STR_MFG		1                      /* manufacuturer id */#define ID_STR_MFG_VAL		"Wind River Systems"   /* manufacturer name */#define ID_STR_PROD		2                      /* product id */#define ID_STR_PROD_VAL		"USB printer emulator" /* product name */#define PRN_CAPS	"mfg:WRS;model=emulator;" /* printer */						  /* "capabilities" string */#define PRN_USB10_VERSION	0x0100		/* full speed version */#define PRN_USB20_VERSION	0x0200		/* high speed version */#define PRN_NUM_CONFIG		1		/* number of configurations *//* printer configuration */#define PRN_CONFIG_VALUE	1	/* Printer configuration value */#define PRN_NUM_INTERFACES	1	/* number of interface *//* printer interface */#define PRN_INTERFACE_NUM		0	/* interface number */#define PRN_INTERFACE_ALT_SETTING	0	/* alternate setting */#define PRN_NUM_ENDPOINTS		1	/* number of endpoints *//* printer BULK OUT endpoint */#ifdef	USE_DMA_ENDPOINT#define PRN_BULK_OUT_ENDPOINT_NUM	0x02    /* dma endpoint number */#define PRN_BULK_OUT_MAX_PACKETSIZE	64      /* max packet size */#else#define PRN_BULK_OUT_ENDPOINT_NUM	0x01    /* PIO mode endpoint number */#define PRN_BULK_OUT_MAX_PACKETSIZE	16      /* max packet size-FS */#endif#define BULK_BFR_LEN			4096    /* total bulk buffer length */#define PRN_HIGH_SPEED_CONTROL_MAX_PACKET_SIZE  0x40 /* maximum packet size for                                                      * the default control                                                      * endpoint, if the device                                                      * is operating at high                                                      * speed                                                      */LOCAL USB_TARG_CHANNEL	channel;		/* target channel */LOCAL UINT8		curConfiguration;	/* curr config */LOCAL UINT8		curAlternateSetting;	/* current alternate setting */LOCAL USB_TARG_PIPE	bulkPipeHandle;		/* bulk pipe handle */LOCAL USB_ERP		bulkErp;		/* bulk ERP */LOCAL BOOL		bulkInUse;		/* states whether bulk ERP */ 						/* is in use. */LOCAL pUINT8		bulkBfr;		/* buffer for bulk data */LOCAL BOOL		bulkBfrValid;LOCAL UINT32		uDeviceFeature = 0;	/* device feature */LOCAL UINT32		uEndpointNumberBitmap = 0; /* bitmaps for the enpoints*/                                                   /* supported by Target */                                                   /* Controller */LOCAL UINT32		uSpeed = USB_TCD_FULL_SPEED;  /* USB Speed */LOCAL UINT8		uDeviceStatus = 0x01;	/* status of the device */LOCAL UINT8		uDeviceAddress = 0;	/* Device Address */LOCAL char capsString [] = PRN_CAPS;/* Printer Port Status */LOCAL USB_PRINTER_PORT_STATUS portStatus = {USB_PRN_STS_SELECTED |                                            USB_PRN_STS_NOT_ERROR};/* Language Descriptor */LOCAL USB_LANGUAGE_DESCR langDescr = {sizeof (USB_LANGUAGE_DESCR),                                      USB_DESCR_STRING,	                              {TO_LITTLEW (UNICODE_ENGLISH)}};LOCAL char	*pStrMfg = ID_STR_MFG_VAL;    /* Manufacturer Name */LOCAL char	*pStrProd = ID_STR_PROD_VAL;  /* Product Name */LOCAL USB_DEVICE_DESCR devDescr =	/* Device Descriptor */    {    USB_DEVICE_DESCR_LEN,		/* bLength */    USB_DESCR_DEVICE,			/* bDescriptorType */    TO_LITTLEW (PRN_USB10_VERSION),	/* bcdUsb */    0,					/* bDeviceClass */    0,					/* bDeviceSubclass */    0,					/* bDeviceProtocol */    USB_MIN_CTRL_PACKET_SIZE,		/* maxPacketSize0 */    0,					/* idVendor */    0,					/* idProduct */    0,					/* bcdDevice */    ID_STR_MFG,				/* iManufacturer */    ID_STR_PROD,			/* iProduct */    0,					/* iSerialNumber */    PRN_NUM_CONFIG			/* bNumConfigurations */    };LOCAL USB_DEVICE_QUALIFIER_DESCR devQualifierDescr =  /* Device Qualifier */    {    USB_DEVICE_QUALIFIER_DESCR_LEN,	/* bLength */    USB_DESCR_DEVICE_QUALIFIER,		/* bDescriptorType */    TO_LITTLEW (PRN_USB20_VERSION),	/* bcdUsb */    0,					/* bDeviceClass */    0,					/* bDeviceSubclass */    0,					/* bDeviceProtocol */    USB_MIN_CTRL_PACKET_SIZE,		/* maxPacketSize0 */    PRN_NUM_CONFIG,			/* bNumConfigurations */    0					/* Reserved */    };LOCAL USB_CONFIG_DESCR configDescr =	/* Configuration Descriptor */    {    USB_CONFIG_DESCR_LEN,	    /* bLength */    USB_DESCR_CONFIGURATION,	    /* bDescriptorType */    TO_LITTLEW (USB_CONFIG_DESCR_LEN + USB_INTERFACE_DESCR_LEN +    USB_ENDPOINT_DESCR_LEN),	    /* wTotalLength */    PRN_NUM_INTERFACES, 	    /* bNumInterfaces */    PRN_CONFIG_VALUE,		    /* bConfigurationValue */    0,				    /* iConfiguration */    USB_ATTR_SELF_POWERED,	    /* bmAttributes */    0				    /* MaxPower */    };LOCAL USB_CONFIG_DESCR otherSpeedConfigDescr =	/* Other Speed */						/* Configuration Descriptor */    {    USB_CONFIG_DESCR_LEN,		/* bLength */    USB_DESCR_OTHER_SPEED_CONFIGURATION,	/* bDescriptorType */    TO_LITTLEW (USB_CONFIG_DESCR_LEN + USB_INTERFACE_DESCR_LEN +    USB_ENDPOINT_DESCR_LEN),		/* wTotalLength */    PRN_NUM_INTERFACES,			/* bNumInterfaces */    PRN_CONFIG_VALUE,			/* bConfigurationValue */    0,					/* iConfiguration */    USB_ATTR_SELF_POWERED,		/* bmAttributes */    0					/* MaxPower */    };LOCAL USB_INTERFACE_DESCR ifDescr =	/* Interface Descriptor */    {    USB_INTERFACE_DESCR_LEN,		/* bLength */    USB_DESCR_INTERFACE,		/* bDescriptorType */    PRN_INTERFACE_NUM,			/* bInterfaceNumber */    PRN_INTERFACE_ALT_SETTING,		/* bAlternateSetting */    PRN_NUM_ENDPOINTS,			/* bNumEndpoints */    USB_CLASS_PRINTER,			/* bInterfaceClass */    USB_SUBCLASS_PRINTER,		/* bInterfaceSubClass */    USB_PROTOCOL_PRINTER_UNIDIR,	/* bInterfaceProtocol */    0					/* iInterface */    };LOCAL USB_ENDPOINT_DESCR epDescr =	/* Endpoint Descriptor */    {    USB_ENDPOINT_DESCR_LEN,		/* bLength */    USB_DESCR_ENDPOINT,			/* bDescriptorType */    PRN_BULK_OUT_ENDPOINT_NUM,		/* bEndpointAddress */    USB_ATTR_BULK,			/* bmAttributes */    TO_LITTLEW(PRN_BULK_OUT_MAX_PACKETSIZE),	/* maxPacketSize */    0					/* bInterval */    };LOCAL USB_ENDPOINT_DESCR otherSpeedEpDescr =    /* Other Speed Endpoint */						/* Descriptor */    {    USB_ENDPOINT_DESCR_LEN,		/* bLength */    USB_DESCR_ENDPOINT,			/* bDescriptorType */    PRN_BULK_OUT_ENDPOINT_NUM,		/* bEndpointAddress */    USB_ATTR_BULK,			/* bmAttributes */    TO_LITTLEW(PRN_BULK_OUT_MAX_PACKETSIZE),	/* maxPacketSize */    0					/* bInterval */    };/* forward declarations */LOCAL STATUS mngmtFunc (pVOID param, USB_TARG_CHANNEL targChannel,                         UINT16 mngmtCode, pVOID pContext);LOCAL STATUS featureClear (pVOID param, USB_TARG_CHANNEL targChannel,                           UINT8 requestType, UINT16 feature,UINT16 index);LOCAL STATUS featureSet (pVOID param, USB_TARG_CHANNEL targChannel,                         UINT8 requestType, UINT16 feature, UINT16 index);LOCAL STATUS configurationGet (pVOID param, USB_TARG_CHANNEL targChannel,                               pUINT8 pConfiguration);LOCAL STATUS configurationSet (pVOID param, USB_TARG_CHANNEL targChannel,                               UINT8 configuration);LOCAL STATUS descriptorGet (pVOID param, USB_TARG_CHANNEL targChannel,                            UINT8 requestType, UINT8 descriptorType,                            UINT8 descriptorIndex, UINT16 languageId,                            UINT16 length, pUINT8 pBfr, pUINT16 pActLen);LOCAL STATUS interfaceGet (pVOID param, USB_TARG_CHANNEL targChannel,                           UINT16 interfaceIndex, pUINT8 pAlternateSetting);LOCAL STATUS interfaceSet (pVOID param, USB_TARG_CHANNEL targChannel,                           UINT16 interfaceIndex, UINT8 alternateSetting);LOCAL STATUS statusGet (pVOID param, USB_TARG_CHANNEL targChannel,                        UINT16 requestType, UINT16 index, UINT16 length,                        pUINT8 pBfr);LOCAL STATUS addressSet (pVOID param, USB_TARG_CHANNEL targChannel,                         UINT16 deviceAddress);LOCAL STATUS vendorSpecific (pVOID param, USB_TARG_CHANNEL targChannel,                             UINT8 requestType, UINT8 request, UINT16 value,                             UINT16 index, UINT16 length);LOCAL STATUS initBulkOutErp (void);LOCAL USB_TARG_CALLBACK_TABLE usbTargPrnCallbackTable =  /* Callback Table */    {    mngmtFunc,		/* mngmtFunc */    featureClear,       /* featureClear */    featureSet,		/* featureSet */    configurationGet,	/* configurationGet */    configurationSet,	/* configurationSet */    descriptorGet,	/* descriptorGet */    NULL,		/* descriptorSet */    interfaceGet,	/* interfaceGet */    interfaceSet,	/* interfaceSet */    statusGet,		/* statusGet */    addressSet,		/* addressSet */    NULL,		/* synchFrameGet */    vendorSpecific	/* vendorSpecific */    };/* functions *//******************************************************************************** bulkErpCallback - called when report ERP terminates** This callback is invoked when an Endpoint Request Packet terminates.** RETURNS: N/A** ERRNO:*  none** \NOMANUAL*/LOCAL VOID bulkErpCallback    (    pVOID	p		/* pointer to ERP */    )    {    bulkInUse = FALSE;    bulkBfrValid = TRUE;#ifdef TEST_PRINT_PERFORMANCE    initBulkOutErp();#endif    }/******************************************************************************** initBulkOutErp - listen for output printer data** This function initializes the Bulk Out ERP and listens to the data* sent by the Printer.** RETURNS: OK, or ERROR if unable to submit ERP.** ERRNO:*  none** \NOMANUAL*/LOCAL STATUS initBulkOutErp (void)    {    if (bulkBfr == NULL)	return ERROR;    if (bulkInUse)	return OK;    /* Initialize bulk ERP */    memset (&bulkErp, 0, sizeof (bulkErp));    bulkErp.erpLen = sizeof (bulkErp);    bulkErp.userCallback = bulkErpCallback;    bulkErp.bfrCount = 1;    bulkErp.bfrList [0].pid = USB_PID_OUT;    bulkErp.bfrList [0].pBfr = bulkBfr;    bulkErp.bfrList [0].bfrLen = BULK_BFR_LEN;    bulkInUse = TRUE;    bulkBfrValid = FALSE;    if (usbTargTransfer (bulkPipeHandle, &bulkErp) != OK)	{	bulkInUse = FALSE;	return ERROR;	}    return OK;    }/******************************************************************************** usbTargPrnCallbackInfo - returns usbTargPrnLib callback table** This function is called by the initialization routine. It returns the * information about the callback table.** RETURNS: N/A* * ERRNO:*  none*/VOID usbTargPrnCallbackInfo    (    pUSB_TARG_CALLBACK_TABLE	*ppCallbacks,	/* Pointer to callback */						/* table */    pVOID	*pCallbackParam			/* target app-specific */						/* parameter */    )    {    if (ppCallbacks != NULL)	*ppCallbacks = &usbTargPrnCallbackTable;    if (pCallbackParam != NULL)	*pCallbackParam = NULL;    }/********************************************************************************* usbTargPrnDataInfo - returns buffer status/info** This function returns the status the bulk buffer which consist of the * data sent by the printer. <pActLen> will consist of the actual length of* data to be printed.** RETURNS: OK if buffer has valid data, else ERROR** ERRNO:*  none.*/STATUS usbTargPrnDataInfo    (    pUINT8	* ppBfr,	/* Pointer to the buffer address */    pUINT16	pActLen		/* Actual length of the data */    )    {    if (!bulkBfrValid)	return ERROR;    if (ppBfr != NULL)	*ppBfr = bulkBfr;    if (pActLen != NULL)	*pActLen = bulkErp.bfrList [0].actLen;    return OK;    }

⌨️ 快捷键说明

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