From 25e3954793e042ddd5bc4845d24e9f8d5c7f3830 Mon Sep 17 00:00:00 2001 From: jcmartin Date: Wed, 17 May 2023 23:25:27 -0700 Subject: [PATCH 1/2] Addresses issue #408 for macOS. Under macOS, when libusb_cancel_transfer is called on one transfer, all transfers on the same endpoint are cancelled. Calling libusb_cancel_transfer on additional transfers on the same endpoint _may_ result in macOS returning kIOReturnAborted. The net result is the bladeRF can no longer be communicated with. The fix to this is to only call libusb_cancel_transfer once in cancel_all_transfers and set the appropriate state for all transfers. Refer to libusb_cancel_transfer documentation for more details. --- .../libbladeRF/src/backend/usb/libusb.c | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/host/libraries/libbladeRF/src/backend/usb/libusb.c b/host/libraries/libbladeRF/src/backend/usb/libusb.c index 6100f8adf..5de060db5 100644 --- a/host/libraries/libbladeRF/src/backend/usb/libusb.c +++ b/host/libraries/libbladeRF/src/backend/usb/libusb.c @@ -1003,6 +1003,29 @@ static inline void cancel_all_transfers(struct bladerf_stream *stream) int status; struct lusb_stream_data *stream_data = stream->backend_data; +#ifdef __APPLE__ + /* For macOS and iOS, canceling one transfer will cause all transfers + * on the same endpoint to be cancelled. + */ + bool have_cancelled = false; + + for (i = 0; i < stream_data->num_transfers; i++) { + if (stream_data->transfer_status[i] == TRANSFER_IN_FLIGHT) { + if (!have_cancelled) { + status = libusb_cancel_transfer(stream_data->transfers[i]); + if (status < 0 && status != LIBUSB_ERROR_NOT_FOUND) { + log_error("Error canceling transfer (%d): %s\n", + status, libusb_error_name(status)); + } else { + stream_data->transfer_status[i] = TRANSFER_CANCEL_PENDING; + } + have_cancelled = true; + } else { + stream_data->transfer_status[i] = TRANSFER_CANCEL_PENDING; + } + } + } +#else for (i = 0; i < stream_data->num_transfers; i++) { if (stream_data->transfer_status[i] == TRANSFER_IN_FLIGHT) { status = libusb_cancel_transfer(stream_data->transfers[i]); @@ -1014,6 +1037,7 @@ static inline void cancel_all_transfers(struct bladerf_stream *stream) } } } +#endif } static inline size_t transfer_idx(struct lusb_stream_data *stream_data, From 13e406f47e4f173c1cbf530cfe1275d6db34e519 Mon Sep 17 00:00:00 2001 From: jcmartin Date: Mon, 1 Jul 2024 14:32:20 -0700 Subject: [PATCH 2/2] Remove unused variables that compilers complain about. --- host/libraries/libbladeRF/src/driver/si5338.c | 6 +++--- host/libraries/libbladeRF_test/test_parse/src/main.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/host/libraries/libbladeRF/src/driver/si5338.c b/host/libraries/libbladeRF/src/driver/si5338.c index 7aada028f..61ef9c26c 100644 --- a/host/libraries/libbladeRF/src/driver/si5338.c +++ b/host/libraries/libbladeRF/src/driver/si5338.c @@ -349,7 +349,7 @@ static int si5338_calculate_multisynth(struct si5338_multisynth *ms, struct bladerf_rational_rate req; struct bladerf_rational_rate abc; - uint8_t r_value, r_power; + uint8_t r_value; //, r_power; /* Don't muss with the users data */ req = *rate; @@ -363,11 +363,11 @@ static int si5338_calculate_multisynth(struct si5338_multisynth *ms, /* Find a suitable R value */ r_value = 1; - r_power = 0; + //r_power = 0; while (req.integer < 5000000 && r_value < 32) { si5338_rational_double(&req); r_value <<= 1; - r_power++; + //r_power++; } if (r_value == 32 && req.integer < 5000000) { diff --git a/host/libraries/libbladeRF_test/test_parse/src/main.c b/host/libraries/libbladeRF_test/test_parse/src/main.c index db30a31f5..160f0f3c3 100644 --- a/host/libraries/libbladeRF_test/test_parse/src/main.c +++ b/host/libraries/libbladeRF_test/test_parse/src/main.c @@ -177,12 +177,12 @@ bool test_csv2int() int main(int argc, char *argv[]) { - size_t good = 0, bad = 0; + size_t bad = 0; // good = 0, bad = 0; printf("*** testing csv2int ***\n"); if (test_csv2int()) { printf("*** testing csv2int: PASSED ***\n"); - ++good; + //++good; } else { printf("*** testing csv2int: FAILED ***\n"); ++bad;