X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fsysclk-lwla%2Fapi.c;h=36c9ee608bfc7dc05796437cae9728707ee8e023;hb=04f2428354068c6ed85ad090dd4baac253e940c4;hp=e8c2cb0cdf359fc98f5d9ad2246d3f6d3361c9b7;hpb=93ed0241aaf6e791e113b741435fa857891e86c2;p=libsigrok.git diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index e8c2cb0c..36c9ee60 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -23,7 +23,7 @@ #include #include #include -#include "libsigrok-internal.h" +#include #include "protocol.h" /* Supported device scan options. @@ -264,7 +264,7 @@ static int drain_usb(struct sr_usb_dev_inst *usb, unsigned int endpoint) do { xfer_len = 0; ret = libusb_bulk_transfer(usb->devhdl, endpoint, - buf, sizeof buf, &xfer_len, + buf, sizeof(buf), &xfer_len, drain_timeout_ms); drained += xfer_len; } while (ret == LIBUSB_SUCCESS && xfer_len != 0); @@ -325,12 +325,17 @@ static int dev_open(struct sr_dev_inst *sdi) } ret = drain_usb(usb, EP_REPLY); - if (ret != SR_OK) + if (ret != SR_OK) { + sr_usb_close(usb); return ret; + } + /* This delay appears to be necessary for reliable operation. */ + g_usleep(30 * 1000); sdi->status = SR_ST_ACTIVE; devc->active_fpga_config = FPGA_NOCONF; + devc->short_transfer_quirk = FALSE; devc->state = STATE_IDLE; ret = (*devc->model->apply_fpga_config)(sdi); @@ -341,8 +346,12 @@ static int dev_open(struct sr_dev_inst *sdi) if (ret != SR_OK) { sdi->status = SR_ST_INACTIVE; sr_usb_close(usb); + return ret; } - return ret; + if (devc->short_transfer_quirk) + sr_warn("Short transfer quirk detected! " + "Memory reads will be slow."); + return SR_OK; } /* Shutdown and close device. @@ -594,13 +603,14 @@ static int prepare_trigger_masks(const struct sr_dev_inst *sdi) uint64_t trigger_mask; uint64_t trigger_values; uint64_t trigger_edge_mask; - uint64_t channel_bit; + uint64_t level_bit, type_bit; struct dev_context *devc; struct sr_trigger *trigger; struct sr_trigger_stage *stage; struct sr_trigger_match *match; const GSList *node; int idx; + enum sr_trigger_matches trg; devc = sdi->priv; @@ -625,30 +635,27 @@ static int prepare_trigger_masks(const struct sr_dev_inst *sdi) continue; /* ignore disabled channel */ idx = match->channel->index; + trg = match->match; if (idx < 0 || idx >= devc->model->num_channels) { sr_err("Channel index %d out of range.", idx); return SR_ERR_BUG; /* should not happen */ } - channel_bit = UINT64_C(1) << idx; - trigger_mask |= channel_bit; - - switch (match->match) { - case SR_TRIGGER_ZERO: - break; - case SR_TRIGGER_ONE: - trigger_values |= channel_bit; - break; - case SR_TRIGGER_RISING: - trigger_values |= channel_bit; - /* Fall through for edge mask. */ - case SR_TRIGGER_FALLING: - trigger_edge_mask |= channel_bit; - break; - default: + if (trg != SR_TRIGGER_ZERO + && trg != SR_TRIGGER_ONE + && trg != SR_TRIGGER_RISING + && trg != SR_TRIGGER_FALLING) { sr_err("Unsupported trigger match for CH%d.", idx + 1); return SR_ERR_ARG; } + level_bit = (trg == SR_TRIGGER_ONE + || trg == SR_TRIGGER_RISING) ? 1 : 0; + type_bit = (trg == SR_TRIGGER_RISING + || trg == SR_TRIGGER_FALLING) ? 1 : 0; + + trigger_mask |= UINT64_C(1) << idx; + trigger_values |= level_bit << idx; + trigger_edge_mask |= type_bit << idx; } devc->trigger_mask = trigger_mask; devc->trigger_values = trigger_values;