From: Uwe Hermann Date: Sun, 14 Aug 2016 21:51:49 +0000 (+0200) Subject: hantek-6xxx: Fix some issues by using power-of-two data sizes. X-Git-Tag: libsigrok-0.5.0~282 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=af7f88242eef2bdcbaa7ff2d58f74ad616305b48;p=libsigrok.git hantek-6xxx: Fix some issues by using power-of-two data sizes. 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. --- diff --git a/src/hardware/hantek-6xxx/api.c b/src/hardware/hantek-6xxx/api.c index 8848c913..29d5f6e2 100644 --- a/src/hardware/hantek-6xxx/api.c +++ b/src/hardware/hantek-6xxx/api.c @@ -519,7 +519,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * 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) { @@ -531,11 +531,14 @@ static uint32_t data_amount(const struct sr_dev_inst *sdi) 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,