]> sigrok.org Git - libsigrok.git/commitdiff
saleae-logic16: Use new library software trigger.
authorBert Vermeulen <redacted>
Thu, 29 May 2014 20:16:58 +0000 (22:16 +0200)
committerBert Vermeulen <redacted>
Thu, 29 May 2014 20:16:58 +0000 (22:16 +0200)
hardware/saleae-logic16/api.c
hardware/saleae-logic16/protocol.c
hardware/saleae-logic16/protocol.h

index 388d95a53c20b5f3c05313ae923351425e97543b..dee3d25cfdd952b88620c30e641ed7c0777ee572 100644 (file)
@@ -49,12 +49,21 @@ static const int32_t hwcaps[] = {
        SR_CONF_LOGIC_ANALYZER,
        SR_CONF_SAMPLERATE,
        SR_CONF_VOLTAGE_THRESHOLD,
+       SR_CONF_TRIGGER_MATCH,
 
        /* These are really implemented in the driver, not the hardware. */
        SR_CONF_LIMIT_SAMPLES,
        SR_CONF_CONTINUOUS,
 };
 
+static const int32_t soft_trigger_matches[] = {
+       SR_TRIGGER_ZERO,
+       SR_TRIGGER_ONE,
+       SR_TRIGGER_RISING,
+       SR_TRIGGER_FALLING,
+       SR_TRIGGER_EDGE,
+};
+
 static const char *channel_names[] = {
        "0", "1", "2", "3", "4", "5", "6", "7", "8",
        "9", "10", "11", "12", "13", "14", "15",
@@ -562,6 +571,11 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
                }
                *data = g_variant_builder_end(&gvb);
                break;
+       case SR_CONF_TRIGGER_MATCH:
+               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
+                               soft_trigger_matches, ARRAY_SIZE(soft_trigger_matches),
+                               sizeof(int32_t));
+               break;
        default:
                return SR_ERR_NA;
        }
@@ -573,7 +587,7 @@ static void abort_acquisition(struct dev_context *devc)
 {
        int i;
 
-       devc->num_samples = -1;
+       devc->sent_samples = -1;
 
        for (i = devc->num_transfers - 1; i >= 0; i--) {
                if (devc->transfers[i])
@@ -686,7 +700,7 @@ static int receive_data(int fd, int revents, void *cb_data)
        tv.tv_sec = tv.tv_usec = 0;
        libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv);
 
-       if (devc->num_samples == -2) {
+       if (devc->sent_samples == -2) {
                logic16_abort_acquisition(sdi);
                abort_acquisition(devc);
        }
@@ -699,6 +713,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;
@@ -719,11 +734,17 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        }
 
        devc->cb_data = cb_data;
-       devc->num_samples = 0;
+       devc->sent_samples = 0;
        devc->empty_transfer_count = 0;
        devc->cur_channel = 0;
        memset(devc->channel_data, 0, sizeof(devc->channel_data));
 
+       if ((trigger = sr_session_trigger_get())) {
+               devc->stl = soft_trigger_logic_new(sdi, trigger);
+               devc->trigger_fired = FALSE;
+       } else
+               devc->trigger_fired = TRUE;
+
        timeout = get_timeout(devc);
        num_transfers = get_number_of_transfers(devc);
        size = get_buffer_size(devc);
index e2c5f88c98a561ccf16d494b2ce8ae0cfd611f73..288c7de5d2f5217640d310149152e4555fdc764d 100644 (file)
@@ -590,6 +590,10 @@ static void finish_acquisition(struct dev_context *devc)
        devc->num_transfers = 0;
        g_free(devc->transfers);
        g_free(devc->convbuffer);
+       if (devc->stl) {
+               soft_trigger_logic_free(devc->stl);
+               devc->stl = NULL;
+       }
 }
 
 static void free_transfer(struct libusb_transfer *transfer)
@@ -731,7 +735,8 @@ SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer)
        struct sr_datafeed_packet packet;
        struct sr_datafeed_logic logic;
        struct dev_context *devc;
-       size_t converted_length;
+       size_t new_samples, num_samples;
+       int trigger_offset;
 
        devc = transfer->user_data;
 
@@ -739,7 +744,7 @@ SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer)
         * If acquisition has already ended, just free any queued up
         * transfer that come in.
         */
