SR_PRIV struct sr_dev_driver fx2lafw_driver_info;
static struct sr_dev_driver *fdi = &fx2lafw_driver_info;
static int hw_dev_close(struct sr_dev_inst *sdi);
static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
const void *value);
SR_PRIV struct sr_dev_driver fx2lafw_driver_info;
static struct sr_dev_driver *fdi = &fx2lafw_driver_info;
static int hw_dev_close(struct sr_dev_inst *sdi);
static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
const void *value);
for (i = 0; i < device_count; i++) {
if ((ret = libusb_get_device_descriptor(devlist[i], &des))) {
for (i = 0; i < device_count; i++) {
if ((ret = libusb_get_device_descriptor(devlist[i], &des))) {
* This device is fully enumerated, so we need to find
* this device by vendor, product, bus and address.
*/
* This device is fully enumerated, so we need to find
* this device by vendor, product, bus and address.
*/
- if (libusb_get_bus_number(devlist[i]) != ctx->usb->bus
- || libusb_get_device_address(devlist[i]) != ctx->usb->address)
+ if (libusb_get_bus_number(devlist[i]) != devc->usb->bus
+ || libusb_get_device_address(devlist[i]) != devc->usb->address)
- if (!(ret = libusb_open(devlist[i], &ctx->usb->devhdl))) {
- if (ctx->usb->address == 0xff)
+ if (!(ret = libusb_open(devlist[i], &devc->usb->devhdl))) {
+ if (devc->usb->address == 0xff)
/*
* first time we touch this device after firmware upload,
* so we don't know the address yet.
*/
/*
* first time we touch this device after firmware upload,
* so we don't know the address yet.
*/
sdi->status = SR_ST_ACTIVE;
sr_info("fx2lafw: Opened device %d on %d.%d "
"interface %d, firmware %d.%d, REVID %d.",
sdi->status = SR_ST_ACTIVE;
sr_info("fx2lafw: Opened device %d on %d.%d "
"interface %d, firmware %d.%d, REVID %d.",
- sdi->index, ctx->usb->bus, ctx->usb->address,
+ sdi->index, devc->usb->bus, devc->usb->address,
USB_INTERFACE, vi.major, vi.minor, revid);
break;
USB_INTERFACE, vi.major, vi.minor, revid);
break;
- if (!(ctx = g_try_malloc0(sizeof(struct context)))) {
- sr_err("fx2lafw: %s: ctx malloc failed.", __func__);
+ if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
+ sr_err("fx2lafw: %s: devc malloc failed.", __func__);
if (!(sdi = l->data)) {
/* Log error, but continue cleaning up the rest. */
sr_err("fx2lafw: %s: sdi was NULL, continuing.",
if (!(sdi = l->data)) {
/* Log error, but continue cleaning up the rest. */
sr_err("fx2lafw: %s: sdi was NULL, continuing.",
/* Log error, but continue cleaning up the rest. */
sr_err("fx2lafw: %s: sdi->priv was NULL, continuing",
__func__);
/* Log error, but continue cleaning up the rest. */
sr_err("fx2lafw: %s: sdi->priv was NULL, continuing",
__func__);
- if (libusb_init(&usb_context) != 0) {
- sr_warn("fx2lafw: Failed to initialize libusb.");
- return SR_ERR;
+ if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
+ sr_err("fx2lafw: driver context malloc failed.");
+ return SR_ERR_MALLOC;
struct sr_probe *probe;
libusb_device **devlist;
int devcnt, num_logic_probes, ret, i, j;
struct sr_probe *probe;
libusb_device **devlist;
int devcnt, num_logic_probes, ret, i, j;
/* This scan always invalidates any previous scans. */
clear_instances();
/* Find all fx2lafw compatible devices and upload firmware to them. */
devices = NULL;
/* This scan always invalidates any previous scans. */
clear_instances();
/* Find all fx2lafw compatible devices and upload firmware to them. */
devices = NULL;
for (i = 0; devlist[i]; i++) {
if ((ret = libusb_get_device_descriptor(
devlist[i], &des)) != 0) {
for (i = 0; devlist[i]; i++) {
if ((ret = libusb_get_device_descriptor(
devlist[i], &des)) != 0) {
sdi = sr_dev_inst_new(devcnt, SR_ST_INITIALIZING,
prof->vendor, prof->model, prof->model_version);
if (!sdi)
sdi = sr_dev_inst_new(devcnt, SR_ST_INITIALIZING,
prof->vendor, prof->model, prof->model_version);
if (!sdi)
- ctx = fx2lafw_dev_new();
- ctx->profile = prof;
- sdi->priv = ctx;
- fdi->instances = g_slist_append(fdi->instances, sdi);
+ devc = fx2lafw_dev_new();
+ devc->profile = prof;
+ sdi->priv = devc;
+ drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
if (check_conf_profile(devlist[i])) {
/* Already has the firmware, so fix the new address. */
sr_dbg("fx2lafw: Found an fx2lafw device.");
sdi->status = SR_ST_INACTIVE;
devices = g_slist_append(devices, sdi);
if (check_conf_profile(devlist[i])) {
/* Already has the firmware, so fix the new address. */
sr_dbg("fx2lafw: Found an fx2lafw device.");
sdi->status = SR_ST_INACTIVE;
(libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), NULL);
} else {
if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION,
prof->firmware) == SR_OK)
/* Remember when the firmware on this device was updated */
(libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), NULL);
} else {
if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION,
prof->firmware) == SR_OK)
/* Remember when the firmware on this device was updated */
/*
* If the firmware was recently uploaded, wait up to MAX_RENUM_DELAY_MS
* milliseconds for the FX2 to renumerate.
*/
ret = SR_ERR;
/*
* If the firmware was recently uploaded, wait up to MAX_RENUM_DELAY_MS
* milliseconds for the FX2 to renumerate.
*/
ret = SR_ERR;
sr_info("fx2lafw: Waiting for device to reset.");
/* takes at least 300ms for the FX2 to be gone from the USB bus */
g_usleep(300 * 1000);
sr_info("fx2lafw: Waiting for device to reset.");
/* takes at least 300ms for the FX2 to be gone from the USB bus */
g_usleep(300 * 1000);
timediff_ms = timediff_us / 1000;
sr_spew("fx2lafw: waited %" PRIi64 " ms", timediff_ms);
}
timediff_ms = timediff_us / 1000;
sr_spew("fx2lafw: waited %" PRIi64 " ms", timediff_ms);
}
/* Samplerate hasn't been set; default to the slowest one. */
if (hw_dev_config_set(sdi, SR_HWCAP_SAMPLERATE,
&supported_samplerates[0]) == SR_ERR)
/* Samplerate hasn't been set; default to the slowest one. */
if (hw_dev_config_set(sdi, SR_HWCAP_SAMPLERATE,
&supported_samplerates[0]) == SR_ERR)
- sdi->index, ctx->usb->bus, ctx->usb->address, USB_INTERFACE);
- libusb_release_interface(ctx->usb->devhdl, USB_INTERFACE);
- libusb_close(ctx->usb->devhdl);
- ctx->usb->devhdl = NULL;
+ sdi->index, devc->usb->bus, devc->usb->address, USB_INTERFACE);
+ libusb_release_interface(devc->usb->devhdl, USB_INTERFACE);
+ libusb_close(devc->usb->devhdl);
+ devc->usb->devhdl = NULL;
static int hw_info_get(int info_id, const void **data,
const struct sr_dev_inst *sdi)
{
static int hw_info_get(int info_id, const void **data,
const struct sr_dev_inst *sdi)
{
-static int hw_dev_status_get(int dev_index)
-{
- const struct sr_dev_inst *const sdi =
- sr_dev_inst_get(fdi->instances, dev_index);
-
- if (!sdi)
- return SR_ST_NOT_FOUND;
-
- return sdi->status;
-}
-
- for (i = ctx->num_transfers - 1; i >= 0; i--) {
- if (ctx->transfers[i])
- libusb_cancel_transfer(ctx->transfers[i]);
+ for (i = devc->num_transfers - 1; i >= 0; i--) {
+ if (devc->transfers[i])
+ libusb_cancel_transfer(devc->transfers[i]);
for (i = 0; lupfd[i]; i++)
sr_source_remove(lupfd[i]->fd);
free(lupfd); /* NOT g_free()! */
for (i = 0; lupfd[i]; i++)
sr_source_remove(lupfd[i]->fd);
free(lupfd); /* NOT g_free()! */
- for (i = 0; i < ctx->num_transfers; i++) {
- if (ctx->transfers[i] == transfer) {
- ctx->transfers[i] = NULL;
+ for (i = 0; i < devc->num_transfers; i++) {
+ if (devc->transfers[i] == transfer) {
+ devc->transfers[i] = NULL;
- ctx->submitted_transfers--;
- if (ctx->submitted_transfers == 0)
- finish_acquisition(ctx);
+ devc->submitted_transfers--;
+ if (devc->submitted_transfers == 0)
+ finish_acquisition(devc);
- if (libusb_submit_transfer(transfer) != 0) {
- free_transfer(transfer);
- /* TODO: Stop session? */
- /* TODO: Better error message. */
- sr_err("fx2lafw: %s: libusb_submit_transfer error.", __func__);
- }
+ int ret = libusb_submit_transfer(transfer);
+
+ if (LIBUSB_SUCCESS == ret)
+ return;
+
+ free_transfer(transfer);
+ /* TODO: Stop session? */
+
+ sr_err("fx2lafw: %s: %s", __func__, libusb_error_name(ret));
gboolean packet_has_error = FALSE;
struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
gboolean packet_has_error = FALSE;
struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
/* Save incoming transfer before reusing the transfer struct. */
uint8_t *const cur_buf = transfer->buffer;
/* Save incoming transfer before reusing the transfer struct. */
uint8_t *const cur_buf = transfer->buffer;
const int cur_sample_count = transfer->actual_length / sample_width;
switch (transfer->status) {
case LIBUSB_TRANSFER_NO_DEVICE:
const int cur_sample_count = transfer->actual_length / sample_width;
switch (transfer->status) {
case LIBUSB_TRANSFER_NO_DEVICE:
/*
* The FX2 gave up. End the acquisition, the frontend
* will work out that the samplecount is short.
*/
/*
* The FX2 gave up. End the acquisition, the frontend
* will work out that the samplecount is short.
*/
- if ((cur_sample & ctx->trigger_mask[ctx->trigger_stage]) ==
- ctx->trigger_value[ctx->trigger_stage]) {
+ if ((cur_sample & devc->trigger_mask[devc->trigger_stage]) ==
+ devc->trigger_value[devc->trigger_stage]) {
- 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);
+ logic.unitsize = sizeof(*devc->trigger_buffer);
+ logic.length = devc->trigger_stage * logic.unitsize;
+ logic.data = devc->trigger_buffer;
+ sr_session_send(devc->session_dev_id, &packet);
/*
* 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
/*
* 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
* the next sample from the one that matched originally, which the
* counter increment at the end of the loop takes care of.
*/
* the next sample from the one that matched originally, which the
* counter increment at the end of the loop takes care of.
*/
if (i < -1)
i = -1; /* Oops, went back past this buffer. */
/* Reset trigger stage. */
if (i < -1)
i = -1; /* Oops, went back past this buffer. */
/* Reset trigger stage. */
/* Send the incoming transfer to the session bus. */
const int trigger_offset_bytes = trigger_offset * sample_width;
packet.type = SR_DF_LOGIC;
/* Send the incoming transfer to the session bus. */
const int trigger_offset_bytes = trigger_offset * sample_width;
packet.type = SR_DF_LOGIC;
logic.length = transfer->actual_length - trigger_offset_bytes;
logic.unitsize = sample_width;
logic.data = cur_buf + trigger_offset_bytes;
logic.length = transfer->actual_length - trigger_offset_bytes;
logic.unitsize = sample_width;
logic.data = cur_buf + trigger_offset_bytes;
- ctx->num_samples += cur_sample_count;
- if (ctx->limit_samples &&
- (unsigned int)ctx->num_samples > ctx->limit_samples) {
- abort_acquisition(ctx);
+ devc->num_samples += cur_sample_count;
+ if (devc->limit_samples &&
+ (unsigned int)devc->num_samples > devc->limit_samples) {
+ abort_acquisition(devc);
- total_size = get_buffer_size(ctx) * get_number_of_transfers(ctx);
- timeout = total_size / to_bytes_per_ms(ctx->cur_samplerate);
+ total_size = get_buffer_size(devc) * get_number_of_transfers(devc);
+ timeout = total_size / to_bytes_per_ms(devc->cur_samplerate);
struct sr_datafeed_packet packet;
struct sr_datafeed_header header;
struct sr_datafeed_meta_logic meta;
struct sr_datafeed_packet packet;
struct sr_datafeed_header header;
struct sr_datafeed_meta_logic meta;
- const unsigned int timeout = get_timeout(ctx);
- const unsigned int num_transfers = get_number_of_transfers(ctx);
- const size_t size = get_buffer_size(ctx);
+ const unsigned int timeout = get_timeout(devc);
+ const unsigned int num_transfers = get_number_of_transfers(devc);
+ const size_t size = get_buffer_size(devc);
- ctx->transfers = g_try_malloc0(sizeof(*ctx->transfers) * num_transfers);
- if (!ctx->transfers)
- return SR_ERR;
+ devc->transfers = g_try_malloc0(sizeof(*devc->transfers) * num_transfers);
+ if (!devc->transfers) {
+ sr_err("fx2lafw: USB transfers malloc failed.");
+ return SR_ERR_MALLOC;
+ }
2 | LIBUSB_ENDPOINT_IN, buf, size,
2 | LIBUSB_ENDPOINT_IN, buf, size,
- receive_transfer, ctx, timeout);
- if (libusb_submit_transfer(transfer) != 0) {
+ receive_transfer, devc, timeout);
+ if ((ret = libusb_submit_transfer(transfer)) != 0) {
+ sr_err("fx2lafw: %s: libusb_submit_transfer: %s.",
+ __func__, libusb_error_name(ret));
for (i = 0; lupfd[i]; i++)
sr_source_add(lupfd[i]->fd, lupfd[i]->events,
timeout, receive_data, NULL);
for (i = 0; lupfd[i]; i++)
sr_source_add(lupfd[i]->fd, lupfd[i]->events,
timeout, receive_data, NULL);
- if ((ret = command_start_acquisition (ctx->usb->devhdl,
- ctx->cur_samplerate, ctx->sample_wide)) != SR_OK) {
- abort_acquisition(ctx);
+ if ((ret = command_start_acquisition (devc->usb->devhdl,
+ devc->cur_samplerate, devc->sample_wide)) != SR_OK) {
+ abort_acquisition(devc);
.dev_config_set = hw_dev_config_set,
.dev_acquisition_start = hw_dev_acquisition_start,
.dev_acquisition_stop = hw_dev_acquisition_stop,
.dev_config_set = hw_dev_config_set,
.dev_acquisition_start = hw_dev_acquisition_start,
.dev_acquisition_stop = hw_dev_acquisition_stop,