📄 usbtargphilipsd12evallib.c
字号:
/* usbTargPhilipsD12EvalLib.c - emulates Philips PDIUSBD12 eval firmware *//* Copyright 2000 Wind River Systems, Inc. *//*Modification history--------------------01d,19mar00,rcb Add handling for CLEAR_FEATURE...Newer Philips test program now invokes this function.01c,23nov99,rcb Change #include ../xxx references to lower case.01b,12nov99,rcb Shorted path names...affects "#include" directives.01a,03sep99,rcb First.*//*DESCRIPTIONThe Philips PDIUSBD12 evaluation kit is shipped with sample firmware. The"firmware" is a program which runs under MS-DOS and responds to certain standardand "vendor specific" USB requests. A custom Windows application - also providedby Philips - can be used to exercise this "firmware".In order to provide a different example of working target behavoir, this moduleemulates the behavoir of the Philips evaluation firmware, allowing this targetmodule to work with the Philips Windows-based exerciser program. The "scan","print", and "loopback" portions of that test work correctly. The "LED buttons"supported by the Philips firmware are not emulated, and do nothing.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 callingusbTargPhilipsD12EvalCallbackInfo(). It is not necessary to initialize the usbTartPhilipsD12EvalLib or to shut it down. It performs all of its operationsin response to callbacks from usbTargLib.*//* includes */#include "usb/usbPlatform.h"#include "string.h"#include "usb/usb.h"#include "usb/usbDescrCopyLib.h" /* USB utility functions */#include "usb/target/usbTargLib.h" /* USB target functions */#include "drv/usb/target/usbPdiusbd12.h" /* Philips definitions */#include "drv/usb/target/usbTargPhilipsD12EvalLib.h" /* our API *//* defines */#define BULK_BFR_LEN 64000 /* size used by Philips *//* string identifiers */#define UNICODE_ENGLISH 0x409#define ID_STR_MFG 1#define ID_STR_MFG_VAL "Wind River Systems"#define ID_STR_PROD 2#define ID_STR_PROD_VAL "Philips firmware emulator"/* descriptor constants */#define CONFIG_VAL 1#define NUM_ENDPOINTS 4#define CONFIG_DESCRIPTOR_LENGTH \ USB_CONFIG_DESCR_LEN + USB_INTERFACE_DESCR_LEN + \ (NUM_ENDPOINTS * USB_ENDPOINT_DESCR_LEN)/* vendor specific commands */#define READ_WRITE_REGISTER 12/* wIndex parameters to the vendor specific READ_WRITE_REGISTER cmd */#define SETUP_DMA_REQUEST 0x0471#define GET_FIRMWARE_VERSION 0x0472#define GET_SET_TWAIN_REQUEST 0x0473/* typedefs *//* IO_REQUEST is the parameter to the SETUP_DMA_REQUEST vendor-specific * command. */#define IO_REQUEST_LEN 6typedef struct io_request { UINT8 bytes [IO_REQUEST_LEN];} IO_REQUEST, *pIO_REQUEST;/* forward declarations */LOCAL STATUS mngmtFunc ( pVOID param, USB_TARG_CHANNEL targChannel, UINT16 mngmtCode );LOCAL STATUS featureClear ( 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 vendorSpecific ( pVOID param, USB_TARG_CHANNEL targChannel, UINT8 requestType, UINT8 request, UINT16 value, UINT16 index, UINT16 length );LOCAL STATUS initBulkErp ( USB_TARG_PIPE pipeHandle, UINT16 pid, UINT16 bfrOffset, UINT16 length );/* locals */LOCAL USB_TARG_CALLBACK_TABLE usbTargPrnCallbackTable = { mngmtFunc, /* mngmtFunc */ featureClear, /* featureClear */ NULL, /* featureSet */ configurationGet, /* configurationGet */ configurationSet, /* configurationSet */ descriptorGet, /* descriptorGet */ NULL, /* descriptorSet */ interfaceGet, /* interfaceGet */ interfaceSet, /* interfaceSet */ NULL, /* statusGet */ NULL, /* addressSet */ NULL, /* synchFrameGet */ vendorSpecific, /* vendorSpecific */ };LOCAL USB_TARG_CHANNEL channel;LOCAL UINT16 numEndpoints;LOCAL pUSB_TARG_ENDPOINT_INFO pEndpoints;LOCAL UINT16 curConfiguration;LOCAL UINT16 curAlternateSetting;LOCAL USB_TARG_PIPE bulkOutPipeHandle;LOCAL USB_TARG_PIPE bulkInPipeHandle;LOCAL USB_ERP payloadErp;LOCAL IO_REQUEST ioRequest;LOCAL USB_ERP bulkErp;LOCAL pUINT8 bulkBfr;LOCAL BOOL bulkInUse;LOCAL UINT32 bulkCanceled;LOCAL UINT32 bulkErrors;LOCAL UINT8 fwVersion = 0x01; /* version for PDIUSBD12 PC kit *//* descriptors */LOCAL USB_LANGUAGE_DESCR langDescr = {sizeof (USB_LANGUAGE_DESCR), USB_DESCR_STRING, {TO_LITTLEW (UNICODE_ENGLISH)}};LOCAL char *pStrMfg = ID_STR_MFG_VAL;LOCAL char *pStrProd = ID_STR_PROD_VAL;LOCAL USB_DEVICE_DESCR devDescr = { USB_DEVICE_DESCR_LEN, /* bLength */ USB_DESCR_DEVICE, /* bDescriptorType */ TO_LITTLEW (0x0100), /* bcdUsb */ 0xdc, /* test class */ /* bDeviceClass */ 0, /* bDeviceSubclass */ 0, /* bDeviceProtocol */ USB_MIN_CTRL_PACKET_SIZE, /* maxPacketSize0 */ TO_LITTLEW (0x0471), /* idVendor */ TO_LITTLEW (0x0222), /* idProduct */ TO_LITTLEW (0x0100), /* bcdDevice */ ID_STR_MFG, /* iManufacturer */ ID_STR_PROD, /* iProduct */ 0, /* iSerialNumber */ 1 /* bNumConfigurations */ };LOCAL USB_CONFIG_DESCR configDescr = { USB_CONFIG_DESCR_LEN, /* bLength */ USB_DESCR_CONFIGURATION, /* bDescriptorType */ TO_LITTLEW (CONFIG_DESCRIPTOR_LENGTH), /* wTotalLength */ 1, /* bNumInterfaces */ CONFIG_VAL, /* bConfigurationValue */ 0, /* iConfiguration */ USB_ATTR_SELF_POWERED, /* bmAttributes */ 0 /* MaxPower */ };LOCAL USB_INTERFACE_DESCR ifDescr = { USB_INTERFACE_DESCR_LEN, /* bLength */ USB_DESCR_INTERFACE, /* bDescriptorType */ 0, /* bInterfaceNumber */ 0, /* bAlternateSetting */ NUM_ENDPOINTS, /* bNumEndpoints */ 0xdc, /* test class */ /* bInterfaceClass */ 0xa0, /* bInterfaceSubClass */ 0xb0, /* bInterfaceProtocol */ 0 /* iInterface */ };LOCAL USB_ENDPOINT_DESCR epDescr1 = { USB_ENDPOINT_DESCR_LEN, /* bLength */ USB_DESCR_ENDPOINT, /* bDescriptorType */ 0x81, /* bEndpointAddress */ USB_ATTR_INTERRUPT, /* bmAttributes */ USB_MIN_CTRL_PACKET_SIZE, /* maxPacketSize */ 10 /* bInterval */ };LOCAL USB_ENDPOINT_DESCR epDescr2 = { USB_ENDPOINT_DESCR_LEN, /* bLength */ USB_DESCR_ENDPOINT, /* bDescriptorType */ 0x01, /* bEndpointAddress */ USB_ATTR_INTERRUPT, /* bmAttributes */ USB_MIN_CTRL_PACKET_SIZE, /* maxPacketSize */ 10 /* bInterval */ };LOCAL USB_ENDPOINT_DESCR epDescr3 = { USB_ENDPOINT_DESCR_LEN, /* bLength */ USB_DESCR_ENDPOINT, /* bDescriptorType */ 0x82, /* bEndpointAddress */ USB_ATTR_BULK, /* bmAttributes */ USB_MIN_CTRL_PACKET_SIZE, /* maxPacketSize */ 0 /* bInterval */ };LOCAL USB_ENDPOINT_DESCR epDescr4 = { USB_ENDPOINT_DESCR_LEN, /* bLength */ USB_DESCR_ENDPOINT, /* bDescriptorType */ 0x02, /* bEndpointAddress */ USB_ATTR_BULK, /* bmAttributes */ USB_MIN_CTRL_PACKET_SIZE, /* maxPacketSize */ 0 /* bInterval */ };/* functions *//***************************************************************************** usbTargPhilipsD12EvalCallbackInfo - returns callback table** RETURNS: N/A*/VOID usbTargPhilipsD12EvalCallbackInfo ( pUSB_TARG_CALLBACK_TABLE *ppCallbacks, pVOID *pCallbackParam ) { if (ppCallbacks != NULL) *ppCallbacks = &usbTargPrnCallbackTable; if (pCallbackParam != NULL) *pCallbackParam = NULL; }/***************************************************************************** mngmtFunc - invoked by usbTargLib for connection management events** RETURNS: OK if able to handle event, or ERROR if unable to handle event*/LOCAL STATUS mngmtFunc ( pVOID param, USB_TARG_CHANNEL targChannel, UINT16 mngmtCode /* management code */ ) { switch (mngmtCode) { case TCD_MNGMT_ATTACH: /* Initialize global data */ channel = targChannel; usbTargEndpointInfoGet (targChannel, &numEndpoints, &pEndpoints); curConfiguration = 0; curAlternateSetting = 0; bulkInPipeHandle = NULL; bulkOutPipeHandle = NULL; bulkCanceled = 0; bulkErrors = 0; /* Initialize control pipe maxPacketSize. */ devDescr.maxPacketSize0 = pEndpoints [0].maxPacketSize; /* Initialize bulk endpoint max packet size. */ epDescr1.maxPacketSize = pEndpoints [D12_ENDPOINT_1_IN].intInMaxPacketSize; epDescr2.maxPacketSize = pEndpoints [D12_ENDPOINT_1_OUT].intOutMaxPacketSize; epDescr3.maxPacketSize = pEndpoints [D12_ENDPOINT_2_IN].bulkInMaxPacketSize; epDescr4.maxPacketSize = pEndpoints [D12_ENDPOINT_2_OUT].bulkOutMaxPacketSize; /* Allocate buffer */ if ((bulkBfr = OSS_MALLOC (BULK_BFR_LEN)) == NULL) return ERROR; break; case TCD_MNGMT_DETACH: /* De-allocate buffer */ if (bulkBfr != NULL) { OSS_FREE (bulkBfr); bulkBfr = NULL; } break; case TCD_MNGMT_BUS_RESET: case TCD_MNGMT_VBUS_LOST: /* revert to power-ON configuration */ configurationSet (param, targChannel, 0); break; default: break; } return OK; }/***************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -