drivers: SR_CONF_CAPTURE_RATIO fixes.

Move the check for the capture ratio being 0..100 into the wrappers,
drop unneeded helper functions, fix incorrect variable types, minor
other consistency fixes.
This commit is contained in:
Uwe Hermann 2017-07-28 21:29:12 +02:00
parent 758906aa71
commit efad7cccec
20 changed files with 35 additions and 74 deletions

View File

@ -193,7 +193,6 @@ static int config_set(uint32_t key, GVariant *data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct dev_context *devc;
uint64_t tmp;
(void)cg;
@ -206,16 +205,13 @@ static int config_set(uint32_t key, GVariant *data,
devc->limit_msec = g_variant_get_uint64(data);
break;
case SR_CONF_LIMIT_SAMPLES:
tmp = g_variant_get_uint64(data);
devc->limit_samples = tmp;
devc->limit_msec = sigma_limit_samples_to_msec(devc, tmp);
devc->limit_samples = g_variant_get_uint64(data);
devc->limit_msec = sigma_limit_samples_to_msec(devc,
devc->limit_samples);
break;
#if ASIX_SIGMA_WITH_TRIGGER
case SR_CONF_CAPTURE_RATIO:
tmp = g_variant_get_uint64(data);
if (tmp > 100)
return SR_ERR;
devc->capture_ratio = tmp;
devc->capture_ratio = g_variant_get_uint64(data);
break;
#endif
default:

View File

@ -264,7 +264,7 @@ struct dev_context {
int num_channels;
int cur_channels;
int samples_per_event;
int capture_ratio;
uint64_t capture_ratio;
struct sigma_trigger trigger;
int use_triggers;
struct sigma_state state;

View File

@ -227,9 +227,7 @@ static int config_set(uint32_t key, GVariant *data,
return beaglelogic_set_triggerflags(devc);
case SR_CONF_CAPTURE_RATIO:
devc->capture_ratio = g_variant_get_uint64(data);
if (devc->capture_ratio > 100)
return SR_ERR;
return SR_OK;
break;
default:
return SR_ERR_NA;
}
@ -279,7 +277,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
if ((trigger = sr_session_trigger_get(sdi->session))) {
int pre_trigger_samples = 0;
if (devc->limit_samples > 0)
pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100;
pre_trigger_samples = (devc->capture_ratio * devc->limit_samples) / 100;
devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
if (!devc->stl)
return SR_ERR_MALLOC;

View File

@ -464,7 +464,7 @@ static int config_set(uint32_t key, GVariant *data,
break;
case SR_CONF_CAPTURE_RATIO:
devc->capture_ratio = g_variant_get_uint64(data);
return (devc->capture_ratio > 100) ? SR_ERR : SR_OK;
break;
case SR_CONF_VOLTAGE_THRESHOLD:
if (!strcmp(devc->profile->model, "DSLogic")) {
if ((idx = std_double_tuple_idx(data, ARRAY_AND_SIZE(voltage_thresholds))) < 0)

View File

@ -508,7 +508,7 @@ static int config_set(uint32_t key, GVariant *data,
break;
case SR_CONF_CAPTURE_RATIO:
devc->capture_ratio = g_variant_get_uint64(data);
return (devc->capture_ratio > 100) ? SR_ERR : SR_OK;
break;
default:
return SR_ERR_NA;
}

View File

@ -614,7 +614,7 @@ static int start_transfers(const struct sr_dev_inst *sdi)
if ((trigger = sr_session_trigger_get(sdi->session))) {
int pre_trigger_samples = 0;
if (devc->limit_samples > 0)
pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100;
pre_trigger_samples = (devc->capture_ratio * devc->limit_samples) / 100;
devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
if (!devc->stl)
return SR_ERR_MALLOC;

View File

@ -270,10 +270,13 @@ static int config_get(uint32_t key, GVariant **data,
static int config_set(uint32_t key, GVariant *data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
uint64_t samplerate, limit_samples, capture_ratio;
struct dev_context *devc;
uint64_t samplerate, limit_samples;
(void)cg;
devc = sdi->priv;
switch (key) {
case SR_CONF_LIMIT_SAMPLES:
limit_samples = g_variant_get_uint64(data);
@ -282,8 +285,8 @@ static int config_set(uint32_t key, GVariant *data,
samplerate = g_variant_get_uint64(data);
return sl2_set_samplerate(sdi, samplerate);
case SR_CONF_CAPTURE_RATIO:
capture_ratio = g_variant_get_uint64(data);
return sl2_set_capture_ratio(sdi, capture_ratio);
devc->capture_ratio = g_variant_get_uint64(data);
break;
default:
return SR_ERR_NA;
}

View File

@ -531,25 +531,6 @@ SR_PRIV int sl2_convert_trigger(const struct sr_dev_inst *sdi)
return SR_OK;
}
SR_PRIV int sl2_set_capture_ratio(const struct sr_dev_inst *sdi,
uint64_t capture_ratio)
{
struct dev_context *devc;
devc = sdi->priv;
if (capture_ratio > 100) {
sr_err("Invalid capture ratio: %" PRIu64 " %%.", capture_ratio);
return SR_ERR_ARG;
}
sr_info("Capture ratio set to %" PRIu64 " %%.", capture_ratio);
devc->capture_ratio = capture_ratio;
return SR_OK;
}
SR_PRIV int sl2_set_after_trigger_delay(const struct sr_dev_inst *sdi,
uint64_t after_trigger_delay)
{

View File

@ -138,7 +138,7 @@ struct dev_context {
uint8_t trigger_channel;
uint8_t trigger_type;
unsigned int capture_ratio;
uint64_t capture_ratio;
/* Time that the trigger will be delayed in milliseconds. */
uint16_t after_trigger_delay;
@ -218,8 +218,6 @@ SR_PRIV int sl2_set_samplerate(const struct sr_dev_inst *sdi,
SR_PRIV int sl2_set_limit_samples(const struct sr_dev_inst *sdi,
uint64_t limit_samples);
SR_PRIV int sl2_convert_trigger(const struct sr_dev_inst *sdi);
SR_PRIV int sl2_set_capture_ratio(const struct sr_dev_inst *sdi,
uint64_t capture_ratio);
SR_PRIV int sl2_set_after_trigger_delay(const struct sr_dev_inst *sdi,
uint64_t after_trigger_delay);
SR_PRIV void sl2_calculate_trigger_samples(const struct sr_dev_inst *sdi);

View File

@ -393,8 +393,6 @@ static int config_set(uint32_t key, GVariant *data,
return lls_set_samplerate(sdi, g_variant_get_uint64(data));
case SR_CONF_CAPTURE_RATIO:
devc->capture_ratio = g_variant_get_uint64(data);
if (devc->capture_ratio > 100)
return SR_ERR;
break;
default:
return SR_ERR_NA;

View File

@ -1127,7 +1127,7 @@ SR_PRIV int lls_start_acquisition(const struct sr_dev_inst *sdi)
total_samples = devc->num_thousand_samples * 1000;
pre_trigger_samples = total_samples * devc->capture_ratio / 100;
pre_trigger_samples = (total_samples * devc->capture_ratio) / 100;
post_trigger_samples = total_samples - pre_trigger_samples;
pre_trigger_tr = transform_sample_count(devc, pre_trigger_samples);

View File

@ -253,10 +253,6 @@ static int config_set(uint32_t key, GVariant *data,
break;
case SR_CONF_CAPTURE_RATIO:
devc->capture_ratio = g_variant_get_uint64(data);
if (devc->capture_ratio < 0 || devc->capture_ratio > 100)
return SR_ERR;
else
return SR_OK;
break;
case SR_CONF_EXTERNAL_CLOCK:
if (g_variant_get_boolean(data)) {

View File

@ -75,7 +75,7 @@ struct dev_context {
uint64_t cur_samplerate;
uint32_t cur_samplerate_divider;
uint64_t limit_samples;
int capture_ratio;
uint64_t capture_ratio;
int trigger_at;
uint32_t channel_mask;
uint32_t trigger_mask[NUM_TRIGGER_STAGES];

View File

@ -264,10 +264,6 @@ static int config_set(uint32_t key, GVariant *data,
break;
case SR_CONF_CAPTURE_RATIO:
devc->capture_ratio = g_variant_get_uint64(data);
if (devc->capture_ratio < 0 || devc->capture_ratio > 100)
return SR_ERR;
else
return SR_OK;
break;
case SR_CONF_EXTERNAL_CLOCK:
if (g_variant_get_boolean(data)) {

View File

@ -87,7 +87,7 @@ struct dev_context {
uint32_t cur_samplerate_divider;
uint32_t max_samples;
uint64_t limit_samples;
int capture_ratio;
uint64_t capture_ratio;
int trigger_at;
uint32_t channel_mask;
uint32_t trigger_mask[NUM_TRIGGER_STAGES];

View File

@ -468,7 +468,7 @@ static int config_set(uint32_t key, GVariant *data,
break;
case SR_CONF_CAPTURE_RATIO:
devc->capture_ratio = g_variant_get_uint64(data);
return (devc->capture_ratio > 100) ? SR_ERR : SR_OK;
break;
case SR_CONF_VOLTAGE_THRESHOLD:
if ((idx = std_double_tuple_idx(data, ARRAY_AND_SIZE(volt_thresholds))) < 0)
return SR_ERR_ARG;
@ -649,7 +649,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
if ((trigger = sr_session_trigger_get(sdi->session))) {
int pre_trigger_samples = 0;
if (devc->limit_samples > 0)
pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100;
pre_trigger_samples = (devc->capture_ratio * devc->limit_samples) / 100;
devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
if (!devc->stl)
return SR_ERR_MALLOC;

View File

@ -372,7 +372,8 @@ static int config_set(uint32_t key, GVariant *data,
case SR_CONF_LIMIT_SAMPLES:
return set_limit_samples(devc, g_variant_get_uint64(data));
case SR_CONF_CAPTURE_RATIO:
return set_capture_ratio(devc, g_variant_get_uint64(data));
devc->capture_ratio = g_variant_get_uint64(data);
break;
case SR_CONF_VOLTAGE_THRESHOLD:
g_variant_get(data, "(dd)", &low, &high);
return set_voltage_threshold(devc, (low + high) / 2.0);

View File

@ -79,20 +79,6 @@ SR_PRIV int set_limit_samples(struct dev_context *devc, uint64_t samples)
return SR_OK;
}
SR_PRIV int set_capture_ratio(struct dev_context *devc, uint64_t ratio)
{
if (ratio > 100) {
sr_err("Invalid capture ratio: %" PRIu64 ".", ratio);
return SR_ERR_ARG;
}
devc->capture_ratio = ratio;
sr_info("Setting capture ratio to %d%%.", devc->capture_ratio);
return SR_OK;
}
SR_PRIV int set_voltage_threshold(struct dev_context *devc, double thresh)
{
if (thresh > 6.0)
@ -118,7 +104,7 @@ SR_PRIV void set_triggerbar(struct dev_context *devc)
trigger_depth = devc->limit_samples;
if (devc->trigger)
triggerbar = trigger_depth * devc->capture_ratio / 100;
triggerbar = (trigger_depth * devc->capture_ratio) / 100;
else
triggerbar = 0;

View File

@ -42,7 +42,7 @@ struct dev_context {
//uint8_t trigger_value[NUM_TRIGGER_STAGES];
// uint8_t trigger_buffer[NUM_TRIGGER_STAGES];
int trigger;
unsigned int capture_ratio;
uint64_t capture_ratio;
double cur_threshold;
const struct zp_model *prof;
};
@ -50,7 +50,6 @@ struct dev_context {
SR_PRIV unsigned int get_memory_size(int type);
SR_PRIV int zp_set_samplerate(struct dev_context *devc, uint64_t samplerate);
SR_PRIV int set_limit_samples(struct dev_context *devc, uint64_t samples);
SR_PRIV int set_capture_ratio(struct dev_context *devc, uint64_t ratio);
SR_PRIV int set_voltage_threshold(struct dev_context *devc, double thresh);
SR_PRIV void set_triggerbar(struct dev_context *devc);

View File

@ -690,6 +690,15 @@ static int check_key(const struct sr_dev_driver *driver,
return SR_ERR_ARG;
}
break;
case SR_CONF_CAPTURE_RATIO:
/* Capture ratio must always be between 0 and 100. */
if (op != SR_CONF_SET || !data)
break;
if (g_variant_get_uint64(data) > 100) {
sr_err("Capture ratio must be 0..100.");
return SR_ERR_ARG;
}
break;
}
if (sr_config_list(driver, sdi, cg, SR_CONF_DEVICE_OPTIONS, &gvar_opts) != SR_OK) {