From: Aurelien Jacobs Date: Tue, 25 Nov 2014 21:12:33 +0000 (+0100) Subject: beaglelogic: Add SR_CONF_CAPTURE_RATIO support. X-Git-Tag: libsigrok-0.4.0~706 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e743a47d6d23050c72aa1276c5df4a45a6bc5357;p=libsigrok.git beaglelogic: Add SR_CONF_CAPTURE_RATIO support. --- diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index 3c8cc3b3..098efa06 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -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; diff --git a/src/hardware/beaglelogic/protocol.c b/src/hardware/beaglelogic/protocol.c index 05dcccf1..a0a784e8 100644 --- a/src/hardware/beaglelogic/protocol.c +++ b/src/hardware/beaglelogic/protocol.c @@ -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); diff --git a/src/hardware/beaglelogic/protocol.h b/src/hardware/beaglelogic/protocol.h index f2acfeb0..90fad482 100644 --- a/src/hardware/beaglelogic/protocol.h +++ b/src/hardware/beaglelogic/protocol.h @@ -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;