2013-01-05 01:03:20 +00:00
|
|
|
/*
|
2013-04-23 20:24:30 +00:00
|
|
|
* This file is part of the libsigrok project.
|
2013-01-05 01:03:20 +00:00
|
|
|
*
|
2013-01-08 01:30:40 +00:00
|
|
|
* Copyright (C) 2011 Daniel Ribeiro <drwyrm@gmail.com>
|
|
|
|
* Copyright (C) 2012 Renato Caldas <rmsc@fe.up.pt>
|
|
|
|
* Copyright (C) 2013 Lior Elazary <lelazary@yahoo.com>
|
2013-01-05 01:03:20 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "protocol.h"
|
|
|
|
|
2013-03-31 19:25:51 +00:00
|
|
|
static const int32_t hwcaps[] = {
|
2013-01-08 16:27:52 +00:00
|
|
|
SR_CONF_OSCILLOSCOPE,
|
2013-01-21 22:22:47 +00:00
|
|
|
SR_CONF_LOGIC_ANALYZER,
|
|
|
|
SR_CONF_SAMPLERATE,
|
|
|
|
SR_CONF_TRIGGER_SLOPE,
|
|
|
|
SR_CONF_HORIZ_TRIGGERPOS,
|
|
|
|
// SR_CONF_CAPTURE_RATIO,
|
|
|
|
SR_CONF_LIMIT_SAMPLES,
|
|
|
|
// SR_CONF_RLE,
|
2013-01-05 01:03:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2014-03-24 20:34:20 +00:00
|
|
|
* Channels are numbered 0 to 7.
|
2013-01-05 01:03:20 +00:00
|
|
|
*
|
|
|
|
* See also: http://www.linkinstruments.com/images/mso19_1113.gif
|
|
|
|
*/
|
2014-03-24 21:39:42 +00:00
|
|
|
SR_PRIV const char *mso19_channel_names[NUM_CHANNELS + 1] = {
|
2013-01-08 16:27:52 +00:00
|
|
|
/* Note: DSO needs to be first. */
|
|
|
|
"DSO", "0", "1", "2", "3", "4", "5", "6", "7", NULL,
|
2013-01-05 01:03:20 +00:00
|
|
|
};
|
|
|
|
|
2013-03-31 19:25:51 +00:00
|
|
|
static const uint64_t samplerates[] = {
|
|
|
|
SR_HZ(100),
|
|
|
|
SR_MHZ(200),
|
|
|
|
SR_HZ(100),
|
2013-01-05 01:03:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SR_PRIV struct sr_dev_driver link_mso19_driver_info;
|
|
|
|
static struct sr_dev_driver *di = &link_mso19_driver_info;
|
|
|
|
|
2013-06-02 14:54:31 +00:00
|
|
|
/* TODO: Use sr_dev_inst to store connection handle & use std_dev_clear(). */
|
|
|
|
static int dev_clear(void)
|
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
struct sr_dev_inst *sdi;
|
|
|
|
struct drv_context *drvc;
|
|
|
|
struct dev_context *devc;
|
|
|
|
int ret = SR_OK;
|
|
|
|
|
|
|
|
if (!(drvc = di->priv))
|
|
|
|
return SR_OK;
|
|
|
|
|
|
|
|
/* Properly close and free all devices. */
|
|
|
|
for (l = drvc->instances; l; l = l->next) {
|
|
|
|
if (!(sdi = l->data)) {
|
|
|
|
/* Log error, but continue cleaning up the rest. */
|
|
|
|
sr_err("%s: sdi was NULL, continuing", __func__);
|
|
|
|
ret = SR_ERR_BUG;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!(devc = sdi->priv)) {
|
|
|
|
/* Log error, but continue cleaning up the rest. */
|
|
|
|
sr_err("%s: sdi->priv was NULL, continuing", __func__);
|
|
|
|
ret = SR_ERR_BUG;
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-07 18:47:43 +00:00
|
|
|
std_serial_dev_close(sdi);
|
2013-06-02 14:54:31 +00:00
|
|
|
sr_serial_dev_inst_free(devc->serial);
|
|
|
|
sr_dev_inst_free(sdi);
|
|
|
|
}
|
|
|
|
g_slist_free(drvc->instances);
|
|
|
|
drvc->instances = NULL;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int init(struct sr_context *sr_ctx)
|
2013-01-05 01:03:20 +00:00
|
|
|
{
|
2013-05-31 13:46:57 +00:00
|
|
|
return std_init(sr_ctx, di, LOG_PREFIX);
|
2013-01-05 01:03:20 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static GSList *scan(GSList *options)
|
2013-01-05 01:03:20 +00:00
|
|
|
{
|
2013-01-08 01:48:49 +00:00
|
|
|
int i;
|
|
|
|
GSList *devices = NULL;
|
|
|
|
const char *conn = NULL;
|
|
|
|
const char *serialcomm = NULL;
|
|
|
|
GSList *l;
|
2013-01-06 16:41:30 +00:00
|
|
|
struct sr_config *src;
|
2013-01-08 01:48:49 +00:00
|
|
|
struct udev *udev;
|
2013-01-08 16:27:52 +00:00
|
|
|
int ptype;
|
2013-01-05 01:03:20 +00:00
|
|
|
|
|
|
|
for (l = options; l; l = l->next) {
|
2013-01-06 16:41:30 +00:00
|
|
|
src = l->data;
|
|
|
|
switch (src->key) {
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_CONN:
|
2013-03-31 19:25:51 +00:00
|
|
|
conn = g_variant_get_string(src->data, NULL);
|
2013-01-05 01:03:20 +00:00
|
|
|
break;
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_SERIALCOMM:
|
2013-05-03 12:03:49 +00:00
|
|
|
serialcomm = g_variant_get_string(src->data, NULL);
|
2013-01-05 01:03:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!conn)
|
2013-01-08 01:48:49 +00:00
|
|
|
conn = SERIALCONN;
|
2013-01-05 01:03:20 +00:00
|
|
|
if (serialcomm == NULL)
|
|
|
|
serialcomm = SERIALCOMM;
|
|
|
|
|
2013-01-08 01:48:49 +00:00
|
|
|
udev = udev_new();
|
2013-01-05 01:03:20 +00:00
|
|
|
if (!udev) {
|
|
|
|
sr_err("Failed to initialize udev.");
|
|
|
|
}
|
2013-01-08 01:48:49 +00:00
|
|
|
|
2013-01-05 01:03:20 +00:00
|
|
|
struct udev_enumerate *enumerate = udev_enumerate_new(udev);
|
|
|
|
udev_enumerate_add_match_subsystem(enumerate, "usb-serial");
|
|
|
|
udev_enumerate_scan_devices(enumerate);
|
|
|
|
struct udev_list_entry *devs = udev_enumerate_get_list_entry(enumerate);
|
|
|
|
struct udev_list_entry *dev_list_entry;
|
2013-01-08 01:48:49 +00:00
|
|
|
for (dev_list_entry = devs;
|
|
|
|
dev_list_entry != NULL;
|
|
|
|
dev_list_entry = udev_list_entry_get_next(dev_list_entry)) {
|
2013-01-05 01:03:20 +00:00
|
|
|
const char *syspath = udev_list_entry_get_name(dev_list_entry);
|
2013-01-08 01:48:49 +00:00
|
|
|
struct udev_device *dev =
|
|
|
|
udev_device_new_from_syspath(udev, syspath);
|
2013-01-05 01:03:20 +00:00
|
|
|
const char *sysname = udev_device_get_sysname(dev);
|
2013-01-08 01:48:49 +00:00
|
|
|
struct udev_device *parent =
|
|
|
|
udev_device_get_parent_with_subsystem_devtype(dev, "usb",
|
|
|
|
"usb_device");
|
2013-01-05 01:03:20 +00:00
|
|
|
|
|
|
|
if (!parent) {
|
|
|
|
sr_err("Unable to find parent usb device for %s",
|
|
|
|
sysname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-01-08 01:48:49 +00:00
|
|
|
const char *idVendor =
|
|
|
|
udev_device_get_sysattr_value(parent, "idVendor");
|
|
|
|
const char *idProduct =
|
|
|
|
udev_device_get_sysattr_value(parent, "idProduct");
|
2013-01-05 01:03:20 +00:00
|
|
|
if (strcmp(USB_VENDOR, idVendor)
|
2013-01-08 01:48:49 +00:00
|
|
|
|| strcmp(USB_PRODUCT, idProduct))
|
2013-01-05 01:03:20 +00:00
|
|
|
continue;
|
|
|
|
|
2013-01-08 01:48:49 +00:00
|
|
|
const char *iSerial =
|
|
|
|
udev_device_get_sysattr_value(parent, "serial");
|
|
|
|
const char *iProduct =
|
|
|
|
udev_device_get_sysattr_value(parent, "product");
|
2013-01-05 01:03:20 +00:00
|
|
|
|
2013-01-08 01:48:49 +00:00
|
|
|
char path[32];
|
2013-01-05 01:03:20 +00:00
|
|
|
snprintf(path, sizeof(path), "/dev/%s", sysname);
|
2013-01-08 01:48:49 +00:00
|
|
|
conn = path;
|
2013-01-05 01:03:20 +00:00
|
|
|
|
|
|
|
size_t s = strcspn(iProduct, " ");
|
2013-01-08 01:48:49 +00:00
|
|
|
char product[32];
|
|
|
|
char manufacturer[32];
|
2013-01-05 01:03:20 +00:00
|
|
|
if (s > sizeof(product) ||
|
2013-01-08 01:48:49 +00:00
|
|
|
strlen(iProduct) - s > sizeof(manufacturer)) {
|
|
|
|
sr_err("Could not parse iProduct: %s.", iProduct);
|
2013-01-05 01:03:20 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
strncpy(product, iProduct, s);
|
|
|
|
product[s] = 0;
|
2013-01-05 17:29:00 +00:00
|
|
|
strcpy(manufacturer, iProduct + s + 1);
|
2013-01-08 01:48:49 +00:00
|
|
|
|
|
|
|
//Create the device context and set its params
|
|
|
|
struct dev_context *devc;
|
|
|
|
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
|
|
|
|
sr_err("Device context malloc failed.");
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mso_parse_serial(iSerial, iProduct, devc) != SR_OK) {
|
|
|
|
sr_err("Invalid iSerial: %s.", iSerial);
|
|
|
|
g_free(devc);
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
|
|
|
char hwrev[32];
|
|
|
|
sprintf(hwrev, "r%d", devc->hwrev);
|
|
|
|
devc->ctlbase1 = 0;
|
|
|
|
devc->protocol_trigger.spimode = 0;
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
devc->protocol_trigger.word[i] = 0;
|
|
|
|
devc->protocol_trigger.mask[i] = 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(devc->serial = sr_serial_dev_inst_new(conn, serialcomm))) {
|
|
|
|
g_free(devc);
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sr_dev_inst *sdi = sr_dev_inst_new(0, SR_ST_INACTIVE,
|
|
|
|
manufacturer, product, hwrev);
|
|
|
|
|
|
|
|
if (!sdi) {
|
|
|
|
sr_err("Unable to create device instance for %s",
|
|
|
|
sysname);
|
|
|
|
sr_dev_inst_free(sdi);
|
|
|
|
g_free(devc);
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
|
|
|
sdi->driver = di;
|
|
|
|
sdi->priv = devc;
|
|
|
|
|
2014-03-24 21:39:42 +00:00
|
|
|
for (i = 0; i < NUM_CHANNELS; i++) {
|
2014-03-24 20:34:20 +00:00
|
|
|
struct sr_channel *ch;
|
2014-03-24 21:39:42 +00:00
|
|
|
ptype = (i == 0) ? SR_CHANNEL_ANALOG : SR_CHANNEL_LOGIC;
|
2014-03-24 20:36:04 +00:00
|
|
|
if (!(ch = sr_channel_new(i, ptype, TRUE,
|
2014-03-24 20:34:20 +00:00
|
|
|
mso19_channel_names[i])))
|
2013-01-08 01:48:49 +00:00
|
|
|
return 0;
|
2014-03-24 20:34:20 +00:00
|
|
|
sdi->channels = g_slist_append(sdi->channels, ch);
|
2013-01-08 01:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Add the driver
|
|
|
|
struct drv_context *drvc = di->priv;
|
|
|
|
drvc->instances = g_slist_append(drvc->instances, sdi);
|
|
|
|
devices = g_slist_append(devices, sdi);
|
|
|
|
}
|
2013-01-06 02:12:45 +00:00
|
|
|
|
2013-01-05 01:03:20 +00:00
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static GSList *dev_list(void)
|
2013-01-05 01:03:20 +00:00
|
|
|
{
|
2013-02-02 18:52:26 +00:00
|
|
|
return ((struct drv_context *)(di->priv))->instances;
|
2013-01-05 01:03:20 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int dev_open(struct sr_dev_inst *sdi)
|
2013-01-05 01:03:20 +00:00
|
|
|
{
|
2013-01-08 01:48:49 +00:00
|
|
|
int ret;
|
2013-01-05 01:03:20 +00:00
|
|
|
struct dev_context *devc;
|
|
|
|
|
|
|
|
devc = sdi->priv;
|
|
|
|
|
|
|
|
if (serial_open(devc->serial, SERIAL_RDWR) != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
|
|
|
|
sdi->status = SR_ST_ACTIVE;
|
|
|
|
|
|
|
|
/* FIXME: discard serial buffer */
|
|
|
|
mso_check_trigger(devc->serial, &devc->trigger_state);
|
|
|
|
sr_dbg("Trigger state: 0x%x.", devc->trigger_state);
|
|
|
|
|
2013-01-08 01:48:49 +00:00
|
|
|
ret = mso_reset_adc(sdi);
|
2013-01-05 01:03:20 +00:00
|
|
|
if (ret != SR_OK)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
mso_check_trigger(devc->serial, &devc->trigger_state);
|
|
|
|
sr_dbg("Trigger state: 0x%x.", devc->trigger_state);
|
|
|
|
|
2013-01-08 01:48:49 +00:00
|
|
|
// ret = mso_reset_fsm(sdi);
|
|
|
|
// if (ret != SR_OK)
|
|
|
|
// return ret;
|
|
|
|
// return SR_ERR;
|
2013-01-05 01:03:20 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int cleanup(void)
|
2013-01-05 01:03:20 +00:00
|
|
|
{
|
2013-06-02 14:54:31 +00:00
|
|
|
return dev_clear();
|
2013-01-05 01:03:20 +00:00
|
|
|
}
|
|
|
|
|
2013-04-20 00:00:49 +00:00
|
|
|
static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
|
2014-03-20 20:58:01 +00:00
|
|
|
const struct sr_channel_group *cg)
|
2013-01-05 01:03:20 +00:00
|
|
|
{
|
|
|
|
struct dev_context *devc;
|
|
|
|
|
2014-03-20 20:58:01 +00:00
|
|
|
(void)cg;
|
2013-04-20 00:00:49 +00:00
|
|
|
|
2013-01-24 18:19:09 +00:00
|
|
|
switch (id) {
|
2013-01-25 02:17:36 +00:00
|
|
|
case SR_CONF_SAMPLERATE:
|
2013-01-05 01:03:20 +00:00
|
|
|
if (sdi) {
|
|
|
|
devc = sdi->priv;
|
2013-03-31 19:25:51 +00:00
|
|
|
*data = g_variant_new_uint64(devc->cur_rate);
|
2013-01-05 01:03:20 +00:00
|
|
|
} else
|
|
|
|
return SR_ERR;
|
|
|
|
break;
|
|
|
|
default:
|
2013-04-16 00:33:03 +00:00
|
|
|
return SR_ERR_NA;
|
2013-01-05 01:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-20 00:00:49 +00:00
|
|
|
static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
|
2014-03-20 20:58:01 +00:00
|
|
|
const struct sr_channel_group *cg)
|
2013-01-05 01:03:20 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2013-01-06 17:46:01 +00:00
|
|
|
struct dev_context *devc;
|
2014-01-26 23:22:01 +00:00
|
|
|
uint64_t num_samples;
|
|
|
|
const char *slope;
|
2013-01-08 01:48:49 +00:00
|
|
|
int trigger_pos;
|
2013-03-31 19:25:51 +00:00
|
|
|
double pos;
|
2013-01-08 01:48:49 +00:00
|
|
|
|
2014-03-20 20:58:01 +00:00
|
|
|
(void)cg;
|
2013-01-08 01:48:49 +00:00
|
|
|
devc = sdi->priv;
|
2013-01-06 17:46:01 +00:00
|
|
|
|
2013-01-05 01:03:20 +00:00
|
|
|
if (sdi->status != SR_ST_ACTIVE)
|
2013-04-23 13:14:42 +00:00
|
|
|
return SR_ERR_DEV_CLOSED;
|
2013-01-05 01:03:20 +00:00
|
|
|
|
2013-01-24 18:19:09 +00:00
|
|
|
switch (id) {
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_SAMPLERATE:
|
2013-01-08 01:48:49 +00:00
|
|
|
// FIXME
|
2013-03-31 19:25:51 +00:00
|
|
|
return mso_configure_rate(sdi, g_variant_get_uint64(data));
|
2013-01-05 01:03:20 +00:00
|
|
|
ret = SR_OK;
|
|
|
|
break;
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_LIMIT_SAMPLES:
|
2013-03-31 19:25:51 +00:00
|
|
|
num_samples = g_variant_get_uint64(data);
|
2013-01-08 16:00:57 +00:00
|
|
|
if (num_samples != 1024) {
|
|
|
|
sr_err("Only 1024 samples are supported.");
|
2013-01-08 01:48:49 +00:00
|
|
|
ret = SR_ERR_ARG;
|
|
|
|
} else {
|
|
|
|
devc->limit_samples = num_samples;
|
|
|
|
sr_dbg("setting limit_samples to %i\n",
|
|
|
|
num_samples);
|
|
|
|
ret = SR_OK;
|
|
|
|
}
|
2013-01-05 01:03:20 +00:00
|
|
|
break;
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_CAPTURE_RATIO:
|
2013-01-08 01:48:49 +00:00
|
|
|
ret = SR_OK;
|
|
|
|
break;
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_TRIGGER_SLOPE:
|
2014-01-26 23:22:01 +00:00
|
|
|
slope = g_variant_get_string(data, NULL);
|
|
|
|
|
|
|
|
if (!slope || !(slope[0] == 'f' || slope[0] == 'r'))
|
2013-01-08 01:48:49 +00:00
|
|
|
sr_err("Invalid trigger slope");
|
|
|
|
ret = SR_ERR_ARG;
|
|
|
|
} else {
|
2014-01-26 23:22:01 +00:00
|
|
|
devc->trigger_slope = (slope[0] == 'r')
|
|
|
|
? SLOPE_POSITIVE : SLOPE_NEGATIVE;
|
2013-01-08 01:48:49 +00:00
|
|
|
ret = SR_OK;
|
|
|
|
}
|
|
|
|
break;
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_HORIZ_TRIGGERPOS:
|
2013-03-31 19:25:51 +00:00
|
|
|
pos = g_variant_get_double(data);
|
2013-01-08 01:48:49 +00:00
|
|
|
if (pos < 0 || pos > 255) {
|
|
|
|
sr_err("Trigger position (%f) should be between 0 and 255.", pos);
|
|
|
|
ret = SR_ERR_ARG;
|
|
|
|
} else {
|
|
|
|
trigger_pos = (int)pos;
|
|
|
|
devc->trigger_holdoff[0] = trigger_pos & 0xff;
|
|
|
|
ret = SR_OK;
|
|
|
|
}
|
2013-01-05 01:03:20 +00:00
|
|
|
break;
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_RLE:
|
2013-01-08 01:48:49 +00:00
|
|
|
ret = SR_OK;
|
2013-01-05 01:03:20 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-04-16 00:33:03 +00:00
|
|
|
ret = SR_ERR_NA;
|
2013-01-08 01:48:49 +00:00
|
|
|
break;
|
2013-01-05 01:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-20 00:00:49 +00:00
|
|
|
static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
|
2014-03-20 20:58:01 +00:00
|
|
|
const struct sr_channel_group *cg)
|
2013-01-25 01:32:05 +00:00
|
|
|
{
|
2013-03-31 19:25:51 +00:00
|
|
|
GVariant *gvar;
|
|
|
|
GVariantBuilder gvb;
|
2013-01-25 01:32:05 +00:00
|
|
|
|
2014-03-20 20:58:01 +00:00
|
|
|
(void)cg;
|
2013-01-25 01:32:05 +00:00
|
|
|
(void)sdi;
|
|
|
|
|
|
|
|
switch (key) {
|
2013-01-25 14:01:49 +00:00
|
|
|
case SR_CONF_DEVICE_OPTIONS:
|
2013-03-31 19:25:51 +00:00
|
|
|
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
|
|
|
|
hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
|
2013-01-25 14:01:49 +00:00
|
|
|
break;
|
2013-01-25 01:32:05 +00:00
|
|
|
case SR_CONF_SAMPLERATE:
|
2013-03-31 19:25:51 +00:00
|
|
|
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
|
|
|
|
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,
|
|
|
|
ARRAY_SIZE(samplerates), sizeof(uint64_t));
|
|
|
|
g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar);
|
|
|
|
*data = g_variant_builder_end(&gvb);
|
2013-01-25 01:32:05 +00:00
|
|
|
break;
|
2013-01-25 10:52:27 +00:00
|
|
|
case SR_CONF_TRIGGER_TYPE:
|
2013-03-31 19:25:51 +00:00
|
|
|
*data = g_variant_new_string(TRIGGER_TYPE);
|
2013-01-25 10:52:27 +00:00
|
|
|
break;
|
2013-01-25 01:32:05 +00:00
|
|
|
default:
|
2013-04-16 00:33:03 +00:00
|
|
|
return SR_ERR_NA;
|
2013-01-25 01:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
|
2013-01-05 01:03:20 +00:00
|
|
|
{
|
|
|
|
struct dev_context *devc;
|
|
|
|
int ret = SR_ERR;
|
2013-01-08 01:48:49 +00:00
|
|
|
|
2013-01-05 01:03:20 +00:00
|
|
|
if (sdi->status != SR_ST_ACTIVE)
|
2013-04-23 13:14:42 +00:00
|
|
|
return SR_ERR_DEV_CLOSED;
|
|
|
|
|
|
|
|
devc = sdi->priv;
|
2013-01-05 01:03:20 +00:00
|
|
|
|
2014-03-24 20:34:20 +00:00
|
|
|
if (mso_configure_channels(sdi) != SR_OK) {
|
|
|
|
sr_err("Failed to configure channels.");
|
2013-01-06 02:12:45 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
2013-01-05 01:03:20 +00:00
|
|
|
|
|
|
|
/* FIXME: No need to do full reconfigure every time */
|
2013-01-08 01:48:49 +00:00
|
|
|
// ret = mso_reset_fsm(sdi);
|
|
|
|
// if (ret != SR_OK)
|
|
|
|
// return ret;
|
2013-01-05 01:03:20 +00:00
|
|
|
|
|
|
|
/* FIXME: ACDC Mode */
|
|
|
|
devc->ctlbase1 &= 0x7f;
|
2013-01-08 01:48:49 +00:00
|
|
|
// devc->ctlbase1 |= devc->acdcmode;
|
2013-01-05 01:03:20 +00:00
|
|
|
|
|
|
|
ret = mso_configure_rate(sdi, devc->cur_rate);
|
|
|
|
if (ret != SR_OK)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* set dac offset */
|
|
|
|
ret = mso_dac_out(sdi, devc->dac_offset);
|
|
|
|
if (ret != SR_OK)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = mso_configure_threshold_level(sdi);
|
|
|
|
if (ret != SR_OK)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = mso_configure_trigger(sdi);
|
|
|
|
if (ret != SR_OK)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* END of config hardware part */
|
2013-01-08 01:48:49 +00:00
|
|
|
ret = mso_arm(sdi);
|
|
|
|
if (ret != SR_OK)
|
|
|
|
return ret;
|
2013-01-05 01:03:20 +00:00
|
|
|
|
|
|
|
/* Start acquisition on the device. */
|
2013-01-05 17:29:00 +00:00
|
|
|
mso_check_trigger(devc->serial, &devc->trigger_state);
|
|
|
|
ret = mso_check_trigger(devc->serial, NULL);
|
2013-01-05 01:03:20 +00:00
|
|
|
if (ret != SR_OK)
|
|
|
|
return ret;
|
|
|
|
|
2013-01-08 16:27:52 +00:00
|
|
|
/* Reset trigger state. */
|
|
|
|
devc->trigger_state = 0x00;
|
|
|
|
|
2013-02-06 18:57:32 +00:00
|
|
|
/* Send header packet to the session bus. */
|
2013-05-03 19:59:32 +00:00
|
|
|
std_session_send_df_header(cb_data, LOG_PREFIX);
|
2013-01-05 01:03:20 +00:00
|
|
|
|
2014-03-24 20:34:20 +00:00
|
|
|
/* Our first channel is analog, the other 8 are of type 'logic'. */
|
2013-01-08 16:27:52 +00:00
|
|
|
/* TODO. */
|
|
|
|
|
2013-11-30 12:54:02 +00:00
|
|
|
serial_source_add(devc->serial, G_IO_IN, -1, mso_receive_data, cb_data);
|
2013-01-05 01:03:20 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-06 17:46:01 +00:00
|
|
|
/* This stops acquisition on ALL devices, ignoring dev_index. */
|
2013-05-10 17:37:54 +00:00
|
|
|
static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
|
2013-01-05 01:03:20 +00:00
|
|
|
{
|
|
|
|
(void)cb_data;
|
|
|
|
|
|
|
|
stop_acquisition(sdi);
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
SR_PRIV struct sr_dev_driver link_mso19_driver_info = {
|
|
|
|
.name = "link-mso19",
|
|
|
|
.longname = "Link Instruments MSO-19",
|
|
|
|
.api_version = 1,
|
2013-05-10 17:37:54 +00:00
|
|
|
.init = init,
|
|
|
|
.cleanup = cleanup,
|
|
|
|
.scan = scan,
|
|
|
|
.dev_list = dev_list,
|
2013-06-02 14:54:31 +00:00
|
|
|
.dev_clear = dev_clear,
|
2013-01-24 18:19:09 +00:00
|
|
|
.config_get = config_get,
|
|
|
|
.config_set = config_set,
|
2013-01-25 01:32:05 +00:00
|
|
|
.config_list = config_list,
|
2013-05-10 17:37:54 +00:00
|
|
|
.dev_open = dev_open,
|
2013-12-07 18:47:43 +00:00
|
|
|
.dev_close = std_serial_dev_close,
|
2013-05-10 17:37:54 +00:00
|
|
|
.dev_acquisition_start = dev_acquisition_start,
|
|
|
|
.dev_acquisition_stop = dev_acquisition_stop,
|
2013-01-05 01:03:20 +00:00
|
|
|
.priv = NULL,
|
|
|
|
};
|