2 * This file is part of the sigrok project.
4 * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
5 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "libsigrok.h"
28 #include "libsigrok-internal.h"
32 static const struct fx2lafw_profile supported_fx2[] = {
35 * EE Electronics ESLA201A
38 { 0x08a9, 0x0014, "CWAV", "USBee AX", NULL,
39 FIRMWARE_DIR "/fx2lafw-cwav-usbeeax.fw",
45 { 0x08a9, 0x0015, "CWAV", "USBee DX", NULL,
46 FIRMWARE_DIR "/fx2lafw-cwav-usbeedx.fw",
52 { 0x08a9, 0x0009, "CWAV", "USBee SX", NULL,
53 FIRMWARE_DIR "/fx2lafw-cwav-usbeesx.fw",
58 * EE Electronics ESLA100
60 * Robomotic BugLogic 3
62 { 0x0925, 0x3881, "Saleae", "Logic", NULL,
63 FIRMWARE_DIR "/fx2lafw-saleae-logic.fw",
67 * Default Cypress FX2 without EEPROM, e.g.:
69 * Braintechnology USB Interface V2.x
71 { 0x04B4, 0x8613, "Cypress", "FX2", NULL,
72 FIRMWARE_DIR "/fx2lafw-cypress-fx2.fw",
76 * Braintechnology USB-LPS
78 { 0x16d0, 0x0498, "Braintechnology", "USB-LPS", NULL,
79 FIRMWARE_DIR "/fx2lafw-braintechnology-usb-lps.fw",
82 { 0, 0, 0, 0, 0, 0, 0 }
85 static const int hwcaps[] = {
86 SR_HWCAP_LOGIC_ANALYZER,
89 /* These are really implemented in the driver, not the hardware. */
90 SR_HWCAP_LIMIT_SAMPLES,
95 static const char *probe_names[] = {
115 static const uint64_t supported_samplerates[] = {
135 static const struct sr_samplerates samplerates = {
139 supported_samplerates,
142 static libusb_context *usb_context = NULL;
144 SR_PRIV struct sr_dev_driver fx2lafw_driver_info;
145 static struct sr_dev_driver *fdi = &fx2lafw_driver_info;
146 static int hw_dev_config_set(int dev_index, int hwcap, const void *value);
147 static int hw_dev_acquisition_stop(int dev_index, void *cb_data);
150 * Check the USB configuration to determine if this is an fx2lafw device.
152 * @return TRUE if the device's configuration profile match fx2lafw
153 * configuration, FALSE otherwise.
155 static gboolean check_conf_profile(libusb_device *dev)
157 struct libusb_device_descriptor des;
158 struct libusb_device_handle *hdl;
160 unsigned char strdesc[64];
165 /* Assume the FW has not been loaded, unless proven wrong. */
166 if (libusb_get_device_descriptor(dev, &des) != 0)
169 if (libusb_open(dev, &hdl) != 0)
172 if (libusb_get_string_descriptor_ascii(hdl,
173 des.iManufacturer, strdesc, sizeof(strdesc)) < 0)
175 if (strncmp((const char *)strdesc, "sigrok", 6))
178 if (libusb_get_string_descriptor_ascii(hdl,
179 des.iProduct, strdesc, sizeof(strdesc)) < 0)
181 if (strncmp((const char *)strdesc, "fx2lafw", 7))
184 /* If we made it here, it must be an fx2lafw. */
193 static int fx2lafw_dev_open(int dev_index)
195 libusb_device **devlist;
196 struct libusb_device_descriptor des;
197 struct sr_dev_inst *sdi;
199 struct version_info vi;
203 if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index)))
207 if (sdi->status == SR_ST_ACTIVE)
212 const int device_count = libusb_get_device_list(usb_context, &devlist);
213 if (device_count < 0) {
214 sr_err("fx2lafw: Failed to retrieve device list (%d)",
219 for (i = 0; i < device_count; i++) {
220 if ((ret = libusb_get_device_descriptor(devlist[i], &des))) {
221 sr_err("fx2lafw: Failed to get device descriptor: %d.",
226 if (des.idVendor != ctx->profile->vid
227 || des.idProduct != ctx->profile->pid)
230 if (sdi->status == SR_ST_INITIALIZING) {
231 if (skip != dev_index) {
232 /* Skip devices of this type that aren't the one we want. */
236 } else if (sdi->status == SR_ST_INACTIVE) {
238 * This device is fully enumerated, so we need to find
239 * this device by vendor, product, bus and address.
241 if (libusb_get_bus_number(devlist[i]) != ctx->usb->bus
242 || libusb_get_device_address(devlist[i]) != ctx->usb->address)
243 /* this is not the one */
247 if (!(ret = libusb_open(devlist[i], &ctx->usb->devhdl))) {
248 if (ctx->usb->address == 0xff)
250 * first time we touch this device after firmware upload,
251 * so we don't know the address yet.
253 ctx->usb->address = libusb_get_device_address(devlist[i]);
255 sr_err("fx2lafw: Failed to open device: %d.", ret);
259 ret = command_get_fw_version(ctx->usb->devhdl, &vi);
261 sr_err("fx2lafw: Failed to retrieve "
262 "firmware version information.");
266 ret = command_get_revid_version(ctx->usb->devhdl, &revid);
268 sr_err("fx2lafw: Failed to retrieve REVID.");
273 * Changes in major version mean incompatible/API changes, so
274 * bail out if we encounter an incompatible version.
275 * Different minor versions are OK, they should be compatible.
277 if (vi.major != FX2LAFW_REQUIRED_VERSION_MAJOR) {
278 sr_err("fx2lafw: Expected firmware version %d.x, "
279 "got %d.%d.", FX2LAFW_REQUIRED_VERSION_MAJOR,
284 sdi->status = SR_ST_ACTIVE;
285 sr_info("fx2lafw: Opened device %d on %d.%d "
286 "interface %d, firmware %d.%d, REVID %d.",
287 sdi->index, ctx->usb->bus, ctx->usb->address,
288 USB_INTERFACE, vi.major, vi.minor, revid);
292 libusb_free_device_list(devlist, 1);
294 if (sdi->status != SR_ST_ACTIVE)
300 static void close_dev(struct sr_dev_inst *sdi)
306 if (ctx->usb->devhdl == NULL)
309 sr_info("fx2lafw: Closing device %d on %d.%d interface %d.",
310 sdi->index, ctx->usb->bus, ctx->usb->address, USB_INTERFACE);
311 libusb_release_interface(ctx->usb->devhdl, USB_INTERFACE);
312 libusb_close(ctx->usb->devhdl);
313 ctx->usb->devhdl = NULL;
314 sdi->status = SR_ST_INACTIVE;
317 static int configure_probes(struct context *ctx, GSList *probes)
319 struct sr_probe *probe;
321 int probe_bit, stage, i;
324 for (i = 0; i < NUM_TRIGGER_STAGES; i++) {
325 ctx->trigger_mask[i] = 0;
326 ctx->trigger_value[i] = 0;
330 for (l = probes; l; l = l->next) {
331 probe = (struct sr_probe *)l->data;
332 if (probe->enabled == FALSE)
335 if (probe->index > 8)
336 ctx->sample_wide = TRUE;
338 probe_bit = 1 << (probe->index - 1);
339 if (!(probe->trigger))
343 for (tc = probe->trigger; *tc; tc++) {
344 ctx->trigger_mask[stage] |= probe_bit;
346 ctx->trigger_value[stage] |= probe_bit;
348 if (stage > NUM_TRIGGER_STAGES)
355 * We didn't configure any triggers, make sure acquisition
356 * doesn't wait for any.
358 ctx->trigger_stage = TRIGGER_FIRED;
360 ctx->trigger_stage = 0;
365 static struct context *fx2lafw_dev_new(void)
369 if (!(ctx = g_try_malloc0(sizeof(struct context)))) {
370 sr_err("fx2lafw: %s: ctx malloc failed.", __func__);
374 ctx->trigger_stage = TRIGGER_FIRED;
379 static int clear_instances(void)
382 struct sr_dev_inst *sdi;
387 for (l = fdi->instances; l; l = l->next) {
388 if (!(sdi = l->data)) {
389 /* Log error, but continue cleaning up the rest. */
390 sr_err("fx2lafw: %s: sdi was NULL, continuing.",
395 if (!(ctx = sdi->priv)) {
396 /* Log error, but continue cleaning up the rest. */
397 sr_err("fx2lafw: %s: sdi->priv was NULL, continuing",
404 sr_dev_inst_free(sdi);
407 g_slist_free(fdi->instances);
408 fdi->instances = NULL;
418 static int hw_init(void)
421 if (libusb_init(&usb_context) != 0) {
422 sr_warn("fx2lafw: Failed to initialize libusb.");
429 static GSList *hw_scan(GSList *options)
432 struct libusb_device_descriptor des;
433 struct sr_dev_inst *sdi;
434 const struct fx2lafw_profile *prof;
436 struct sr_probe *probe;
437 libusb_device **devlist;
438 int devcnt, num_logic_probes, ret, i, j;
440 /* Avoid compiler warnings. */
443 /* This scan always invalidates any previous scans. */
446 /* Find all fx2lafw compatible devices and upload firmware to them. */
448 libusb_get_device_list(usb_context, &devlist);
449 for (i = 0; devlist[i]; i++) {
451 if ((ret = libusb_get_device_descriptor(
452 devlist[i], &des)) != 0) {
453 sr_warn("fx2lafw: Failed to get device descriptor: %d.", ret);
458 for (j = 0; supported_fx2[j].vid; j++) {
459 if (des.idVendor == supported_fx2[j].vid &&
460 des.idProduct == supported_fx2[j].pid) {
461 prof = &supported_fx2[j];
465 /* Skip if the device was not found */
469 devcnt = g_slist_length(fdi->instances);
470 sdi = sr_dev_inst_new(devcnt, SR_ST_INITIALIZING,
471 prof->vendor, prof->model, prof->model_version);
476 /* Fill in probelist according to this device's profile. */
477 num_logic_probes = prof->dev_caps & DEV_CAPS_16BIT ? 16 : 8;
478 for (j = 0; j < num_logic_probes; j++) {
479 if (!(probe = sr_probe_new(j, SR_PROBE_LOGIC, TRUE,
482 sdi->probes = g_slist_append(sdi->probes, probe);
485 ctx = fx2lafw_dev_new();
488 fdi->instances = g_slist_append(fdi->instances, sdi);
489 devices = g_slist_append(devices, sdi);
491 if (check_conf_profile(devlist[i])) {
492 /* Already has the firmware, so fix the new address. */
493 sr_dbg("fx2lafw: Found an fx2lafw device.");
494 sdi->status = SR_ST_INACTIVE;
495 ctx->usb = sr_usb_dev_inst_new
496 (libusb_get_bus_number(devlist[i]),
497 libusb_get_device_address(devlist[i]), NULL);
499 if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION,
500 prof->firmware) == SR_OK)
501 /* Remember when the firmware on this device was updated */
502 ctx->fw_updated = g_get_monotonic_time();
504 sr_err("fx2lafw: Firmware upload failed for "
505 "device %d.", devcnt);
506 ctx->usb = sr_usb_dev_inst_new
507 (libusb_get_bus_number(devlist[i]), 0xff, NULL);
510 libusb_free_device_list(devlist, 1);
515 static int hw_dev_open(int dev_index)
517 struct sr_dev_inst *sdi;
520 int64_t timediff_us, timediff_ms;
522 if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index)))
527 * If the firmware was recently uploaded, wait up to MAX_RENUM_DELAY_MS
528 * milliseconds for the FX2 to renumerate.
531 if (ctx->fw_updated > 0) {
532 sr_info("fx2lafw: Waiting for device to reset.");
533 /* takes at least 300ms for the FX2 to be gone from the USB bus */
534 g_usleep(300 * 1000);
536 while (timediff_ms < MAX_RENUM_DELAY_MS) {
537 if ((ret = fx2lafw_dev_open(dev_index)) == SR_OK)
539 g_usleep(100 * 1000);
541 timediff_us = g_get_monotonic_time() - ctx->fw_updated;
542 timediff_ms = timediff_us / 1000;
543 sr_spew("fx2lafw: waited %" PRIi64 " ms", timediff_ms);
545 sr_info("fx2lafw: Device came back after %d ms.", timediff_ms);
547 ret = fx2lafw_dev_open(dev_index);
551 sr_err("fx2lafw: Unable to open device.");
556 ret = libusb_claim_interface(ctx->usb->devhdl, USB_INTERFACE);
559 case LIBUSB_ERROR_BUSY:
560 sr_err("fx2lafw: Unable to claim USB interface. Another "
561 "program or driver has already claimed it.");
564 case LIBUSB_ERROR_NO_DEVICE:
565 sr_err("fx2lafw: Device has been disconnected.");
569 sr_err("fx2lafw: Unable to claim interface: %d.", ret);
576 if (ctx->cur_samplerate == 0) {
577 /* Samplerate hasn't been set; default to the slowest one. */
578 if (hw_dev_config_set(dev_index, SR_HWCAP_SAMPLERATE,
579 &supported_samplerates[0]) == SR_ERR)
586 static int hw_dev_close(int dev_index)
588 struct sr_dev_inst *sdi;
590 if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index))) {
591 sr_err("fx2lafw: %s: sdi was NULL.", __func__);
601 static int hw_cleanup(void)
605 ret = clear_instances();
608 libusb_exit(usb_context);
614 static int hw_info_get(int info_id, const void **data,
615 const struct sr_dev_inst *sdi)
626 case SR_DI_NUM_PROBES:
629 *data = GINT_TO_POINTER(
630 (ctx->profile->dev_caps & DEV_CAPS_16BIT) ?
635 case SR_DI_PROBE_NAMES:
638 case SR_DI_SAMPLERATES:
639 *data = &samplerates;
641 case SR_DI_TRIGGER_TYPES:
642 *data = TRIGGER_TYPES;
644 case SR_DI_CUR_SAMPLERATE:
647 *data = &ctx->cur_samplerate;
658 static int hw_dev_status_get(int dev_index)
660 const struct sr_dev_inst *const sdi =
661 sr_dev_inst_get(fdi->instances, dev_index);
664 return SR_ST_NOT_FOUND;
669 static int hw_dev_config_set(int dev_index, int hwcap, const void *value)
671 struct sr_dev_inst *sdi;
675 if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index)))
679 if (hwcap == SR_HWCAP_SAMPLERATE) {
680 ctx->cur_samplerate = *(const uint64_t *)value;
682 } else if (hwcap == SR_HWCAP_PROBECONFIG) {
683 ret = configure_probes(ctx, (GSList *) value);
684 } else if (hwcap == SR_HWCAP_LIMIT_SAMPLES) {
685 ctx->limit_samples = *(const uint64_t *)value;
694 static int receive_data(int fd, int revents, void *cb_data)
698 /* Avoid compiler warnings. */
703 tv.tv_sec = tv.tv_usec = 0;
704 libusb_handle_events_timeout(usb_context, &tv);
709 static void abort_acquisition(struct context *ctx)
713 ctx->num_samples = -1;
715 for (i = ctx->num_transfers - 1; i >= 0; i--) {
716 if (ctx->transfers[i])
717 libusb_cancel_transfer(ctx->transfers[i]);
721 static void finish_acquisition(struct context *ctx)
723 struct sr_datafeed_packet packet;
726 /* Terminate session */
727 packet.type = SR_DF_END;
728 sr_session_send(ctx->session_dev_id, &packet);
730 /* Remove fds from polling */
731 const struct libusb_pollfd **const lupfd =
732 libusb_get_pollfds(usb_context);
733 for (i = 0; lupfd[i]; i++)
734 sr_source_remove(lupfd[i]->fd);
735 free(lupfd); /* NOT g_free()! */
737 ctx->num_transfers = 0;
738 g_free(ctx->transfers);
741 static void free_transfer(struct libusb_transfer *transfer)
743 struct context *ctx = transfer->user_data;
746 g_free(transfer->buffer);
747 transfer->buffer = NULL;
748 libusb_free_transfer(transfer);
750 for (i = 0; i < ctx->num_transfers; i++) {
751 if (ctx->transfers[i] == transfer) {
752 ctx->transfers[i] = NULL;
757 ctx->submitted_transfers--;
758 if (ctx->submitted_transfers == 0)
759 finish_acquisition(ctx);
763 static void resubmit_transfer(struct libusb_transfer *transfer)
765 if (libusb_submit_transfer(transfer) != 0) {
766 free_transfer(transfer);
767 /* TODO: Stop session? */
768 /* TODO: Better error message. */
769 sr_err("fx2lafw: %s: libusb_submit_transfer error.", __func__);
773 static void receive_transfer(struct libusb_transfer *transfer)
775 gboolean packet_has_error = FALSE;
776 struct sr_datafeed_packet packet;
777 struct sr_datafeed_logic logic;
778 struct context *ctx = transfer->user_data;
779 int trigger_offset, i;
782 * If acquisition has already ended, just free any queued up
783 * transfer that come in.
785 if (ctx->num_samples == -1) {
786 free_transfer(transfer);
790 sr_info("fx2lafw: receive_transfer(): status %d received %d bytes.",
791 transfer->status, transfer->actual_length);
793 /* Save incoming transfer before reusing the transfer struct. */
794 uint8_t *const cur_buf = transfer->buffer;
795 const int sample_width = ctx->sample_wide ? 2 : 1;
796 const int cur_sample_count = transfer->actual_length / sample_width;
798 switch (transfer->status) {
799 case LIBUSB_TRANSFER_NO_DEVICE:
800 abort_acquisition(ctx);
801 free_transfer(transfer);
803 case LIBUSB_TRANSFER_COMPLETED:
804 case LIBUSB_TRANSFER_TIMED_OUT: /* We may have received some data though */
807 packet_has_error = TRUE;
811 if (transfer->actual_length == 0 || packet_has_error) {
812 ctx->empty_transfer_count++;
813 if (ctx->empty_transfer_count > MAX_EMPTY_TRANSFERS) {
815 * The FX2 gave up. End the acquisition, the frontend
816 * will work out that the samplecount is short.
818 abort_acquisition(ctx);
819 free_transfer(transfer);
821 resubmit_transfer(transfer);
825 ctx->empty_transfer_count = 0;
829 if (ctx->trigger_stage >= 0) {
830 for (i = 0; i < cur_sample_count; i++) {
832 const uint16_t cur_sample = ctx->sample_wide ?
833 *((const uint16_t*)cur_buf + i) :
834 *((const uint8_t*)cur_buf + i);
836 if ((cur_sample & ctx->trigger_mask[ctx->trigger_stage]) ==
837 ctx->trigger_value[ctx->trigger_stage]) {
838 /* Match on this trigger stage. */
839 ctx->trigger_buffer[ctx->trigger_stage] = cur_sample;
840 ctx->trigger_stage++;
842 if (ctx->trigger_stage == NUM_TRIGGER_STAGES ||
843 ctx->trigger_mask[ctx->trigger_stage] == 0) {
844 /* Match on all trigger stages, we're done. */
845 trigger_offset = i + 1;
848 * TODO: Send pre-trigger buffer to session bus.
849 * Tell the frontend we hit the trigger here.
851 packet.type = SR_DF_TRIGGER;
852 packet.payload = NULL;
853 sr_session_send(ctx->session_dev_id, &packet);
856 * Send the samples that triggered it, since we're
857 * skipping past them.
859 packet.type = SR_DF_LOGIC;
860 packet.payload = &logic;
861 logic.unitsize = sizeof(*ctx->trigger_buffer);
862 logic.length = ctx->trigger_stage * logic.unitsize;
863 logic.data = ctx->trigger_buffer;
864 sr_session_send(ctx->session_dev_id, &packet);
866 ctx->trigger_stage = TRIGGER_FIRED;
869 } else if (ctx->trigger_stage > 0) {
871 * We had a match before, but not in the next sample. However, we may
872 * have a match on this stage in the next bit -- trigger on 0001 will
873 * fail on seeing 00001, so we need to go back to stage 0 -- but at
874 * the next sample from the one that matched originally, which the
875 * counter increment at the end of the loop takes care of.
877 i -= ctx->trigger_stage;
879 i = -1; /* Oops, went back past this buffer. */
880 /* Reset trigger stage. */
881 ctx->trigger_stage = 0;
886 if (ctx->trigger_stage == TRIGGER_FIRED) {
887 /* Send the incoming transfer to the session bus. */
888 const int trigger_offset_bytes = trigger_offset * sample_width;
889 packet.type = SR_DF_LOGIC;
890 packet.payload = &logic;
891 logic.length = transfer->actual_length - trigger_offset_bytes;
892 logic.unitsize = sample_width;
893 logic.data = cur_buf + trigger_offset_bytes;
894 sr_session_send(ctx->session_dev_id, &packet);
896 ctx->num_samples += cur_sample_count;
897 if (ctx->limit_samples &&
898 (unsigned int)ctx->num_samples > ctx->limit_samples) {
899 abort_acquisition(ctx);
900 free_transfer(transfer);
905 * TODO: Buffer pre-trigger data in capture
906 * ratio-sized buffer.
910 resubmit_transfer(transfer);
913 static unsigned int to_bytes_per_ms(unsigned int samplerate)
915 return samplerate / 1000;
918 static size_t get_buffer_size(struct context *ctx)
922 /* The buffer should be large enough to hold 10ms of data and a multiple
924 s = 10 * to_bytes_per_ms(ctx->cur_samplerate);
925 return (s + 511) & ~511;
928 static unsigned int get_number_of_transfers(struct context *ctx)
932 /* Total buffer size should be able to hold about 500ms of data */
933 n = 500 * to_bytes_per_ms(ctx->cur_samplerate) / get_buffer_size(ctx);
935 if (n > NUM_SIMUL_TRANSFERS)
936 return NUM_SIMUL_TRANSFERS;
941 static unsigned int get_timeout(struct context *ctx)
944 unsigned int timeout;
946 total_size = get_buffer_size(ctx) * get_number_of_transfers(ctx);
947 timeout = total_size / to_bytes_per_ms(ctx->cur_samplerate);
948 return timeout + timeout / 4; /* Leave a headroom of 25% percent */
951 static int hw_dev_acquisition_start(int dev_index, void *cb_data)
953 struct sr_dev_inst *sdi;
954 struct sr_datafeed_packet packet;
955 struct sr_datafeed_header header;
956 struct sr_datafeed_meta_logic meta;
958 struct libusb_transfer *transfer;
959 const struct libusb_pollfd **lupfd;
964 if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index)))
968 if (ctx->submitted_transfers != 0)
971 ctx->session_dev_id = cb_data;
972 ctx->num_samples = 0;
973 ctx->empty_transfer_count = 0;
975 const unsigned int timeout = get_timeout(ctx);
976 const unsigned int num_transfers = get_number_of_transfers(ctx);
977 const size_t size = get_buffer_size(ctx);
979 ctx->transfers = g_try_malloc0(sizeof(*ctx->transfers) * num_transfers);
983 ctx->num_transfers = num_transfers;
985 for (i = 0; i < num_transfers; i++) {
986 if (!(buf = g_try_malloc(size))) {
987 sr_err("fx2lafw: %s: buf malloc failed.", __func__);
988 return SR_ERR_MALLOC;
990 transfer = libusb_alloc_transfer(0);
991 libusb_fill_bulk_transfer(transfer, ctx->usb->devhdl,
992 2 | LIBUSB_ENDPOINT_IN, buf, size,
993 receive_transfer, ctx, timeout);
994 if (libusb_submit_transfer(transfer) != 0) {
995 libusb_free_transfer(transfer);
997 abort_acquisition(ctx);
1000 ctx->transfers[i] = transfer;
1001 ctx->submitted_transfers++;
1004 lupfd = libusb_get_pollfds(usb_context);
1005 for (i = 0; lupfd[i]; i++)
1006 sr_source_add(lupfd[i]->fd, lupfd[i]->events,
1007 timeout, receive_data, NULL);
1008 free(lupfd); /* NOT g_free()! */
1010 packet.type = SR_DF_HEADER;
1011 packet.payload = &header;
1012 header.feed_version = 1;
1013 gettimeofday(&header.starttime, NULL);
1014 sr_session_send(cb_data, &packet);
1016 /* Send metadata about the SR_DF_LOGIC packets to come. */
1017 packet.type = SR_DF_META_LOGIC;
1018 packet.payload = &meta;
1019 meta.samplerate = ctx->cur_samplerate;
1020 meta.num_probes = ctx->sample_wide ? 16 : 8;
1021 sr_session_send(cb_data, &packet);
1023 if ((ret = command_start_acquisition (ctx->usb->devhdl,
1024 ctx->cur_samplerate, ctx->sample_wide)) != SR_OK) {
1025 abort_acquisition(ctx);
1032 /* TODO: This stops acquisition on ALL devices, ignoring dev_index. */
1033 static int hw_dev_acquisition_stop(int dev_index, void *cb_data)
1035 struct sr_dev_inst *sdi;
1037 /* Avoid compiler warnings. */
1040 if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index)))
1043 abort_acquisition(sdi->priv);
1048 SR_PRIV struct sr_dev_driver fx2lafw_driver_info = {
1050 .longname = "fx2lafw (generic driver for FX2 based LAs)",
1053 .cleanup = hw_cleanup,
1055 .dev_open = hw_dev_open,
1056 .dev_close = hw_dev_close,
1057 .info_get = hw_info_get,
1058 .dev_status_get = hw_dev_status_get,
1059 .dev_config_set = hw_dev_config_set,
1060 .dev_acquisition_start = hw_dev_acquisition_start,
1061 .dev_acquisition_stop = hw_dev_acquisition_stop,