beaglelogic: Add SR_CONF_CAPTURE_RATIO support.

This commit is contained in:
Aurelien Jacobs 2014-11-25 22:12:33 +01:00
parent 5a971f66a3
commit e743a47d6d
3 changed files with 23 additions and 2 deletions

View 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;

View 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);

View 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;