]> sigrok.org Git - libsigrok.git/commitdiff
fx2lafw: Use new library software trigger.
authorBert Vermeulen <redacted>
Wed, 28 May 2014 13:54:46 +0000 (15:54 +0200)
committerBert Vermeulen <redacted>
Wed, 28 May 2014 13:54:46 +0000 (15:54 +0200)
hardware/fx2lafw/api.c
hardware/fx2lafw/protocol.c
hardware/fx2lafw/protocol.h

index a3e67614f26271a8a8bbac19c59509d61b0940ee..49236511f2735576b3c005a71a3e88a0c6e5dd7c 100644 (file)
@@ -96,6 +96,9 @@ static const char *channel_names[] = {
 static const int32_t soft_trigger_matches[] = {
        SR_TRIGGER_ZERO,
        SR_TRIGGER_ONE,
+       SR_TRIGGER_RISING,
+       SR_TRIGGER_FALLING,
+       SR_TRIGGER_EDGE,
 };
 
 static const uint64_t samplerates[] = {
@@ -513,6 +516,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        struct dev_context *devc;
        struct drv_context *drvc;
        struct sr_usb_dev_inst *usb;
+       struct sr_trigger *trigger;
        struct libusb_transfer *transfer;
        unsigned int i, timeout, num_transfers;
        int ret;
@@ -531,10 +535,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        devc->acq_aborted = FALSE;
        devc->empty_transfer_count = 0;
 
-       if (sr_session_trigger_get()) {
+       if ((trigger = sr_session_trigger_get())) {
+               devc->stl = soft_trigger_logic_new(sdi, trigger);
                devc->trigger_fired = FALSE;
-               devc->cur_trigger_stage = 0;
-               devc->cur_trigger_step = 0;
        } else
                devc->trigger_fired = TRUE;
 
index 98b483c46e0d12106623d0412e51ffefab564601..836e27840941cbb2e9a114bd2048d1323d842ab4 100644 (file)
@@ -311,6 +311,7 @@ SR_PRIV struct dev_context *fx2lafw_dev_new(void)
        devc->cur_samplerate = 0;
        devc->limit_samples = 0;
        devc->sample_wide = FALSE;
+       devc->stl = NULL;
 
        return devc;
 }
@@ -340,6 +341,11 @@ static void finish_acquisition(struct dev_context *devc)
 
        devc->num_transfers = 0;
        g_free(devc->transfers);
+
+       if (devc->stl) {
+               soft_trigger_logic_free(devc->stl);
+               devc->stl = NULL;
+       }
 }
 
 static void free_transfer(struct libusb_transfer *transfer)
@@ -379,95 +385,6 @@ static void resubmit_transfer(struct libusb_transfer *transfer)
 
 }
 
-static gboolean check_match(uint16_t sample, struct sr_trigger_match *match)
-{
-       gboolean bit, result;
-
-       result = FALSE;
-       bit = sample & (1 << match->channel->index);
-       if (match->match == SR_TRIGGER_ZERO && !bit)
-               result = TRUE;
-       else if (match->match == SR_TRIGGER_ONE && bit)
-               result = TRUE;
-
-       return result;
-}
-
-/* Returns the offset (in samples) within buf of where the trigger
- * occurred, or -1 if not triggered. */
-static int soft_trigger(struct sr_dev_inst *sdi, uint8_t *buf,
-               int len)
-{
-       struct dev_context *devc;
-       struct sr_datafeed_packet packet;
-       struct sr_trigger *trigger;
-       struct sr_trigger_stage *stage;
-       struct sr_trigger_match *match;
-       GSList *l, *lst;;
-       int offset;
-       uint16_t sample;
-       int unitsize, i;
-       gboolean match_found;
-
-       devc = sdi->priv;
-       offset = -1;
-       trigger = sr_session_trigger_get();
-       unitsize = devc->sample_wide ? 2 : 1;
-       for (i = 0; i < len; i += unitsize) {
-               memcpy(&sample, buf + i, unitsize);
-
-               lst = g_slist_nth(trigger->stages, devc->cur_trigger_stage);
-               stage = lst->data;
-               if (!stage->matches)
-                       /* No matches supplied, client error. */
-                       return SR_ERR_ARG;
-
-               match_found = TRUE;
-               for (l = stage->matches; l; l = l->next) {
-                       match = l->data;
-                       if (!match->channel->enabled)
-                               /* Ignore disabled channels with a trigger. */
-                               continue;
-                       if (!check_match(sample, match)) {
-                               match_found = FALSE;
-                               break;
-                       }
-               }
-               if (match_found) {
-                       /* Matched on the current stage. */
-                       if (lst->next) {
-                               /* Advance to next stage. */
-                               devc->cur_trigger_stage++;
-                       } else {
-                               /* Matched on last stage, fire trigger. */
-                               offset = i / unitsize;
-
-                               packet.type = SR_DF_TRIGGER;
-                               packet.payload = NULL;
-                               sr_session_send(devc->cb_data, &packet);
-                               break;
-                       }
-               } else if (devc->cur_trigger_stage > 0) {
-                       /*
-                        * We had a match at an earlier stage, but failed on the
-                        * current stage. However, we may have a match on this
-                        * stage in the next bit -- trigger on 0001 will fail on
-                        * seeing 00001, so we need to go back to stage 0 -- but
-                        * at the next sample from the one that matched originally,
-                        * which the counter increment at the end of the loop
-                        * takes care of.
-                        */
-                       i -= devc->cur_trigger_stage * unitsize;
-                       if (i < -1)
-                               i = -1; /* Oops, went back past this buffer. */
-                       /* Reset trigger stage. */
-                       devc->cur_trigger_stage = 0;
-               }
-       }
-
-       return offset;
-}
-
 SR_PRIV void fx2lafw_receive_transfer(struct libusb_transfer *transfer)
 {
        struct sr_dev_inst *sdi;
@@ -543,7 +460,8 @@ SR_PRIV void fx2lafw_receive_transfer(struct libusb_transfer *transfer)
                        devc->sent_samples += cur_sample_count;
                }
        } else {
-               trigger_offset = soft_trigger(sdi, transfer->buffer, transfer->actual_length);
+               trigger_offset = soft_trigger_logic_check(devc->stl,
+                               transfer->buffer, transfer->actual_length);
                if (trigger_offset > -1) {
                        packet.type = SR_DF_LOGIC;
                        packet.payload = &logic;
index 11887c80d7bd2ac93c41392ba6d7564ab2949706..fef0dd76bb85f8ae730d4553fb9760b780ac625c 100644 (file)
@@ -85,8 +85,7 @@ struct dev_context {
        gboolean trigger_fired;
        gboolean acq_aborted;
        gboolean sample_wide;
-       unsigned int cur_trigger_stage;
-       int cur_trigger_step;
+       struct soft_trigger_logic *stl;
 
        unsigned int sent_samples;
        int submitted_transfers;