From 7b5d1c64fca5e95ce81ced1358dab2e2b7a68d39 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 24 Apr 2016 23:06:28 +0200 Subject: [PATCH] fx2lafw: Factor out packet sending This will make it possible to use different senders based on driver mode. This is needed for USBee AX support. --- src/hardware/fx2lafw/api.c | 2 ++ src/hardware/fx2lafw/protocol.c | 41 ++++++++++++++++++++++----------- src/hardware/fx2lafw/protocol.h | 4 ++++ 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index 02468036..d7f60282 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -710,6 +710,8 @@ static int start_transfers(const struct sr_dev_inst *sdi) devc->submitted_transfers++; } + devc->send_data_proc = la_send_data_proc; + /* Send header packet to the session bus. */ std_session_send_df_header(sdi, LOG_PREFIX); diff --git a/src/hardware/fx2lafw/protocol.c b/src/hardware/fx2lafw/protocol.c index 8fe7b6c1..8a11514e 100644 --- a/src/hardware/fx2lafw/protocol.c +++ b/src/hardware/fx2lafw/protocol.c @@ -382,13 +382,28 @@ static void resubmit_transfer(struct libusb_transfer *transfer) } +SR_PRIV void la_send_data_proc(void *cb_data, + uint8_t *data, size_t length, size_t sample_width) +{ + const struct sr_datafeed_logic logic = { + .length = length, + .unitsize = sample_width, + .data = data + }; + + const struct sr_datafeed_packet packet = { + .type = SR_DF_LOGIC, + .payload = &logic + }; + + sr_session_send(cb_data, &packet); +} + SR_PRIV void LIBUSB_CALL fx2lafw_receive_transfer(struct libusb_transfer *transfer) { struct sr_dev_inst *sdi; struct dev_context *devc; gboolean packet_has_error = FALSE; - struct sr_datafeed_packet packet; - struct sr_datafeed_logic logic; unsigned int num_samples; int trigger_offset, cur_sample_count, unitsize; int pre_trigger_samples; @@ -446,16 +461,15 @@ SR_PRIV void LIBUSB_CALL fx2lafw_receive_transfer(struct libusb_transfer *transf if (devc->trigger_fired) { if (!devc->limit_samples || devc->sent_samples < devc->limit_samples) { /* Send the incoming transfer to the session bus. */ - packet.type = SR_DF_LOGIC; - packet.payload = &logic; if (devc->limit_samples && devc->sent_samples + cur_sample_count > devc->limit_samples) num_samples = devc->limit_samples - devc->sent_samples; else num_samples = cur_sample_count; - logic.length = num_samples * unitsize; - logic.unitsize = unitsize; - logic.data = transfer->buffer; - sr_session_send(devc->cb_data, &packet); + + devc->send_data_proc(devc->cb_data, + (uint8_t*)transfer->buffer, + num_samples * unitsize, + unitsize); devc->sent_samples += num_samples; } } else { @@ -463,16 +477,15 @@ SR_PRIV void LIBUSB_CALL fx2lafw_receive_transfer(struct libusb_transfer *transf transfer->buffer, transfer->actual_length, &pre_trigger_samples); if (trigger_offset > -1) { devc->sent_samples += pre_trigger_samples; - packet.type = SR_DF_LOGIC; - packet.payload = &logic; num_samples = cur_sample_count - 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 * unitsize; - logic.unitsize = unitsize; - logic.data = transfer->buffer + trigger_offset * unitsize; - sr_session_send(devc->cb_data, &packet); + + devc->send_data_proc(devc->cb_data, + (uint8_t*)transfer->buffer + trigger_offset * unitsize, + num_samples * unitsize, + unitsize); devc->sent_samples += num_samples; devc->trigger_fired = TRUE; diff --git a/src/hardware/fx2lafw/protocol.h b/src/hardware/fx2lafw/protocol.h index 50e0ea4b..0220ae24 100644 --- a/src/hardware/fx2lafw/protocol.h +++ b/src/hardware/fx2lafw/protocol.h @@ -122,6 +122,8 @@ struct dev_context { unsigned int num_transfers; struct libusb_transfer **transfers; struct sr_context *ctx; + void (*send_data_proc)(void *cb_data, + uint8_t *data, size_t length, size_t sample_width); /* Is this a DSLogic? */ gboolean dslogic; @@ -140,5 +142,7 @@ SR_PRIV void LIBUSB_CALL fx2lafw_receive_transfer(struct libusb_transfer *transf SR_PRIV size_t fx2lafw_get_buffer_size(struct dev_context *devc); SR_PRIV unsigned int fx2lafw_get_number_of_transfers(struct dev_context *devc); SR_PRIV unsigned int fx2lafw_get_timeout(struct dev_context *devc); +SR_PRIV void la_send_data_proc(void *cb_data, uint8_t *data, size_t length, + size_t sample_width); #endif