There were issues when using non-power-of-two data sizes with e.g.
the Hantek 6022BE device. For example, on Windows the acquisition would
simply hang and never complete:
hantek-6xxx: receive_transfer(): status LIBUSB_TRANSFER_ERROR received 0 bytes
The issue was reported by Erik Montnemery on the mailing list, the
original patch was posted by "mmark" here (thanks!):
http://www.eevblog.com/forum/testgear/sainsmart-dds120-usb-oscilloscope-(buudai-bm102)/msg911729/#msg911729
The issue has been verified by me on Windows and Linux, and also that
this change does indeed fix it (tested Hantek 6022BE and Sainsmart DDS120).
Neither PulseView nor sigrok-cli hang anymore on Windows, and on Linux
the log messages suggest improvements as well:
-hantek-6xxx: data_amount 712
+hantek-6xxx: data_amount: 200 (rounded to power of 2: 512)
-hantek-6xxx: receive_transfer(): calculated samplerate == 2327ks/s
-hantek-6xxx: receive_transfer(): status LIBUSB_TRANSFER_OVERFLOW received 512 bytes.
+hantek-6xxx: receive_transfer(): calculated samplerate == 1969ks/s
+hantek-6xxx: receive_transfer(): status LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED received 512 bytes.
This fixes bug #821.
static uint32_t data_amount(const struct sr_dev_inst *sdi)
{
struct dev_context *devc = sdi->priv;
- uint32_t data_left;
+ uint32_t data_left, data_left_2, i;
int32_t time_left;
if (devc->limit_msec) {
data_left = devc->samplerate * NUM_CHANNELS;
}
- data_left += MIN_PACKET_SIZE; /* Driver does not handle small buffers. */
+ /* Round up to nearest power of two. */
+ for (i = MIN_PACKET_SIZE; i < data_left; i *= 2)
+ ;
+ data_left_2 = i;
- sr_spew("data_amount %u", data_left);
+ sr_spew("data_amount: %u (rounded to power of 2: %u)", data_left, data_left_2);
- return data_left;
+ return data_left_2;
}
static void send_chunk(struct sr_dev_inst *sdi, unsigned char *buf,