From: Bert Vermeulen Date: Thu, 29 May 2014 20:16:58 +0000 (+0200) Subject: saleae-logic16: Use new library software trigger. X-Git-Tag: libsigrok-0.4.0~1295 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=863357fb1091489d5ecb4257bcb879b3beb79734;p=libsigrok.git saleae-logic16: Use new library software trigger. --- diff --git a/hardware/saleae-logic16/api.c b/hardware/saleae-logic16/api.c index 388d95a5..dee3d25c 100644 --- a/hardware/saleae-logic16/api.c +++ b/hardware/saleae-logic16/api.c @@ -49,12 +49,21 @@ static const int32_t hwcaps[] = { SR_CONF_LOGIC_ANALYZER, SR_CONF_SAMPLERATE, SR_CONF_VOLTAGE_THRESHOLD, + SR_CONF_TRIGGER_MATCH, /* These are really implemented in the driver, not the hardware. */ SR_CONF_LIMIT_SAMPLES, SR_CONF_CONTINUOUS, }; +static const int32_t soft_trigger_matches[] = { + SR_TRIGGER_ZERO, + SR_TRIGGER_ONE, + SR_TRIGGER_RISING, + SR_TRIGGER_FALLING, + SR_TRIGGER_EDGE, +}; + static const char *channel_names[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", @@ -562,6 +571,11 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, } *data = g_variant_builder_end(&gvb); break; + case SR_CONF_TRIGGER_MATCH: + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, + soft_trigger_matches, ARRAY_SIZE(soft_trigger_matches), + sizeof(int32_t)); + break; default: return SR_ERR_NA; } @@ -573,7 +587,7 @@ static void abort_acquisition(struct dev_context *devc) { int i; - devc->num_samples = -1; + devc->sent_samples = -1; for (i = devc->num_transfers - 1; i >= 0; i--) { if (devc->transfers[i]) @@ -686,7 +700,7 @@ static int receive_data(int fd, int revents, void *cb_data) tv.tv_sec = tv.tv_usec = 0; libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv); - if (devc->num_samples == -2) { + if (devc->sent_samples == -2) { logic16_abort_acquisition(sdi); abort_acquisition(devc); } @@ -699,6 +713,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) struct dev_context *devc; struct drv_context *drvc; struct sr_usb_dev_inst *usb; + struct sr_trigger *trigger; struct libusb_transfer *transfer; unsigned int i, timeout, num_transfers; int ret; @@ -719,11 +734,17 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) } devc->cb_data = cb_data; - devc->num_samples = 0; + devc->sent_samples = 0; devc->empty_transfer_count = 0; devc->cur_channel = 0; memset(devc->channel_data, 0, sizeof(devc->channel_data)); + if ((trigger = sr_session_trigger_get())) { + devc->stl = soft_trigger_logic_new(sdi, trigger); + devc->trigger_fired = FALSE; + } else + devc->trigger_fired = TRUE; + timeout = get_timeout(devc); num_transfers = get_number_of_transfers(devc); size = get_buffer_size(devc); diff --git a/hardware/saleae-logic16/protocol.c b/hardware/saleae-logic16/protocol.c index e2c5f88c..288c7de5 100644 --- a/hardware/saleae-logic16/protocol.c +++ b/hardware/saleae-logic16/protocol.c @@ -590,6 +590,10 @@ static void finish_acquisition(struct dev_context *devc) devc->num_transfers = 0; g_free(devc->transfers); g_free(devc->convbuffer); + if (devc->stl) { + soft_trigger_logic_free(devc->stl); + devc->stl = NULL; + } } static void free_transfer(struct libusb_transfer *transfer) @@ -731,7 +735,8 @@ SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer) struct sr_datafeed_packet packet; struct sr_datafeed_logic logic; struct dev_context *devc; - size_t converted_length; + size_t new_samples, num_samples; + int trigger_offset; devc = transfer->user_data; @@ -739,7 +744,7 @@ SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer) * If acquisition has already ended, just free any queued up * transfer that come in. */ - if (devc->num_samples < 0) { + if (devc->sent_samples < 0) { free_transfer(transfer); return; } @@ -749,7 +754,7 @@ SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer) switch (transfer->status) { case LIBUSB_TRANSFER_NO_DEVICE: - devc->num_samples = -2; + devc->sent_samples = -2; free_transfer(transfer); return; case LIBUSB_TRANSFER_COMPLETED: @@ -775,7 +780,7 @@ SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer) * The FX2 gave up. End the acquisition, the frontend * will work out that the samplecount is short. */ - devc->num_samples = -2; + devc->sent_samples = -2; free_transfer(transfer); } else { resubmit_transfer(transfer); @@ -785,31 +790,46 @@ SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer) devc->empty_transfer_count = 0; } - converted_length = convert_sample_data(devc, devc->convbuffer, - devc->convbuffer_size, transfer->buffer, - transfer->actual_length, devc->unitsize); - - if (converted_length > 0) { - /* Cap sample count if needed. */ - if (devc->limit_samples && - (uint64_t)devc->num_samples + converted_length - > devc->limit_samples) { - converted_length = - devc->limit_samples - devc->num_samples; + new_samples = convert_sample_data(devc, devc->convbuffer, + devc->convbuffer_size, transfer->buffer, + transfer->actual_length, devc->unitsize); + + if (new_samples > 0) { + if (devc->trigger_fired) { + /* Send the incoming transfer to the session bus. */ + packet.type = SR_DF_LOGIC; + packet.payload = &logic; + if (devc->limit_samples && + new_samples > devc->limit_samples - devc->sent_samples) + new_samples = devc->limit_samples - devc->sent_samples; + logic.length = new_samples * devc->unitsize; + logic.unitsize = devc->unitsize; + logic.data = devc->convbuffer; + sr_session_send(devc->cb_data, &packet); + devc->sent_samples += new_samples; + } else { + trigger_offset = soft_trigger_logic_check(devc->stl, + devc->convbuffer, new_samples * devc->unitsize); + if (trigger_offset > -1) { + packet.type = SR_DF_LOGIC; + packet.payload = &logic; + num_samples = new_samples - trigger_offset; + if (devc->limit_samples && + num_samples > devc->limit_samples - devc->sent_samples) + num_samples = devc->limit_samples - devc->sent_samples; + logic.length = num_samples * devc->unitsize; + logic.unitsize = devc->unitsize; + logic.data = devc->convbuffer + trigger_offset * devc->unitsize; + sr_session_send(devc->cb_data, &packet); + devc->sent_samples += num_samples; + + devc->trigger_fired = TRUE; + } } - /* Send the incoming transfer to the session bus. */ - packet.type = SR_DF_LOGIC; - packet.payload = &logic; - logic.length = converted_length * devc->unitsize; - logic.unitsize = devc->unitsize; - logic.data = devc->convbuffer; - sr_session_send(devc->cb_data, &packet); - - devc->num_samples += converted_length; if (devc->limit_samples && - (uint64_t)devc->num_samples >= devc->limit_samples) { - devc->num_samples = -2; + (uint64_t)devc->sent_samples >= devc->limit_samples) { + devc->sent_samples = -2; free_transfer(transfer); return; } diff --git a/hardware/saleae-logic16/protocol.h b/hardware/saleae-logic16/protocol.h index 00f96560..8557a3e3 100644 --- a/hardware/saleae-logic16/protocol.h +++ b/hardware/saleae-logic16/protocol.h @@ -63,7 +63,7 @@ struct dev_context { /* EEPROM data from address 8. */ uint8_t eeprom_data[8]; - int64_t num_samples; + int64_t sent_samples; int submitted_transfers; int empty_transfer_count; int num_channels, cur_channel, unitsize; @@ -71,6 +71,8 @@ struct dev_context { uint16_t channel_data[16]; uint8_t *convbuffer; size_t convbuffer_size; + struct soft_trigger_logic *stl; + gboolean trigger_fired; void *cb_data; unsigned int num_transfers;