mikroSDK Reference Manual
usbtmc.h
1
2/*
3 * The MIT License (MIT)
4 *
5 * Copyright (c) 2019 N Conrad
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 *
25 * This file is part of the TinyUSB stack.
26 */
27
28#ifndef _TUSB_USBTMC_H__
29#define _TUSB_USBTMC_H__
30
31#include "common/tusb_common.h"
32
33
34/* Implements USBTMC Revision 1.0, April 14, 2003
35
36 String descriptors must have a "LANGID=0x409"/US English string.
37 Characters must be 0x20 (' ') to 0x7E ('~') ASCII,
38 But MUST not contain: "/:?\*
39 Also must not have leading or trailing space (' ')
40 Device descriptor must state USB version 0x0200 or greater
41
42 If USB488DeviceCapabilites.D2 = 1 (SR1), then there must be a INT endpoint.
43*/
44
45#define USBTMC_VERSION 0x0100
46#define USBTMC_488_VERSION 0x0100
47
48typedef enum {
49 USBTMC_MSGID_DEV_DEP_MSG_OUT = 1u,
50 USBTMC_MSGID_DEV_DEP_MSG_IN = 2u,
51 USBTMC_MSGID_VENDOR_SPECIFIC_MSG_OUT = 126u,
52 USBTMC_MSGID_VENDOR_SPECIFIC_IN = 127u,
53 USBTMC_MSGID_USB488_TRIGGER = 128u,
54} usbtmc_msgid_enum;
55
57typedef struct TU_ATTR_PACKED
58{
59 uint8_t MsgID ;
60 uint8_t bTag ;
61 uint8_t bTagInverse ;
62 uint8_t _reserved ;
64
65typedef struct TU_ATTR_PACKED
66{
68 uint8_t data[8];
70
71/* Uses on the bulk-out endpoint: */
72// Next 8 bytes are message-specific
73typedef struct TU_ATTR_PACKED {
75 uint32_t TransferSize ;
76 struct TU_ATTR_PACKED
77 {
78 unsigned int EOM : 1 ;
79 } bmTransferAttributes;
80 uint8_t _reserved[3];
82
83TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_dev_dep_out) == 12u, "struct wrong length");
84
85// Next 8 bytes are message-specific
86typedef struct TU_ATTR_PACKED
87{
89 uint32_t TransferSize ;
90 struct TU_ATTR_PACKED
91 {
92 unsigned int TermCharEnabled : 1 ;
93 } bmTransferAttributes;
94 uint8_t TermChar;
95 uint8_t _reserved[2];
97
98TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_dev_dep_in) == 12u, "struct wrong length");
99
100/* Bulk-in headers */
101
102typedef struct TU_ATTR_PACKED
103{
105 uint32_t TransferSize;
106 struct TU_ATTR_PACKED
107 {
108 uint8_t EOM: 1;
109 uint8_t UsingTermChar: 1;
110 } bmTransferAttributes;
111 uint8_t _reserved[3];
113
114TU_VERIFY_STATIC(sizeof(usbtmc_msg_dev_dep_msg_in_header_t) == 12u, "struct wrong length");
115
116/* Unsupported vendor things.... Are these ever used?*/
117
118typedef struct TU_ATTR_PACKED
119{
121 uint32_t TransferSize ;
122 uint8_t _reserved[4];
124
125
126TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_vendor_specific_out) == 12u, "struct wrong length");
127
128typedef struct TU_ATTR_PACKED
129{
131 uint32_t TransferSize ;
132 uint8_t _reserved[4];
134
135TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_vendor_specific_in) == 12u, "struct wrong length");
136
137// Control request type should use tusb_control_request_t
138
139/*
140typedef struct TU_ATTR_PACKED {
141 struct {
142 unsigned int Recipient : 5 ; ///< EOM set on last byte
143 unsigned int Type : 2 ; ///< EOM set on last byte
144 unsigned int DirectionToHost : 1 ; ///< 0 is OUT, 1 is IN
145 } bmRequestType;
146 uint8_t bRequest ; ///< If bmRequestType.Type = Class, see usmtmc_request_type_enum
147 uint16_t wValue ;
148 uint16_t wIndex ;
149 uint16_t wLength ; // Number of bytes in data stage
150} usbtmc_class_specific_control_req;
151
152*/
153// bulk-in protocol errors
154enum {
155 USBTMC_BULK_IN_ERR_INCOMPLETE_HEADER = 1u,
156 USBTMC_BULK_IN_ERR_UNSUPPORTED = 2u,
157 USBTMC_BULK_IN_ERR_BAD_PARAMETER = 3u,
158 USBTMC_BULK_IN_ERR_DATA_TOO_SHORT = 4u,
159 USBTMC_BULK_IN_ERR_DATA_TOO_LONG = 5u,
160};
161// built-in halt errors
162enum {
163 USBTMC_BULK_IN_ERR = 1u,
165};
166
167typedef enum {
168 USBTMC_bREQUEST_INITIATE_ABORT_BULK_OUT = 1u,
169 USBTMC_bREQUEST_CHECK_ABORT_BULK_OUT_STATUS = 2u,
170 USBTMC_bREQUEST_INITIATE_ABORT_BULK_IN = 3u,
171 USBTMC_bREQUEST_CHECK_ABORT_BULK_IN_STATUS = 4u,
172 USBTMC_bREQUEST_INITIATE_CLEAR = 5u,
173 USBTMC_bREQUEST_CHECK_CLEAR_STATUS = 6u,
174 USBTMC_bREQUEST_GET_CAPABILITIES = 7u,
175
176 USBTMC_bREQUEST_INDICATOR_PULSE = 64u, // Optional
177
178 /****** USBTMC 488 *************/
179 USB488_bREQUEST_READ_STATUS_BYTE = 128u,
180 USB488_bREQUEST_REN_CONTROL = 160u,
181 USB488_bREQUEST_GO_TO_LOCAL = 161u,
182 USB488_bREQUEST_LOCAL_LOCKOUT = 162u,
183
184} usmtmc_request_type_enum;
185
186typedef enum {
187 USBTMC_STATUS_SUCCESS = 0x01,
188 USBTMC_STATUS_PENDING = 0x02,
189 USBTMC_STATUS_FAILED = 0x80,
190 USBTMC_STATUS_TRANSFER_NOT_IN_PROGRESS = 0x81,
191 USBTMC_STATUS_SPLIT_NOT_IN_PROGRESS = 0x82,
192 USBTMC_STATUS_SPLIT_IN_PROGRESS = 0x83,
193
194 /****** USBTMC 488 *************/
195 USB488_STATUS_INTERRUPT_IN_BUSY = 0x20
196} usbtmc_status_enum;
197
198/************************************************************
199 * Control Responses
200 */
201
202typedef struct TU_ATTR_PACKED {
204 uint8_t _reserved;
205 uint16_t bcdUSBTMC;
206
207 struct TU_ATTR_PACKED
208 {
209 unsigned int listenOnly :1;
210 unsigned int talkOnly :1;
211 unsigned int supportsIndicatorPulse :1;
212 } bmIntfcCapabilities;
213 struct TU_ATTR_PACKED
214 {
215 unsigned int canEndBulkInOnTermChar :1;
216 } bmDevCapabilities;
217 uint8_t _reserved2[6];
218 uint8_t _reserved3[12];
220
221TU_VERIFY_STATIC(sizeof(usbtmc_response_capabilities_t) == 0x18, "struct wrong length");
222
223typedef struct TU_ATTR_PACKED
224{
225 uint8_t USBTMC_status;
226 struct TU_ATTR_PACKED
227 {
228 unsigned int BulkInFifoBytes :1;
229 } bmClear;
231
232TU_VERIFY_STATIC(sizeof(usbtmc_get_clear_status_rsp_t) == 2u, "struct wrong length");
233
234// Used for both abort bulk IN and bulk OUT
235typedef struct TU_ATTR_PACKED
236{
237 uint8_t USBTMC_status;
238 uint8_t bTag;
240
241TU_VERIFY_STATIC(sizeof(usbtmc_get_clear_status_rsp_t) == 2u, "struct wrong length");
242
243// Used for both check_abort_bulk_in_status and check_abort_bulk_out_status
244typedef struct TU_ATTR_PACKED
245{
246 uint8_t USBTMC_status;
247 struct TU_ATTR_PACKED
248 {
249 unsigned int BulkInFifoBytes : 1;
250 } bmAbortBulkIn;
251 uint8_t _reserved[2];
252 uint32_t NBYTES_RXD_TXD;
254
255TU_VERIFY_STATIC(sizeof(usbtmc_check_abort_bulk_rsp_t) == 8u, "struct wrong length");
256
257typedef struct TU_ATTR_PACKED
258{
259 uint8_t USBTMC_status;
260 uint8_t _reserved;
261 uint16_t bcdUSBTMC;
262
263 struct TU_ATTR_PACKED
264 {
265 uint8_t listenOnly :1;
266 uint8_t talkOnly :1;
267 uint8_t supportsIndicatorPulse :1;
268 } bmIntfcCapabilities;
269
270 struct TU_ATTR_PACKED
271 {
272 uint8_t canEndBulkInOnTermChar :1;
273 } bmDevCapabilities;
274
275 uint8_t _reserved2[6];
276 uint16_t bcdUSB488;
277
278 struct TU_ATTR_PACKED
279 {
280 uint8_t supportsTrigger :1;
281 uint8_t supportsREN_GTL_LLO :1;
282 uint8_t is488_2 :1;
283 } bmIntfcCapabilities488;
284
285 struct TU_ATTR_PACKED
286 {
287 uint8_t DT1 :1;
288 uint8_t RL1 :1;
289 uint8_t SR1 :1;
290 uint8_t SCPI :1;
291 } bmDevCapabilities488;
292 uint8_t _reserved3[8];
294
295TU_VERIFY_STATIC(sizeof(usbtmc_response_capabilities_488_t) == 0x18, "struct wrong length");
296
297typedef struct TU_ATTR_PACKED
298{
299 uint8_t USBTMC_status;
300 uint8_t bTag;
301 uint8_t statusByte;
303
304TU_VERIFY_STATIC(sizeof(usbtmc_read_stb_rsp_488_t) == 3u, "struct wrong length");
305
306typedef struct TU_ATTR_PACKED
307{
308 struct TU_ATTR_PACKED
309 {
310 unsigned int bTag : 7;
311 unsigned int one : 1;
312 } bNotify1;
313 uint8_t StatusByte;
315
316TU_VERIFY_STATIC(sizeof(usbtmc_read_stb_interrupt_488_t) == 2u, "struct wrong length");
317
318#endif
Definition audio.h:758
uint8_t UsingTermChar
Support TermChar && Request.TermCharEnabled && last char in transfer is TermChar.
Definition usbtmc.h:109
uint8_t EOM
Last byte of transfer is the end of the message.
Definition usbtmc.h:108
unsigned int BulkInFifoBytes
Has queued data or a short packet that is queued.
Definition usbtmc.h:228
unsigned int TermCharEnabled
"The Bulk-IN transfer must terminate on the specified TermChar."; CAPABILITIES must list TermChar
Definition usbtmc.h:92
unsigned int EOM
EOM set on last byte.
Definition usbtmc.h:78
AUDIO Channel Cluster Descriptor (4.1)
Definition audio.h:647
uint8_t USBTMC_status
usbtmc_status_enum
Definition usbtmc.h:203
uint8_t MsgID
Message type ID (usbtmc_msgid_enum)
Definition usbtmc.h:59
uint32_t TransferSize
Transfer size; LSB first.
Definition usbtmc.h:75
usbtmc_msg_header_t header
Header.
Definition usbtmc.h:67
uint8_t bTagInverse
Complement of the tag.
Definition usbtmc.h:61
uint8_t bTag
Transfer ID 1<=bTag<=255.
Definition usbtmc.h:60
uint16_t bcdUSBTMC
USBTMC_VERSION.
Definition usbtmc.h:205
uint8_t _reserved
Must be 0x00.
Definition usbtmc.h:62