]> sigrok.org Git - libsigrok.git/blobdiff - hardware/fx2lafw/fx2lafw.c
fx2lafw: fix broken firmware upload timeout
[libsigrok.git] / hardware / fx2lafw / fx2lafw.c
index aa8331f182b3d24905b104fbbc769df18a4454a5..2e88241ecfec61e0b17f71b5a4972172fcf578cf 100644 (file)
@@ -467,8 +467,7 @@ static int hw_dev_open(int dev_index)
         * If the firmware was recently uploaded, wait up to MAX_RENUM_DELAY_MS
         * milliseconds for the FX2 to renumerate.
         */
-       ret = 0;
-
+       ret = SR_ERR;
        if (ctx->fw_updated > 0) {
                sr_info("fx2lafw: Waiting for device to reset.");
                /* takes at least 300ms for the FX2 to be gone from the USB bus */
@@ -480,9 +479,8 @@ static int hw_dev_open(int dev_index)
                        g_usleep(100 * 1000);
 
                        timediff_us = g_get_monotonic_time() - ctx->fw_updated;
-                       timediff_ms = timediff_us / G_USEC_PER_SEC;
-                       sr_spew("fx2lafw: timediff: %" PRIi64 " us.",
-                               timediff_us);
+                       timediff_ms = timediff_us / 1000;
+                       sr_spew("fx2lafw: waited %" PRIi64 " ms", timediff_ms);
                }
                sr_info("fx2lafw: Device came back after %d ms.", timediff_ms);
        } else {
@@ -706,6 +704,7 @@ static void receive_transfer(struct libusb_transfer *transfer)
        /* Fire off a new request. */
        if (!(new_buf = g_try_malloc(4096))) {
                sr_err("fx2lafw: %s: new_buf malloc failed.", __func__);
+               libusb_free_transfer(transfer);
                return; /* TODO: SR_ERR_MALLOC */
        }
 
@@ -726,6 +725,7 @@ static void receive_transfer(struct libusb_transfer *transfer)
                         */
                        abort_acquisition(ctx);
                }
+               g_free(cur_buf);
                return;
        } else {
                empty_transfer_count = 0;
@@ -764,25 +764,22 @@ static void receive_transfer(struct libusb_transfer *transfer)
                                         */
                                        packet.type = SR_DF_LOGIC;
                                        packet.payload = &logic;
-                                       logic.length = ctx->trigger_stage;
-                                       logic.unitsize = 1;
+                                       logic.unitsize = sizeof(*ctx->trigger_buffer);
+                                       logic.length = ctx->trigger_stage * logic.unitsize;
                                        logic.data = ctx->trigger_buffer;
                                        sr_session_send(ctx->session_dev_id, &packet);
 
                                        ctx->trigger_stage = TRIGGER_FIRED;
                                        break;
                                }
-                               return;
-                       }
-
-                       /*
-                        * We had a match before, but not in the next sample. However, we may
-                        * have a match on this stage in the next bit -- trigger on 0001 will
-                        * fail on seeing 00001, so we need to go back to stage 0 -- but at
-                        * the next sample from the one that matched originally, which the
-                        * counter increment at the end of the loop takes care of.
-                        */
-                       if (ctx->trigger_stage > 0) {
+                       } else if (ctx->trigger_stage > 0) {
+                               /*
+                                * We had a match before, but not in the next sample. However, we may
+                                * have a match on this stage in the next bit -- trigger on 0001 will
+                                * fail on seeing 00001, so we need to go back to stage 0 -- but at
+                                * the next sample from the one that matched originally, which the
+                                * counter increment at the end of the loop takes care of.
+                                */
                                i -= ctx->trigger_stage;
                                if (i < -1)
                                        i = -1; /* Oops, went back past this buffer. */
@@ -801,7 +798,6 @@ static void receive_transfer(struct libusb_transfer *transfer)
                logic.unitsize = sample_width;
                logic.data = cur_buf + trigger_offset_bytes;
                sr_session_send(ctx->session_dev_id, &packet);
-               g_free(cur_buf);
 
                ctx->num_samples += cur_sample_count;
                if (ctx->limit_samples &&
@@ -814,6 +810,7 @@ static void receive_transfer(struct libusb_transfer *transfer)
                 * ratio-sized buffer.
                 */
        }
+       g_free(cur_buf);
 }
 
 static int hw_dev_acquisition_start(int dev_index, void *cb_data)