From: Lars-Peter Clausen Date: Sun, 1 May 2016 11:53:39 +0000 (+0200) Subject: mic-985xx: Use software limit helpers X-Git-Tag: libsigrok-0.5.0~448 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=301090aa58844e78e7c4d45275a4b6c29b31c72a;p=libsigrok.git mic-985xx: Use software limit helpers Signed-off-by: Lars-Peter Clausen --- diff --git a/src/hardware/mic-985xx/api.c b/src/hardware/mic-985xx/api.c index 46cad7db..b0b64115 100644 --- a/src/hardware/mic-985xx/api.c +++ b/src/hardware/mic-985xx/api.c @@ -90,6 +90,7 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx) sdi->vendor = g_strdup(mic_devs[idx].vendor); sdi->model = g_strdup(mic_devs[idx].device); devc = g_malloc0(sizeof(struct dev_context)); + sr_sw_limits_init(&devc->limits); sdi->inst_type = SR_INST_SERIAL; sdi->conn = serial; sdi->priv = devc; @@ -152,18 +153,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd devc = sdi->priv; - switch (key) { - case SR_CONF_LIMIT_SAMPLES: - devc->limit_samples = g_variant_get_uint64(data); - break; - case SR_CONF_LIMIT_MSEC: - devc->limit_msec = g_variant_get_uint64(data); - break; - default: - return SR_ERR_NA; - } - - return SR_OK; + return sr_sw_limits_config_set(&devc->limits, key, data); } static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, @@ -206,9 +196,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, int idx) return SR_ERR_DEV_CLOSED; devc = sdi->priv; - devc->num_samples = 0; - devc->starttime = g_get_monotonic_time(); + sr_sw_limits_acquisition_start(&devc->limits); std_session_send_df_header(sdi, LOG_PREFIX); /* Poll every 100ms, or whenever some data comes in. */ diff --git a/src/hardware/mic-985xx/protocol.c b/src/hardware/mic-985xx/protocol.c index 151b7c83..9bd7dcd8 100644 --- a/src/hardware/mic-985xx/protocol.c +++ b/src/hardware/mic-985xx/protocol.c @@ -142,7 +142,7 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx) g_slist_free(l); } - devc->num_samples++; + sr_sw_limits_update_samples_read(&devc->limits, 1); return SR_OK; } @@ -186,7 +186,6 @@ static int receive_data(int fd, int revents, int idx, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; - int64_t t; static gboolean first_time = TRUE; struct sr_serial_dev_inst *serial; @@ -211,20 +210,8 @@ static int receive_data(int fd, int revents, int idx, void *cb_data) } } - if (devc->limit_samples && devc->num_samples >= devc->limit_samples) { - sr_info("Requested number of samples reached."); + if (sr_sw_limits_check(&devc->limits)) sdi->driver->dev_acquisition_stop(sdi); - return TRUE; - } - - if (devc->limit_msec) { - t = (g_get_monotonic_time() - devc->starttime) / 1000; - if (t > (int64_t)devc->limit_msec) { - sr_info("Requested time limit reached."); - sdi->driver->dev_acquisition_stop(sdi); - return TRUE; - } - } return TRUE; } diff --git a/src/hardware/mic-985xx/protocol.h b/src/hardware/mic-985xx/protocol.h index d522c0a4..d3aaf37b 100644 --- a/src/hardware/mic-985xx/protocol.h +++ b/src/hardware/mic-985xx/protocol.h @@ -54,16 +54,7 @@ extern SR_PRIV const struct mic_dev_info mic_devs[]; /** Private, per-device-instance driver context. */ struct dev_context { - /** The current sampling limit (in number of samples). */ - uint64_t limit_samples; - - /** The current sampling limit (in ms). */ - uint64_t limit_msec; - - /** The current number of already received samples. */ - uint64_t num_samples; - - int64_t starttime; + struct sr_sw_limits limits; uint8_t buf[SERIAL_BUFSIZE]; int bufoffset;