]> sigrok.org Git - libsigrok.git/commitdiff
kingst-la2016: determine packets per chunk at runtime per model
authorGerhard Sittig <redacted>
Mon, 31 Jan 2022 22:01:41 +0000 (23:01 +0100)
committerGerhard Sittig <redacted>
Sun, 6 Feb 2022 17:53:54 +0000 (18:53 +0100)
The layout of capture data in memory most probably depends on devices'
channel counts. Chunks of 16 bytes each could either carry 5 samples of
16bit data with an 8bit repeat count, or 3 samples with 32bit data each.
Derive the number of packets per chunk at runtime from the connected
device type. Which could unbreak the LA5032 device but is yet untested.
It's an educated guess.

src/hardware/kingst-la2016/api.c
src/hardware/kingst-la2016/protocol.c
src/hardware/kingst-la2016/protocol.h

index 243b3ab1348fba0f9110d2c7c3e32b8788dec37f..3fec45b625ea9b60f2d12810f2e82ad107962d73 100644 (file)
@@ -1025,6 +1025,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
                        sr_err("Cannot allocate buffer for session feed.");
                        return SR_ERR_MALLOC;
                }
+               devc->packets_per_chunk = TRANSFER_PACKET_LENGTH;
+               devc->packets_per_chunk--;
+               devc->packets_per_chunk /= unitsize + sizeof(uint8_t);
        }
 
        sr_sw_limits_acquisition_start(&devc->sw_limits);
index d5ac7d2c635daf3cdf4ecd33631f40b28e5390a3..29ca1ebe8123ba9be83c7040b829f74317118b5a 100644 (file)
@@ -96,17 +96,6 @@ static const struct kingst_model models[] = {
 #define RUNSTATE_TRGD_BIT      (1UL << 2)
 #define RUNSTATE_POST_BIT      (1UL << 3)
 
-/*
- * Properties related to the layout of capture data downloads.
- *
- * TODO Check the layout of 32 channel models' capture data. Could it be
- * 3x (u32 + u8) instead of 5x (u16 + u8) perhaps? Same 16 bytes chunk
- * but fewer packets per chunk and thus per transfer? Which questions
- * the NUM_PACKETS_IN_CHUNK literal, maybe needs to be a runtime value?
- */
-#define NUM_PACKETS_IN_CHUNK   5
-#define TRANSFER_PACKET_LENGTH 16
-
 static int ctrl_in(const struct sr_dev_inst *sdi,
        uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
        void *data, uint16_t wLength)
@@ -861,10 +850,10 @@ static int get_capture_info(const struct sr_dev_inst *sdi)
                devc->info.n_rep_packets_before_trigger,
                devc->info.write_pos, devc->info.write_pos);
 
-       if (devc->info.n_rep_packets % NUM_PACKETS_IN_CHUNK) {
-               sr_warn("Unexpected packets count %lu, not a multiple of %d.",
+       if (devc->info.n_rep_packets % devc->packets_per_chunk) {
+               sr_warn("Unexpected packets count %lu, not a multiple of %lu.",
                        (unsigned long)devc->info.n_rep_packets,
-                       NUM_PACKETS_IN_CHUNK);
+                       (unsigned long)devc->packets_per_chunk);
        }
 
        return SR_OK;
@@ -981,8 +970,10 @@ static int la2016_start_download(const struct sr_dev_inst *sdi,
        if (ret != SR_OK)
                return ret;
 
-       devc->n_transfer_packets_to_read = devc->info.n_rep_packets / NUM_PACKETS_IN_CHUNK;
-       devc->n_bytes_to_read = devc->n_transfer_packets_to_read * TRANSFER_PACKET_LENGTH;
+       devc->n_transfer_packets_to_read = devc->info.n_rep_packets;
+       devc->n_transfer_packets_to_read /= devc->packets_per_chunk;
+       devc->n_bytes_to_read = devc->n_transfer_packets_to_read;
+       devc->n_bytes_to_read *= TRANSFER_PACKET_LENGTH;
        devc->read_pos = devc->info.write_pos - devc->n_bytes_to_read;
        devc->n_reps_until_trigger = devc->info.n_rep_packets_before_trigger;
 
@@ -1074,8 +1065,7 @@ static void send_chunk(struct sr_dev_inst *sdi,
        sample_value = 0;
        rp = packets;
        while (num_xfers--) {
-               /* XXX model dependent? 5 or 3? */
-               num_pkts = NUM_PACKETS_IN_CHUNK;
+               num_pkts = devc->packets_per_chunk;
                while (num_pkts--) {
 
                        /* TODO Verify 32channel layout. */
index 3b251ed1d16aef4d1863168b6f061328e9ad1d44..11ee28347c19165add79ce3c4955ee79739c497d 100644 (file)
@@ -78,6 +78,8 @@
 #define LA2016_THR_VOLTAGE_MIN 0.40
 #define LA2016_THR_VOLTAGE_MAX 4.00
 
+/* Properties related to the layout of capture data downloads. */
+#define TRANSFER_PACKET_LENGTH 16
 #define LA2016_NUM_SAMPLES_MAX (UINT64_C(10 * 1000 * 1000 * 1000))
 
 /* Maximum device capabilities. May differ between models. */
@@ -129,6 +131,7 @@ struct dev_context {
        gboolean trigger_involved;
        gboolean completion_seen;
        gboolean download_finished;
+       uint32_t packets_per_chunk;
        struct capture_info {
                uint32_t n_rep_packets;
                uint32_t n_rep_packets_before_trigger;