]> sigrok.org Git - libsigrok.git/commitdiff
hantek-6xxx: Fix some issues by using power-of-two data sizes.
authorUwe Hermann <redacted>
Sun, 14 Aug 2016 21:51:49 +0000 (23:51 +0200)
committerUwe Hermann <redacted>
Sun, 14 Aug 2016 22:58:10 +0000 (00:58 +0200)
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.

src/hardware/hantek-6xxx/api.c

index 8848c9138576c8cf1330154ddf3bf6d900510d68..29d5f6e2148c5c285c90559afd27e482128b8915 100644 (file)
@@ -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,