Skip to content

Commit f78ad7f

Browse files
committed
If the host knows our buffer size, don't auto-flush.
1 parent a8a3bbf commit f78ad7f

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
@@ -56,6 +56,11 @@
5656

5757
#define BUF_HALF_MASK (USB_SAMP_BUFFER_SIZE >> 1)
5858

59+
// Unless we know the host knows our buffer size, we'll avoid leaving TX
60+
// until we've transmitted all bytes sent by the host. This flag is cleared
61+
// when the host requests our buffer size.
62+
bool auto_tx_flush = true;
63+
5964
volatile uint32_t dma_started, dma_pending, usb_started, usb_completed;
6065

6166
typedef struct {
@@ -345,7 +350,7 @@ volatile transceiver_request_t transceiver_request = {
345350
void transceiver_usb_setup_complete(usb_endpoint_t* const endpoint)
346351
{
347352
if (transceiver_request.mode == TRANSCEIVER_MODE_TX &&
348-
endpoint->setup.request == 1) {
353+
endpoint->setup.request == 1 && auto_tx_flush) {
349354
// This is a request to leave TX mode. Do so but NAK for now.
350355
request_transceiver_mode(endpoint->setup.value);
351356
} else {
@@ -493,6 +498,11 @@ usb_request_status_t usb_vendor_request_get_buffer_size(
493498
NULL,
494499
NULL);
495500
usb_transfer_schedule_ack(endpoint->out);
501+
502+
// We now know the host is aware of our buffer size, so it
503+
// can make its own decisions about flushing the buffer.
504+
auto_tx_flush = false;
505+
496506
return USB_REQUEST_STATUS_OK;
497507
}
498508
return USB_REQUEST_STATUS_OK;
@@ -643,9 +653,17 @@ void tx_mode(uint32_t seq)
643653
}
644654
}
645655

646-
// Host has now requested to stop TX. We won't initiate any further USB
647-
// transfers into the bulk buffer. However, we should make sure all
648-
// data currently in the USB bulk buffer reaches the sample buffer.
656+
// Host has now requested to stop TX. If we're not auto-flushing, we
657+
// should now stop TX immediately.
658+
659+
if (!auto_tx_flush) {
660+
transceiver_shutdown();
661+
return;
662+
}
663+
664+
// Otherwise, we should now ensure all bytes sent by the host are
665+
// transmitted before we leave TX. First, we should make sure all data
666+
// currently in the USB bulk buffer reaches the sample buffer.
649667

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

0 commit comments

Comments
 (0)