]> sigrok.org Git - libsigrok.git/commitdiff
fx2lafw: Add SR_CONF_CAPTURE_RATIO support.
authorAurelien Jacobs <redacted>
Tue, 25 Nov 2014 11:28:36 +0000 (12:28 +0100)
committerAurelien Jacobs <redacted>
Tue, 25 Nov 2014 15:56:34 +0000 (16:56 +0100)
src/hardware/fx2lafw/api.c
src/hardware/fx2lafw/protocol.c
src/hardware/fx2lafw/protocol.h

index 796749a34dbd0d3f004c7111654b6aa4e604f77f..213be9cf2d72488a9a5d3a216e086829c3dfc2b6 100644 (file)
@@ -87,6 +87,7 @@ static const uint32_t devopts[] = {
        SR_CONF_CONN | SR_CONF_GET,
        SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
        SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
+       SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET,
 };
 
 static const char *channel_names[] = {
@@ -435,6 +436,9 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
        case SR_CONF_SAMPLERATE:
                *data = g_variant_new_uint64(devc->cur_samplerate);
                break;
+       case SR_CONF_CAPTURE_RATIO:
+               *data = g_variant_new_uint64(devc->capture_ratio);
+               break;
        default:
                return SR_ERR_NA;
        }
@@ -477,6 +481,14 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                case SR_CONF_LIMIT_SAMPLES:
                        devc->limit_samples = g_variant_get_uint64(data);
                        break;
+               case SR_CONF_CAPTURE_RATIO:
+                       devc->capture_ratio = g_variant_get_uint64(data);
+                       if (devc->capture_ratio > 100) {
+                               devc->capture_ratio = 0;
+                               ret = SR_ERR;
+                       } else
+                               ret = SR_OK;
+                       break;
                default:
                        ret = SR_ERR_NA;
        }
@@ -567,7 +579,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        devc->empty_transfer_count = 0;
 
        if ((trigger = sr_session_trigger_get(sdi->session))) {
-               devc->stl = soft_trigger_logic_new(sdi, trigger, 0);
+               int pre_trigger_samples = 0;
+               if (devc->limit_samples > 0)
+                       pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100;
+               devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
+               if (devc->stl == NULL)
+                       return SR_ERR_MALLOC;
                devc->trigger_fired = FALSE;
        } else
                devc->trigger_fired = TRUE;
index d1d2d6a6df627710bea1e370a4bc859b1610d9ee..bc3228f12d23fff44b4013da873011c4d4c5932c 100644 (file)
@@ -304,6 +304,7 @@ SR_PRIV struct dev_context *fx2lafw_dev_new(void)
        devc->fw_updated = 0;
        devc->cur_samplerate = 0;
        devc->limit_samples = 0;
+       devc->capture_ratio = 0;
        devc->sample_wide = FALSE;
        devc->stl = NULL;
 
@@ -391,6 +392,7 @@ SR_PRIV void fx2lafw_receive_transfer(struct libusb_transfer *transfer)
        struct sr_datafeed_logic logic;
        unsigned int num_samples;
        int trigger_offset, cur_sample_count, unitsize;
+       int pre_trigger_samples;
 
        sdi = transfer->user_data;
        devc = sdi->priv;
@@ -458,8 +460,9 @@ SR_PRIV void fx2lafw_receive_transfer(struct libusb_transfer *transfer)
                }
        } else {
                trigger_offset = soft_trigger_logic_check(devc->stl,
-                               transfer->buffer, transfer->actual_length, NULL);
+                       transfer->buffer, transfer->actual_length, &pre_trigger_samples);
                if (trigger_offset > -1) {
+                       devc->sent_samples += pre_trigger_samples;
                        packet.type = SR_DF_LOGIC;
                        packet.payload = &logic;
                        num_samples = cur_sample_count - trigger_offset;
index fef0dd76bb85f8ae730d4553fb9760b780ac625c..48be99309f13ddafa2805ca52a8359e7de0210b6 100644 (file)
@@ -80,6 +80,7 @@ struct dev_context {
        /* Device/capture settings */
        uint64_t cur_samplerate;
        uint64_t limit_samples;
+       uint64_t capture_ratio;
 
        /* Operational settings */
        gboolean trigger_fired;