]> sigrok.org Git - libsigrok.git/commitdiff
WIP
authorBert Vermeulen <redacted>
Tue, 22 Apr 2014 16:08:40 +0000 (18:08 +0200)
committerBert Vermeulen <redacted>
Wed, 23 Apr 2014 17:27:31 +0000 (19:27 +0200)
hardware/fx2lafw/api.c
hardware/fx2lafw/protocol.c
hardware/fx2lafw/protocol.h

index b1b338f7bdfe7b6f7b977e2a510ad42f23b02861..00b8ad5d0eefc6b78736bd92bed99dbd271e017f 100644 (file)
@@ -483,7 +483,8 @@ 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->acq_aborted = FALSE;
        devc->empty_transfer_count = 0;
 
        timeout = fx2lafw_get_timeout(devc);
index a19b324311439ffa609c18392cecfc530054c090..006613600a100a9909795bcb5eeec357f37e70be 100644 (file)
@@ -330,14 +330,16 @@ SR_PRIV int fx2lafw_configure_channels(const struct sr_dev_inst *sdi)
                }
        }
 
-       if (stage == -1)
+       if (stage == -1) {
                /*
                 * We didn't configure any triggers, make sure acquisition
                 * doesn't wait for any.
                 */
-               devc->trigger_stage = TRIGGER_FIRED;
-       else
+               devc->trigger_fired = TRUE;
+       } else {
+               devc->trigger_fired = FALSE;
                devc->trigger_stage = 0;
+       }
 
        return SR_OK;
 }
@@ -364,7 +366,7 @@ SR_PRIV void fx2lafw_abort_acquisition(struct dev_context *devc)
 {
        int i;
 
-       devc->num_samples = -1;
+       devc->acq_aborted = TRUE;
 
        for (i = devc->num_transfers - 1; i >= 0; i--) {
                if (devc->transfers[i])
@@ -429,8 +431,8 @@ SR_PRIV void fx2lafw_receive_transfer(struct libusb_transfer *transfer)
        struct sr_datafeed_packet packet;
        struct sr_datafeed_logic logic;
        struct dev_context *devc;
-       int trigger_offset, i, sample_width, cur_sample_count;
-       int trigger_offset_bytes;
+       int cur_sample_count, num_samples, trigger_offset, sample_width;
+       int i;
        uint8_t *cur_buf;
        uint16_t cur_sample;
 
@@ -440,7 +442,7 @@ SR_PRIV void fx2lafw_receive_transfer(struct libusb_transfer *transfer)
         * If acquisition has already ended, just free any queued up
         * transfer that come in.
         */
-       if (devc->num_samples == -1) {
+       if (devc->acq_aborted) {
                free_transfer(transfer);
                return;
        }
@@ -484,9 +486,8 @@ SR_PRIV void fx2lafw_receive_transfer(struct libusb_transfer *transfer)
        }
 
        trigger_offset = 0;
-       if (devc->trigger_stage >= 0) {
+       if (!devc->trigger_fired) {
                for (i = 0; i < cur_sample_count; i++) {
-
                        cur_sample = devc->sample_wide ?
                                *((uint16_t *)cur_buf + i) :
                                *((uint8_t *)cur_buf + i);
@@ -517,11 +518,16 @@ SR_PRIV void fx2lafw_receive_transfer(struct libusb_transfer *transfer)
                                        packet.type = SR_DF_LOGIC;
                                        packet.payload = &logic;
                                        logic.unitsize = sample_width;
-                                       logic.length = devc->trigger_stage * logic.unitsize;
+                                       if (devc->trigger_stage > devc->limit_samples)
+                                               num_samples = devc->trigger_stage;
+                                       else
+                                               num_samples = devc->limit_samples;
+                                       logic.length = num_samples * sample_width;
                                        logic.data = devc->trigger_buffer;
                                        sr_session_send(devc->cb_data, &packet);
+                                       devc->sent_samples += num_samples;
 
-                                       devc->trigger_stage = TRIGGER_FIRED;
+                                       devc->trigger_fired = TRUE;
                                        break;
                                }
                        } else if (devc->trigger_stage > 0) {
@@ -541,19 +547,22 @@ SR_PRIV void fx2lafw_receive_transfer(struct libusb_transfer *transfer)
                }
        }
 
-       if (devc->trigger_stage == TRIGGER_FIRED) {
+       if (devc->trigger_fired) {
                /* Send the incoming transfer to the session bus. */
-               trigger_offset_bytes = trigger_offset * sample_width;
                packet.type = SR_DF_LOGIC;
                packet.payload = &logic;
-               logic.length = transfer->actual_length - trigger_offset_bytes;
+               if (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 * sample_width;
                logic.unitsize = sample_width;
-               logic.data = cur_buf + trigger_offset_bytes;
+               logic.data = cur_buf + trigger_offset * sample_width;
                sr_session_send(devc->cb_data, &packet);
 
-               devc->num_samples += cur_sample_count;
+               devc->sent_samples += cur_sample_count;
                if (devc->limit_samples &&
-                       (unsigned int)devc->num_samples > devc->limit_samples) {
+                       (unsigned int)devc->sent_samples > devc->limit_samples) {
                        fx2lafw_abort_acquisition(devc);
                        free_transfer(transfer);
                        return;
index 25a8c56a29e42e6d1e0dc5fd77de353a7752962e..dc1c83ff62098f2895737b20c0c6eaad7df84e52 100644 (file)
@@ -48,9 +48,6 @@
 /* 6 delay states of up to 256 clock ticks */
 #define MAX_SAMPLE_DELAY       (6 * 256)
 
-/* Software trigger implementation: positive values indicate trigger stage. */
-#define TRIGGER_FIRED          -1
-
 #define DEV_CAPS_16BIT_POS     0
 
 #define DEV_CAPS_16BIT         (1 << DEV_CAPS_16BIT_POS)
@@ -83,13 +80,15 @@ struct dev_context {
        uint64_t limit_samples;
 
        /* Operational settings */
+       gboolean trigger_fired;
+       gboolean acq_aborted;
        gboolean sample_wide;
        uint16_t trigger_mask[NUM_TRIGGER_STAGES];
        uint16_t trigger_value[NUM_TRIGGER_STAGES];
-       int trigger_stage;
+       unsigned int trigger_stage;
        uint16_t trigger_buffer[NUM_TRIGGER_STAGES];
 
-       int num_samples;
+       unsigned int sent_samples;
        int submitted_transfers;
        int empty_transfer_count;