demo: Fixup soft-trigger
This commit is contained in:
parent
6fc51fb1ee
commit
d10781808d
|
@ -442,6 +442,27 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
||||||
devc->sent_samples = 0;
|
devc->sent_samples = 0;
|
||||||
devc->sent_frame_samples = 0;
|
devc->sent_frame_samples = 0;
|
||||||
|
|
||||||
|
/* Setup triggers */
|
||||||
|
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;
|
||||||
|
devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
|
||||||
|
if (!devc->stl)
|
||||||
|
return SR_ERR_MALLOC;
|
||||||
|
|
||||||
|
/* Disable all analog channels since using them when there are logic
|
||||||
|
* triggers set up would require having pre-trigger sample buffers
|
||||||
|
* for analog sample data.
|
||||||
|
*/
|
||||||
|
for (l = sdi->channels; l; l = l->next) {
|
||||||
|
ch = l->data;
|
||||||
|
if (ch->type == SR_CHANNEL_ANALOG)
|
||||||
|
ch->enabled = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
devc->trigger_fired = FALSE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determine the numbers of logic and analog channels that are
|
* Determine the numbers of logic and analog channels that are
|
||||||
* involved in the acquisition. Determine an offset and a mask to
|
* involved in the acquisition. Determine an offset and a mask to
|
||||||
|
@ -502,18 +523,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
||||||
devc->spent_us = 0;
|
devc->spent_us = 0;
|
||||||
devc->step = 0;
|
devc->step = 0;
|
||||||
|
|
||||||
/* Store Triggers to stl and preset trigger_fired */
|
|
||||||
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;
|
|
||||||
devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
|
|
||||||
if (!devc->stl)
|
|
||||||
return SR_ERR_MALLOC;
|
|
||||||
devc->trigger_fired = FALSE;
|
|
||||||
} else
|
|
||||||
devc->trigger_fired = TRUE;
|
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -419,8 +419,7 @@ static void send_analog_packet(struct analog_gen *ag,
|
||||||
ag_pattern_pos + i)) / 2;
|
ag_pattern_pos + i)) / 2;
|
||||||
ag->num_avgs++;
|
ag->num_avgs++;
|
||||||
/* Time to send averaged data? */
|
/* Time to send averaged data? */
|
||||||
if (devc->avg_samples > 0 &&
|
if ((devc->avg_samples > 0) && (ag->num_avgs >= devc->avg_samples))
|
||||||
ag->num_avgs >= devc->avg_samples)
|
|
||||||
goto do_send;
|
goto do_send;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,6 +511,7 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data)
|
||||||
logic_done = devc->num_logic_channels > 0 ? 0 : samples_todo;
|
logic_done = devc->num_logic_channels > 0 ? 0 : samples_todo;
|
||||||
if (!devc->enabled_logic_channels)
|
if (!devc->enabled_logic_channels)
|
||||||
logic_done = samples_todo;
|
logic_done = samples_todo;
|
||||||
|
|
||||||
analog_done = devc->num_analog_channels > 0 ? 0 : samples_todo;
|
analog_done = devc->num_analog_channels > 0 ? 0 : samples_todo;
|
||||||
if (!devc->enabled_analog_channels)
|
if (!devc->enabled_analog_channels)
|
||||||
analog_done = samples_todo;
|
analog_done = samples_todo;
|
||||||
|
@ -522,32 +522,51 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data)
|
||||||
sending_now = MIN(samples_todo - logic_done,
|
sending_now = MIN(samples_todo - logic_done,
|
||||||
LOGIC_BUFSIZE / devc->logic_unitsize);
|
LOGIC_BUFSIZE / devc->logic_unitsize);
|
||||||
logic_generator(sdi, sending_now * devc->logic_unitsize);
|
logic_generator(sdi, sending_now * devc->logic_unitsize);
|
||||||
/* Trigger */
|
/* Check for trigger and send pre-trigger data if needed */
|
||||||
if (!devc->trigger_fired) {
|
if (devc->stl && (!devc->trigger_fired)) {
|
||||||
trigger_offset = soft_trigger_logic_check(devc->stl,
|
trigger_offset = soft_trigger_logic_check(devc->stl,
|
||||||
devc->logic_data, sending_now * devc->logic_unitsize,
|
devc->logic_data, sending_now * devc->logic_unitsize,
|
||||||
&pre_trigger_samples);
|
&pre_trigger_samples);
|
||||||
if (trigger_offset > -1)
|
if (trigger_offset > -1) {
|
||||||
devc->trigger_fired = TRUE;
|
devc->trigger_fired = TRUE;
|
||||||
logic_done = pre_trigger_samples;
|
logic_done = pre_trigger_samples;
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
trigger_offset = 0;
|
trigger_offset = 0;
|
||||||
|
|
||||||
/* Remaining data */
|
/* Send logic samples if needed */
|
||||||
if (devc->trigger_fired && trigger_offset < (unsigned int)sending_now) {
|
|
||||||
packet.type = SR_DF_LOGIC;
|
packet.type = SR_DF_LOGIC;
|
||||||
packet.payload = &logic;
|
packet.payload = &logic;
|
||||||
logic.length = (sending_now - trigger_offset) * devc->logic_unitsize;
|
|
||||||
logic.unitsize = devc->logic_unitsize;
|
logic.unitsize = devc->logic_unitsize;
|
||||||
|
|
||||||
|
if (devc->stl) {
|
||||||
|
if (devc->trigger_fired && (trigger_offset < (int)sending_now)) {
|
||||||
|
/* Send after-trigger data */
|
||||||
|
logic.length = (sending_now - trigger_offset) * devc->logic_unitsize;
|
||||||
logic.data = devc->logic_data + trigger_offset * devc->logic_unitsize;
|
logic.data = devc->logic_data + trigger_offset * devc->logic_unitsize;
|
||||||
logic_fixup_feed(devc, &logic);
|
logic_fixup_feed(devc, &logic);
|
||||||
sr_session_send(sdi, &packet);
|
sr_session_send(sdi, &packet);
|
||||||
logic_done += sending_now - trigger_offset;
|
logic_done += sending_now - trigger_offset;
|
||||||
|
/* End acquisition */
|
||||||
|
sr_dbg("Triggered, stopping acquisition.");
|
||||||
|
sr_dev_acquisition_stop(sdi);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
/* Send nothing */
|
||||||
|
logic_done += sending_now;
|
||||||
|
}
|
||||||
|
} else if (!devc->stl) {
|
||||||
|
/* No trigger defined, send logic samples */
|
||||||
|
logic.length = sending_now * devc->logic_unitsize;
|
||||||
|
logic.data = devc->logic_data;
|
||||||
|
logic_fixup_feed(devc, &logic);
|
||||||
|
sr_session_send(sdi, &packet);
|
||||||
|
logic_done += sending_now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Analog, one channel at a time */
|
/* Analog, one channel at a time */
|
||||||
if (devc->trigger_fired && analog_done < samples_todo) {
|
if (analog_done < samples_todo) {
|
||||||
analog_sent = 0;
|
analog_sent = 0;
|
||||||
|
|
||||||
g_hash_table_iter_init(&iter, devc->ch_ag);
|
g_hash_table_iter_init(&iter, devc->ch_ag);
|
||||||
|
@ -558,12 +577,6 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data)
|
||||||
}
|
}
|
||||||
analog_done += analog_sent;
|
analog_done += analog_sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If trigger didn't happen continue to next iteration
|
|
||||||
* Allow the client to stop this process
|
|
||||||
*/
|
|
||||||
if (!devc->trigger_fired)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t min = MIN(logic_done, analog_done);
|
uint64_t min = MIN(logic_done, analog_done);
|
||||||
|
|
|
@ -1044,6 +1044,7 @@ struct soft_trigger_logic {
|
||||||
int pre_trigger_fill;
|
int pre_trigger_fill;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SR_PRIV int logic_channel_unitsize(GSList *channels);
|
||||||
SR_PRIV struct soft_trigger_logic *soft_trigger_logic_new(
|
SR_PRIV struct soft_trigger_logic *soft_trigger_logic_new(
|
||||||
const struct sr_dev_inst *sdi, struct sr_trigger *trigger,
|
const struct sr_dev_inst *sdi, struct sr_trigger *trigger,
|
||||||
int pre_trigger_samples);
|
int pre_trigger_samples);
|
||||||
|
|
|
@ -26,22 +26,21 @@
|
||||||
#define LOG_PREFIX "soft-trigger"
|
#define LOG_PREFIX "soft-trigger"
|
||||||
/* @endcond */
|
/* @endcond */
|
||||||
|
|
||||||
static size_t logic_channel_unitsize(GSList *channels)
|
SR_PRIV int logic_channel_unitsize(GSList *channels)
|
||||||
{
|
{
|
||||||
size_t number = 0;
|
int number = 0;
|
||||||
struct sr_channel *channel;
|
struct sr_channel *channel;
|
||||||
GSList *l;
|
GSList *l;
|
||||||
|
|
||||||
for (l = channels; l; l = l->next) {
|
for (l = channels; l; l = l->next) {
|
||||||
channel = l->data;
|
channel = l->data;
|
||||||
if (channel->type == SR_CHANNEL_LOGIC)
|
if (channel->type == SR_CHANNEL_LOGIC)
|
||||||
number += 1;
|
number++;
|
||||||
}
|
}
|
||||||
sr_dbg("number of logic channels: %d", (int) number);
|
|
||||||
return (number + 7) / 8;
|
return (number + 7) / 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SR_PRIV struct soft_trigger_logic *soft_trigger_logic_new(
|
SR_PRIV struct soft_trigger_logic *soft_trigger_logic_new(
|
||||||
const struct sr_dev_inst *sdi, struct sr_trigger *trigger,
|
const struct sr_dev_inst *sdi, struct sr_trigger *trigger,
|
||||||
int pre_trigger_samples)
|
int pre_trigger_samples)
|
||||||
|
@ -51,7 +50,6 @@ SR_PRIV struct soft_trigger_logic *soft_trigger_logic_new(
|
||||||
stl = g_malloc0(sizeof(struct soft_trigger_logic));
|
stl = g_malloc0(sizeof(struct soft_trigger_logic));
|
||||||
stl->sdi = sdi;
|
stl->sdi = sdi;
|
||||||
stl->trigger = trigger;
|
stl->trigger = trigger;
|
||||||
/* Retreive number of logic channels, unitsize */
|
|
||||||
stl->unitsize = logic_channel_unitsize(sdi->channels);
|
stl->unitsize = logic_channel_unitsize(sdi->channels);
|
||||||
stl->prev_sample = g_malloc0(stl->unitsize);
|
stl->prev_sample = g_malloc0(stl->unitsize);
|
||||||
stl->pre_trigger_size = stl->unitsize * pre_trigger_samples;
|
stl->pre_trigger_size = stl->unitsize * pre_trigger_samples;
|
||||||
|
|
Loading…
Reference in New Issue