]> sigrok.org Git - libsigrok.git/blobdiff - hardware/asix-sigma/asix-sigma.c
update plugins and cli to use new DF_HEADER
[libsigrok.git] / hardware / asix-sigma / asix-sigma.c
index fe57d857c7dc7d7ad073c5e17cf54e82bc4663b9..d4d9fddfdaf6a765ffc50c52d134c832b8008549 100644 (file)
@@ -727,6 +727,37 @@ static int hw_set_configuration(int device_index, int capability, void *value)
        return ret;
 }
 
+/* Software trigger to determine exact trigger position. */
+static int get_trigger_offset(uint16_t *samples, uint16_t last_sample,
+                             struct sigma_trigger *t)
+{
+       int i;
+
+       for (i = 0; i < 8; ++i) {
+               if (i > 0)
+                       last_sample = samples[i-1];
+
+               /* Simple triggers. */
+               if ((samples[i] & t->simplemask) != t->simplevalue)
+                       continue;
+
+               /* Rising edge. */
+               if ((last_sample & t->risingmask) != 0 || (samples[i] &
+                   t->risingmask) != t->risingmask)
+                       continue;
+
+               /* Falling edge. */
+               if ((last_sample & t->fallingmask) != t->fallingmask ||
+                   (samples[i] & t->fallingmask) != 0)
+                       continue;
+
+               break;
+       }
+
+       /* If we did not match, return original trigger pos. */
+       return i & 0x7;
+}
+
 /*
  * Decode chunk of 1024 bytes, 64 clusters, 7 events per cluster.
  * Each event is 20ns apart, and can contain multiple samples.
@@ -748,14 +779,11 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
        uint16_t *event;
        uint16_t cur_sample;
        int triggerts = -1;
-       int triggeroff = 0;
 
        /* Check if trigger is in this chunk. */
        if (triggerpos != -1) {
                if (cur_samplerate <= MHZ(50))
-                       triggerpos -= EVENTS_PER_CLUSTER;
-               else
-                       triggeroff = 3;
+                       triggerpos -= EVENTS_PER_CLUSTER - 1;
 
                if (triggerpos < 0)
                        triggerpos = 0;
@@ -784,8 +812,9 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
                while (sent < n) {
                        tosend = MIN(2048, n - sent);
 
-                       packet.type = DF_LOGIC16;
+                       packet.type = DF_LOGIC;
                        packet.length = tosend * sizeof(uint16_t);
+                       packet.unitsize = 2;
                        packet.payload = samples + sent;
                        session_bus(user_data, &packet);
 
@@ -817,17 +846,18 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
                sent = 0;
                if (i == triggerts) {
                        /*
-                        * Trigger is presumptively not accurate to sample.
-                        * However, it always trigger before the actual event,
-                        * so it would be possible to forward to correct position
-                        * here by manually checking for trigger condition.
+                        * Trigger is not always accurate to sample because of
+                        * pipeline delay. However, it always triggers before
+                        * the actual event. We therefore look at the next
+                        * samples to pinpoint the exact position of the trigger.
                         */
-
-                       tosend = (triggerpos % 7) - triggeroff;
+                       tosend = get_trigger_offset(samples, *lastsample,
+                                                   &trigger);
 
                        if (tosend > 0) {
-                               packet.type = DF_LOGIC16;
+                               packet.type = DF_LOGIC;
                                packet.length = tosend * sizeof(uint16_t);
+                               packet.unitsize = 2;
                                packet.payload = samples;
                                session_bus(user_data, &packet);
 
@@ -843,8 +873,9 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
                /* Send rest of the chunk to sigrok. */
                tosend = n - sent;
 
-               packet.type = DF_LOGIC16;
+               packet.type = DF_LOGIC;
                packet.length = tosend * sizeof(uint16_t);
+               packet.unitsize = 2;
                packet.payload = samples + sent;
                session_bus(user_data, &packet);
 
@@ -1188,7 +1219,8 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
        gettimeofday(&header.starttime, NULL);
        header.samplerate = cur_samplerate;
        header.protocol_id = PROTO_RAW;
-       header.num_probes = num_probes;
+       header.num_logic_probes = num_probes;
+       header.num_analog_probes = 0;
        session_bus(session_device_id, &packet);
 
        /* Add capture source. */