]> sigrok.org Git - libsigrok.git/blobdiff - hardware/asix-sigma/asix-sigma.c
asix-sigma: Properly fetch timestamp in decode_chunk_ts()
[libsigrok.git] / hardware / asix-sigma / asix-sigma.c
index e57373248ec81d565d2ade7f349964956f2aa26f..64ebcbb8505778c8dd1904ba5c6c90aa3a6e4c38 100644 (file)
@@ -929,6 +929,15 @@ static int get_trigger_offset(uint16_t *samples, uint16_t last_sample,
        return i & 0x7;
 }
 
+
+/*
+ * Return the timestamp of "DRAM cluster".
+ */
+static uint16_t sigma_dram_cluster_ts(struct sigma_dram_cluster *cluster)
+{
+       return (cluster->timestamp_hi << 8) | cluster->timestamp_lo;
+}
+
 /*
  * Decode chunk of 1024 bytes, 64 clusters, 7 events per cluster.
  * Each event is 20ns apart, and can contain multiple samples.
@@ -938,10 +947,12 @@ static int get_trigger_offset(uint16_t *samples, uint16_t last_sample,
  * For 50 MHz and below, events contain one sample for each channel,
  * spread 20 ns apart.
  */
-static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
+static int decode_chunk_ts(struct sigma_dram_line *dram_line, uint16_t *lastts,
                           uint16_t *lastsample, int triggerpos,
                           uint16_t limit_chunk, void *cb_data)
 {
+       uint8_t *buf = (uint8_t *)dram_line;
+       struct sigma_dram_cluster *dram_cluster;
        struct sr_dev_inst *sdi = cb_data;
        struct dev_context *devc = sdi->priv;
        uint16_t tsdiff, ts;
@@ -968,8 +979,9 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
        }
 
        /* For each ts. */
-       for (i = 0; i < 64; ++i) {
-               ts = *(uint16_t *) &buf[i * 16];
+       for (i = 0; i < 64; i++) {
+               dram_cluster = &dram_line->cluster[i];
+               ts = sigma_dram_cluster_ts(dram_cluster);
                tsdiff = ts - *lastts;
                *lastts = ts;
 
@@ -1074,7 +1086,6 @@ static int download_capture(struct sr_dev_inst *sdi)
        struct dev_context *devc = sdi->priv;
        const int chunks_per_read = 32;
        struct sigma_dram_line *dram_line;
-       unsigned char *buf;
        int bufsz;
        uint32_t stoppos, triggerpos;
        struct sr_datafeed_packet packet;
@@ -1089,8 +1100,6 @@ static int download_capture(struct sr_dev_inst *sdi)
        if (!dram_line)
                return FALSE;
 
-       buf = (unsigned char *)dram_line;
-
        sr_info("Downloading sample data.");
 
        /* Stop acquisition. */
@@ -1121,13 +1130,15 @@ static int download_capture(struct sr_dev_inst *sdi)
                /* We can download only up-to 32 DRAM lines in one go! */
                dl_lines_curr = MIN(chunks_per_read, dl_lines_total);
 
-               bufsz = sigma_read_dram(dl_lines_done, dl_lines_curr, buf, devc);
+               bufsz = sigma_read_dram(dl_lines_done, dl_lines_curr,
+                                       (uint8_t *)dram_line, devc);
                /* TODO: Check bufsz. For now, just avoid compiler warnings. */
                (void)bufsz;
 
                /* This is the first DRAM line, so find the initial timestamp. */
                if (dl_lines_done == 0) {
-                       devc->state.lastts = RL16(buf) - 1;
+                       devc->state.lastts =
+                               sigma_dram_cluster_ts(&dram_line[0].cluster[0]);
                        devc->state.lastsample = 0;
                }
 
@@ -1142,7 +1153,7 @@ static int download_capture(struct sr_dev_inst *sdi)
                        if (dl_lines_done + i == trg_line)
                                trigger_line = trg_line;
 
-                       decode_chunk_ts(buf + (i * CHUNK_SIZE),
+                       decode_chunk_ts(dram_line + i,
                                        &devc->state.lastts,
                                        &devc->state.lastsample,
                                        trigger_line, dl_limit, sdi);