]> sigrok.org Git - libsigrok.git/commitdiff
beaglelogic: Add SR_CONF_CAPTURE_RATIO support.
authorAurelien Jacobs <redacted>
Tue, 25 Nov 2014 21:12:33 +0000 (22:12 +0100)
committerAurelien Jacobs <redacted>
Tue, 25 Nov 2014 21:13:36 +0000 (22:13 +0100)
src/hardware/beaglelogic/api.c
src/hardware/beaglelogic/protocol.c
src/hardware/beaglelogic/protocol.h

index 3c8cc3b39f72c309c56cccaef94b04b06632285c..098efa0627927cc3bb3453ff8d8a0b76d9207baa 100644 (file)
@@ -35,6 +35,7 @@ static const uint32_t devopts[] = {
        SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
        SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET,
        SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
+       SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET,
        SR_CONF_NUM_LOGIC_CHANNELS | SR_CONF_GET,
 };
 
@@ -242,6 +243,10 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
                *data = g_variant_new_uint64(devc->cur_samplerate);
                break;
 
+       case SR_CONF_CAPTURE_RATIO:
+               *data = g_variant_new_uint64(devc->capture_ratio);
+               break;
+
        case SR_CONF_NUM_LOGIC_CHANNELS:
                *data = g_variant_new_uint32(g_slist_length(sdi->channels));
                break;
@@ -286,6 +291,14 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                }
                return beaglelogic_set_triggerflags(devc);
 
+       case SR_CONF_CAPTURE_RATIO:
+               devc->capture_ratio = g_variant_get_uint64(data);
+               if (devc->capture_ratio > 100) {
+                       devc->capture_ratio = 0;
+                       return SR_ERR;
+               }
+               return SR_OK;
+
        default:
                return SR_ERR_NA;
        }
@@ -361,7 +374,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
 
        /* Configure triggers & send header packet */
        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 05dcccf1ffac25bc0a1f0e3784e150f94bd68c7e..a0a784e874502d6ca5ef93498674ac241c331468 100644 (file)
@@ -40,6 +40,7 @@ SR_PRIV int beaglelogic_receive_data(int fd, int revents, void *cb_data)
        struct sr_datafeed_logic logic;
 
        int trigger_offset;
+       int pre_trigger_samples;
        uint32_t packetsize;
        uint64_t bytes_remaining;
 
@@ -67,8 +68,9 @@ SR_PRIV int beaglelogic_receive_data(int fd, int revents, void *cb_data)
                } else {
                        /* Check for trigger */
                        trigger_offset = soft_trigger_logic_check(devc->stl,
-                                       logic.data, packetsize, NULL);
+                                       logic.data, packetsize, &pre_trigger_samples);
                        if (trigger_offset > -1) {
+                               devc->bytes_read += pre_trigger_samples * logic.unitsize;
                                trigger_offset *= logic.unitsize;
                                logic.length = MIN(packetsize - trigger_offset,
                                                bytes_remaining);
index f2acfeb0151e84da53ae42fb7ab876edb4a4008b..90fad482e56b896c7f6d946f6e3f6703bbb1d133 100644 (file)
@@ -43,6 +43,7 @@ struct dev_context {
        uint64_t limit_samples;
        uint32_t sampleunit;
        uint32_t triggerflags;
+       uint64_t capture_ratio;
 
        /* Buffers: size of each buffer block and the total buffer area */
        uint32_t bufunitsize;