/*
* This file is part of the libsigrok project.
*
- * Copyright (C) 2014 Kumar Abhishek <abhishek@theembeddedkitchen.net>
+ * Copyright (C) 2014-2017 Kumar Abhishek <abhishek@theembeddedkitchen.net>
*
* 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
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)10000000;
- 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)
}
/* 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 {
}
}
- 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 {
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,
sdi->priv = devc;
return std_scan_complete(di, g_slist_append(NULL, sdi));
+
err_free:
g_free(sdi->model);
g_free(sdi->version);
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)
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)
}
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;