usbBulkDevLib.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:10k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* usbBulkDevLib.h - USB Bulk only Mass Storage class header file */
  2. /* Copyright 1999-2000 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01g,07may01,wef changed module number to be (module num << 8) | M_usbHostLib
  7. 01f,02may01,wef changed module number to be M_<module> + M_usbHostLib
  8. 01e,30mar01,wef added READ10/WRITE10 command
  9. 01d,05dec00,wef moved Module number defs to vwModNum.h - add this
  10.                 to #includes, removed command status codes that lived
  11.                 here and in usbCbiUfiDevLib.h and put into own file in
  12.                 h/usb/usbMassStorage.h
  13. 01c,02sep00,bri added support for multiple devices.
  14. 01b,04aug00,bri updated as per review. 
  15. 01a,22may00,bri created.
  16. */
  17. #ifndef __INCusbBulkDevLibh
  18. #define __INCusbBulkDevLibh
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #ifndef _ASMLANGUAGE
  23. /* includes */
  24. #include "vwModNum.h"           /* USB Module Number Def's */
  25. #include "usb/usbMassStorage.h"     /* Command Status codes */
  26. /* Module number and error code definitions */
  27. /* 
  28.  * USB errnos are defined as being part of the USB host Module, as are all
  29.  * vxWorks module numbers, but the USB Module number is further divided into 
  30.  * sub-modules.  Each sub-module has upto 255 values for its own error codes
  31.  */
  32.  
  33. #define USB_BULK_SUB_MODULE  11
  34. #define M_usbBulkLib  ( (USB_BULK_SUB_MODULE  << 8) | M_usbHostLib )
  35. #define usbBulkErr(x)   (M_usbBulkLib | (x))
  36. #define S_usbBulkDevLib_NOT_INITIALIZED     usbBulkErr (1)
  37. #define S_usbBulkDevLib_BAD_PARAM           usbBulkErr (2)
  38. #define S_usbBulkDevLib_OUT_OF_MEMORY       usbBulkErr (3)
  39. #define S_usbBulkDevLib_OUT_OF_RESOURCES    usbBulkErr (4)
  40. #define S_usbBulkDevLib_GENERAL_FAULT       usbBulkErr (5)
  41. #define S_usbBulkDevLib_QUEUE_FULL          usbBulkErr (6)
  42. #define S_usbBulkDevLib_QUEUE_EMPTY         usbBulkErr (7)
  43. #define S_usbBulkDevLib_NOT_IMPLEMENTED     usbBulkErr (8)
  44. #define S_usbBulkDevLib_USBD_FAULT          usbBulkErr (9)
  45. #define S_usbBulkDevLib_NOT_REGISTERED      usbBulkErr (10)
  46. #define S_usbBulkDevLib_NOT_LOCKED          usbBulkErr (11)
  47. #define USB_CLASS_MASS_STORAGE           0x08 /* USB Mass storage class code */
  48. #define USB_SUBCLASS_SCSI_COMMAND_SET    0x06 /* SCSI command set definition */
  49. #define USB_INTERFACE_PROTOCOL_BULK_ONLY 0x50 /* BULK only interface protocol*/
  50. /* 
  51.  * usbBulkDevIoctl function codes - chosen outside existing IO control 
  52.  * codes supported by file systems
  53.  */
  54. #define USB_BULK_DESCRIPTOR_GET          0xF0 /* Shows all descriptors  */ 
  55. #define USB_BULK_DEV_RESET               0xF1 /* Class-specific reset   */
  56. #define USB_BULK_MAX_LUN                 0xF2 /* Max. LUN on the device */
  57. #define USB_BULK_EJECT_MEDIA             0xF3 /* Eject media command    */
  58. /* Bulk only protocol constants */
  59. #define USB_CBW_SIGNATURE                0x43425355   /* Command block ID  */
  60. #define USB_CBW_TAG                      0xA5A5A5A5   /* Command block Tag */
  61. #define USB_CSW_SIGNATURE                0x53425355   /* Status block ID   */
  62. #define USB_CBW_DIR_NONE                 0x00 /* No direction => no data xfer */  
  63. #define USB_CBW_DIR_OUT                  0x00 /* Direction OUT - to device    */
  64. #define USB_CBW_DIR_IN                   0x80 /* Direction IN  - from device  */
  65. #define USB_CBW_LUN_MASK                 0x0F /* Mask for LUN field in CBW    */
  66. #define USB_CBW_CBLEN_MASK               0x1F /* Mask for Command length field*/
  67. #define USB_CBW_LENGTH                   0x1F /* Length of CBW                */ 
  68. #define USB_CBW_MAX_CBLEN                0x10 /* Max. length of command block */
  69. #define USB_CSW_LENGTH                   0x0D /* Length of CSW                */
  70. /* Status code in CSW */
  71. #define USB_CSW_STATUS_PASS              0x00 /* CBW Command success */ 
  72. #define USB_CSW_STATUS_FAIL              0x01 /* CBW Command failed  */
  73. #define USB_CSW_PHASE_ERROR              0x02 /* Phase Error         */
  74. /* IRP Time out in millisecs */
  75. #define USB_BULK_IRP_TIME_OUT            5000
  76. /* SCSI Commands and related constants */
  77. #define USB_SCSI_WRITE6                  0x0A /* 6-byte WRITE command     */ 
  78. #define USB_SCSI_WRITE10                 0x2A /* 6-byte WRITE command     */ 
  79. #define USB_SCSI_READ6                  0x08 /* 6-byte READ command      */ 
  80. #define USB_SCSI_READ10                  0x28 /* 10-byte READ command      */ 
  81. #define USB_SCSI_INQUIRY                 0x12 /* Standard INQUIRY command */
  82. #define USB_SCSI_START_STOP_UNIT         0x1B /* Start Stop Unit command  */
  83. #define USB_SCSI_REQ_SENSE               0x03 /* REQUEST SENSE data       */ 
  84. #define USB_SCSI_TEST_UNIT_READY         0x00 /* TEST UNIT READY command  */
  85. #define USB_SCSI_READ_CAPACITY           0x25 /* READ CAPACITY command    */
  86. #define USB_SCSI_PREVENT_REMOVAL         0x1E /* Prevent media removal    */
  87. #define USB_SCSI_FORMAT_UNIT             0x04 /* FORMAT UNIT Command      */  
  88. /* specific bit definitions in SCSI commands */
  89. #define USB_SCSI_STD_INQUIRY_LEN         0x24 /* Length of std INQUIRY data */
  90. #define USB_SCSI_REQ_SENSE_LEN           0x0E /* Length of Req Sense data   */
  91. #define USB_SCSI_READ_CAP_LEN            0x08 /* Length of RD_CAP response  */
  92. #define USB_SCSI_INQUIRY_RMB_BIT         0x80 /* Media Type bit             */
  93. #define USB_SCSI_START_STOP_LOEJ         0x02 /* Media load eject bit       */
  94. #define USB_SCSI_START_STOP_START        0x01 /* Media start bit            */
  95. /* definitions with in request sense data */
  96. #define USB_SCSI_SENSE_KEY_OFFSET        0x02 /* Sense key offset in sense   */
  97. #define USB_SCSI_SENSE_ASC               0x0C /* Add'tl sense code offset    */
  98. #define USB_SCSI_SENSE_ASCQ              0x0D /* Add'tl sense code qualifier */ 
  99. #define USB_SCSI_SENSE_CUR_ERR           0x70 /* code for Current Errors     */ 
  100. #define USB_SCSI_SENSE_KEY_MASK          0x0F /* Mask for sense key          */
  101. #define USB_SCSI_KEY_NO_SENSE            0x00 /* No specific sense key       */
  102. #define USB_SCSI_KEY_NOT_READY           0x02 /* Not ready value for key     */
  103. #define USB_SCSI_KEY_UNIT_ATTN           0x06 /* Unit Attn value for key     */
  104. #define USB_SCSI_KEY_HW_ERROR            0x04 /* Hardware Err value for key  */ 
  105. #define USB_SCSI_ASC_NO_MEDIA            0x3A /* Media not present code      */ 
  106. #define USB_SCSI_ASC_RESET               0x29 /* Reset or media change code  */
  107. /* device create flag bits */
  108. /* 
  109.  * The fourth parameter to usbBulkBlkDevCreate is an int inteded to be a bit 
  110.  * field.  The first bit is used to determine which type of SCSI read / write
  111.  * command is used.  All other bits are undefined and available for furture use.
  112.  */
  113. #define USB_SCSI_FLAG_READ_WRITE10 0x00000001 /* READ/WRITE10 */
  114. #define USB_SCSI_FLAG_READ_WRITE6 0x00000000 /* READ/WRITE6 */
  115. /* Class specific commands */
  116. #define USB_BULK_RESET                   0xFF /* Mass storage reset command  */ 
  117. #define USB_BULK_GET_MAX_LUN             0xFE /* Acquire Max. LUN command    */
  118. /* Attach codes used by USB_BULK_ATTACH_CALLBACK. */
  119. #define USB_BULK_ATTACH                 0      /* Bulk-only Device attached  */
  120. #define USB_BULK_REMOVE                 1      /* Bulk-only Device removed   */
  121. /* Swap macros */
  122. /* 
  123.  * SCSI Response is in BIG ENDIAN format. Needs swapping on LITTLE ENDIAN 
  124.  * platforms.
  125.  */
  126. #if (_BYTE_ORDER == _BIG_ENDIAN)
  127. #define USB_SCSI_SWAP_32
  128. #define USB_SCSI_SWAP_16
  129. #else
  130. #define USB_SCSI_SWAP_32(x)  LONGSWAP((UINT)x)
  131. #define USB_SCSI_SWAP_16(x)  ((LSB(x) << 8)|MSB(x))
  132. #endif
  133. /* 
  134.  * Command blocks for Bulk-only devices are in LITTLE ENDIAN format. Need 
  135.  * swapping on BIG ENDIAN platforms.
  136.  */
  137. #if (_BYTE_ORDER == _BIG_ENDIAN)
  138. #define USB_BULK_SWAP_32(x)  LONGSWAP((UINT)x)
  139. #define USB_BULK_SWAP_16(x)  ((LSB(x) << 8)|MSB(x))
  140. #else   /* _BYTE_ORDER == _BIG_ENDIAN   */
  141. #define USB_BULK_SWAP_32   
  142. #define USB_BULK_SWAP_16
  143. #endif  /* _BYTE_ORDER == _BIG_ENDIAN   */
  144. /* command block wrapper */
  145. typedef struct usbBulkCbw
  146.     {
  147.     UINT32 signature;              /* CBW Signature */
  148.     UINT32 tag;                    /* Tag field     */
  149.     UINT32 dataXferLength;         /* Size of data (bytes) */
  150.     UINT8 direction;              /* direction bit */
  151.     UINT8 lun;                    /* Logical Unit Number */
  152.     UINT8 length;                 /* Length of command block */
  153.     UINT8 CBD [USB_CBW_MAX_CBLEN];/* buffer for command block */
  154.     } USB_BULK_CBW, *pUSB_BULK_CBW;
  155. typedef struct usbBulkCsw
  156.     {
  157.     UINT32 signature;              /* CBW Signature */
  158.     UINT32 tag;                    /* Tag field  */
  159.     UINT32 dataResidue;            /* Size of residual data(bytes) */
  160.     UINT8 status;                 /* buffer for command block */
  161.     } USB_BULK_CSW, *pUSB_BULK_CSW;
  162. /* USB_BULK_ATTACH_CALLBACK defines a callback routine which will be
  163.  * invoked by usbBulkDevLib.c when the attachment or removal of a MSC/SCSI/
  164.  * BULK-ONLY device is detected.  When the callback is invoked with an attach 
  165.  * code of USB_BULK_ATTACH, the nodeId represents the ID of newly added device.
  166.  * When the attach code is USB_BULK_REMOVE, nodeId points to the Bulk-only device 
  167.  * which is no longer attached.
  168.  */
  169. typedef VOID (*USB_BULK_ATTACH_CALLBACK) 
  170.     (
  171.     pVOID arg,           /* caller-defined argument           */
  172.     USBD_NODE_ID nodeId, /* nodeId of the bulk-only device    */
  173.     UINT16 attachCode    /* attach or remove code             */
  174.     );
  175. /* function prototypes */
  176. STATUS usbBulkDevInit (void);
  177. STATUS usbBulkDevShutDown (int errCode);
  178. STATUS usbBulkDynamicAttachRegister ( USB_BULK_ATTACH_CALLBACK callback, 
  179.                                         pVOID arg);
  180. BLK_DEV *usbBulkBlkDevCreate (USBD_NODE_ID nodeId, UINT32 numBlks, 
  181.                               UINT32 blkOffset, UINT32 flags);
  182. STATUS usbBulkDevIoctl (BLK_DEV * pBlkDev, int request, int someArg); 
  183. STATUS usbBulkDynamicAttachUnregister ( USB_BULK_ATTACH_CALLBACK callback,
  184.                                         pVOID arg);
  185. STATUS usbBulkDevLock (USBD_NODE_ID nodeId);
  186. STATUS usbBulkDevUnlock (USBD_NODE_ID nodeId);
  187. #endif /* _ASMLANGUAGE */
  188. #ifdef __cplusplus
  189. }
  190. #endif /* __cplusplus */
  191. #endif /* __INCusbBulkDevLibh */