return ret;
}
+
+SR_PRIV int usb_source_add(struct sr_context *ctx, int timeout,
+ sr_receive_data_callback_t cb, void *cb_data)
+{
+#ifdef _WIN32
+ sr_err("Operation not supported on Windows yet.");
+ return SR_ERR;
+#else
+ const struct libusb_pollfd **lupfd;
+ unsigned int i;
+
+ lupfd = libusb_get_pollfds(ctx->libusb_ctx);
+ for (i = 0; lupfd[i]; i++)
+ sr_source_add(lupfd[i]->fd, lupfd[i]->events, timeout, cb, cb_data);
+ free(lupfd);
+
+ return SR_OK;
+#endif
+}
+
+SR_PRIV int usb_source_remove(struct sr_context *ctx)
+{
+#ifdef _WIN32
+ sr_err("Operation not supported on Windows yet.");
+ return SR_ERR;
+#else
+ const struct libusb_pollfd **lupfd;
+ unsigned int i;
+
+ lupfd = libusb_get_pollfds(ctx->libusb_ctx);
+ for (i = 0; lupfd[i]; i++)
+ sr_source_remove(lupfd[i]->fd);
+ free(lupfd);
+
+ return SR_OK;
+#endif
+}
struct drv_context *drvc;
struct sr_usb_dev_inst *usb;
struct libusb_transfer *transfer;
- const struct libusb_pollfd **lupfd;
unsigned int i, timeout, num_transfers;
int ret;
unsigned char *buf;
devc->submitted_transfers++;
}
- lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
- for (i = 0; lupfd[i]; i++);
- if (!(devc->usbfd = g_try_malloc(sizeof(struct libusb_pollfd) * (i + 1))))
- return SR_ERR;
- for (i = 0; lupfd[i]; i++) {
- sr_source_add(lupfd[i]->fd, lupfd[i]->events,
- timeout, receive_data, NULL);
- devc->usbfd[i] = lupfd[i]->fd;
- }
- devc->usbfd[i] = -1;
- free(lupfd);
+ devc->ctx = drvc->sr_ctx;
+
+ usb_source_add(devc->ctx, timeout, receive_data, NULL);
/* Send header packet to the session bus. */
std_session_send_df_header(cb_data, LOG_PREFIX);
static void finish_acquisition(struct dev_context *devc)
{
struct sr_datafeed_packet packet;
- int i;
/* Terminate session. */
packet.type = SR_DF_END;
sr_session_send(devc->cb_data, &packet);
/* Remove fds from polling. */
- for (i = 0; devc->usbfd[i] != -1; i++)
- sr_source_remove(devc->usbfd[i]);
- g_free(devc->usbfd);
+ usb_source_remove(devc->ctx);
devc->num_transfers = 0;
g_free(devc->transfers);
void *cb_data;
unsigned int num_transfers;
struct libusb_transfer **transfers;
- int *usbfd;
+ struct sr_context *ctx;
};
SR_PRIV int fx2lafw_command_start_acquisition(libusb_device_handle *devhdl,
struct timeval tv;
struct dev_context *devc;
struct drv_context *drvc = di->priv;
- const struct libusb_pollfd **lupfd;
- int num_probes, i;
+ int num_probes;
uint32_t trigger_offset;
uint8_t capturestate;
* TODO: Doesn't really cancel pending transfers so they might
* come in after SR_DF_END is sent.
*/
- lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
- for (i = 0; lupfd[i]; i++)
- sr_source_remove(lupfd[i]->fd);
- free(lupfd);
+ usb_source_remove(drvc->sr_ctx);
packet.type = SR_DF_END;
sr_session_send(sdi, &packet);
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
{
- const struct libusb_pollfd **lupfd;
struct dev_context *devc;
struct drv_context *drvc = di->priv;
- int i;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
return SR_ERR;
devc->dev_state = CAPTURE;
- lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
- for (i = 0; lupfd[i]; i++)
- sr_source_add(lupfd[i]->fd, lupfd[i]->events, TICK,
- handle_event, (void *)sdi);
- free(lupfd);
+ usb_source_add(drvc->sr_ctx, TICK, handle_event, (void *)sdi);
/* Send header packet to the session bus. */
std_session_send_df_header(cb_data, LOG_PREFIX);
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
{
- const struct libusb_pollfd **pfd;
struct drv_context *drvc;
struct dev_context *devc;
uint16_t trigger_bytes, tmp;
tmp = GUINT16_TO_LE(devc->after_trigger_delay);
memcpy(devc->xfer_data_out + 10, &tmp, sizeof(tmp));
- if (!(pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx))) {
- sr_err("libusb_get_pollfds failed.");
- return SR_ERR;
- }
-
- /* Count the number of file descriptors. */
- for (devc->num_usbfd = 0; pfd[devc->num_usbfd]; devc->num_usbfd++);
-
- if (!(devc->usbfd = g_try_malloc(devc->num_usbfd * sizeof(int)))) {
- sr_err("File descriptor array malloc failed.");
- free(pfd);
- return SR_ERR_MALLOC;
- }
-
if ((ret = libusb_submit_transfer(devc->xfer_out)) != 0) {
sr_err("Submit transfer failed: %s.", libusb_error_name(ret));
- g_free(devc->usbfd);
return SR_ERR;
}
- for (i = 0; i < devc->num_usbfd; i++) {
- sr_source_add(pfd[i]->fd, pfd[i]->events, 100,
- ikalogic_scanalogic2_receive_data, (void *)sdi);
-
- devc->usbfd[i] = pfd[i]->fd;
- }
-
- free(pfd);
+ usb_source_add(drvc->sr_ctx, 100, ikalogic_scanalogic2_receive_data, (void *)sdi);
sr_dbg("Acquisition started successfully.");
static void stop_acquisition(struct sr_dev_inst *sdi)
{
+ struct drv_context *drvc = sdi->driver->priv;
struct dev_context *devc;
struct sr_datafeed_packet packet;
- unsigned int i;
devc = sdi->priv;
/* Remove USB file descriptors from polling. */
- for (i = 0; i < devc->num_usbfd; i++)
- sr_source_remove(devc->usbfd[i]);
-
- g_free(devc->usbfd);
+ usb_source_remove(drvc->sr_ctx);
packet.type = SR_DF_END;
sr_session_send(devc->cb_data, &packet);
static void abort_acquisition(struct sr_dev_inst *sdi)
{
+ struct drv_context *drvc = sdi->driver->priv;
struct dev_context *devc;
struct sr_datafeed_packet packet;
- unsigned int i;
devc = sdi->priv;
/* Remove USB file descriptors from polling. */
- for (i = 0; i < devc->num_usbfd; i++)
- sr_source_remove(devc->usbfd[i]);
-
- g_free(devc->usbfd);
+ usb_source_remove(drvc->sr_ctx);
packet.type = SR_DF_END;
sr_session_send(devc->cb_data, &packet);
/* Array to provide an index based access to all probes. */
const struct sr_probe *probes[NUM_PROBES];
- unsigned int num_usbfd;
- int *usbfd;
-
struct libusb_transfer *xfer_in, *xfer_out;
/*
struct sr_config *src;
struct sr_usb_dev_inst *usb;
GVariant *gvar, *rational[2];
- const struct libusb_pollfd **pfd;
const uint64_t *si;
- int stored_mqflags, req_len, buf_len, len, ret, i;
+ int stored_mqflags, req_len, buf_len, len, ret;
unsigned char buf[9];
if (sdi->status != SR_ST_ACTIVE)
if (!(devc->xfer = libusb_alloc_transfer(0)))
return SR_ERR;
- pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
- for (i = 0; pfd[i]; i++) {
- /* Handle USB events every 10ms. */
- sr_source_add(pfd[i]->fd, pfd[i]->events, 10,
- kecheng_kc_330b_handle_events, (void *)sdi);
- /* We'll need to remove this fd later. */
- devc->usbfd[i] = pfd[i]->fd;
- }
- devc->usbfd[i] = -1;
+ usb_source_add(drvc->sr_ctx, 10,
+ kecheng_kc_330b_handle_events, (void *)sdi);
if (devc->data_source == DATA_SOURCE_LIVE) {
buf[0] = CMD_GET_LIVE_SPL;
struct timeval tv;
const uint64_t *intv_entry;
gint64 now, interval;
- int offset, len, ret, i;
+ int offset, len, ret;
unsigned char buf[4];
(void)fd;
if (sdi->status == SR_ST_STOPPING) {
libusb_free_transfer(devc->xfer);
- for (i = 0; devc->usbfd[i] != -1; i++)
- sr_source_remove(devc->usbfd[i]);
+ usb_source_remove(drvc->sr_ctx);
packet.type = SR_DF_END;
sr_session_send(cb_data, &packet);
sdi->status = SR_ST_ACTIVE;
uint64_t num_samples;
uint64_t stored_samples;
void *cb_data;
- int usbfd[10];
struct libusb_transfer *xfer;
unsigned char buf[128];
struct drv_context *drvc;
struct sr_usb_dev_inst *usb;
struct libusb_transfer *xfer_in, *xfer_out;
- const struct libusb_pollfd **pfd;
struct timeval tv;
uint64_t interval;
- int ret, i;
+ int ret;
unsigned char cmd[3], resp[4], *buf;
if (sdi->status != SR_ST_ACTIVE)
devc->log_size = xfer_in->buffer[1] + (xfer_in->buffer[2] << 8);
libusb_free_transfer(xfer_out);
- pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
- for (i = 0; pfd[i]; i++) {
- /* Handle USB events every 100ms, for decent latency. */
- sr_source_add(pfd[i]->fd, pfd[i]->events, 100,
- lascar_el_usb_handle_events, (void *)sdi);
- /* We'll need to remove this fd later. */
- devc->usbfd[i] = pfd[i]->fd;
- }
- devc->usbfd[i] = -1;
+ usb_source_add(drvc->sr_ctx, 100, lascar_el_usb_handle_events, (void *)sdi);
buf = g_try_malloc(4096);
libusb_fill_bulk_transfer(xfer_in, usb->devhdl, LASCAR_EP_IN,
SR_PRIV int lascar_el_usb_handle_events(int fd, int revents, void *cb_data)
{
- struct dev_context *devc;
struct drv_context *drvc = di->priv;
struct sr_datafeed_packet packet;
struct sr_dev_inst *sdi;
struct timeval tv;
- int i;
(void)fd;
(void)revents;
sdi = cb_data;
- devc = sdi->priv;
if (sdi->status == SR_ST_STOPPING) {
- for (i = 0; devc->usbfd[i] != -1; i++)
- sr_source_remove(devc->usbfd[i]);
+ usb_source_remove(drvc->sr_ctx);
packet.type = SR_DF_END;
sr_session_send(cb_data, &packet);
struct dev_context {
void *cb_data;
const struct elusb_profile *profile;
- int usbfd[10];
/* Generic EL-USB */
unsigned char config[MAX_CONFIGBLOCK_SIZE];
unsigned int log_size;
struct drv_context *drvc;
struct sr_usb_dev_inst *usb;
struct libusb_transfer *transfer;
- const struct libusb_pollfd **lupfd;
unsigned int i, timeout, num_transfers;
int ret;
unsigned char *buf;
size = get_buffer_size(devc);
convsize = (size / devc->num_channels + 2) * 16;
devc->submitted_transfers = 0;
- devc->usbfd = NULL;
devc->convbuffer_size = convsize;
if (!(devc->convbuffer = g_try_malloc(convsize))) {
devc->submitted_transfers++;
}
- lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
- for (i = 0; lupfd[i]; i++);
- devc->usbfd = g_try_malloc(sizeof(struct libusb_pollfd) * (i + 1));
- if (!devc->usbfd) {
- abort_acquisition(devc);
- free(lupfd);
- return SR_ERR;
- }
- for (i = 0; lupfd[i]; i++) {
- sr_source_add(lupfd[i]->fd, lupfd[i]->events,
- timeout, receive_data, (void *)sdi);
- devc->usbfd[i] = lupfd[i]->fd;
- }
- devc->usbfd[i] = -1;
- free(lupfd);
+ devc->ctx = drvc->sr_ctx;
+
+ usb_source_add(devc->ctx, timeout, receive_data, (void *)sdi);
/* Send header packet to the session bus. */
std_session_send_df_header(cb_data, LOG_PREFIX);
static void finish_acquisition(struct dev_context *devc)
{
struct sr_datafeed_packet packet;
- int i;
/* Terminate session. */
packet.type = SR_DF_END;
sr_session_send(devc->cb_data, &packet);
/* Remove fds from polling. */
- if (devc->usbfd != NULL) {
- for (i = 0; devc->usbfd[i] != -1; i++)
- sr_source_remove(devc->usbfd[i]);
- g_free(devc->usbfd);
- }
+ usb_source_remove(devc->ctx);
devc->num_transfers = 0;
g_free(devc->transfers);
void *cb_data;
unsigned int num_transfers;
struct libusb_transfer **transfers;
- int *usbfd;
+ struct sr_context *ctx;
};
SR_PRIV int logic16_setup_acquisition(const struct sr_dev_inst *sdi,
struct drv_context *drvc;
struct dev_context *devc;
struct sr_usb_dev_inst *usb;
- const struct libusb_pollfd **pfd;
- int len, ret, i;
+ int len, ret;
unsigned char cmd[2];
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR;
}
- pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
- for (i = 0; pfd[i]; i++) {
- /* Handle USB events every 10ms. */
- sr_source_add(pfd[i]->fd, pfd[i]->events, 10,
- uni_t_ut32x_handle_events, (void *)sdi);
- /* We'll need to remove this fd later. */
- devc->usbfd[i] = pfd[i]->fd;
- }
- devc->usbfd[i] = -1;
+ usb_source_add(drvc->sr_ctx, 10, uni_t_ut32x_handle_events, (void *)sdi);
return SR_OK;
}
struct sr_datafeed_packet packet;
struct sr_usb_dev_inst *usb;
struct timeval tv;
- int len, ret, i;
+ int len, ret;
unsigned char cmd[2];
(void)fd;
NULL);
if (sdi->status == SR_ST_STOPPING) {
- for (i = 0; devc->usbfd[i] != -1; i++)
- sr_source_remove(devc->usbfd[i]);
+ usb_source_remove(drvc->sr_ctx);
packet.type = SR_DF_END;
sr_session_send(cb_data, &packet);
/* Operational state */
uint64_t num_samples;
- int usbfd[10];
unsigned char buf[8];
struct libusb_transfer *xfer;
void *cb_data;
struct sr_dev_inst *sdi;
struct timeval tv;
gint64 now;
- int i;
(void)fd;
(void)revents;
}
if (sdi->status == SR_ST_STOPPING) {
- for (i = 0; devc->usbfd[i] != -1; i++)
- sr_source_remove(devc->usbfd[i]);
+ usb_source_remove(drvc->sr_ctx);
dev_close(sdi);
{
struct dev_context *devc;
struct drv_context *drvc = di->priv;
- const struct libusb_pollfd **pfd;
struct sr_usb_dev_inst *usb;
struct libusb_transfer *transfer;
- int ret, i;
+ int ret;
unsigned char *buf;
if (sdi->status != SR_ST_ACTIVE)
/* Send header packet to the session bus. */
std_session_send_df_header(cb_data, LOG_PREFIX);
- pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
- for (i = 0; pfd[i]; i++) {
- /* Handle USB events every 100ms, for decent latency. */
- sr_source_add(pfd[i]->fd, pfd[i]->events, 100,
- handle_events, (void *)sdi);
- /* We'll need to remove this fd later. */
- devc->usbfd[i] = pfd[i]->fd;
- }
- devc->usbfd[i] = -1;
+ usb_source_add(drvc->sr_ctx, 100, handle_events, (void *)sdi);
buf = g_try_malloc(DMM_DATA_SIZE);
transfer = libusb_alloc_transfer(0);
/** The current number of already received samples. */
uint64_t num_samples;
gint64 end_time;
-
- /* Only requires 3 really. */
- int usbfd[10];
};
SR_PRIV int victor_dmm_receive_data(struct sr_dev_inst *sdi, unsigned char *buf);
#ifdef HAVE_LIBUSB_1_0
SR_PRIV GSList *sr_usb_find(libusb_context *usb_ctx, const char *conn);
SR_PRIV int sr_usb_open(libusb_context *usb_ctx, struct sr_usb_dev_inst *usb);
+SR_PRIV int usb_source_add(struct sr_context *ctx, int timeout,
+ sr_receive_data_callback_t cb, void *cb_data);
+SR_PRIV int usb_source_remove(struct sr_context *ctx);
#endif
/*--- hardware/common/scpi.c ------------------------------------------------*/