Skip to content

Commit 55d3e02

Browse files
committed
If the host knows our buffer size, don't auto-flush.
1 parent 8f6a63f commit 55d3e02

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

firmware/hackrf_usb/usb_api_transceiver.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646

4747
#define BUF_HALF_MASK (USB_SAMP_BUFFER_SIZE >> 1)
4848

49+
// Unless we know the host knows our buffer size, we'll avoid leaving TX
50+
// until we've transmitted all bytes sent by the host. This flag is cleared
51+
// when the host requests our buffer size.
52+
bool auto_tx_flush = true;
53+
4954
volatile uint32_t dma_started, dma_pending, usb_started, usb_completed;
5055

5156
typedef struct {
@@ -303,7 +308,7 @@ volatile transceiver_request_t transceiver_request = {
303308
void transceiver_usb_setup_complete(usb_endpoint_t* const endpoint)
304309
{
305310
if (transceiver_request.mode == TRANSCEIVER_MODE_TX &&
306-
endpoint->setup.request == 1) {
311+
endpoint->setup.request == 1 && auto_tx_flush) {
307312
// This is a request to leave TX mode. Do so but NAK for now.
308313
request_transceiver_mode(endpoint->setup.value);
309314
} else {
@@ -445,6 +450,11 @@ usb_request_status_t usb_vendor_request_get_buffer_size(
445450
NULL,
446451
NULL);
447452
usb_transfer_schedule_ack(endpoint->out);
453+
454+
// We now know the host is aware of our buffer size, so it
455+
// can make its own decisions about flushing the buffer.
456+
auto_tx_flush = false;
457+
448458
return USB_REQUEST_STATUS_OK;
449459
}
450460
return USB_REQUEST_STATUS_OK;
@@ -606,9 +616,17 @@ void tx_mode(uint32_t seq)
606616
radio_update(&radio);
607617
}
608618

609-
// Host has now requested to stop TX. We won't initiate any further USB
610-
// transfers into the bulk buffer. However, we should make sure all
611-
// data currently in the USB bulk buffer reaches the sample buffer.
619+
// Host has now requested to stop TX. If we're not auto-flushing, we
620+
// should now stop TX immediately.
621+
622+
if (!auto_tx_flush) {
623+
transceiver_shutdown();
624+
return;
625+
}
626+
627+
// Otherwise, we should now ensure all bytes sent by the host are
628+
// transmitted before we leave TX. First, we should make sure all data
629+
// currently in the USB bulk buffer reaches the sample buffer.
612630

613631
if ((usb_started - usb_completed) > 0) {
614632
// We were part way through a 16KB firmware-side transfer when

0 commit comments

Comments
 (0)