static int scpi_usbtmc_libusb_source_add(void *priv, int events, int timeout, sr_receive_data_callback_t cb, void *cb_data) { struct scpi_usbtmc_libusb *uscpi = priv; (void)events; return usb_source_add(uscpi->ctx, timeout, cb, cb_data); }
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; struct drv_context *drvc = di->priv; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; devc = sdi->priv; devc->cb_data = cb_data; if (configure_probes(sdi) != SR_OK) { sr_err("Failed to configure probes."); return SR_ERR; } if (dso_init(sdi) != SR_OK) return SR_ERR; if (dso_capture_start(sdi) != SR_OK) return SR_ERR; devc->dev_state = CAPTURE; 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); return SR_OK; }
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc = di->context; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; devc = sdi->priv; devc->cb_data = cb_data; if (configure_channels(sdi) != SR_OK) { sr_err("Failed to configure channels."); return SR_ERR; } if (hantek_6xxx_init(sdi) != SR_OK) return SR_ERR; /* Send header packet to the session bus. */ std_session_send_df_header(cb_data, LOG_PREFIX); devc->samp_received = 0; devc->dev_state = FLUSH; usb_source_add(sdi->session, drvc->sr_ctx, TICK, handle_event, (void *)sdi); hantek_6xxx_start_data_collecting(sdi); read_channel(sdi, FLUSH_PACKET_SIZE); return SR_OK; }
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct drv_context *drvc; struct dev_context *devc; struct acquisition_state *acq; int ret; (void)cb_data; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; devc = sdi->priv; drvc = di->priv; if (devc->acquisition) { sr_err("Acquisition still in progress?"); return SR_ERR; } acq = lwla_alloc_acquisition_state(); if (!acq) return SR_ERR_MALLOC; devc->stopping_in_progress = FALSE; devc->transfer_error = FALSE; sr_info("Starting acquisition."); devc->acquisition = acq; lwla_convert_trigger(sdi); ret = lwla_setup_acquisition(sdi); if (ret != SR_OK) { sr_err("Failed to set up acquisition."); devc->acquisition = NULL; lwla_free_acquisition_state(acq); return ret; } ret = lwla_start_acquisition(sdi); if (ret != SR_OK) { sr_err("Failed to start acquisition."); devc->acquisition = NULL; lwla_free_acquisition_state(acq); return ret; } usb_source_add(sdi->session, drvc->sr_ctx, 100, &lwla_receive_data, (struct sr_dev_inst *)sdi); sr_info("Waiting for data."); /* Send header packet to the session bus. */ std_session_send_df_header(sdi, LOG_PREFIX); return SR_OK; }
SR_PRIV int lwla_start_acquisition(const struct sr_dev_inst *sdi) { struct drv_context *drvc; struct dev_context *devc; int ret; const int poll_interval_ms = 100; drvc = sdi->driver->context; devc = sdi->priv; if (devc->state != STATE_IDLE) { sr_err("Not in idle state, cannot start acquisition."); return SR_ERR; } devc->cancel_requested = FALSE; devc->transfer_error = FALSE; ret = init_acquisition_state(sdi); if (ret != SR_OK) return ret; ret = (*devc->model->setup_acquisition)(sdi); if (ret != SR_OK) { sr_err("Failed to set up device for acquisition."); clear_acquisition_state(sdi); return ret; } /* Register event source for asynchronous USB I/O. */ ret = usb_source_add(sdi->session, drvc->sr_ctx, poll_interval_ms, &transfer_event, (struct sr_dev_inst *)sdi); if (ret != SR_OK) { clear_acquisition_state(sdi); return ret; } ret = submit_request(sdi, STATE_START_CAPTURE); if (ret == SR_OK) ret = std_session_send_df_header(sdi, LOG_PREFIX); if (ret != SR_OK) { usb_source_remove(sdi->session, drvc->sr_ctx); clear_acquisition_state(sdi); } return ret; }
static int dev_acquisition_start(const struct sr_dev_inst *sdi) { struct drv_context *drvc; int ret; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; drvc = sdi->driver->context; if ((ret = lls_start_acquisition(sdi)) < 0) return ret; std_session_send_df_header(sdi); return usb_source_add(sdi->session, drvc->sr_ctx, 100, receive_usb_data, drvc); }
SR_PRIV int fx2lafw_start_acquisition(const struct sr_dev_inst *sdi) { struct sr_dev_driver *di; struct drv_context *drvc; struct dev_context *devc; int timeout, ret; size_t size; di = sdi->driver; drvc = di->context; devc = sdi->priv; devc->ctx = drvc->sr_ctx; devc->sent_samples = 0; devc->empty_transfer_count = 0; devc->acq_aborted = FALSE; if (configure_channels(sdi) != SR_OK) { sr_err("Failed to configure channels."); return SR_ERR; } timeout = get_timeout(devc); usb_source_add(sdi->session, devc->ctx, timeout, receive_data, drvc); size = get_buffer_size(devc); /* Prepare for analog sampling. */ if (g_slist_length(devc->enabled_analog_channels) > 0) { /* We need a buffer half the size of a transfer. */ devc->logic_buffer = g_try_malloc(size / 2); devc->analog_buffer = g_try_malloc( sizeof(float) * size / 2); } start_transfers(sdi); if ((ret = command_start_acquisition(sdi)) != SR_OK) { fx2lafw_abort_acquisition(devc); return ret; } return SR_OK; }
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct drv_context *drvc; struct dev_context *devc; uint16_t trigger_bytes, tmp; unsigned int i, j; int ret; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; devc = sdi->priv; drvc = di->priv; devc->cb_data = cb_data; devc->wait_data_ready_locked = TRUE; devc->stopping_in_progress = FALSE; devc->transfer_error = FALSE; devc->samples_processed = 0; devc->channel = 0; devc->sample_packet = 0; /* * The trigger must be configured first because the calculation of the * pre and post trigger samples depends on a configured trigger. */ sl2_configure_trigger(sdi); sl2_calculate_trigger_samples(sdi); trigger_bytes = devc->pre_trigger_bytes + devc->post_trigger_bytes; /* Calculate the number of expected sample packets. */ devc->num_sample_packets = trigger_bytes / PACKET_NUM_SAMPLE_BYTES; /* Round up the number of expected sample packets. */ if (trigger_bytes % PACKET_NUM_SAMPLE_BYTES != 0) devc->num_sample_packets++; devc->num_enabled_probes = 0; /* * Count the number of enabled probes and number them for a sequential * access. */ for (i = 0, j = 0; i < NUM_PROBES; i++) { if (devc->probes[i]->enabled) { devc->num_enabled_probes++; devc->probe_map[j] = i; j++; } } sr_dbg("Number of enabled probes: %i.", devc->num_enabled_probes); /* Set up the transfer buffer for the acquisition. */ devc->xfer_data_out[0] = CMD_SAMPLE; devc->xfer_data_out[1] = 0x00; tmp = GUINT16_TO_LE(devc->pre_trigger_bytes); memcpy(devc->xfer_data_out + 2, &tmp, sizeof(tmp)); tmp = GUINT16_TO_LE(devc->post_trigger_bytes); memcpy(devc->xfer_data_out + 4, &tmp, sizeof(tmp)); devc->xfer_data_out[6] = devc->samplerate_id; devc->xfer_data_out[7] = devc->trigger_type; devc->xfer_data_out[8] = devc->trigger_channel; devc->xfer_data_out[9] = 0x00; tmp = GUINT16_TO_LE(devc->after_trigger_delay); memcpy(devc->xfer_data_out + 10, &tmp, sizeof(tmp)); if ((ret = libusb_submit_transfer(devc->xfer_out)) != 0) { sr_err("Submit transfer failed: %s.", libusb_error_name(ret)); return SR_ERR; } usb_source_add(drvc->sr_ctx, 100, ikalogic_scanalogic2_receive_data, (void *)sdi); sr_dbg("Acquisition started successfully."); /* Send header packet to the session bus. */ std_session_send_df_header(cb_data, LOG_PREFIX); devc->next_state = STATE_SAMPLE; return SR_OK; }
static int dev_acquisition_start(const struct sr_dev_inst *sdi) { struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc; struct dev_context *devc; struct sr_datafeed_packet packet; struct sr_datafeed_meta meta; struct sr_config *src; struct sr_usb_dev_inst *usb; GVariant *gvar, *rational[2]; const uint64_t *si; int req_len, buf_len, len, ret; unsigned char buf[9]; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; drvc = di->context; devc = sdi->priv; usb = sdi->conn; devc->num_samples = 0; std_session_send_df_header(sdi); if (devc->data_source == DATA_SOURCE_LIVE) { /* Force configuration. */ kecheng_kc_330b_configure(sdi); if (kecheng_kc_330b_status_get(sdi, &ret) != SR_OK) return SR_ERR; if (ret != DEVICE_ACTIVE) { sr_err("Device is inactive"); /* Still continue though, since the device will * just return 30.0 until the user hits the button * on the device -- and then start feeding good * samples back. */ } } else { if (kecheng_kc_330b_log_info_get(sdi, buf) != SR_OK) return SR_ERR; devc->mqflags = buf[4] ? SR_MQFLAG_SPL_TIME_WEIGHT_S : SR_MQFLAG_SPL_TIME_WEIGHT_F; devc->mqflags |= buf[5] ? SR_MQFLAG_SPL_FREQ_WEIGHT_C : SR_MQFLAG_SPL_FREQ_WEIGHT_A; devc->stored_samples = (buf[7] << 8) | buf[8]; if (devc->stored_samples == 0) { /* Notify frontend of empty log by sending start/end packets. */ std_session_send_df_end(sdi); return SR_OK; } if (devc->limit_samples && devc->limit_samples < devc->stored_samples) devc->stored_samples = devc->limit_samples; si = kecheng_kc_330b_sample_intervals[buf[1]]; rational[0] = g_variant_new_uint64(si[0]); rational[1] = g_variant_new_uint64(si[1]); gvar = g_variant_new_tuple(rational, 2); src = sr_config_new(SR_CONF_SAMPLE_INTERVAL, gvar); packet.type = SR_DF_META; packet.payload = &meta; meta.config = g_slist_append(NULL, src); sr_session_send(sdi, &packet); g_free(src); } if (!(devc->xfer = libusb_alloc_transfer(0))) return SR_ERR; usb_source_add(sdi->session, drvc->sr_ctx, 10, kecheng_kc_330b_handle_events, (void *)sdi); if (devc->data_source == DATA_SOURCE_LIVE) { buf[0] = CMD_GET_LIVE_SPL; buf_len = 1; devc->state = LIVE_SPL_WAIT; devc->last_live_request = g_get_monotonic_time() / 1000; req_len = 3; } else { buf[0] = CMD_GET_LOG_DATA; buf[1] = 0; buf[2] = 0; buf_len = 4; devc->state = LOG_DATA_WAIT; if (devc->stored_samples < 63) buf[3] = devc->stored_samples; else buf[3] = 63; /* Command ack byte + 2 bytes per sample. */ req_len = 1 + buf[3] * 2; } ret = libusb_bulk_transfer(usb->devhdl, EP_OUT, buf, buf_len, &len, 5); if (ret != 0 || len != 1) { sr_dbg("Failed to start acquisition: %s", libusb_error_name(ret)); libusb_free_transfer(devc->xfer); return SR_ERR; } libusb_fill_bulk_transfer(devc->xfer, usb->devhdl, EP_IN, devc->buf, req_len, kecheng_kc_330b_receive_transfer, (void *)sdi, 15); if (libusb_submit_transfer(devc->xfer) != 0) { libusb_free_transfer(devc->xfer); return SR_ERR; } return SR_OK; }
static int dev_acquisition_start(const struct sr_dev_inst *sdi) { struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc; struct dev_context *devc; struct sr_usb_dev_inst *usb; int len, ret; unsigned char cmd[2]; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; drvc = di->context; devc = sdi->priv; usb = sdi->conn; devc->num_samples = 0; devc->packet_len = 0; /* Configure serial port parameters on USB-UART interface * chip inside the device (just baudrate 2400 actually). */ cmd[0] = 0x09; cmd[1] = 0x60; ret = libusb_control_transfer(usb->devhdl, 0x21, 0x09, 0x0300, 0x00, cmd, 2, 5); if (ret != 2) { sr_dbg("Failed to configure CH9325: %s", libusb_error_name(ret)); return SR_ERR; } std_session_send_df_header(sdi); if (!(devc->xfer = libusb_alloc_transfer(0))) return SR_ERR; /* Length of payload to follow. */ cmd[0] = 0x01; if (devc->data_source == DATA_SOURCE_LIVE) cmd[1] = CMD_GET_LIVE; else cmd[1] = CMD_GET_STORED; ret = libusb_bulk_transfer(usb->devhdl, EP_OUT, cmd, 2, &len, 5); if (ret != 0 || len != 2) { sr_dbg("Failed to start acquisition: %s", libusb_error_name(ret)); libusb_free_transfer(devc->xfer); return SR_ERR; } libusb_fill_bulk_transfer(devc->xfer, usb->devhdl, EP_IN, devc->buf, 8, uni_t_ut32x_receive_transfer, (void *)sdi, 15); if (libusb_submit_transfer(devc->xfer) != 0) { libusb_free_transfer(devc->xfer); return SR_ERR; } usb_source_add(sdi->session, drvc->sr_ctx, 10, uni_t_ut32x_handle_events, (void *)sdi); return SR_OK; }
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; struct drv_context *drvc; struct sr_usb_dev_inst *usb; struct sr_trigger *trigger; struct libusb_transfer *transfer; unsigned int i, timeout, num_transfers; int ret; unsigned char *buf; size_t size, convsize; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; drvc = di->priv; devc = sdi->priv; usb = sdi->conn; /* Configures devc->cur_channels. */ if (configure_channels(sdi) != SR_OK) { sr_err("Failed to configure channels."); return SR_ERR; } devc->cb_data = cb_data; devc->sent_samples = 0; devc->empty_transfer_count = 0; devc->cur_channel = 0; memset(devc->channel_data, 0, sizeof(devc->channel_data)); if ((trigger = sr_session_trigger_get(sdi->session))) { int pre_trigger_samples = 0; if (devc->limit_samples > 0) pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100; devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples); if (!devc->stl) return SR_ERR_MALLOC; devc->trigger_fired = FALSE; } else devc->trigger_fired = TRUE; timeout = get_timeout(devc); num_transfers = get_number_of_transfers(devc); size = get_buffer_size(devc); convsize = (size / devc->num_channels + 2) * 16; devc->submitted_transfers = 0; devc->convbuffer_size = convsize; if (!(devc->convbuffer = g_try_malloc(convsize))) { sr_err("Conversion buffer malloc failed."); return SR_ERR_MALLOC; } devc->transfers = g_try_malloc0(sizeof(*devc->transfers) * num_transfers); if (!devc->transfers) { sr_err("USB transfers malloc failed."); g_free(devc->convbuffer); return SR_ERR_MALLOC; } if ((ret = logic16_setup_acquisition(sdi, devc->cur_samplerate, devc->cur_channels)) != SR_OK) { g_free(devc->transfers); g_free(devc->convbuffer); return ret; } devc->num_transfers = num_transfers; for (i = 0; i < num_transfers; i++) { if (!(buf = g_try_malloc(size))) { sr_err("USB transfer buffer malloc failed."); if (devc->submitted_transfers) abort_acquisition(devc); else { g_free(devc->transfers); g_free(devc->convbuffer); } return SR_ERR_MALLOC; } transfer = libusb_alloc_transfer(0); libusb_fill_bulk_transfer(transfer, usb->devhdl, 2 | LIBUSB_ENDPOINT_IN, buf, size, logic16_receive_transfer, (void *)sdi, timeout); if ((ret = libusb_submit_transfer(transfer)) != 0) { sr_err("Failed to submit transfer: %s.", libusb_error_name(ret)); libusb_free_transfer(transfer); g_free(buf); abort_acquisition(devc); return SR_ERR; } devc->transfers[i] = transfer; devc->submitted_transfers++; } devc->ctx = drvc->sr_ctx; usb_source_add(sdi->session, devc->ctx, timeout, receive_data, (void *)sdi); /* Send header packet to the session bus. */ std_session_send_df_header(cb_data, LOG_PREFIX); if ((ret = logic16_start_acquisition(sdi)) != SR_OK) { abort_acquisition(devc); return ret; } return SR_OK; }
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; struct drv_context *drvc; struct sr_usb_dev_inst *usb; struct sr_trigger *trigger; struct libusb_transfer *transfer; unsigned int i, timeout, num_transfers; int ret; unsigned char *buf; size_t size; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; drvc = di->priv; devc = sdi->priv; usb = sdi->conn; devc->cb_data = cb_data; devc->sent_samples = 0; devc->acq_aborted = FALSE; devc->empty_transfer_count = 0; if ((trigger = sr_session_trigger_get())) { devc->stl = soft_trigger_logic_new(sdi, trigger); devc->trigger_fired = FALSE; } else devc->trigger_fired = TRUE; timeout = fx2lafw_get_timeout(devc); num_transfers = fx2lafw_get_number_of_transfers(devc); size = fx2lafw_get_buffer_size(devc); devc->submitted_transfers = 0; devc->transfers = g_try_malloc0(sizeof(*devc->transfers) * num_transfers); if (!devc->transfers) { sr_err("USB transfers malloc failed."); return SR_ERR_MALLOC; } devc->num_transfers = num_transfers; for (i = 0; i < num_transfers; i++) { if (!(buf = g_try_malloc(size))) { sr_err("USB transfer buffer malloc failed."); return SR_ERR_MALLOC; } transfer = libusb_alloc_transfer(0); libusb_fill_bulk_transfer(transfer, usb->devhdl, 2 | LIBUSB_ENDPOINT_IN, buf, size, fx2lafw_receive_transfer, (void *)sdi, timeout); if ((ret = libusb_submit_transfer(transfer)) != 0) { sr_err("Failed to submit transfer: %s.", libusb_error_name(ret)); libusb_free_transfer(transfer); g_free(buf); fx2lafw_abort_acquisition(devc); return SR_ERR; } devc->transfers[i] = transfer; devc->submitted_transfers++; } 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); if ((ret = fx2lafw_command_start_acquisition(sdi)) != SR_OK) { fx2lafw_abort_acquisition(devc); return ret; } return SR_OK; }