?? usbtargmslib.c
字號:
/* usbTargMsLib.c - Mass Storage routine library */
/* Copyright 2004 Wind River Systems, Inc. */
/*
Modification History
--------------------
01e,02aug04,mta Merge changes from integration branch to development branch
01d,29jul04,pdg Fixed coverity error
01c,23jul04,hch change vxworks.h to vxWorks.h
01b,01jul04,mta isp1582 changes
01a,15mar04,jac written.
*/
/*
DESCRIPTION
This module defines those routines directly referenced by the USB peripheral
stack; namely, the routines that intialize the USB_TARG_CALLBACK_TABLE data
structure. Additional routines are also provided which are specific to the
mass storage driver.
INCLUDES: vxWorks.h, stdio.h, errnoLib.h, logLib.h, string.h, blkIo.h,
usb/usbPlatform.h, usb/usb.h, usb/usbDescrCopyLib.h, usb/usbLib.h,
usb/target/usbTargLib.h, drv/usb/usbBulkDevLib.h,
drv/usb/target/usbTargMsLib.h, drv/usb/target/usbTargRbcLib.h
*/
/* includes */
#include "vxWorks.h"
#include "stdio.h"
#include "errnoLib.h"
#include "logLib.h"
#include "string.h"
#include "blkIo.h"
#include "usb/usbPlatform.h"
#include "usb/usb.h"
#include "usb/usbDescrCopyLib.h"
#include "usb/usbLib.h"
#include "usb/target/usbTargLib.h"
#include "drv/usb/usbBulkDevLib.h"
#include "drv/usb/target/usbTargMsLib.h"
#include "drv/usb/target/usbTargRbcCmd.h"
#include "drv/usb/target/usbTargRbcLib.h"
/* defines */
#ifdef USB_DEBUG_PRINT /* debug macros */
#define BUF_SIZE 255
#define DEBUG_PRINT(a) logMsg(a,0,0,0,0,0,0)
#endif
/*
* The USE_MS_TEST_DATA macro allows the bulk-in and bulk-out pipes to be
* tested using dummy data. The host computer must employ a special purpose
* driver that invokes the vendor specific device request with the request
* value set to either MS_BULK_IN_TX_TEST or MS_BULK_IN_RX_TEST. If set to
* MS_BULK_IN_TX_TEST, the device transmits dummy data to the host;
* alternatively, if set to MS_BULK_IN_RX_TEST, the device receives dummy
* data from the host.
*/
#undef USE_MS_TEST_DATA
#ifdef USE_MS_TEST_DATA
#define MS_TEST_DATA_SIZE 32 /* test data size */
#define MS_BULK_IN_TX_TEST 1 /* transmit buffer test */
#define MS_BULK_OUT_RX_TEST 2 /* receive buffer test */
#endif
#ifdef USE_RBC_SUBCLASS
#define USB_MS_SUBCLASS 0x01 /* RBC command block */
#elif defined(USE_SCSI_SUBCLASS)
#define USB_MS_SUBCLASS USB_SUBCLASS_SCSI_COMMAND_SET
/* SCSI command block */
#else
#error USB_MS_SUBCLASS undefined
#endif
/*
* Define USE_DMA_ENDPOINT to direct the bulk I/O data to the
* Philips PDIUSBD12 "main IN" (endpoint number 5) and "main OUT"
* (endpoint number 4) which use DMA. Un-define USE_DMA_ENDPOINT
* to direct data to the generic bulk I/O endpoint numbers which use
* programmed-IO: 3 for bulk In, and 2 for bulk Out.
*/
#undef USE_DMA_ENDPOINT
#define MS_NUM_ENDPOINTS 2 /* mass storage endpoints */
#ifdef MS_USE_DMA_ENDPOINT
#define MS_BULK_IN_ENDPOINT_NUM 0x82 /* BULK IN endpoint */
#define MS_BULK_OUT_ENDPOINT_NUM 0x2 /* BULK OUT endpoint */
#else
#define MS_BULK_IN_ENDPOINT_NUM 0x81 /* BULK IN endpoint */
#define MS_BULK_OUT_ENDPOINT_NUM 0x1 /* BULK OUT endpoint */
#endif
#ifdef USE_DMA_ENDPOINT
#define MS_BULK_IN_ENDPOINT_ID 5 /* DMA - Bulk IN endpoint ID */
#else
#define MS_BULK_IN_ENDPOINT_ID 3 /* PIO - Bulk IN endpoint ID */
#endif
#ifdef USE_DMA_ENDPOINT
#define MS_BULK_OUT_ENDPOINT_ID 4 /* DMA - Bulk OUT endpoint ID */
#else
#define MS_BULK_OUT_ENDPOINT_ID 2 /* PIO - Bulk OUT endpoint ID */
#endif
/* string identifiers and indexes for string descriptors */
#define UNICODE_ENGLISH 0x409 /* unicode */
#define ID_STR_MFG 1 /* manufacture's id */
#define ID_STR_MFG_VAL "Wind River Systems" /* manufacture's name */
#define ID_STR_PROD 2 /* product id */
#define ID_STR_PROD_VAL "USB mass storage emulator"/* product name */
#define MS_USB_HIGH_SPEED 0
#define MS_USB_FULL_SPEED_VERSION 0x0100 /* USB full speed */
#define MS_USB_HIGH_SPEED_VERSION 0x0200 /* USB high speed */
#if (MS_USB_HIGH_SPEED == 1)
#define MS_USB_VERSION MS_USB_HIGH_SPEED_VERSION
#else
#define MS_USB_VERSION MS_USB_FULL_SPEED_VERSION
#endif
/* mass storage configuration */
#define MS_NUM_CONFIG 1 /* number of configuration */
#define MS_CONFIG_VALUE 1 /* configuration value */
/* mass storage interface */
#define MS_NUM_INTERFACES 1 /* number of interfaces */
#define MS_INTERFACE_NUM 0 /* interface number */
#define MS_INTERFACE_ALT_SETTING 0 /* alternate setting */
#define MS_ID_VENDOR 0x0781 /* mass storage vendor ID */
/* Use a SanDisk ID so it */
/* works on Windows */
#ifdef MS_USE_DMA_ENDPOINT
#define MS_BULK_MAX_PACKETSIZE 8 /* bulk max packet size */
#else
#define MS_BULK_MAX_PACKETSIZE 0x10 /* bulk max packet size */
#endif
#define MS_HIGH_SPEED_CONTROL_MAX_PACKET_SIZE 0x40 /* Maximum packet size for */
/* the default control */
/* endpoint, if the device*/
/* is operating at high */
/* speed */
/* globals */
extern BOOL g_bulkInStallFlag; /* bulk IN flag */
extern BOOL g_bulkOutStallFlag; /* bulk OUT flag */
/* locals */
LOCAL char *g_pStrMfg = ID_STR_MFG_VAL; /* manufacture's name */
LOCAL char *g_pStrProd = ID_STR_PROD_VAL; /* product name */
LOCAL UINT8 g_configuration = 0x0; /* configuration value */
/* zero means device unconfigured */
LOCAL UINT8 g_ifAltSetting = 0x0; /* alternate setting */
LOCAL UINT32 g_uDeviceFeature = 0; /* device feature */
LOCAL UINT32 g_uEndpointNumberBitmap = 0; /* endpoint bitmap */
#ifndef USB1_1
LOCAL UINT32 g_uSpeed = USB_TCD_FULL_SPEED; /* device operating speed */
#endif
LOCAL UINT8 g_uDeviceStatus = 0x01; /* device status */
#ifdef USE_MS_TEST_DATA
LOCAL UINT8 g_usbMsTestData[MS_TEST_DATA_SIZE]; /* test data */
#endif
#ifdef USB_DEBUG_PRINT
LOCAL char g_buf[BUF_SIZE]; /* buffer to hold data */
LOCAL BOOL g_usbDbgPrint = FALSE; /* debug flag */
#endif
#ifdef USB1_1
LOCAL UINT16 g_numEndpoints; /* number of endpoints */
LOCAL pUSB_TARG_ENDPOINT_INFO g_pEndpoints; /* USB_TARG_ENDPOINT_INFO */
#endif
LOCAL USB_BULK_CBW g_cbw = /* command block wrapper */
{
USB_BULK_SWAP_32 (USB_CBW_SIGNATURE), /* USB signature */
0,
0,
0,
0,
0,
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
};
LOCAL USB_BULK_CSW g_csw = /* command status wrapper */
{
USB_BULK_SWAP_32 (USB_CSW_SIGNATURE),
0,
0,
0
};
/* bulk-In endpoint variables */
LOCAL USB_ERP g_bulkInErp; /* bulk-In ERP */
LOCAL BOOL g_bulkInInUse; /* bulk-In ERP in use flag */
LOCAL BOOL g_bulkInBfrValid; /* bulk-In ERP buffer valid flag */
LOCAL USB_TARG_PIPE g_bulkInPipeHandle; /* bulk-In ERP pipe handle */
LOCAL BOOL g_bulkInStallStatus = FALSE; /*bulk-in stall status */
/* bulk-Out endpoint variables */
LOCAL USB_ERP g_bulkOutErp; /* bulk-out ERP */
LOCAL BOOL g_bulkOutInUse; /* bulk-out ERP in use flag */
LOCAL BOOL g_bulkOutBfrValid; /* bulk-out ERP buffer valid flag */
LOCAL USB_TARG_PIPE g_bulkOutPipeHandle; /* bulk-out ERP pipe handle */
LOCAL BOOL g_bulkOutStallStatus = FALSE; /* bulk-out stall status */
LOCAL USB_TARG_CHANNEL g_targChannel; /* the target channel */
LOCAL UINT16 g_deviceAddr; /* device address */
#ifdef USB1_1
LOCAL BOOL g_remoteDevWakeup = FALSE; /* remote wakeup flag */
#endif
/* descriptor definitions */
LOCAL USB_LANGUAGE_DESCR g_langDescr = /* language descriptor */
{
sizeof (USB_LANGUAGE_DESCR), /* bLength */
USB_DESCR_STRING, /* string descriptor */
{TO_LITTLEW (UNICODE_ENGLISH)} /* unicode */
};
LOCAL USB_DEVICE_DESCR g_devDescr = /* device descriptor */
{
USB_DEVICE_DESCR_LEN, /* bLength */
USB_DESCR_DEVICE, /* bDescriptorType */
TO_LITTLEW (MS_USB_VERSION), /* bcdUsb */
0, /* bDeviceClass */
0, /* bDeviceSubclass */
0, /* bDeviceProtocol */
USB_MIN_CTRL_PACKET_SIZE, /* maxPacketSize0 */
MS_ID_VENDOR, /* idVendor */
0, /* idProduct */
0, /* bcdDevice */
ID_STR_MFG, /* iManufacturer */
ID_STR_PROD, /* iProduct */
0, /* iSerialNumber */
MS_NUM_CONFIG /* bNumConfigurations */
};
LOCAL USB_CONFIG_DESCR g_configDescr = /* configuration descriptor */
{
USB_CONFIG_DESCR_LEN, /* bLength */
USB_DESCR_CONFIGURATION, /* bDescriptorType */
TO_LITTLEW (USB_CONFIG_DESCR_LEN +
USB_INTERFACE_DESCR_LEN +
2*USB_ENDPOINT_DESCR_LEN), /* wTotalLength */
MS_NUM_INTERFACES, /* bNumInterfaces */
MS_CONFIG_VALUE, /* bConfigurationValue */
0, /* iConfiguration */
0x80 | USB_ATTR_SELF_POWERED, /* bmAttributes */
0 /* MaxPower */
};
LOCAL USB_INTERFACE_DESCR g_ifDescr = /* interface descriptor */
{
USB_INTERFACE_DESCR_LEN, /* bLength */
USB_DESCR_INTERFACE, /* bDescriptorType */
MS_INTERFACE_NUM, /* bInterfaceNumber */
MS_INTERFACE_ALT_SETTING, /* bAlternateSetting */
MS_NUM_ENDPOINTS, /* bNumEndpoints */
USB_CLASS_MASS_STORAGE, /* bInterfaceClass */
USB_MS_SUBCLASS, /* bInterfaceSubClass */
USB_INTERFACE_PROTOCOL_BULK_ONLY, /* bInterfaceProtocol */
0 /* iInterface */
};
LOCAL USB_ENDPOINT_DESCR g_bulkOutEpDescr = /* OUT endpoint descriptor */
{
USB_ENDPOINT_DESCR_LEN, /* bLength */
USB_DESCR_ENDPOINT, /* bDescriptorType */
MS_BULK_OUT_ENDPOINT_NUM, /* bEndpointAddress */
USB_ATTR_BULK, /* bmAttributes */
TO_LITTLEW (MS_BULK_MAX_PACKETSIZE),/* max packet size */
0 /* bInterval */
};
LOCAL USB_ENDPOINT_DESCR g_bulkInEpDescr = /* IN endpoint descriptor */
{
USB_ENDPOINT_DESCR_LEN, /* bLength */
USB_DESCR_ENDPOINT, /* bDescriptorType */
MS_BULK_IN_ENDPOINT_NUM, /* bEndpointAddress */
USB_ATTR_BULK, /* bmAttributes */
#ifdef MS_USE_DMA_ENDPOINT
TO_LITTLEW (0x10), /* max packet size */
#else
TO_LITTLEW (MS_BULK_MAX_PACKETSIZE),/* max packet size */
#endif
0 /* bInterval */
};
#ifndef USB1_1
LOCAL USB_DEVICE_QUALIFIER_DESCR g_usbDevQualDescr = /* device qualifier */
{
USB_DEVICE_QUALIFIER_DESCR_LEN, /* size of descriptor */
USB_DESCR_DEVICE_QUALIFIER, /* DEVICE_QUALIFIER type */
TO_LITTLEW(MS_USB_VERSION), /* USB spec. (0x0200) */
0, /* class code */
0, /* subclass code */
0, /* protocol code */
USB_MIN_CTRL_PACKET_SIZE, /* other speed packet size */
0x1, /* number of other speed configs */
0 /* reserved */
};
#endif
/* forward declarations */
#ifdef USE_MS_TEST_DATA
void usbMsTestTxCallback (pVOID p);
void usbMsTestRxCallback (pVOID p);
#endif
/* The USB1_1 macro is for backward compatibility with the USB 1.1 stack */
#ifdef USB1_1 /* USB1.1 */
LOCAL STATUS mngmtFunc (pVOID param, USB_TARG_CHANNEL targChannel,
UINT16 mngmtCode);
#else /* USB2.0 */
LOCAL STATUS mngmtFunc (pVOID param, USB_TARG_CHANNEL targChannel,
UINT16 mngmtCode, pVOID pContext);
#endif
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);
#ifdef USB1_1 /* USB1.1 */
LOCAL STATUS statusGet (pVOID param, USB_TARG_CHANNEL targChannel,
UINT8 requestType, UINT16 index, UINT16 length,
pUINT8 pBfr, pUINT16 pActLen);
#else /* USB2.0 */
LOCAL STATUS statusGet (pVOID param, USB_TARG_CHANNEL targChannel,
UINT16 requestType, UINT16 index, UINT16 length,
pUINT8 pBfr);
#endif
LOCAL STATUS addressSet (pVOID param, USB_TARG_CHANNEL targChannel,
UINT16 deviceAddress);
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 configurationGet (pVOID param, USB_TARG_CHANNEL targChannel,
pUINT8 pConfiguration);
LOCAL STATUS configurationSet (pVOID param, USB_TARG_CHANNEL targChannel,
UINT8 configuration);
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);
void usbMsTargError (void);
LOCAL USB_TARG_CALLBACK_TABLE usbTargMsCallbackTable = /* 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 */
};
/*******************************************************************************
*
* usbMsDevInit - initialize the mass storage driver
*
* This routine initializes the mass storage driver.
*
* RETURNS: OK or error.
*
* ERRNO:
* none.
*
* \NOMANUAL
*/
LOCAL STATUS usbMsDevInit (void)
{
/* initialize the RBC block I/O device */
STATUS retVal = usbTargRbcBlockDevCreate();
return(retVal);
}
/*******************************************************************************
*
* usbMsCBWGet - get the last mass storage CBW received
*
* This routine retrieves the last CBW received on the bulk-out pipe.
*
* RETURNS: USB_BULK_CBW
*
* ERRNO:
* none.
*/
USB_BULK_CBW *usbMsCBWGet (void)
{
/* return instance of last saved CBW data structure */
return(&g_cbw);
}
/*******************************************************************************
*
* usbMsCBWInit - initialize the mass storage CBW
*
* This routine initializes the CBW by resetting all fields to their default
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -