fx2lafw: Various cosmetics, typo fixes, etc.
This commit is contained in:
parent
a873c5940c
commit
b99457f09c
|
@ -51,8 +51,7 @@ SR_PRIV int command_get_revid_version(libusb_device_handle *devhdl,
|
||||||
revid, 1, 100);
|
revid, 1, 100);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
sr_err("Unable to get REVID: %s.",
|
sr_err("Unable to get REVID: %s.", libusb_error_name(ret));
|
||||||
libusb_error_name(ret));
|
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,19 +83,18 @@ SR_PRIV int command_start_acquisition(libusb_device_handle *devhdl,
|
||||||
delay = SR_MHZ(30) / samplerate - 1;
|
delay = SR_MHZ(30) / samplerate - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sr_info("GPIF delay = %d, clocksource = %sMHz", delay,
|
sr_info("GPIF delay = %d, clocksource = %sMHz.", delay,
|
||||||
(cmd.flags & CMD_START_FLAGS_CLK_48MHZ) ? "48" : "30");
|
(cmd.flags & CMD_START_FLAGS_CLK_48MHZ) ? "48" : "30");
|
||||||
|
|
||||||
if (delay <= 0 || delay > MAX_SAMPLE_DELAY) {
|
if (delay <= 0 || delay > MAX_SAMPLE_DELAY) {
|
||||||
sr_err("Unable to sample at %" PRIu64 "Hz.",
|
sr_err("Unable to sample at %" PRIu64 "Hz.", samplerate);
|
||||||
samplerate);
|
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.sample_delay_h = (delay >> 8) & 0xff;
|
cmd.sample_delay_h = (delay >> 8) & 0xff;
|
||||||
cmd.sample_delay_l = delay & 0xff;
|
cmd.sample_delay_l = delay & 0xff;
|
||||||
|
|
||||||
/* Select the sampling width */
|
/* Select the sampling width. */
|
||||||
cmd.flags |= samplewide ? CMD_START_FLAGS_SAMPLE_16BIT :
|
cmd.flags |= samplewide ? CMD_START_FLAGS_SAMPLE_16BIT :
|
||||||
CMD_START_FLAGS_SAMPLE_8BIT;
|
CMD_START_FLAGS_SAMPLE_8BIT;
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,7 @@ static gboolean check_conf_profile(libusb_device *dev)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (libusb_get_string_descriptor_ascii(hdl,
|
if (libusb_get_string_descriptor_ascii(hdl,
|
||||||
des.iManufacturer, strdesc, sizeof(strdesc)) < 0)
|
des.iManufacturer, strdesc, sizeof(strdesc)) < 0)
|
||||||
break;
|
break;
|
||||||
if (strncmp((const char *)strdesc, "sigrok", 6))
|
if (strncmp((const char *)strdesc, "sigrok", 6))
|
||||||
break;
|
break;
|
||||||
|
@ -194,23 +194,23 @@ static int fx2lafw_dev_open(struct sr_dev_inst *sdi)
|
||||||
libusb_device **devlist;
|
libusb_device **devlist;
|
||||||
struct libusb_device_descriptor des;
|
struct libusb_device_descriptor des;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
struct drv_context *drvc = di->priv;
|
struct drv_context *drvc;
|
||||||
struct version_info vi;
|
struct version_info vi;
|
||||||
int ret, skip, i;
|
int ret, skip, i, device_count;
|
||||||
uint8_t revid;
|
uint8_t revid;
|
||||||
|
|
||||||
|
drvc = di->priv;
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
|
|
||||||
if (sdi->status == SR_ST_ACTIVE)
|
if (sdi->status == SR_ST_ACTIVE)
|
||||||
/* already in use */
|
/* Device is already in use. */
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
|
||||||
skip = 0;
|
skip = 0;
|
||||||
const int device_count = libusb_get_device_list(
|
device_count = libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
|
||||||
drvc->sr_ctx->libusb_ctx, &devlist);
|
|
||||||
if (device_count < 0) {
|
if (device_count < 0) {
|
||||||
sr_err("Failed to retrieve device list (%d)",
|
sr_err("Failed to get device list: %s.",
|
||||||
device_count);
|
libusb_error_name(device_count));
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,15 +238,15 @@ static int fx2lafw_dev_open(struct sr_dev_inst *sdi)
|
||||||
*/
|
*/
|
||||||
if (libusb_get_bus_number(devlist[i]) != devc->usb->bus
|
if (libusb_get_bus_number(devlist[i]) != devc->usb->bus
|
||||||
|| libusb_get_device_address(devlist[i]) != devc->usb->address)
|
|| libusb_get_device_address(devlist[i]) != devc->usb->address)
|
||||||
/* this is not the one */
|
/* This is not the one. */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ret = libusb_open(devlist[i], &devc->usb->devhdl))) {
|
if (!(ret = libusb_open(devlist[i], &devc->usb->devhdl))) {
|
||||||
if (devc->usb->address == 0xff)
|
if (devc->usb->address == 0xff)
|
||||||
/*
|
/*
|
||||||
* first time we touch this device after firmware upload,
|
* First time we touch this device after FW
|
||||||
* so we don't know the address yet.
|
* upload, so we don't know the address yet.
|
||||||
*/
|
*/
|
||||||
devc->usb->address = libusb_get_device_address(devlist[i]);
|
devc->usb->address = libusb_get_device_address(devlist[i]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -257,14 +257,13 @@ static int fx2lafw_dev_open(struct sr_dev_inst *sdi)
|
||||||
|
|
||||||
ret = command_get_fw_version(devc->usb->devhdl, &vi);
|
ret = command_get_fw_version(devc->usb->devhdl, &vi);
|
||||||
if (ret != SR_OK) {
|
if (ret != SR_OK) {
|
||||||
sr_err("Failed to retrieve "
|
sr_err("Failed to get firmware version.");
|
||||||
"firmware version information.");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = command_get_revid_version(devc->usb->devhdl, &revid);
|
ret = command_get_revid_version(devc->usb->devhdl, &revid);
|
||||||
if (ret != SR_OK) {
|
if (ret != SR_OK) {
|
||||||
sr_err("Failed to retrieve REVID.");
|
sr_err("Failed to get REVID.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +280,7 @@ static int fx2lafw_dev_open(struct sr_dev_inst *sdi)
|
||||||
}
|
}
|
||||||
|
|
||||||
sdi->status = SR_ST_ACTIVE;
|
sdi->status = SR_ST_ACTIVE;
|
||||||
sr_info("Opened device %d on %d.%d "
|
sr_info("Opened device %d on %d.%d, "
|
||||||
"interface %d, firmware %d.%d, REVID %d.",
|
"interface %d, firmware %d.%d, REVID %d.",
|
||||||
sdi->index, devc->usb->bus, devc->usb->address,
|
sdi->index, devc->usb->bus, devc->usb->address,
|
||||||
USB_INTERFACE, vi.major, vi.minor, revid);
|
USB_INTERFACE, vi.major, vi.minor, revid);
|
||||||
|
@ -351,7 +350,7 @@ static struct dev_context *fx2lafw_dev_new(void)
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
|
|
||||||
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
|
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
|
||||||
sr_err("%s: devc malloc failed.", __func__);
|
sr_err("Device context malloc failed.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,15 +372,13 @@ static int clear_instances(void)
|
||||||
for (l = drvc->instances; l; l = l->next) {
|
for (l = drvc->instances; l; l = l->next) {
|
||||||
if (!(sdi = l->data)) {
|
if (!(sdi = l->data)) {
|
||||||
/* Log error, but continue cleaning up the rest. */
|
/* Log error, but continue cleaning up the rest. */
|
||||||
sr_err("%s: sdi was NULL, continuing.",
|
sr_err("sdi was NULL, continuing.");
|
||||||
__func__);
|
|
||||||
ret = SR_ERR_BUG;
|
ret = SR_ERR_BUG;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!(devc = sdi->priv)) {
|
if (!(devc = sdi->priv)) {
|
||||||
/* Log error, but continue cleaning up the rest. */
|
/* Log error, but continue cleaning up the rest. */
|
||||||
sr_err("%s: sdi->priv was NULL, continuing",
|
sr_err("sdi->priv was NULL, continuing.");
|
||||||
__func__);
|
|
||||||
ret = SR_ERR_BUG;
|
ret = SR_ERR_BUG;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -397,11 +394,6 @@ static int clear_instances(void)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* API callbacks
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int hw_init(struct sr_context *sr_ctx)
|
static int hw_init(struct sr_context *sr_ctx)
|
||||||
{
|
{
|
||||||
struct drv_context *drvc;
|
struct drv_context *drvc;
|
||||||
|
@ -456,7 +448,7 @@ static GSList *hw_scan(GSList *options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip if the device was not found */
|
/* Skip if the device was not found. */
|
||||||
if (!prof)
|
if (!prof)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -492,7 +484,7 @@ static GSList *hw_scan(GSList *options)
|
||||||
} else {
|
} else {
|
||||||
if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION,
|
if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION,
|
||||||
prof->firmware) == SR_OK)
|
prof->firmware) == SR_OK)
|
||||||
/* Remember when the firmware on this device was updated */
|
/* Store when this device's FW was updated. */
|
||||||
devc->fw_updated = g_get_monotonic_time();
|
devc->fw_updated = g_get_monotonic_time();
|
||||||
else
|
else
|
||||||
sr_err("Firmware upload failed for "
|
sr_err("Firmware upload failed for "
|
||||||
|
@ -530,7 +522,7 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
|
||||||
ret = SR_ERR;
|
ret = SR_ERR;
|
||||||
if (devc->fw_updated > 0) {
|
if (devc->fw_updated > 0) {
|
||||||
sr_info("Waiting for device to reset.");
|
sr_info("Waiting for device to reset.");
|
||||||
/* takes at least 300ms for the FX2 to be gone from the USB bus */
|
/* Takes >= 300ms for the FX2 to be gone from the USB bus. */
|
||||||
g_usleep(300 * 1000);
|
g_usleep(300 * 1000);
|
||||||
timediff_ms = 0;
|
timediff_ms = 0;
|
||||||
while (timediff_ms < MAX_RENUM_DELAY_MS) {
|
while (timediff_ms < MAX_RENUM_DELAY_MS) {
|
||||||
|
@ -540,13 +532,13 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
|
||||||
|
|
||||||
timediff_us = g_get_monotonic_time() - devc->fw_updated;
|
timediff_us = g_get_monotonic_time() - devc->fw_updated;
|
||||||
timediff_ms = timediff_us / 1000;
|
timediff_ms = timediff_us / 1000;
|
||||||
sr_spew("Waited %" PRIi64 " ms", timediff_ms);
|
sr_spew("Waited %" PRIi64 "ms.", timediff_ms);
|
||||||
}
|
}
|
||||||
if (ret != SR_OK) {
|
if (ret != SR_OK) {
|
||||||
sr_err("Device failed to renumerate.");
|
sr_err("Device failed to renumerate.");
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
sr_info("Device came back after %d ms.",
|
sr_info("Device came back after %dms.",
|
||||||
timediff_ms);
|
timediff_ms);
|
||||||
} else {
|
} else {
|
||||||
sr_info("Firmware upload was not needed.");
|
sr_info("Firmware upload was not needed.");
|
||||||
|
@ -565,13 +557,11 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
|
||||||
switch(ret) {
|
switch(ret) {
|
||||||
case LIBUSB_ERROR_BUSY:
|
case LIBUSB_ERROR_BUSY:
|
||||||
sr_err("Unable to claim USB interface. Another "
|
sr_err("Unable to claim USB interface. Another "
|
||||||
"program or driver has already claimed it.");
|
"program or driver has already claimed it.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LIBUSB_ERROR_NO_DEVICE:
|
case LIBUSB_ERROR_NO_DEVICE:
|
||||||
sr_err("Device has been disconnected.");
|
sr_err("Device has been disconnected.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sr_err("Unable to claim interface: %s.",
|
sr_err("Unable to claim interface: %s.",
|
||||||
libusb_error_name(ret));
|
libusb_error_name(ret));
|
||||||
|
@ -599,7 +589,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
|
||||||
if (devc->usb->devhdl == NULL)
|
if (devc->usb->devhdl == NULL)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
|
||||||
sr_info("Closing device %d on %d.%d interface %d.",
|
sr_info("Closing device %d on %d.%d, interface %d.",
|
||||||
sdi->index, devc->usb->bus, devc->usb->address, USB_INTERFACE);
|
sdi->index, devc->usb->bus, devc->usb->address, USB_INTERFACE);
|
||||||
libusb_release_interface(devc->usb->devhdl, USB_INTERFACE);
|
libusb_release_interface(devc->usb->devhdl, USB_INTERFACE);
|
||||||
libusb_close(devc->usb->devhdl);
|
libusb_close(devc->usb->devhdl);
|
||||||
|
@ -690,12 +680,14 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
|
||||||
static int receive_data(int fd, int revents, void *cb_data)
|
static int receive_data(int fd, int revents, void *cb_data)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
struct drv_context *drvc = di->priv;
|
struct drv_context *drvc;
|
||||||
|
|
||||||
(void)fd;
|
(void)fd;
|
||||||
(void)revents;
|
(void)revents;
|
||||||
(void)cb_data;
|
(void)cb_data;
|
||||||
|
|
||||||
|
drvc = di->priv;
|
||||||
|
|
||||||
tv.tv_sec = tv.tv_usec = 0;
|
tv.tv_sec = tv.tv_usec = 0;
|
||||||
libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv);
|
libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv);
|
||||||
|
|
||||||
|
@ -718,16 +710,15 @@ static void finish_acquisition(struct dev_context *devc)
|
||||||
{
|
{
|
||||||
struct sr_datafeed_packet packet;
|
struct sr_datafeed_packet packet;
|
||||||
struct drv_context *drvc = di->priv;
|
struct drv_context *drvc = di->priv;
|
||||||
|
const struct libusb_pollfd **lupfd;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
/* Terminate session. */
|
||||||
/* Terminate session */
|
|
||||||
packet.type = SR_DF_END;
|
packet.type = SR_DF_END;
|
||||||
sr_session_send(devc->session_dev_id, &packet);
|
sr_session_send(devc->session_dev_id, &packet);
|
||||||
|
|
||||||
/* Remove fds from polling */
|
/* Remove fds from polling. */
|
||||||
const struct libusb_pollfd **const lupfd =
|
lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
|
||||||
libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
|
|
||||||
for (i = 0; lupfd[i]; i++)
|
for (i = 0; lupfd[i]; i++)
|
||||||
sr_source_remove(lupfd[i]->fd);
|
sr_source_remove(lupfd[i]->fd);
|
||||||
free(lupfd); /* NOT g_free()! */
|
free(lupfd); /* NOT g_free()! */
|
||||||
|
@ -738,9 +729,11 @@ static void finish_acquisition(struct dev_context *devc)
|
||||||
|
|
||||||
static void free_transfer(struct libusb_transfer *transfer)
|
static void free_transfer(struct libusb_transfer *transfer)
|
||||||
{
|
{
|
||||||
struct dev_context *devc = transfer->user_data;
|
struct dev_context *devc;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
|
devc = transfer->user_data;
|
||||||
|
|
||||||
g_free(transfer->buffer);
|
g_free(transfer->buffer);
|
||||||
transfer->buffer = NULL;
|
transfer->buffer = NULL;
|
||||||
libusb_free_transfer(transfer);
|
libusb_free_transfer(transfer);
|
||||||
|
@ -755,14 +748,13 @@ static void free_transfer(struct libusb_transfer *transfer)
|
||||||
devc->submitted_transfers--;
|
devc->submitted_transfers--;
|
||||||
if (devc->submitted_transfers == 0)
|
if (devc->submitted_transfers == 0)
|
||||||
finish_acquisition(devc);
|
finish_acquisition(devc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resubmit_transfer(struct libusb_transfer *transfer)
|
static void resubmit_transfer(struct libusb_transfer *transfer)
|
||||||
{
|
{
|
||||||
int ret = libusb_submit_transfer(transfer);
|
int ret;
|
||||||
|
|
||||||
if (LIBUSB_SUCCESS == ret)
|
if ((ret = libusb_submit_transfer(transfer)) == LIBUSB_SUCCESS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
free_transfer(transfer);
|
free_transfer(transfer);
|
||||||
|
@ -776,8 +768,12 @@ static void receive_transfer(struct libusb_transfer *transfer)
|
||||||
gboolean packet_has_error = FALSE;
|
gboolean packet_has_error = FALSE;
|
||||||
struct sr_datafeed_packet packet;
|
struct sr_datafeed_packet packet;
|
||||||
struct sr_datafeed_logic logic;
|
struct sr_datafeed_logic logic;
|
||||||
struct dev_context *devc = transfer->user_data;
|
struct dev_context *devc;
|
||||||
int trigger_offset, i;
|
int trigger_offset, i, sample_width, cur_sample_count;
|
||||||
|
int trigger_offset_bytes;
|
||||||
|
uint8_t *cur_buf;
|
||||||
|
|
||||||
|
devc = transfer->user_data;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If acquisition has already ended, just free any queued up
|
* If acquisition has already ended, just free any queued up
|
||||||
|
@ -792,9 +788,9 @@ static void receive_transfer(struct libusb_transfer *transfer)
|
||||||
transfer->status, transfer->actual_length);
|
transfer->status, transfer->actual_length);
|
||||||
|
|
||||||
/* Save incoming transfer before reusing the transfer struct. */
|
/* Save incoming transfer before reusing the transfer struct. */
|
||||||
uint8_t *const cur_buf = transfer->buffer;
|
cur_buf = transfer->buffer;
|
||||||
const int sample_width = devc->sample_wide ? 2 : 1;
|
sample_width = devc->sample_wide ? 2 : 1;
|
||||||
const int cur_sample_count = transfer->actual_length / sample_width;
|
cur_sample_count = transfer->actual_length / sample_width;
|
||||||
|
|
||||||
switch (transfer->status) {
|
switch (transfer->status) {
|
||||||
case LIBUSB_TRANSFER_NO_DEVICE:
|
case LIBUSB_TRANSFER_NO_DEVICE:
|
||||||
|
@ -802,7 +798,7 @@ static void receive_transfer(struct libusb_transfer *transfer)
|
||||||
free_transfer(transfer);
|
free_transfer(transfer);
|
||||||
return;
|
return;
|
||||||
case LIBUSB_TRANSFER_COMPLETED:
|
case LIBUSB_TRANSFER_COMPLETED:
|
||||||
case LIBUSB_TRANSFER_TIMED_OUT: /* We may have received some data though */
|
case LIBUSB_TRANSFER_TIMED_OUT: /* We may have received some data though. */
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
packet_has_error = TRUE;
|
packet_has_error = TRUE;
|
||||||
|
@ -854,8 +850,8 @@ static void receive_transfer(struct libusb_transfer *transfer)
|
||||||
sr_session_send(devc->session_dev_id, &packet);
|
sr_session_send(devc->session_dev_id, &packet);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send the samples that triggered it, since we're
|
* Send the samples that triggered it,
|
||||||
* skipping past them.
|
* since we're skipping past them.
|
||||||
*/
|
*/
|
||||||
packet.type = SR_DF_LOGIC;
|
packet.type = SR_DF_LOGIC;
|
||||||
packet.payload = &logic;
|
packet.payload = &logic;
|
||||||
|
@ -886,7 +882,7 @@ static void receive_transfer(struct libusb_transfer *transfer)
|
||||||
|
|
||||||
if (devc->trigger_stage == TRIGGER_FIRED) {
|
if (devc->trigger_stage == TRIGGER_FIRED) {
|
||||||
/* Send the incoming transfer to the session bus. */
|
/* Send the incoming transfer to the session bus. */
|
||||||
const int trigger_offset_bytes = trigger_offset * sample_width;
|
trigger_offset_bytes = trigger_offset * sample_width;
|
||||||
packet.type = SR_DF_LOGIC;
|
packet.type = SR_DF_LOGIC;
|
||||||
packet.payload = &logic;
|
packet.payload = &logic;
|
||||||
logic.length = transfer->actual_length - trigger_offset_bytes;
|
logic.length = transfer->actual_length - trigger_offset_bytes;
|
||||||
|
@ -920,8 +916,10 @@ static size_t get_buffer_size(struct dev_context *devc)
|
||||||
{
|
{
|
||||||
size_t s;
|
size_t s;
|
||||||
|
|
||||||
/* The buffer should be large enough to hold 10ms of data and a multiple
|
/*
|
||||||
* of 512. */
|
* The buffer should be large enough to hold 10ms of data and
|
||||||
|
* a multiple of 512.
|
||||||
|
*/
|
||||||
s = 10 * to_bytes_per_ms(devc->cur_samplerate);
|
s = 10 * to_bytes_per_ms(devc->cur_samplerate);
|
||||||
return (s + 511) & ~511;
|
return (s + 511) & ~511;
|
||||||
}
|
}
|
||||||
|
@ -930,7 +928,7 @@ static unsigned int get_number_of_transfers(struct dev_context *devc)
|
||||||
{
|
{
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
|
|
||||||
/* Total buffer size should be able to hold about 500ms of data */
|
/* Total buffer size should be able to hold about 500ms of data. */
|
||||||
n = 500 * to_bytes_per_ms(devc->cur_samplerate) / get_buffer_size(devc);
|
n = 500 * to_bytes_per_ms(devc->cur_samplerate) / get_buffer_size(devc);
|
||||||
|
|
||||||
if (n > NUM_SIMUL_TRANSFERS)
|
if (n > NUM_SIMUL_TRANSFERS)
|
||||||
|
@ -946,7 +944,7 @@ static unsigned int get_timeout(struct dev_context *devc)
|
||||||
|
|
||||||
total_size = get_buffer_size(devc) * get_number_of_transfers(devc);
|
total_size = get_buffer_size(devc) * get_number_of_transfers(devc);
|
||||||
timeout = total_size / to_bytes_per_ms(devc->cur_samplerate);
|
timeout = total_size / to_bytes_per_ms(devc->cur_samplerate);
|
||||||
return timeout + timeout / 4; /* Leave a headroom of 25% percent */
|
return timeout + timeout / 4; /* Leave a headroom of 25% percent. */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
|
@ -956,19 +954,22 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
struct sr_datafeed_header header;
|
struct sr_datafeed_header header;
|
||||||
struct sr_datafeed_meta_logic meta;
|
struct sr_datafeed_meta_logic meta;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
struct drv_context *drvc = di->priv;
|
struct drv_context *drvc;
|
||||||
struct libusb_transfer *transfer;
|
struct libusb_transfer *transfer;
|
||||||
const struct libusb_pollfd **lupfd;
|
const struct libusb_pollfd **lupfd;
|
||||||
unsigned int i;
|
unsigned int i, timeout, num_transfers;
|
||||||
int ret;
|
int ret;
|
||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
drvc = di->priv;
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
|
|
||||||
if (devc->submitted_transfers != 0)
|
if (devc->submitted_transfers != 0)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
|
||||||
if (configure_probes(sdi) != SR_OK) {
|
if (configure_probes(sdi) != SR_OK) {
|
||||||
sr_err("Failed to configured probes");
|
sr_err("Failed to configure probes.");
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -976,9 +977,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
devc->num_samples = 0;
|
devc->num_samples = 0;
|
||||||
devc->empty_transfer_count = 0;
|
devc->empty_transfer_count = 0;
|
||||||
|
|
||||||
const unsigned int timeout = get_timeout(devc);
|
timeout = get_timeout(devc);
|
||||||
const unsigned int num_transfers = get_number_of_transfers(devc);
|
num_transfers = get_number_of_transfers(devc);
|
||||||
const size_t size = get_buffer_size(devc);
|
size = get_buffer_size(devc);
|
||||||
|
|
||||||
devc->transfers = g_try_malloc0(sizeof(*devc->transfers) * num_transfers);
|
devc->transfers = g_try_malloc0(sizeof(*devc->transfers) * num_transfers);
|
||||||
if (!devc->transfers) {
|
if (!devc->transfers) {
|
||||||
|
@ -990,7 +991,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
|
|
||||||
for (i = 0; i < num_transfers; i++) {
|
for (i = 0; i < num_transfers; i++) {
|
||||||
if (!(buf = g_try_malloc(size))) {
|
if (!(buf = g_try_malloc(size))) {
|
||||||
sr_err("%s: buf malloc failed.", __func__);
|
sr_err("USB transfer buffer malloc failed.");
|
||||||
return SR_ERR_MALLOC;
|
return SR_ERR_MALLOC;
|
||||||
}
|
}
|
||||||
transfer = libusb_alloc_transfer(0);
|
transfer = libusb_alloc_transfer(0);
|
||||||
|
@ -998,8 +999,8 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
2 | LIBUSB_ENDPOINT_IN, buf, size,
|
2 | LIBUSB_ENDPOINT_IN, buf, size,
|
||||||
receive_transfer, devc, timeout);
|
receive_transfer, devc, timeout);
|
||||||
if ((ret = libusb_submit_transfer(transfer)) != 0) {
|
if ((ret = libusb_submit_transfer(transfer)) != 0) {
|
||||||
sr_err("%s: libusb_submit_transfer: %s.",
|
sr_err("Failed to submit transfer: %s.",
|
||||||
__func__, libusb_error_name(ret));
|
libusb_error_name(ret));
|
||||||
libusb_free_transfer(transfer);
|
libusb_free_transfer(transfer);
|
||||||
g_free(buf);
|
g_free(buf);
|
||||||
abort_acquisition(devc);
|
abort_acquisition(devc);
|
||||||
|
@ -1028,7 +1029,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
meta.num_probes = devc->sample_wide ? 16 : 8;
|
meta.num_probes = devc->sample_wide ? 16 : 8;
|
||||||
sr_session_send(cb_data, &packet);
|
sr_session_send(cb_data, &packet);
|
||||||
|
|
||||||
if ((ret = command_start_acquisition (devc->usb->devhdl,
|
if ((ret = command_start_acquisition(devc->usb->devhdl,
|
||||||
devc->cur_samplerate, devc->sample_wide)) != SR_OK) {
|
devc->cur_samplerate, devc->sample_wide)) != SR_OK) {
|
||||||
abort_acquisition(devc);
|
abort_acquisition(devc);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -18,11 +18,20 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <glib.h>
|
|
||||||
|
|
||||||
#ifndef LIBSIGROK_HARDWARE_FX2LAFW_FX2LAFW_H
|
#ifndef LIBSIGROK_HARDWARE_FX2LAFW_FX2LAFW_H
|
||||||
#define LIBSIGROK_HARDWARE_FX2LAFW_FX2LAFW_H
|
#define LIBSIGROK_HARDWARE_FX2LAFW_FX2LAFW_H
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
/* Message logging helpers with driver-specific prefix string. */
|
||||||
|
#define DRIVER_LOG_DOMAIN "fx2lafw: "
|
||||||
|
#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
|
||||||
|
#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
|
||||||
|
#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
|
||||||
|
#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
|
||||||
|
#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
|
||||||
|
#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
|
||||||
|
|
||||||
#define USB_INTERFACE 0
|
#define USB_INTERFACE 0
|
||||||
#define USB_CONFIGURATION 1
|
#define USB_CONFIGURATION 1
|
||||||
#define NUM_TRIGGER_STAGES 4
|
#define NUM_TRIGGER_STAGES 4
|
||||||
|
@ -47,15 +56,6 @@
|
||||||
|
|
||||||
#define DEV_CAPS_16BIT (1 << DEV_CAPS_16BIT_POS)
|
#define DEV_CAPS_16BIT (1 << DEV_CAPS_16BIT_POS)
|
||||||
|
|
||||||
/* Message logging helpers with driver-specific prefix string. */
|
|
||||||
#define DRIVER_LOG_DOMAIN "fx2lafw: "
|
|
||||||
#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
|
|
||||||
#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
|
|
||||||
#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
|
|
||||||
#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
|
|
||||||
#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
|
|
||||||
#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
|
|
||||||
|
|
||||||
struct fx2lafw_profile {
|
struct fx2lafw_profile {
|
||||||
uint16_t vid;
|
uint16_t vid;
|
||||||
uint16_t pid;
|
uint16_t pid;
|
||||||
|
@ -74,7 +74,7 @@ struct dev_context {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Since we can't keep track of an fx2lafw device after upgrading
|
* Since we can't keep track of an fx2lafw device after upgrading
|
||||||
* the firmware (it re-enumerates into a different device address
|
* the firmware (it renumerates into a different device address
|
||||||
* after the upgrade) this is like a global lock. No device will open
|
* after the upgrade) this is like a global lock. No device will open
|
||||||
* until a proper delay after the last device was upgraded.
|
* until a proper delay after the last device was upgraded.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue