]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/sysclk-lwla/protocol.c
usb: Skip add/remove of FD on destroyed source
[libsigrok.git] / src / hardware / sysclk-lwla / protocol.c
index c00a92fd6919b42886b3842b8cd207c5b2fa324f..5891af4f4296fd2503634e7e3fc55ec0c647a3ed 100644 (file)
@@ -305,7 +305,7 @@ static void process_capture_length(const struct sr_dev_inst *sdi)
 
        sr_dbg("%zu words in capture buffer.", acq->mem_addr_fill);
 
-       if (acq->mem_addr_fill > 0 && sdi->status == SR_ST_ACTIVE)
+       if (acq->mem_addr_fill > 0 && !devc->cancel_requested)
                issue_read_start(sdi);
        else
                issue_read_end(sdi);
@@ -599,8 +599,7 @@ static void end_acquisition(struct sr_dev_inst *sdi)
 
        lwla_free_acquisition_state(devc->acquisition);
        devc->acquisition = NULL;
-
-       sdi->status = SR_ST_ACTIVE;
+       devc->cancel_requested = FALSE;
 }
 
 /* USB output transfer completion callback.
@@ -631,7 +630,7 @@ static void LIBUSB_CALL receive_transfer_out(struct libusb_transfer *transfer)
                        submit_transfer(devc, devc->acquisition->xfer_in);
                        break;
                case STATE_STOP_CAPTURE:
-                       if (sdi->status == SR_ST_ACTIVE)
+                       if (!devc->cancel_requested)
                                request_capture_length(sdi);
                        else
                                end_acquisition(sdi);
@@ -749,10 +748,12 @@ SR_PRIV int lwla_init_device(const struct sr_dev_inst *sdi)
 SR_PRIV int lwla_set_clock_config(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
+       struct drv_context *drvc;
        int ret;
        enum clock_config choice;
 
        devc = sdi->priv;
+       drvc = sdi->driver->context;
 
        if (sdi->status == SR_ST_INACTIVE)
                choice = CONF_CLOCK_NONE;
@@ -765,7 +766,8 @@ SR_PRIV int lwla_set_clock_config(const struct sr_dev_inst *sdi)
 
        if (choice != devc->cur_clock_config) {
                devc->cur_clock_config = CONF_CLOCK_NONE;
-               ret = lwla_send_bitstream(sdi->conn, bitstream_map[choice]);
+               ret = lwla_send_bitstream(drvc->sr_ctx, sdi->conn,
+                                         bitstream_map[choice]);
                if (ret == SR_OK)
                        devc->cur_clock_config = choice;
                return ret;
@@ -972,7 +974,7 @@ SR_PRIV int lwla_receive_data(int fd, int revents, void *cb_data)
 
        /* If no event flags are set the timeout must have expired. */
        if (revents == 0 && devc->state == STATE_STATUS_WAIT) {
-               if (sdi->status == SR_ST_STOPPING)
+               if (devc->cancel_requested)
                        issue_stop_capture(sdi);
                else
                        request_capture_status(sdi);