]> sigrok.org Git - libsigrok.git/commitdiff
baylibre-acme: Use software limit helpers
authorLars-Peter Clausen <redacted>
Sun, 1 May 2016 11:56:57 +0000 (13:56 +0200)
committerUwe Hermann <redacted>
Mon, 9 May 2016 10:12:14 +0000 (12:12 +0200)
Signed-off-by: Lars-Peter Clausen <redacted>
src/hardware/baylibre-acme/api.c
src/hardware/baylibre-acme/protocol.c
src/hardware/baylibre-acme/protocol.h

index 6153513bd5b3017f173a80870e09704741ac6ca7..a556449c67654824a0e89d8935589db53799d91f 100644 (file)
@@ -174,10 +174,8 @@ static int config_get(uint32_t key, GVariant **data,
        ret = SR_OK;
        switch (key) {
        case SR_CONF_LIMIT_SAMPLES:
-               *data = g_variant_new_uint64(devc->limit_samples);
-               break;
        case SR_CONF_LIMIT_MSEC:
-               *data = g_variant_new_uint64(devc->limit_msec);
+               ret = sr_sw_limits_config_get(&devc->limits, key, data);
                break;
        case SR_CONF_SAMPLERATE:
                *data = g_variant_new_uint64(devc->samplerate);
@@ -219,12 +217,8 @@ static int config_set(uint32_t key, GVariant *data,
        ret = SR_OK;
        switch (key) {
        case SR_CONF_LIMIT_SAMPLES:
-               devc->limit_samples = g_variant_get_uint64(data);
-               devc->limit_msec = 0;
-               break;
        case SR_CONF_LIMIT_MSEC:
-               devc->limit_msec = g_variant_get_uint64(data) * 1000;
-               devc->limit_samples = 0;
+               ret = sr_sw_limits_config_set(&devc->limits, key, data);
                break;
        case SR_CONF_SAMPLERATE:
                samplerate = g_variant_get_uint64(data);
@@ -345,7 +339,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
                return SR_ERR;
 
        devc = sdi->priv;
-       devc->samples_read = 0;
        devc->samples_missed = 0;
        devc->timer_fd = timerfd_create(CLOCK_MONOTONIC, 0);
        if (devc->timer_fd < 0) {
@@ -372,7 +365,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
                G_IO_IN | G_IO_ERR, 1000, bl_acme_receive_data, (void *)sdi);
 
        std_session_send_df_header(sdi, LOG_PREFIX);
-       devc->start_time = g_get_monotonic_time();
+       sr_sw_limits_acquisition_start(&devc->limits);
 
        return SR_OK;
 }
index f6ceaf5d208cc92f428e6135d7ae740adbbd3673..ea25d95b00fcb3add71053454df369fd33363c32 100644 (file)
@@ -697,7 +697,6 @@ SR_PRIV void bl_acme_close_channel(struct sr_channel *ch)
 
 SR_PRIV int bl_acme_receive_data(int fd, int revents, void *cb_data)
 {
-       uint32_t cur_time, elapsed_time;
        uint64_t nrexpiration;
        struct sr_datafeed_packet packet, framep;
        struct sr_datafeed_analog_old analog;
@@ -783,23 +782,11 @@ SR_PRIV int bl_acme_receive_data(int fd, int revents, void *cb_data)
                sr_session_send(sdi, &framep);
        }
 
-       devc->samples_read++;
-       if (devc->limit_samples > 0 &&
-           devc->samples_read >= devc->limit_samples) {
-               sr_info("Requested number of samples reached.");
+       sr_sw_limits_update_samples_read(&devc->limits, 1);
+
+       if (sr_sw_limits_check(&devc->limits)) {
                sdi->driver->dev_acquisition_stop(sdi);
-               devc->last_sample_fin = g_get_monotonic_time();
                return TRUE;
-       } else if (devc->limit_msec > 0) {
-               cur_time = g_get_monotonic_time();
-               elapsed_time = cur_time - devc->start_time;
-
-               if (elapsed_time >= devc->limit_msec) {
-                       sr_info("Sampling time limit reached.");
-                       sdi->driver->dev_acquisition_stop(sdi);
-                       devc->last_sample_fin = g_get_monotonic_time();
-                       return TRUE;
-               }
        }
 
        devc->last_sample_fin = g_get_monotonic_time();
index d0c9761d6d0e4ac98832b1f10b0c2c2e04d7d17c..cb5f1f9af994710dc0d9c02e260cfe2800421a26 100644 (file)
@@ -52,13 +52,10 @@ enum probe_type {
 /** Private, per-device-instance driver context. */
 struct dev_context {
        uint64_t samplerate;
-       uint64_t limit_samples;
-       uint64_t limit_msec;
+       struct sr_sw_limits limits;
 
        uint32_t num_channels;
-       uint64_t samples_read;
        uint64_t samples_missed;
-       int64_t start_time;
        int64_t last_sample_fin;
        int timer_fd;
        GIOChannel *channel;