X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fbeaglelogic%2Fapi.c;h=95f53159a85fa073209ad6da1ca5f4eef83ca874;hb=d8fbfcd9d6d66bffcb8607e9de7706ce322d42c7;hp=3188d8f3dc2d462684864b28df2ada7cbd5eb4a6;hpb=d6f20d03663c3ece42b0f7ea0563c333851ea022;p=libsigrok.git diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index 3188d8f3..95f53159 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -1,7 +1,7 @@ /* * This file is part of the libsigrok project. * - * Copyright (C) 2014 Kumar Abhishek + * Copyright (C) 2014-2017 Kumar Abhishek * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,7 +33,7 @@ static const uint32_t drvopts[] = { static const uint32_t devopts[] = { SR_CONF_CONTINUOUS, SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, - SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET, + SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_TRIGGER_MATCH | SR_CONF_LIST, SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET, SR_CONF_NUM_LOGIC_CHANNELS | SR_CONF_GET, @@ -59,31 +59,18 @@ static const uint64_t samplerates[] = { SR_HZ(1), }; -static struct dev_context *beaglelogic_devc_alloc(void) -{ - struct dev_context *devc; - - devc = g_malloc0(sizeof(struct dev_context)); - - /* Default non-zero values (if any) */ - devc->fd = -1; - devc->limit_samples = (uint64_t)-1; - devc->tcp_buffer = 0; - - return devc; -} - static GSList *scan(struct sr_dev_driver *di, GSList *options) { GSList *l; struct sr_config *src; struct sr_dev_inst *sdi; struct dev_context *devc; - const char *conn = NULL; + const char *conn; gchar **params; int i, maxch; maxch = NUM_CHANNELS; + conn = NULL; for (l = options; l; l = l->next) { src = l->data; if (src->key == SR_CONF_NUM_LOGIC_CHANNELS) @@ -93,7 +80,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) } /* Probe for /dev/beaglelogic if not connecting via TCP */ - if (conn == NULL) { + if (!conn) { + params = NULL; if (!g_file_test(BEAGLELOGIC_DEV_NODE, G_FILE_TEST_EXISTS)) return NULL; } else { @@ -110,19 +98,21 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) } } - if (maxch > 8) - maxch = NUM_CHANNELS; - else - maxch = 8; + maxch = (maxch > 8) ? NUM_CHANNELS : 8; sdi = g_new0(struct sr_dev_inst, 1); sdi->status = SR_ST_INACTIVE; sdi->model = g_strdup("BeagleLogic"); sdi->version = g_strdup("1.0"); - devc = beaglelogic_devc_alloc(); + devc = g_malloc0(sizeof(struct dev_context)); - if (conn == NULL) { + /* Default non-zero values (if any) */ + devc->fd = -1; + devc->limit_samples = 10000000; + devc->tcp_buffer = 0; + + if (!conn) { devc->beaglelogic = &beaglelogic_native_ops; sr_info("BeagleLogic device found at "BEAGLELOGIC_DEV_NODE); } else { @@ -136,9 +126,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) goto err_free; if (beaglelogic_tcp_detect(devc) != SR_OK) goto err_free; + if (devc->beaglelogic->close(devc) != SR_OK) + goto err_free; sr_info("BeagleLogic device found at %s : %s", devc->address, devc->port); } + /* Fill the channels */ for (i = 0; i < maxch; i++) sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, @@ -147,6 +140,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sdi->priv = devc; return std_scan_complete(di, g_slist_append(NULL, sdi)); + err_free: g_free(sdi->model); g_free(sdi->version); @@ -163,9 +157,8 @@ static int dev_open(struct sr_dev_inst *sdi) struct dev_context *devc = sdi->priv; /* Open BeagleLogic */ - if (devc->beaglelogic == &beaglelogic_native_ops) - if (devc->beaglelogic->open(devc)) - return SR_ERR; + if (devc->beaglelogic->open(devc)) + return SR_ERR; /* Set fd and local attributes */ if (devc->beaglelogic == &beaglelogic_tcp_ops) @@ -214,14 +207,9 @@ static int dev_close(struct sr_dev_inst *sdi) static void clear_helper(struct dev_context *devc) { - if (devc->tcp_buffer) - g_free(devc->tcp_buffer); - - if (devc->address) - g_free(devc->address); - - if (devc->port) - g_free(devc->port); + g_free(devc->tcp_buffer); + g_free(devc->address); + g_free(devc->port); } static int dev_clear(const struct sr_dev_driver *di) @@ -340,6 +328,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) } devc->beaglelogic->set_sampleunit(devc); + /* If continuous sampling, set the limit_samples to max possible value */ + if (devc->triggerflags == BL_TRIGGERFLAGS_CONTINUOUS) + devc->limit_samples = UINT64_MAX; + /* Configure triggers & send header packet */ if ((trigger = sr_session_trigger_get(sdi->session))) { int pre_trigger_samples = 0;