X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Ffx2lafw%2Fapi.c;h=e56f152f5ff191069020fc3cdb22c382d4b3721d;hb=1f8f5bc08e0f684156baac513431b40d79ab4ea1;hp=d7f602820f75fd49645a0359186a4bd1b0c6e5a3;hpb=7b5d1c64fca5e95ce81ced1358dab2e2b7a68d39;p=libsigrok.git diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index d7f60282..e56f152f 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -125,7 +125,7 @@ static const uint32_t scanopts[] = { }; static const uint32_t devopts[] = { - SR_CONF_CONTINUOUS | SR_CONF_SET, + SR_CONF_CONTINUOUS, SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, SR_CONF_CONN | SR_CONF_GET, SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, @@ -133,15 +133,6 @@ static const uint32_t devopts[] = { SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET, }; -static const char *channel_names[] = { - "0", "1", "2", "3", "4", "5", "6", "7", - "8", "9", "10", "11", "12", "13", "14", "15", -}; - -static const char *ax_channel_names[] = { - "A0", -}; - static const int32_t soft_trigger_matches[] = { SR_TRIGGER_ZERO, SR_TRIGGER_ONE, @@ -192,7 +183,7 @@ SR_PRIV struct sr_dev_driver fx2lafw_driver_info; static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { - return std_init(sr_ctx, di, LOG_PREFIX); + return std_init(di, sr_ctx, LOG_PREFIX); } static GSList *scan(struct sr_dev_driver *di, GSList *options) @@ -201,6 +192,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) struct dev_context *devc; struct sr_dev_inst *sdi; struct sr_usb_dev_inst *usb; + struct sr_channel *ch; + struct sr_channel_group *cg; struct sr_config *src; const struct fx2lafw_profile *prof; GSList *l, *devices, *conn_devices; @@ -212,6 +205,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) int num_logic_channels = 0, num_analog_channels = 0; const char *conn; char manufacturer[64], product[64], serial_num[64], connection_id[64]; + char channel_name[16]; drvc = di->context; @@ -316,17 +310,33 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) num_logic_channels = prof->dev_caps & DEV_CAPS_16BIT ? 16 : 8; num_analog_channels = prof->dev_caps & DEV_CAPS_AX_ANALOG ? 1 : 0; - for (j = 0; j < num_logic_channels; j++) - sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE, - channel_names[j]); - - for (j = 0; j < num_analog_channels; j++) - sr_channel_new(sdi, j, SR_CHANNEL_ANALOG, TRUE, - ax_channel_names[j]); + /* Logic channels, all in one channel group. */ + cg = g_malloc0(sizeof(struct sr_channel_group)); + cg->name = g_strdup("Logic"); + for (j = 0; j < num_logic_channels; j++) { + sprintf(channel_name, "D%d", j); + ch = sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, + TRUE, channel_name); + cg->channels = g_slist_append(cg->channels, ch); + } + sdi->channel_groups = g_slist_append(NULL, cg); + + for (j = 0; j < num_analog_channels; j++) { + snprintf(channel_name, 16, "A%d", j); + ch = sr_channel_new(sdi, j + num_logic_channels, + SR_CHANNEL_ANALOG, TRUE, channel_name); + + /* Every analog channel gets its own channel group. */ + cg = g_malloc0(sizeof(struct sr_channel_group)); + cg->name = g_strdup(channel_name); + cg->channels = g_slist_append(NULL, ch); + sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); + } devc = fx2lafw_dev_new(); devc->profile = prof; - devc->sample_wide = (prof->dev_caps & DEV_CAPS_16BIT) != 0; + if ((prof->dev_caps & DEV_CAPS_16BIT) || (prof->dev_caps & DEV_CAPS_AX_ANALOG)) + devc->sample_wide = TRUE; sdi->priv = devc; drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); @@ -375,9 +385,18 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) return devices; } -static GSList *dev_list(const struct sr_dev_driver *di) +static void clear_dev_context(void *priv) { - return ((struct drv_context *)(di->context))->instances; + struct dev_context *devc; + + devc = priv; + g_slist_free(devc->enabled_analog_channels); + g_free(devc); +} + +static int dev_clear(const struct sr_dev_driver *di) +{ + return std_dev_clear(di, clear_dev_context); } static int dev_open(struct sr_dev_inst *sdi) @@ -485,21 +504,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - int ret; - struct drv_context *drvc; - - if (!(drvc = di->context)) - return SR_OK; - - ret = std_dev_clear(di, NULL); - - g_free(drvc); - - return ret; -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -710,9 +714,11 @@ static int start_transfers(const struct sr_dev_inst *sdi) devc->submitted_transfers++; } - devc->send_data_proc = la_send_data_proc; + if (devc->profile->dev_caps & DEV_CAPS_AX_ANALOG) + devc->send_data_proc = mso_send_data_proc; + else + devc->send_data_proc = la_send_data_proc; - /* Send header packet to the session bus. */ std_session_send_df_header(sdi, LOG_PREFIX); return SR_OK; @@ -721,7 +727,6 @@ static int start_transfers(const struct sr_dev_inst *sdi) static void LIBUSB_CALL dslogic_trigger_receive(struct libusb_transfer *transfer) { const struct sr_dev_inst *sdi; - struct sr_datafeed_packet packet; struct dslogic_trigger_pos *tpos; struct dev_context *devc; @@ -730,8 +735,7 @@ static void LIBUSB_CALL dslogic_trigger_receive(struct libusb_transfer *transfer if (transfer->status == LIBUSB_TRANSFER_CANCELLED) { sr_dbg("Trigger transfer canceled."); /* Terminate session. */ - packet.type = SR_DF_END; - sr_session_send(sdi, &packet); + std_session_send_df_end(sdi, LOG_PREFIX); usb_source_remove(sdi->session, devc->ctx); devc->num_transfers = 0; g_free(devc->transfers); @@ -748,7 +752,6 @@ static void LIBUSB_CALL dslogic_trigger_receive(struct libusb_transfer *transfer } libusb_free_transfer(transfer); - } static int dslogic_trigger_request(const struct sr_dev_inst *sdi) @@ -796,12 +799,38 @@ static int dslogic_trigger_request(const struct sr_dev_inst *sdi) return ret; } -static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) +static int configure_channels(const struct sr_dev_inst *sdi) +{ + struct dev_context *devc; + const GSList *l; + int p; + struct sr_channel *ch; + + devc = sdi->priv; + + g_slist_free(devc->enabled_analog_channels); + devc->enabled_analog_channels = NULL; + memset(devc->ch_enabled, 0, sizeof(devc->ch_enabled)); + + for (l = sdi->channels, p = 0; l; l = l->next, p++) { + ch = l->data; + if ((p <= NUM_CHANNELS) && (ch->type == SR_CHANNEL_ANALOG)) { + devc->ch_enabled[p] = ch->enabled; + devc->enabled_analog_channels = + g_slist_append(devc->enabled_analog_channels, ch); + } + } + + return SR_OK; +} + +static int dev_acquisition_start(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; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; @@ -811,17 +840,29 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) devc = sdi->priv; devc->ctx = drvc->sr_ctx; - devc->cb_data = cb_data; 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 = fx2lafw_get_timeout(devc); usb_source_add(sdi->session, devc->ctx, timeout, receive_data, drvc); if (devc->dslogic) { dslogic_trigger_request(sdi); } else { + size = fx2lafw_get_buffer_size(devc); + /* Prepare for analog sampling. */ + if (devc->profile->dev_caps & DEV_CAPS_AX_ANALOG) { + /* 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 = fx2lafw_command_start_acquisition(sdi)) != SR_OK) { fx2lafw_abort_acquisition(devc); @@ -832,12 +873,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) return SR_OK; } -static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) +static int dev_acquisition_stop(struct sr_dev_inst *sdi) { struct dev_context *devc; - (void)cb_data; - devc = sdi->priv; if (devc->dslogic) @@ -853,10 +892,10 @@ SR_PRIV struct sr_dev_driver fx2lafw_driver_info = { .longname = "fx2lafw (generic driver for FX2 based LAs)", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, - .dev_list = dev_list, - .dev_clear = NULL, + .dev_list = std_dev_list, + .dev_clear = dev_clear, .config_get = config_get, .config_set = config_set, .config_list = config_list,