usb_common.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2012-10-01 Yi Qiu first version
  9. * 2013-04-26 aozima add DEVICEQUALIFIER support.
  10. * 2017-11-15 ZYH fix ep0 transform error
  11. */
  12. #ifndef __USB_COMMON_H__
  13. #define __USB_COMMON_H__
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #include <rtthread.h>
  18. #define RT_DEBUG_USB 0x00
  19. #define USB_DYNAMIC 0x00
  20. #define USB_CLASS_DEVICE 0x00
  21. #define USB_CLASS_AUDIO 0x01
  22. #define USB_CLASS_CDC 0x02
  23. #define USB_CLASS_HID 0x03
  24. #define USB_CLASS_PHYSICAL 0x05
  25. #define USB_CLASS_IMAGE 0x06
  26. #define USB_CLASS_PRINTER 0x07
  27. #define USB_CLASS_MASS_STORAGE 0x08
  28. #define USB_CLASS_HUB 0x09
  29. #define USB_CLASS_CDC_DATA 0x0a
  30. #define USB_CLASS_SMART_CARD 0x0b
  31. #define USB_CLASS_SECURITY 0x0d
  32. #define USB_CLASS_VIDEO 0x0e
  33. #define USB_CLASS_HEALTHCARE 0x0f
  34. #define USB_CLASS_DIAG_DEVICE 0xdc
  35. #define USB_CLASS_WIRELESS 0xe0
  36. #define USB_CLASS_MISC 0xef
  37. #define USB_CLASS_APP_SPECIFIC 0xfe
  38. #define USB_CLASS_VEND_SPECIFIC 0xff
  39. #define USB_DESC_TYPE_DEVICE 0x01
  40. #define USB_DESC_TYPE_CONFIGURATION 0x02
  41. #define USB_DESC_TYPE_STRING 0x03
  42. #define USB_DESC_TYPE_INTERFACE 0x04
  43. #define USB_DESC_TYPE_ENDPOINT 0x05
  44. #define USB_DESC_TYPE_DEVICEQUALIFIER 0x06
  45. #define USB_DESC_TYPE_OTHERSPEED 0x07
  46. #define USB_DESC_TYPE_IAD 0x0b
  47. #define USB_DESC_TYPE_HID 0x21
  48. #define USB_DESC_TYPE_REPORT 0x22
  49. #define USB_DESC_TYPE_PHYSICAL 0x23
  50. #define USB_DESC_TYPE_HUB 0x29
  51. #define USB_DESC_LENGTH_DEVICE 0x12
  52. #define USB_DESC_LENGTH_CONFIG 0x9
  53. #define USB_DESC_LENGTH_IAD 0x8
  54. #define USB_DESC_LENGTH_STRING 0x4
  55. #define USB_DESC_LENGTH_INTERFACE 0x9
  56. #define USB_DESC_LENGTH_ENDPOINT 0x7
  57. #define USB_REQ_TYPE_STANDARD 0x00
  58. #define USB_REQ_TYPE_CLASS 0x20
  59. #define USB_REQ_TYPE_VENDOR 0x40
  60. #define USB_REQ_TYPE_MASK 0x60
  61. #define USB_REQ_TYPE_DIR_OUT 0x00
  62. #define USB_REQ_TYPE_DIR_IN 0x80
  63. #define USB_REQ_TYPE_DEVICE 0x00
  64. #define USB_REQ_TYPE_INTERFACE 0x01
  65. #define USB_REQ_TYPE_ENDPOINT 0x02
  66. #define USB_REQ_TYPE_OTHER 0x03
  67. #define USB_REQ_TYPE_RECIPIENT_MASK 0x1f
  68. #define USB_FEATURE_ENDPOINT_HALT 0x00
  69. #define USB_FEATURE_DEV_REMOTE_WAKEUP 0x01
  70. #define USB_FEATURE_TEST_MODE 0x02
  71. #define USB_REQ_GET_STATUS 0x00
  72. #define USB_REQ_CLEAR_FEATURE 0x01
  73. #define USB_REQ_SET_FEATURE 0x03
  74. #define USB_REQ_SET_ADDRESS 0x05
  75. #define USB_REQ_GET_DESCRIPTOR 0x06
  76. #define USB_REQ_SET_DESCRIPTOR 0x07
  77. #define USB_REQ_GET_CONFIGURATION 0x08
  78. #define USB_REQ_SET_CONFIGURATION 0x09
  79. #define USB_REQ_GET_INTERFACE 0x0A
  80. #define USB_REQ_SET_INTERFACE 0x0B
  81. #define USB_REQ_SYNCH_FRAME 0x0C
  82. #define USB_REQ_SET_ENCRYPTION 0x0D
  83. #define USB_REQ_GET_ENCRYPTION 0x0E
  84. #define USB_REQ_RPIPE_ABORT 0x0E
  85. #define USB_REQ_SET_HANDSHAKE 0x0F
  86. #define USB_REQ_RPIPE_RESET 0x0F
  87. #define USB_REQ_GET_HANDSHAKE 0x10
  88. #define USB_REQ_SET_CONNECTION 0x11
  89. #define USB_REQ_SET_SECURITY_DATA 0x12
  90. #define USB_REQ_GET_SECURITY_DATA 0x13
  91. #define USB_REQ_SET_WUSB_DATA 0x14
  92. #define USB_REQ_LOOPBACK_DATA_WRITE 0x15
  93. #define USB_REQ_LOOPBACK_DATA_READ 0x16
  94. #define USB_REQ_SET_INTERFACE_DS 0x17
  95. #define USB_STRING_LANGID_INDEX 0x00
  96. #define USB_STRING_MANU_INDEX 0x01
  97. #define USB_STRING_PRODUCT_INDEX 0x02
  98. #define USB_STRING_SERIAL_INDEX 0x03
  99. #define USB_STRING_CONFIG_INDEX 0x04
  100. #define USB_STRING_INTERFACE_INDEX 0x05
  101. #define USB_STRING_OS_INDEX 0x06
  102. #define USB_STRING_MAX USB_STRING_OS_INDEX
  103. #define USB_STRING_OS "MSFT100A"
  104. #define USB_PID_OUT 0x01
  105. #define USB_PID_ACK 0x02
  106. #define USB_PID_DATA0 0x03
  107. #define USB_PID_SOF 0x05
  108. #define USB_PID_IN 0x09
  109. #define USB_PID_NACK 0x0A
  110. #define USB_PID_DATA1 0x0B
  111. #define USB_PID_PRE 0x0C
  112. #define USB_PID_SETUP 0x0D
  113. #define USB_PID_STALL 0x0E
  114. #define USB_EP_DESC_OUT 0x00
  115. #define USB_EP_DESC_IN 0x80
  116. #define USB_EP_DESC_NUM_MASK 0x0f
  117. #define USB_EP_ATTR_CONTROL 0x00
  118. #define USB_EP_ATTR_ISOC 0x01
  119. #define USB_EP_ATTR_BULK 0x02
  120. #define USB_EP_ATTR_INT 0x03
  121. #define USB_EP_ATTR_TYPE_MASK 0x03
  122. #define USB_EPNO_MASK 0x7f
  123. #define USB_DIR_OUT 0x00
  124. #define USB_DIR_IN 0x80
  125. #define USB_DIR_INOUT 0x40
  126. #define USB_DIR_MASK 0x80
  127. #define ID_UNASSIGNED 0
  128. #define ID_ASSIGNED 1
  129. #define RH_GET_PORT_STATUS 0
  130. #define RH_SET_PORT_STATUS 1
  131. #define RH_CLEAR_PORT_FEATURE 2
  132. #define RH_SET_PORT_FEATURE 3
  133. #define USB_BUS_POWERED 0
  134. #define USB_SELF_POWERED 1
  135. #define USB_REMOTE_WAKEUP 1
  136. #define USB_EP_HALT 0
  137. /*
  138. * Port feature numbers
  139. */
  140. #define PORT_FEAT_CONNECTION 0
  141. #define PORT_FEAT_ENABLE 1
  142. #define PORT_FEAT_SUSPEND 2
  143. #define PORT_FEAT_OVER_CURRENT 3
  144. #define PORT_FEAT_RESET 4
  145. #define PORT_FEAT_POWER 8
  146. #define PORT_FEAT_LOWSPEED 9
  147. #define PORT_FEAT_HIGHSPEED 10
  148. #define PORT_FEAT_C_CONNECTION 16
  149. #define PORT_FEAT_C_ENABLE 17
  150. #define PORT_FEAT_C_SUSPEND 18
  151. #define PORT_FEAT_C_OVER_CURRENT 19
  152. #define PORT_FEAT_C_RESET 20
  153. /*
  154. The HcRhPortStatus[1:NDP] register is used to control and report port events on a per-port
  155. basis. NumberDownstreamPorts represents the number of HcRhPortStatus registers that are
  156. implemented in hardware. The lower word is used to reflect the port status, whereas the upper
  157. word reflects the status change bits. Some status bits are implemented with special write behavior
  158. (see below). If a transaction (token through handshake) is in progress when a write to change
  159. port status occurs, the resulting port status change must be postponed until the transaction
  160. completes. Reserved bits should always be written '0'.
  161. */
  162. #define PORT_CCS 0x00000001UL /* R:CurrentConnectStatus - W:ClearPortEnable */
  163. #define PORT_PES 0x00000002UL /* R:PortEnableStatus - W:SetPortEnable */
  164. #define PORT_PSS 0x00000004UL /* R:PortSuspendStatus - W:SetPortSuspend */
  165. #define PORT_POCI 0x00000008UL /* R:PortOverCurrentIndicator - W:ClearSuspendStatus */
  166. #define PORT_PRS 0x00000010UL /* R:PortResetStatus - W: SetPortReset */
  167. #define PORT_PPS 0x00000100UL /* R:PortPowerStatus - W: SetPortPower */
  168. #define PORT_LSDA 0x00000200UL /* R:LowSpeedDeviceAttached - W:ClearPortPower */
  169. #define PORT_CCSC 0x00010000UL
  170. #define PORT_PESC 0x00020000UL
  171. #define PORT_PSSC 0x00040000UL
  172. #define PORT_POCIC 0x00080000UL
  173. #define PORT_PRSC 0x00100000UL
  174. /*
  175. *Hub Status & Hub Change bit masks
  176. */
  177. #define HUB_STATUS_LOCAL_POWER 0x0001
  178. #define HUB_STATUS_OVERCURRENT 0x0002
  179. #define HUB_CHANGE_LOCAL_POWER 0x0001
  180. #define HUB_CHANGE_OVERCURRENT 0x0002
  181. #define USB_EP_ATTR(attr) (attr & USB_EP_ATTR_TYPE_MASK)
  182. #define USB_EP_DESC_NUM(addr) (addr & USB_EP_DESC_NUM_MASK)
  183. #define USB_EP_DIR(addr) ((addr & USB_DIR_MASK)>>7)
  184. #define HID_REPORT_ID_KEYBOARD1 1
  185. #define HID_REPORT_ID_KEYBOARD2 2
  186. #define HID_REPORT_ID_KEYBOARD3 3
  187. #define HID_REPORT_ID_KEYBOARD4 7
  188. #define HID_REPORT_ID_MEDIA 4
  189. #define HID_REPORT_ID_GENERAL 5
  190. #define HID_REPORT_ID_MOUSE 6
  191. #define uswap_32(x) \
  192. ((((x) & 0xff000000) >> 24) | \
  193. (((x) & 0x00ff0000) >> 8) | \
  194. (((x) & 0x0000ff00) << 8) | \
  195. (((x) & 0x000000ff) << 24))
  196. #define uswap_8(x) \
  197. (((rt_uint16_t)(*((rt_uint8_t *)(x)))) + \
  198. (((rt_uint16_t)(*(((rt_uint8_t *)(x)) + 1))) << 8))
  199. typedef void (*func_callback)(void *context);
  200. typedef enum
  201. {
  202. USB_STATE_NOTATTACHED = 0,
  203. USB_STATE_ATTACHED,
  204. USB_STATE_POWERED,
  205. USB_STATE_RECONNECTING,
  206. USB_STATE_UNAUTHENTICATED,
  207. USB_STATE_DEFAULT,
  208. USB_STATE_ADDRESS,
  209. USB_STATE_CONFIGURED,
  210. USB_STATE_SUSPENDED
  211. }udevice_state_t;
  212. typedef enum
  213. {
  214. STAGE_IDLE,
  215. STAGE_SETUP,
  216. STAGE_STATUS_IN,
  217. STAGE_STATUS_OUT,
  218. STAGE_DIN,
  219. STAGE_DOUT
  220. } uep0_stage_t;
  221. #pragma pack(1)
  222. struct usb_descriptor
  223. {
  224. rt_uint8_t bLength;
  225. rt_uint8_t type;
  226. };
  227. typedef struct usb_descriptor* udesc_t;
  228. struct udevice_descriptor
  229. {
  230. rt_uint8_t bLength;
  231. rt_uint8_t type;
  232. rt_uint16_t bcdUSB;
  233. rt_uint8_t bDeviceClass;
  234. rt_uint8_t bDeviceSubClass;
  235. rt_uint8_t bDeviceProtocol;
  236. rt_uint8_t bMaxPacketSize0;
  237. rt_uint16_t idVendor;
  238. rt_uint16_t idProduct;
  239. rt_uint16_t bcdDevice;
  240. rt_uint8_t iManufacturer;
  241. rt_uint8_t iProduct;
  242. rt_uint8_t iSerialNumber;
  243. rt_uint8_t bNumConfigurations;
  244. };
  245. typedef struct udevice_descriptor* udev_desc_t;
  246. struct uconfig_descriptor
  247. {
  248. rt_uint8_t bLength;
  249. rt_uint8_t type;
  250. rt_uint16_t wTotalLength;
  251. rt_uint8_t bNumInterfaces;
  252. rt_uint8_t bConfigurationValue;
  253. rt_uint8_t iConfiguration;
  254. rt_uint8_t bmAttributes;
  255. rt_uint8_t MaxPower;
  256. rt_uint8_t data[256];
  257. };
  258. typedef struct uconfig_descriptor* ucfg_desc_t;
  259. struct uinterface_descriptor
  260. {
  261. rt_uint8_t bLength;
  262. rt_uint8_t type;
  263. rt_uint8_t bInterfaceNumber;
  264. rt_uint8_t bAlternateSetting;
  265. rt_uint8_t bNumEndpoints;
  266. rt_uint8_t bInterfaceClass;
  267. rt_uint8_t bInterfaceSubClass;
  268. rt_uint8_t bInterfaceProtocol;
  269. rt_uint8_t iInterface;
  270. };
  271. typedef struct uinterface_descriptor* uintf_desc_t;
  272. /* Interface Association Descriptor (IAD) */
  273. struct uiad_descriptor
  274. {
  275. rt_uint8_t bLength;
  276. rt_uint8_t bDescriptorType;
  277. rt_uint8_t bFirstInterface;
  278. rt_uint8_t bInterfaceCount;
  279. rt_uint8_t bFunctionClass;
  280. rt_uint8_t bFunctionSubClass;
  281. rt_uint8_t bFunctionProtocol;
  282. rt_uint8_t iFunction;
  283. };
  284. typedef struct uiad_descriptor* uiad_desc_t;
  285. struct uendpoint_descriptor
  286. {
  287. rt_uint8_t bLength;
  288. rt_uint8_t type;
  289. rt_uint8_t bEndpointAddress;
  290. rt_uint8_t bmAttributes;
  291. rt_uint16_t wMaxPacketSize;
  292. rt_uint8_t bInterval;
  293. };
  294. typedef struct uendpoint_descriptor* uep_desc_t;
  295. struct ustring_descriptor
  296. {
  297. rt_uint8_t bLength;
  298. rt_uint8_t type;
  299. rt_uint8_t String[64];
  300. };
  301. typedef struct ustring_descriptor* ustr_desc_t;
  302. struct uhub_descriptor
  303. {
  304. rt_uint8_t length;
  305. rt_uint8_t type;
  306. rt_uint8_t num_ports;
  307. rt_uint16_t characteristics;
  308. rt_uint8_t pwron_to_good; /* power on to power good */
  309. rt_uint8_t current;
  310. rt_uint8_t removable[8];
  311. rt_uint8_t pwr_ctl[8];
  312. };
  313. typedef struct uhub_descriptor* uhub_desc_t;
  314. /* USB_DESC_TYPE_DEVICEQUALIFIER: Device Qualifier descriptor */
  315. struct usb_qualifier_descriptor
  316. {
  317. rt_uint8_t bLength;
  318. rt_uint8_t bDescriptorType;
  319. rt_uint16_t bcdUSB; // TODO: big-endian.
  320. rt_uint8_t bDeviceClass;
  321. rt_uint8_t bDeviceSubClass;
  322. rt_uint8_t bDeviceProtocol;
  323. rt_uint8_t bMaxPacketSize0;
  324. rt_uint8_t bNumConfigurations;
  325. rt_uint8_t bRESERVED;
  326. } __attribute__ ((packed));
  327. struct usb_os_header_comp_id_descriptor
  328. {
  329. rt_uint32_t dwLength;
  330. rt_uint16_t bcdVersion;
  331. rt_uint16_t wIndex;
  332. rt_uint8_t bCount;
  333. rt_uint8_t reserved[7];
  334. };
  335. typedef struct usb_os_header_comp_id_descriptor * usb_os_header_desc_t;
  336. struct usb_os_function_comp_id_descriptor
  337. {
  338. rt_list_t list;
  339. rt_uint8_t bFirstInterfaceNumber;
  340. rt_uint8_t reserved1;
  341. rt_uint8_t compatibleID[8];
  342. rt_uint8_t subCompatibleID[8];
  343. rt_uint8_t reserved2[6];
  344. };
  345. typedef struct usb_os_function_comp_id_descriptor * usb_os_func_comp_id_desc_t;
  346. struct usb_os_comp_id_descriptor
  347. {
  348. struct usb_os_header_comp_id_descriptor head_desc;
  349. rt_list_t func_desc;
  350. };
  351. typedef struct usb_os_comp_id_descriptor * usb_os_comp_id_desc_t;
  352. struct usb_os_property_header
  353. {
  354. rt_uint32_t dwLength;
  355. rt_uint16_t bcdVersion;
  356. rt_uint16_t wIndex;
  357. rt_uint16_t wCount;
  358. };
  359. typedef struct usb_os_property_header * usb_os_property_header_t;
  360. struct usb_os_proerty
  361. {
  362. rt_uint32_t dwSize;
  363. rt_uint32_t dwPropertyDataType;
  364. rt_uint16_t wPropertyNameLength;
  365. const char * bPropertyName;
  366. rt_uint32_t dwPropertyDataLength;
  367. const char * bPropertyData;
  368. };
  369. typedef struct usb_os_proerty * usb_os_proerty_t;
  370. // Value Description
  371. // 1 A NULL-terminated Unicode String (REG_SZ)
  372. // 2 A NULL-terminated Unicode String that includes environment variables (REG_EXPAND_SZ)
  373. // 3 Free-form binary (REG_BINARY)
  374. // 4 A little-endian 32-bit integer (REG_DWORD_LITTLE_ENDIAN)
  375. // 5 A big-endian 32-bit integer (REG_DWORD_BIG_ENDIAN)
  376. // 6 A NULL-terminated Unicode string that contains a symbolic link (REG_LINK)
  377. // 7 Multiple NULL-terminated Unicode strings (REG_MULTI_SZ)
  378. #define USB_OS_PROERTY_TYPE_REG_SZ 0x01UL
  379. #define USB_OS_PROERTY_TYPE_REG_EXPAND_SZ 0x02UL
  380. #define USB_OS_PROERTY_TYPE_REG_BINARY 0x03UL
  381. #define USB_OS_PROERTY_TYPE_REG_DWORD_LITTLE_ENDIAN 0x04UL
  382. #define USB_OS_PROERTY_TYPE_REG_DWORD_BIG_ENDIAN 0x05UL
  383. #define USB_OS_PROERTY_TYPE_REG_LINK 0x06UL
  384. #define USB_OS_PROERTY_TYPE_REG_MULTI_SZ 0x07UL
  385. #define USB_OS_PROERTY_DESC(PropertyDataType,PropertyName,PropertyData) \
  386. {\
  387. .dwSize = sizeof(struct usb_os_proerty)-sizeof(const char *)*2\
  388. +sizeof(PropertyName)*2+sizeof(PropertyData)*2,\
  389. .dwPropertyDataType = PropertyDataType,\
  390. .wPropertyNameLength = sizeof(PropertyName)*2,\
  391. .bPropertyName = PropertyName,\
  392. .dwPropertyDataLength = sizeof(PropertyData)*2,\
  393. .bPropertyData = PropertyData\
  394. }
  395. #ifndef HID_SUB_DESCRIPTOR_MAX
  396. #define HID_SUB_DESCRIPTOR_MAX 1
  397. #endif
  398. struct uhid_descriptor
  399. {
  400. rt_uint8_t bLength;
  401. rt_uint8_t type;
  402. rt_uint16_t bcdHID;
  403. rt_uint8_t bCountryCode;
  404. rt_uint8_t bNumDescriptors;
  405. struct hid_descriptor_list
  406. {
  407. rt_uint8_t type;
  408. rt_uint16_t wLength;
  409. }Descriptor[HID_SUB_DESCRIPTOR_MAX];
  410. };
  411. typedef struct uhid_descriptor* uhid_desc_t;
  412. struct hid_report
  413. {
  414. rt_uint8_t report_id;
  415. rt_uint8_t report[63];
  416. rt_uint8_t size;
  417. };
  418. typedef struct hid_report* hid_report_t;
  419. extern void HID_Report_Received(hid_report_t report);
  420. struct urequest
  421. {
  422. rt_uint8_t request_type;
  423. rt_uint8_t bRequest;
  424. rt_uint16_t wValue;
  425. rt_uint16_t wIndex;
  426. rt_uint16_t wLength;
  427. };
  428. typedef struct urequest* ureq_t;
  429. #ifndef MIN
  430. #define MIN(a, b) (a < b ? a : b)
  431. #endif
  432. #ifndef MAX
  433. #define MAX(a, b) (a > b ? a : b)
  434. #endif
  435. /*
  436. * the define related to mass storage
  437. */
  438. #define USBREQ_GET_MAX_LUN 0xfe
  439. #define USBREQ_MASS_STORAGE_RESET 0xff
  440. #define SIZEOF_CSW 0x0d
  441. #define SIZEOF_CBW 0x1f
  442. #define SIZEOF_INQUIRY_CMD 0x24
  443. #define SIZEOF_MODE_SENSE_6 0x4
  444. #define SIZEOF_READ_CAPACITIES 0xc
  445. #define SIZEOF_READ_CAPACITY 0x8
  446. #define SIZEOF_REQUEST_SENSE 0x12
  447. #define CBWFLAGS_DIR_M 0x80
  448. #define CBWFLAGS_DIR_IN 0x80
  449. #define CBWFLAGS_DIR_OUT 0x00
  450. #define SCSI_TEST_UNIT_READY 0x00
  451. #define SCSI_REQUEST_SENSE 0x03
  452. #define SCSI_INQUIRY_CMD 0x12
  453. #define SCSI_ALLOW_REMOVAL 0x1e
  454. #define SCSI_MODE_SENSE_6 0x1a
  455. #define SCSI_START_STOP 0x1b
  456. #define SCSI_READ_CAPACITIES 0x23
  457. #define SCSI_READ_CAPACITY 0x25
  458. #define SCSI_READ_10 0x28
  459. #define SCSI_WRITE_10 0x2a
  460. #define SCSI_VERIFY_10 0x2f
  461. #define CBW_SIGNATURE 0x43425355
  462. #define CSW_SIGNATURE 0x53425355
  463. #define CBW_TAG_VALUE 0x12345678
  464. struct ustorage_cbw
  465. {
  466. rt_uint32_t signature;
  467. rt_uint32_t tag;
  468. rt_uint32_t xfer_len;
  469. rt_uint8_t dflags;
  470. rt_uint8_t lun;
  471. rt_uint8_t cb_len;
  472. rt_uint8_t cb[16];
  473. };
  474. typedef struct ustorage_cbw* ustorage_cbw_t;
  475. struct ustorage_csw
  476. {
  477. rt_uint32_t signature;
  478. rt_uint32_t tag;
  479. rt_int32_t data_reside;
  480. rt_uint8_t status;
  481. };
  482. typedef struct ustorage_csw* ustorage_csw_t;
  483. #pragma pack()
  484. /*
  485. * USB device event loop thread configurations
  486. */
  487. /* the stack size of USB thread */
  488. #ifndef RT_USBD_THREAD_STACK_SZ
  489. #define RT_USBD_THREAD_STACK_SZ 512
  490. #endif
  491. /* the priority of USB thread */
  492. #ifndef RT_USBD_THREAD_PRIO
  493. #define RT_USBD_THREAD_PRIO 8
  494. #endif
  495. #ifdef __cplusplus
  496. }
  497. #endif
  498. #endif