-       if (devc->num_samples < 0) {
+       if (devc->sent_samples < 0) {
                free_transfer(transfer);
                return;
        }
@@ -749,7 +754,7 @@ SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer)
 
        switch (transfer->status) {
        case LIBUSB_TRANSFER_NO_DEVICE:
-               devc->num_samples = -2;
+               devc->sent_samples = -2;
                free_transfer(transfer);
                return;
        case LIBUSB_TRANSFER_COMPLETED:
@@ -775,7 +780,7 @@ SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer)
                         * The FX2 gave up. End the acquisition, the frontend
                         * will work out that the samplecount is short.
                         */
-                       devc->num_samples = -2;
+                       devc->sent_samples = -2;
                        free_transfer(transfer);
                } else {
                        resubmit_transfer(transfer);
@@ -785,31 +790,46 @@ SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer)
                devc->empty_transfer_count = 0;
        }
 
-       converted_length = convert_sample_data(devc, devc->convbuffer,
-                               devc->convbuffer_size, transfer->buffer,
-                               transfer->actual_length, devc->unitsize);
-
-       if (converted_length > 0) {
-               /* Cap sample count if needed. */
-               if (devc->limit_samples &&
-                   (uint64_t)devc->num_samples + converted_length
-                   > devc->limit_samples) {
-                       converted_length =
-                               devc->limit_samples - devc->num_samples;
+       new_samples = convert_sample_data(devc, devc->convbuffer,
+                       devc->convbuffer_size, transfer->buffer,
+                       transfer->actual_length, devc->unitsize);
+
+       if (new_samples > 0) {
+               if (devc->trigger_fired) {
+                       /* Send the incoming transfer to the session bus. */
+                       packet.type = SR_DF_LOGIC;
+                       packet.payload = &logic;
+                       if (devc->limit_samples &&
+                                       new_samples > devc->limit_samples - devc->sent_samples)
+                               new_samples = devc->limit_samples - devc->sent_samples;
+                       logic.length = new_samples * devc->unitsize;
+                       logic.unitsize = devc->unitsize;
+                       logic.data = devc->convbuffer;
+                       sr_session_send(devc->cb_data, &packet);
+                       devc->sent_samples += new_samples;
+               } else {
+                       trigger_offset = soft_trigger_logic_check(devc->stl,
+                                       devc->convbuffer, new_samples * devc->unitsize);
+                       if (trigger_offset > -1) {
+                               packet.type = SR_DF_LOGIC;
+                               packet.payload = &logic;
+                               num_samples = new_samples - trigger_offset;
+                               if (devc->limit_samples &&
+                                               num_samples > devc->limit_samples - devc->sent_samples)
+                                       num_samples = devc->limit_samples - devc->sent_samples;
+                               logic.length = num_samples * devc->unitsize;
+                               logic.unitsize = devc->unitsize;
+                               logic.data = devc->convbuffer + trigger_offset * devc->unitsize;
+                               sr_session_send(devc->cb_data, &packet);
+                               devc->sent_samples += num_samples;
+
+                               devc->trigger_fired = TRUE;
+                       }
                }
 
-               /* Send the incoming transfer to the session bus. */
-               packet.type = SR_DF_LOGIC;
-               packet.payload = &logic;
-               logic.length = converted_length * devc->unitsize;
-               logic.unitsize = devc->unitsize;
-               logic.data = devc->convbuffer;
-               sr_session_send(devc->cb_data, &packet);
-
-               devc->num_samples += converted_length;
                if (devc->limit_samples &&
-                   (uint64_t)devc->num_samples >= devc->limit_samples) {
-                       devc->num_samples = -2;
+                               (uint64_t)devc->sent_samples >= devc->limit_samples) {
+                       devc->sent_samples = -2;
                        free_transfer(transfer);
                        return;
                }
index 00f96560645cb539816bd92f118192fc74b7fc7d..8557a3e3a2b2f1da01c067bb9aa69fa9118478b2 100644 (file)
@@ -63,7 +63,7 @@ struct dev_context {
        /* EEPROM data from address 8. */
        uint8_t eeprom_data[8];
 
-       int64_t num_samples;
+       int64_t sent_samples;
        int submitted_transfers;
        int empty_transfer_count;
        int num_channels, cur_channel, unitsize;
@@ -71,6 +71,8 @@ struct dev_context {
        uint16_t channel_data[16];
        uint8_t *convbuffer;
        size_t convbuffer_size;
+       struct soft_trigger_logic *stl;
+       gboolean trigger_fired;
 
        void *cb_data;
        unsigned int num_transfers;