X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fsysclk-lwla%2Fprotocol.c;h=1c9bca885e08f3af60949aa8f807d1003331015b;hb=e57057aee778e723da572a6b5e2bd01526cc7beb;hp=f1ae8b3d5d1fe1c1b146fa5d41ddb3eeb0f7ad50;hpb=155b680da482cea2381becb73c51cfb838bff31e;p=libsigrok.git diff --git a/src/hardware/sysclk-lwla/protocol.c b/src/hardware/sysclk-lwla/protocol.c index f1ae8b3d..1c9bca88 100644 --- a/src/hardware/sysclk-lwla/protocol.c +++ b/src/hardware/sysclk-lwla/protocol.c @@ -17,8 +17,9 @@ * along with this program. If not, see . */ -#include "protocol.h" +#include #include +#include "protocol.h" /* Bit mask for the RLE repeat-count-follows flag. */ #define RLE_FLAG_LEN_FOLLOWS ((uint64_t)1 << 35) @@ -65,7 +66,7 @@ static int capture_setup(const struct sr_dev_inst *sdi) uint64_t divider_count; uint64_t trigger_mask; uint64_t memory_limit; - uint16_t command[3 + 10*4]; + uint16_t command[3 + (10 * 4)]; devc = sdi->priv; acq = devc->acquisition; @@ -107,8 +108,12 @@ static int capture_setup(const struct sr_dev_inst *sdi) /* Set bits to select external TRG input edge. */ if (devc->cfg_trigger_source == TRIGGER_EXT_TRG) switch (devc->cfg_trigger_slope) { - case EDGE_POSITIVE: trigger_mask |= (uint64_t)1 << 35; break; - case EDGE_NEGATIVE: trigger_mask |= (uint64_t)1 << 34; break; + case EDGE_POSITIVE: + trigger_mask |= (uint64_t)1 << 35; + break; + case EDGE_NEGATIVE: + trigger_mask |= (uint64_t)1 << 34; + break; } command[19] = LWLA_WORD_0(trigger_mask); @@ -127,10 +132,10 @@ static int capture_setup(const struct sr_dev_inst *sdi) command[25] = LWLA_WORD_2(memory_limit); command[26] = LWLA_WORD_3(memory_limit); - /* Fill remaining 64-bit words with zeroes. */ - memset(&command[27], 0, 16 * sizeof(uint16_t)); + /* Fill remaining words with zeroes. */ + memset(&command[27], 0, sizeof(command) - 27 * sizeof(command[0])); - return lwla_send_command(sdi->conn, command, G_N_ELEMENTS(command)); + return lwla_send_command(sdi->conn, command, ARRAY_SIZE(command)); } /* Issue a register write command as an asynchronous USB transfer. @@ -279,7 +284,7 @@ static void issue_read_end(const struct sr_dev_inst *sdi) devc->state = STATE_READ_END; } -/* Decode an incoming reponse to a buffer fill level request and act on it +/* Decode an incoming response to a buffer fill level request and act on it * as appropriate. Note that this function changes the device context state. */ static void process_capture_length(const struct sr_dev_inst *sdi) @@ -300,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); @@ -346,7 +351,7 @@ static void issue_stop_capture(const struct sr_dev_inst *sdi) } } -/* Decode an incoming capture status reponse and act on it as appropriate. +/* Decode an incoming capture status response and act on it as appropriate. * Note that this function changes the device state. */ static void process_capture_status(const struct sr_dev_inst *sdi) @@ -578,7 +583,7 @@ static void end_acquisition(struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_datafeed_packet packet; - drvc = sdi->driver->priv; + drvc = sdi->driver->context; devc = sdi->priv; if (devc->state == STATE_IDLE) @@ -594,13 +599,12 @@ 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. */ -static void receive_transfer_out(struct libusb_transfer *transfer) +static void LIBUSB_CALL receive_transfer_out(struct libusb_transfer *transfer) { struct sr_dev_inst *sdi; struct dev_context *devc; @@ -626,7 +630,7 @@ static void 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); @@ -654,7 +658,7 @@ static void receive_transfer_out(struct libusb_transfer *transfer) /* USB input transfer completion callback. */ -static void receive_transfer_in(struct libusb_transfer *transfer) +static void LIBUSB_CALL receive_transfer_in(struct libusb_transfer *transfer) { struct sr_dev_inst *sdi; struct dev_context *devc; @@ -738,55 +742,6 @@ SR_PRIV int lwla_init_device(const struct sr_dev_inst *sdi) return ret; } -SR_PRIV int lwla_convert_trigger(const struct sr_dev_inst *sdi) -{ - struct dev_context *devc; - struct sr_trigger *trigger; - struct sr_trigger_stage *stage; - struct sr_trigger_match *match; - const GSList *l, *m; - uint64_t channel_index; - - devc = sdi->priv; - - devc->trigger_mask = 0; - devc->trigger_values = 0; - devc->trigger_edge_mask = 0; - - if (!(trigger = sr_session_trigger_get(sdi->session))) - return SR_OK; - - if (g_slist_length(trigger->stages) > 1) { - sr_err("This device only supports 1 trigger stage."); - return SR_ERR; - } - - for (l = trigger->stages; l; l = l->next) { - stage = l->data; - for (m = stage->matches; m; m = m->next) { - match = m->data; - if (!match->channel->enabled) - /* Ignore disabled channels with a trigger. */ - continue; - channel_index = 1 << match->channel->index; - devc->trigger_mask |= channel_index; - switch (match->match) { - case SR_TRIGGER_ONE: - devc->trigger_values |= channel_index; - break; - case SR_TRIGGER_RISING: - devc->trigger_values |= channel_index; - /* Fall through for edge mask. */ - case SR_TRIGGER_FALLING: - devc->trigger_edge_mask |= channel_index; - break; - } - } - } - - return SR_OK; -} - /* Select the LWLA clock configuration. If the clock source changed from * the previous setting, this will download a new bitstream to the FPGA. */ @@ -890,7 +845,7 @@ SR_PRIV int lwla_setup_acquisition(const struct sr_dev_inst *sdi) regvals[6].reg = REG_DIV_BYPASS; regvals[6].val = acq->bypass_clockdiv; - ret = lwla_write_regs(usb, regvals, G_N_ELEMENTS(regvals)); + ret = lwla_write_regs(usb, regvals, ARRAY_SIZE(regvals)); if (ret != SR_OK) return ret; @@ -919,13 +874,13 @@ SR_PRIV int lwla_start_acquisition(const struct sr_dev_inst *sdi) libusb_fill_bulk_transfer(acq->xfer_out, usb->devhdl, EP_COMMAND, (unsigned char *)acq->xfer_buf_out, 0, &receive_transfer_out, - (struct sr_dev_inst *)sdi, USB_TIMEOUT); + (struct sr_dev_inst *)sdi, USB_TIMEOUT_MS); libusb_fill_bulk_transfer(acq->xfer_in, usb->devhdl, EP_REPLY, (unsigned char *)acq->xfer_buf_in, sizeof acq->xfer_buf_in, &receive_transfer_in, - (struct sr_dev_inst *)sdi, USB_TIMEOUT); + (struct sr_dev_inst *)sdi, USB_TIMEOUT_MS); regvals = devc->reg_write_seq; @@ -955,11 +910,7 @@ SR_PRIV struct acquisition_state *lwla_alloc_acquisition_state(void) { struct acquisition_state *acq; - acq = g_try_new0(struct acquisition_state, 1); - if (!acq) { - sr_err("Acquisition state malloc failed."); - return NULL; - } + acq = g_malloc0(sizeof(struct acquisition_state)); acq->xfer_in = libusb_alloc_transfer(0); if (!acq->xfer_in) { @@ -1004,7 +955,7 @@ SR_PRIV int lwla_receive_data(int fd, int revents, void *cb_data) sdi = cb_data; devc = sdi->priv; - drvc = sdi->driver->priv; + drvc = sdi->driver->context; if (!devc || !drvc) return FALSE; @@ -1020,7 +971,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);