usb_tmc.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * @file
  3. * @brief USB TMC Class public header
  4. *
  5. */
  6. #ifndef _USB_TMC_H_
  7. #define _USB_TMC_H_
  8. /**@addtogroup MODULE_TMC USB TMC class
  9. * @brief This module contains USB Device Test and Measurement Class definitions.
  10. * @details This module based on
  11. * [USB Device Test and Measurement Class Specification, Revision 1.0]
  12. * (https://www.usb.org/sites/default/files/USBTMC_1_006a.zip)
  13. * @{*/
  14. /**@name USB TMC class, subclass and protocol definitions
  15. * @{*/
  16. #define TMC_SUBCLASS_TMC 0x03
  17. #define TMC_PROTOCOL_NONE 0x00 /**< No subclass specification applies. */
  18. #define TMC_PROTOCOL_USB488 0x01 /**< USBTMC USB488 subclass interface. */
  19. /** @}*/
  20. /**@name USBTMC requests
  21. * @{*/
  22. #define TMC_REQUEST_INITIATE_ABORT_BULK_OUT 1
  23. #define TMC_REQUEST_CHECK_ABORT_BULK_OUT_STATUS 2
  24. #define TMC_REQUEST_INITIATE_ABORT_BULK_IN 3
  25. #define TMC_REQUEST_CHECK_ABORT_BULK_IN_STATUS 4
  26. #define TMC_REQUEST_INITIATE_CLEAR 5
  27. #define TMC_REQUEST_CHECK_CLEAR_STATUS 6
  28. #define TMC_REQUEST_GET_CAPABILITIES 7
  29. #define TMC_REQUEST_INDICATOR_PULSE 64
  30. /**@}*/
  31. /**@name USBTMC status values
  32. * @{*/
  33. #define TMC_STATUS_SUCCESS 0x01
  34. #define TMC_STATUS_PENDING 0x02
  35. #define TMC_STATUS_FAILED 0x80
  36. #define TMC_STATUS_TRANSFER_NOT_IN_PROGRESS 0x81
  37. #define TMC_STATUS_SPLIT_NOT_IN_PROGRESS 0x82
  38. #define TMC_STATUS_SPLIT_IN_PROGRESS 0x83
  39. /**@}*/
  40. /** GET_CAPABILITIES request response */
  41. struct tmc_get_capabilities_response {
  42. uint8_t USBTMC_status;
  43. uint8_t Reserved0;
  44. uint16_t bcdUSBTMC;
  45. uint8_t InterfaceCapabilities;
  46. uint8_t DeviceCapabilities;
  47. uint8_t Reserved1[18];
  48. } __PACKED;
  49. /**@name MsgId values
  50. * @{*/
  51. #define TMC_DEV_DEP_MSG_OUT 1
  52. #define TMC_REQUEST_DEV_DEP_MSG_IN 2
  53. #define TMC_DEV_DEP_MSG_IN 2
  54. #define TMC_VENDOR_SPECIFIC_OUT 126
  55. #define TMC_REQUEST_VENDOR_SPECIFIC_IN 127
  56. #define TMC_VENDOR_SPECIFIC_IN 127
  57. /**@}*/
  58. /**@name Transfer Attributes
  59. * @{*/
  60. /** The last USBTMC message data byte in the transfer is the last byte of the
  61. * USBTMC message. */
  62. #define TMC_TRANSFER_ATTR_EOM 0x01
  63. /** The Bulk-IN transfer must terminate on the specified TermChar. The Host may
  64. * only set this bit if the USBTMC interface indicates it supports TermChar in
  65. * the GET_CAPABILITIES response packet */
  66. #define TMC_TRANSFER_ATTR_TERM_CHAR 0x02
  67. /**@}*/
  68. /** Message specific part of bulk header */
  69. union usb_tmc_bulk_header_specific {
  70. struct {
  71. uint32_t TransferSize;
  72. uint8_t bmTransferAttributes;
  73. uint8_t Reserved[3];
  74. } dev_dep_msg_out;
  75. struct {
  76. uint32_t TransferSize;
  77. uint8_t bmTransferAttributes;
  78. uint8_t TermChar;
  79. uint8_t Reserved[2];
  80. } request_dev_dep_msg_in;
  81. struct {
  82. uint32_t TransferSize;
  83. uint8_t bmTransferAttributes;
  84. uint8_t Reserved[3];
  85. } dev_dep_msg_in;
  86. struct {
  87. uint32_t TransferSize;
  88. uint8_t Reserved[4];
  89. } vendor_specific_out;
  90. struct {
  91. uint32_t TransferSize;
  92. uint8_t Reserved[4];
  93. } request_vendor_specific_in;
  94. struct {
  95. uint32_t TransferSize;
  96. uint8_t Reserved[4];
  97. } vendor_specific_in;
  98. };
  99. /** Host must begin the first USB transaction in each Bulk transfer of
  100. * command message content with a Bulk Header. */
  101. struct usb_tmc_bulk_header {
  102. /** Specifies the USBTMC message and the type of the USBTMC message. */
  103. uint8_t MsgId;
  104. /** A transfer identifier. The Host must set bTag different than the
  105. * bTag used in the previous Bulk-OUT Header. The Host should increment
  106. * the bTag by 1 each time it sends a new Bulk-OUT Header. */
  107. uint8_t bTag;
  108. /** The inverse (one's complement) of the bTag */
  109. uint8_t bTagInverse;
  110. uint8_t Reserved;
  111. /** USBTMC command message specific */
  112. union usb_tmc_bulk_header_specific MsgSpecific;
  113. } __PACKED;
  114. #endif /* _USB_TMC_H_ */