]> sigrok.org Git - libsigrok.git/commitdiff
fx2lafw: Moved num_samples into context struct
authorJoel Holdsworth <redacted>
Sat, 3 Mar 2012 15:22:51 +0000 (15:22 +0000)
committerJoel Holdsworth <redacted>
Wed, 7 Mar 2012 07:52:05 +0000 (07:52 +0000)
hardware/fx2lafw/fx2lafw.c
hardware/fx2lafw/fx2lafw.h

index 5a40be92c0a831bcd43ec68e72be64c68874b73c..b0bd0e6067b6cb06db6924b3ef2eab9ac94a1ba9 100644 (file)
@@ -506,26 +506,33 @@ static int receive_data(int fd, int revents, void *cb_data)
        return TRUE;
 }
 
+static void abort_acquisition(struct context *ctx)
+{
+       struct sr_datafeed_packet packet;
+
+       packet.type = SR_DF_END;
+       sr_session_send(ctx->session_dev_id, &packet);
+
+       ctx->num_samples = -1;
+
+       /* TODO: Need to cancel and free any queued up transfers. */
+}
+
 static void receive_transfer(struct libusb_transfer *transfer)
 {
        /* TODO: These statics have to move to the ctx struct. */
-       static int num_samples = 0;
        static int empty_transfer_count = 0;
        struct sr_datafeed_packet packet;
        struct sr_datafeed_logic logic;
-       struct context *ctx;
+       struct context *ctx = transfer->user_data;
        int cur_buflen;
        unsigned char *cur_buf, *new_buf;
 
-       /* hw_dev_acquisition_stop() is telling us to stop. */
-       if (transfer == NULL)
-               num_samples = -1;
-
        /*
         * If acquisition has already ended, just free any queued up
         * transfer that come in.
         */
-       if (num_samples == -1) {
+       if (ctx->num_samples == -1) {
                if (transfer)
                        libusb_free_transfer(transfer);
                return;
@@ -560,7 +567,7 @@ static void receive_transfer(struct libusb_transfer *transfer)
                         * The FX2 gave up. End the acquisition, the frontend
                         * will work out that the samplecount is short.
                         */
-                       hw_dev_acquisition_stop(-1, ctx->session_dev_id);
+                       abort_acquisition(ctx);
                }
                return;
        } else {
@@ -576,10 +583,10 @@ static void receive_transfer(struct libusb_transfer *transfer)
        sr_session_send(ctx->session_dev_id, &packet);
        g_free(cur_buf);
 
-       num_samples += cur_buflen;
+       ctx->num_samples += cur_buflen;
        if (ctx->limit_samples &&
-               (unsigned int) num_samples > ctx->limit_samples) {
-               hw_dev_acquisition_stop(-1, ctx->session_dev_id);
+               (unsigned int) ctx->num_samples > ctx->limit_samples) {
+               abort_acquisition(ctx);
        }
 }
 
@@ -598,6 +605,7 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data)
                return SR_ERR;
        ctx = sdi->priv;
        ctx->session_dev_id = cb_data;
+       ctx->num_samples = 0;
 
        if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
                sr_err("fx2lafw: %s: packet malloc failed", __func__);
@@ -655,17 +663,15 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data)
 /* TODO: This stops acquisition on ALL devices, ignoring dev_index. */
 static int hw_dev_acquisition_stop(int dev_index, void *cb_data)
 {
-       struct sr_datafeed_packet packet;
-
-       /* Avoid compiler warnings. */
-       (void)dev_index;
-
-       packet.type = SR_DF_END;
-       sr_session_send(cb_data, &packet);
+       struct sr_dev_inst *sdi;
 
-       receive_transfer(NULL);
+       /* unused parameter */
+       (void)cb_data;
 
-       /* TODO: Need to cancel and free any queued up transfers. */
+       if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
+               return SR_ERR;
+       abort_acquisition(sdi->priv);
 
        return SR_OK;
 }
index fd1b5012be7c22fe4ed218d7f8a5a711dafcbb26..bbdaf33eca53ababf1e5a47d112ca2740e5872cc 100644 (file)
@@ -55,6 +55,8 @@ struct context {
        uint64_t cur_samplerate;
        uint64_t limit_samples;
 
+       int num_samples;
+
        void *session_dev_id;
 
        struct sr_usb_dev_inst *usb;