Skip to content

Commit c675deb

Browse files
committed
USBTMC: Handle busy interrupt in.
1 parent 239b5d5 commit c675deb

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/class/usbtmc/usbtmc.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,10 @@ typedef enum {
189189
USBTMC_STATUS_FAILED = 0x80,
190190
USBTMC_STATUS_TRANSFER_NOT_IN_PROGRESS = 0x81,
191191
USBTMC_STATUS_SPLIT_NOT_IN_PROGRESS = 0x82,
192-
USBTMC_STATUS_SPLIT_IN_PROGRESS = 0x83
192+
USBTMC_STATUS_SPLIT_IN_PROGRESS = 0x83,
193+
194+
/****** USBTMC 488 *************/
195+
USB488_STATUS_INTERRUPT_IN_BUSY = 0x20
193196
} usbtmc_status_enum;
194197

195198
/************************************************************

src/class/usbtmc/usbtmc_device.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -831,26 +831,32 @@ bool usbtmcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request
831831

832832
bTag = request->wValue & 0x7F;
833833
TU_VERIFY(request->bmRequestType == 0xA1);
834-
TU_VERIFY((request->wValue & (~0x7F)) == 0u); // Other bits are required to be zero
834+
TU_VERIFY((request->wValue & (~0x7F)) == 0u); // Other bits are required to be zero (USB488v1.0 Table 11)
835835
TU_VERIFY(bTag >= 0x02 && bTag <= 127);
836836
TU_VERIFY(request->wIndex == usbtmc_state.itf_id);
837837
TU_VERIFY(request->wLength == 0x0003);
838838
rsp.bTag = (uint8_t)bTag;
839839
if(usbtmc_state.ep_int_in != 0)
840840
{
841-
rsp.USBTMC_status = USBTMC_STATUS_SUCCESS;
842-
rsp.statusByte = 0x00; // Use interrupt endpoint, instead.
843-
844-
usbtmc_read_stb_interrupt_488_t intMsg =
841+
rsp.statusByte = 0x00; // Use interrupt endpoint, instead. Must be 0x00 (USB488v1.0 4.3.1.2)
842+
if(usbd_edpt_busy(rhport, usbtmc_state.ep_int_in))
843+
{
844+
rsp.USBTMC_status = USB488_STATUS_INTERRUPT_IN_BUSY;
845+
}
846+
else
845847
{
846-
.bNotify1 = {
847-
.one = 1,
848-
.bTag = bTag & 0x7Fu,
849-
},
850-
.StatusByte = tud_usbtmc_get_stb_cb(&(rsp.USBTMC_status))
851-
};
852-
// USB488 spec states that transfer must be queued before control request response sent.
853-
usbd_edpt_xfer(rhport, usbtmc_state.ep_int_in, (void*)&intMsg, sizeof(intMsg));
848+
rsp.USBTMC_status = USBTMC_STATUS_SUCCESS;
849+
usbtmc_read_stb_interrupt_488_t intMsg =
850+
{
851+
.bNotify1 = {
852+
.one = 1,
853+
.bTag = bTag & 0x7Fu,
854+
},
855+
.StatusByte = tud_usbtmc_get_stb_cb(&(rsp.USBTMC_status))
856+
};
857+
// Must be queued before control request response sent (USB488v1.0 4.3.1.2)
858+
usbd_edpt_xfer(rhport, usbtmc_state.ep_int_in, (void*)&intMsg, sizeof(intMsg));
859+
}
854860
}
855861
else
856862
{

0 commit comments

Comments
 (0)