2011-01-06 18:16:47 +00:00
|
|
|
/*
|
2013-04-23 20:24:30 +00:00
|
|
|
* This file is part of the libsigrok project.
|
2011-01-06 18:16:47 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
|
2011-01-10 21:49:38 +00:00
|
|
|
* Copyright (C) 2011 Olivier Fauchon <olivier@aixmarseille.com>
|
2012-12-01 18:49:15 +00:00
|
|
|
* Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
|
2011-01-06 18:16:47 +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 2 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2011-01-08 17:29:10 +00:00
|
|
|
#include <unistd.h>
|
2011-01-06 18:16:47 +00:00
|
|
|
#include <string.h>
|
2014-01-14 22:03:08 +00:00
|
|
|
#include <math.h>
|
2011-01-16 13:12:52 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <io.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#define pipe(fds) _pipe(fds, 4096, _O_BINARY)
|
|
|
|
#endif
|
2012-07-04 22:55:07 +00:00
|
|
|
#include "libsigrok.h"
|
|
|
|
#include "libsigrok-internal.h"
|
2011-01-06 18:16:47 +00:00
|
|
|
|
2013-12-23 03:38:35 +00:00
|
|
|
#define LOG_PREFIX "demo"
|
2012-11-10 17:24:05 +00:00
|
|
|
|
2013-12-24 10:27:40 +00:00
|
|
|
#define DEFAULT_NUM_LOGIC_PROBES 8
|
|
|
|
#define DEFAULT_NUM_ANALOG_PROBES 4
|
2011-05-06 18:34:12 +00:00
|
|
|
|
2013-12-27 22:52:23 +00:00
|
|
|
/* The size in bytes of chunks to send through the session bus. */
|
2013-12-22 17:46:45 +00:00
|
|
|
#define LOGIC_BUFSIZE 4096
|
2013-12-27 22:52:23 +00:00
|
|
|
/* Size of the analog pattern space per channel. */
|
|
|
|
#define ANALOG_BUFSIZE 4096
|
2013-03-03 20:17:48 +00:00
|
|
|
|
2014-01-14 22:03:08 +00:00
|
|
|
#define ANALOG_AMPLITUDE 25
|
|
|
|
#define ANALOG_SAMPLES_PER_PERIOD 20
|
|
|
|
|
2014-01-12 22:31:23 +00:00
|
|
|
/* Logic patterns we can generate. */
|
2011-01-15 04:12:41 +00:00
|
|
|
enum {
|
2011-05-04 20:37:12 +00:00
|
|
|
/**
|
2013-12-22 17:46:45 +00:00
|
|
|
* Spells "sigrok" across 8 probes using '0's (with '1's as
|
|
|
|
* "background") when displayed using the 'bits' output format.
|
2013-12-24 10:27:40 +00:00
|
|
|
* The pattern is repeasted every 8 probes, shifted to the right
|
|
|
|
* in time by one bit.
|
2011-05-04 20:37:12 +00:00
|
|
|
*/
|
2011-05-05 11:02:48 +00:00
|
|
|
PATTERN_SIGROK,
|
2011-05-04 20:37:12 +00:00
|
|
|
|
2013-12-24 10:27:40 +00:00
|
|
|
/** Pseudo-random values on all probes. */
|
2011-05-05 11:02:48 +00:00
|
|
|
PATTERN_RANDOM,
|
2011-05-04 20:37:12 +00:00
|
|
|
|
|
|
|
/**
|
2013-12-24 10:27:40 +00:00
|
|
|
* Incrementing number across 8 probes. The pattern is repeasted
|
|
|
|
* every 8 probes, shifted to the right in time by one bit.
|
2011-05-04 20:37:12 +00:00
|
|
|
*/
|
2011-05-05 11:02:48 +00:00
|
|
|
PATTERN_INC,
|
2011-05-06 18:34:12 +00:00
|
|
|
|
2013-12-22 17:46:45 +00:00
|
|
|
/** All probes have a low logic state. */
|
2011-05-06 18:34:12 +00:00
|
|
|
PATTERN_ALL_LOW,
|
|
|
|
|
2013-12-22 17:46:45 +00:00
|
|
|
/** All probes have a high logic state. */
|
2011-05-06 18:34:12 +00:00
|
|
|
PATTERN_ALL_HIGH,
|
2014-01-12 22:31:23 +00:00
|
|
|
};
|
2013-12-27 22:52:23 +00:00
|
|
|
|
2014-01-12 22:31:23 +00:00
|
|
|
/* Analog patterns we can generate. */
|
|
|
|
enum {
|
2013-12-27 22:52:23 +00:00
|
|
|
/**
|
|
|
|
* Square wave.
|
|
|
|
*/
|
|
|
|
PATTERN_SQUARE,
|
2014-01-14 22:03:08 +00:00
|
|
|
PATTERN_SINE,
|
2014-01-14 22:03:09 +00:00
|
|
|
PATTERN_TRIANGLE,
|
2014-01-14 22:03:10 +00:00
|
|
|
PATTERN_SAWTOOTH,
|
2011-01-15 04:12:41 +00:00
|
|
|
};
|
2011-01-08 17:29:10 +00:00
|
|
|
|
2013-12-27 22:52:23 +00:00
|
|
|
static const char *logic_pattern_str[] = {
|
2013-12-22 17:46:45 +00:00
|
|
|
"sigrok",
|
|
|
|
"random",
|
|
|
|
"incremental",
|
|
|
|
"all-low",
|
|
|
|
"all-high",
|
|
|
|
};
|
|
|
|
|
2013-12-27 22:52:23 +00:00
|
|
|
static const char *analog_pattern_str[] = {
|
|
|
|
"square",
|
2014-01-14 22:03:08 +00:00
|
|
|
"sine",
|
2014-01-14 22:03:09 +00:00
|
|
|
"triangle",
|
2014-01-14 22:03:10 +00:00
|
|
|
"sawtooth",
|
2013-12-27 22:52:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct analog_gen {
|
|
|
|
int pattern;
|
|
|
|
float pattern_data[ANALOG_BUFSIZE];
|
|
|
|
unsigned int num_samples;
|
|
|
|
struct sr_datafeed_analog packet;
|
|
|
|
};
|
|
|
|
|
2012-08-02 21:53:31 +00:00
|
|
|
/* Private, per-device-instance driver context. */
|
|
|
|
struct dev_context {
|
2011-01-15 04:12:41 +00:00
|
|
|
int pipe_fds[2];
|
2013-04-13 15:43:16 +00:00
|
|
|
GIOChannel *channel;
|
2013-04-14 16:00:47 +00:00
|
|
|
uint64_t cur_samplerate;
|
|
|
|
uint64_t limit_samples;
|
|
|
|
uint64_t limit_msec;
|
2014-01-25 19:39:50 +00:00
|
|
|
uint64_t logic_counter;
|
|
|
|
uint64_t analog_counter;
|
2012-12-02 00:07:10 +00:00
|
|
|
int64_t starttime;
|
2013-12-22 17:46:45 +00:00
|
|
|
uint64_t step;
|
2013-12-27 22:52:23 +00:00
|
|
|
/* Logic */
|
2013-12-24 10:27:40 +00:00
|
|
|
int32_t num_logic_probes;
|
|
|
|
unsigned int logic_unitsize;
|
2014-03-14 20:09:37 +00:00
|
|
|
/* There is only ever one logic channel group, so its pattern goes here. */
|
2013-12-24 10:27:40 +00:00
|
|
|
uint8_t logic_pattern;
|
|
|
|
unsigned char logic_data[LOGIC_BUFSIZE];
|
2013-12-27 22:52:23 +00:00
|
|
|
/* Analog */
|
2013-12-24 10:27:40 +00:00
|
|
|
int32_t num_analog_probes;
|
2014-03-14 20:09:37 +00:00
|
|
|
GSList *analog_channel_groups;
|
2013-12-24 10:27:40 +00:00
|
|
|
};
|
|
|
|
|
2014-01-12 21:36:39 +00:00
|
|
|
static const int32_t scanopts[] = {
|
2013-12-24 10:27:40 +00:00
|
|
|
SR_CONF_NUM_LOGIC_PROBES,
|
|
|
|
SR_CONF_NUM_ANALOG_PROBES,
|
2011-01-15 04:12:41 +00:00
|
|
|
};
|
2011-01-08 17:29:10 +00:00
|
|
|
|
2014-01-12 21:36:39 +00:00
|
|
|
static const int devopts[] = {
|
2013-01-21 22:22:47 +00:00
|
|
|
SR_CONF_LOGIC_ANALYZER,
|
|
|
|
SR_CONF_DEMO_DEV,
|
|
|
|
SR_CONF_SAMPLERATE,
|
|
|
|
SR_CONF_LIMIT_SAMPLES,
|
|
|
|
SR_CONF_LIMIT_MSEC,
|
2011-01-06 18:16:47 +00:00
|
|
|
};
|
|
|
|
|
2014-03-14 20:22:29 +00:00
|
|
|
static const int devopts_cg[] = {
|
2014-01-12 21:36:39 +00:00
|
|
|
SR_CONF_PATTERN_MODE,
|
|
|
|
};
|
|
|
|
|
2013-03-26 21:02:45 +00:00
|
|
|
static const uint64_t samplerates[] = {
|
|
|
|
SR_HZ(1),
|
|
|
|
SR_GHZ(1),
|
|
|
|
SR_HZ(1),
|
2011-02-12 02:24:23 +00:00
|
|
|
};
|
|
|
|
|
2011-05-05 11:02:48 +00:00
|
|
|
static uint8_t pattern_sigrok[] = {
|
2011-01-15 13:28:03 +00:00
|
|
|
0x4c, 0x92, 0x92, 0x92, 0x64, 0x00, 0x00, 0x00,
|
|
|
|
0x82, 0xfe, 0xfe, 0x82, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x7c, 0x82, 0x82, 0x92, 0x74, 0x00, 0x00, 0x00,
|
|
|
|
0xfe, 0x12, 0x12, 0x32, 0xcc, 0x00, 0x00, 0x00,
|
|
|
|
0x7c, 0x82, 0x82, 0x82, 0x7c, 0x00, 0x00, 0x00,
|
|
|
|
0xfe, 0x10, 0x28, 0x44, 0x82, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0xbe, 0xbe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
};
|
|
|
|
|
2012-07-13 11:47:27 +00:00
|
|
|
SR_PRIV struct sr_dev_driver demo_driver_info;
|
2012-12-17 23:52:39 +00:00
|
|
|
static struct sr_dev_driver *di = &demo_driver_info;
|
2011-01-06 18:16:47 +00:00
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data);
|
2011-01-06 18:16:47 +00:00
|
|
|
|
2013-12-24 10:27:40 +00:00
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int init(struct sr_context *sr_ctx)
|
2012-07-05 09:27:48 +00:00
|
|
|
{
|
2013-05-31 13:46:57 +00:00
|
|
|
return std_init(sr_ctx, di, LOG_PREFIX);
|
2012-07-05 09:27:48 +00:00
|
|
|
}
|
|
|
|
|
2014-03-14 20:09:37 +00:00
|
|
|
static void generate_analog_pattern(const struct sr_channel_group *channel_group, uint64_t sample_rate)
|
2013-12-27 22:52:23 +00:00
|
|
|
{
|
|
|
|
struct analog_gen *ag;
|
2014-01-14 22:03:08 +00:00
|
|
|
double t, frequency;
|
2013-12-27 22:52:23 +00:00
|
|
|
float value;
|
|
|
|
unsigned int num_samples, i;
|
|
|
|
int last_end;
|
|
|
|
|
2014-03-14 20:09:37 +00:00
|
|
|
ag = channel_group->priv;
|
2014-01-14 22:03:08 +00:00
|
|
|
num_samples = ANALOG_BUFSIZE / sizeof(float);
|
|
|
|
|
2014-03-14 20:09:37 +00:00
|
|
|
sr_dbg("Generating %s pattern for channel group %s",
|
2014-01-14 22:03:08 +00:00
|
|
|
analog_pattern_str[ag->pattern],
|
2014-03-14 20:09:37 +00:00
|
|
|
channel_group->name);
|
2013-12-27 22:52:23 +00:00
|
|
|
|
2014-01-14 22:03:08 +00:00
|
|
|
switch (ag->pattern) {
|
2013-12-27 22:52:23 +00:00
|
|
|
case PATTERN_SQUARE:
|
2014-01-15 00:51:04 +00:00
|
|
|
value = ANALOG_AMPLITUDE;
|
2013-12-27 22:52:23 +00:00
|
|
|
last_end = 0;
|
|
|
|
for (i = 0; i < num_samples; i++) {
|
|
|
|
if (i % 5 == 0)
|
|
|
|
value = -value;
|
|
|
|
if (i % 10 == 0)
|
|
|
|
last_end = i - 1;
|
|
|
|
ag->pattern_data[i] = value;
|
|
|
|
}
|
|
|
|
ag->num_samples = last_end;
|
|
|
|
break;
|
2014-01-14 22:03:08 +00:00
|
|
|
|
|
|
|
case PATTERN_SINE:
|
2014-01-26 20:30:57 +00:00
|
|
|
frequency = (double) sample_rate / ANALOG_SAMPLES_PER_PERIOD;
|
2014-01-14 22:03:08 +00:00
|
|
|
|
|
|
|
/* Make sure the number of samples we put out is an integer
|
|
|
|
* multiple of our period size */
|
|
|
|
/* FIXME we actually need only one period. A ringbuffer would be
|
|
|
|
* usefull here.*/
|
|
|
|
while (num_samples % ANALOG_SAMPLES_PER_PERIOD != 0)
|
|
|
|
num_samples--;
|
|
|
|
|
|
|
|
for (i = 0; i < num_samples; i++) {
|
|
|
|
t = (double) i / (double) sample_rate;
|
|
|
|
ag->pattern_data[i] = ANALOG_AMPLITUDE *
|
|
|
|
sin(2 * M_PI * frequency * t);
|
|
|
|
}
|
|
|
|
|
2014-01-14 22:03:09 +00:00
|
|
|
ag->num_samples = num_samples;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PATTERN_TRIANGLE:
|
2014-01-26 20:30:57 +00:00
|
|
|
frequency = (double) sample_rate / ANALOG_SAMPLES_PER_PERIOD;
|
2014-01-14 22:03:09 +00:00
|
|
|
|
|
|
|
while (num_samples % ANALOG_SAMPLES_PER_PERIOD != 0)
|
|
|
|
num_samples--;
|
|
|
|
|
|
|
|
for (i = 0; i < num_samples; i++) {
|
|
|
|
t = (double) i / (double) sample_rate;
|
|
|
|
ag->pattern_data[i] = (2 * ANALOG_AMPLITUDE / M_PI) *
|
|
|
|
asin(sin(2 * M_PI * frequency * t));
|
|
|
|
}
|
|
|
|
|
2014-01-14 22:03:10 +00:00
|
|
|
ag->num_samples = num_samples;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PATTERN_SAWTOOTH:
|
2014-01-26 20:30:57 +00:00
|
|
|
frequency = (double) sample_rate / ANALOG_SAMPLES_PER_PERIOD;
|
2014-01-14 22:03:10 +00:00
|
|
|
|
|
|
|
while (num_samples % ANALOG_SAMPLES_PER_PERIOD != 0)
|
|
|
|
num_samples--;
|
|
|
|
|
|
|
|
for (i = 0; i < num_samples; i++) {
|
|
|
|
t = (double) i / (double) sample_rate;
|
|
|
|
ag->pattern_data[i] = 2 * ANALOG_AMPLITUDE *
|
|
|
|
((t * frequency) - floor(0.5f + t * frequency));
|
|
|
|
}
|
|
|
|
|
2014-01-14 22:03:08 +00:00
|
|
|
ag->num_samples = num_samples;
|
|
|
|
break;
|
2013-12-27 22:52:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static GSList *scan(GSList *options)
|
2011-01-06 18:16:47 +00:00
|
|
|
{
|
2012-08-02 21:53:31 +00:00
|
|
|
struct drv_context *drvc;
|
2013-04-14 14:46:15 +00:00
|
|
|
struct dev_context *devc;
|
2013-12-24 10:27:40 +00:00
|
|
|
struct sr_dev_inst *sdi;
|
|
|
|
struct sr_probe *probe;
|
2014-03-14 20:22:29 +00:00
|
|
|
struct sr_channel_group *cg;
|
2013-12-24 10:27:40 +00:00
|
|
|
struct sr_config *src;
|
2013-12-27 22:52:23 +00:00
|
|
|
struct analog_gen *ag;
|
2013-12-24 10:27:40 +00:00
|
|
|
GSList *devices, *l;
|
2014-01-21 17:25:50 +00:00
|
|
|
int num_logic_probes, num_analog_probes, pattern, i;
|
2013-12-22 17:46:45 +00:00
|
|
|
char probe_name[16];
|
2012-07-14 13:49:30 +00:00
|
|
|
|
2012-12-17 23:52:39 +00:00
|
|
|
drvc = di->priv;
|
2013-01-28 19:00:54 +00:00
|
|
|
|
2013-12-24 10:27:40 +00:00
|
|
|
num_logic_probes = DEFAULT_NUM_LOGIC_PROBES;
|
|
|
|
num_analog_probes = DEFAULT_NUM_ANALOG_PROBES;
|
|
|
|
for (l = options; l; l = l->next) {
|
|
|
|
src = l->data;
|
|
|
|
switch (src->key) {
|
|
|
|
case SR_CONF_NUM_LOGIC_PROBES:
|
|
|
|
num_logic_probes = g_variant_get_int32(src->data);
|
|
|
|
break;
|
|
|
|
case SR_CONF_NUM_ANALOG_PROBES:
|
|
|
|
num_analog_probes = g_variant_get_int32(src->data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-01-08 17:29:10 +00:00
|
|
|
|
2013-12-24 10:27:40 +00:00
|
|
|
devices = NULL;
|
2013-12-22 17:46:45 +00:00
|
|
|
sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, "Demo device", NULL, NULL);
|
2011-05-06 18:34:12 +00:00
|
|
|
if (!sdi) {
|
2013-04-15 10:27:55 +00:00
|
|
|
sr_err("Device instance creation failed.");
|
|
|
|
return NULL;
|
2011-05-06 18:34:12 +00:00
|
|
|
}
|
2012-12-17 23:52:39 +00:00
|
|
|
sdi->driver = di;
|
2011-01-15 04:12:41 +00:00
|
|
|
|
2013-12-27 22:52:23 +00:00
|
|
|
if (!(devc = g_try_malloc(sizeof(struct dev_context)))) {
|
|
|
|
sr_err("Device context malloc failed.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
devc->cur_samplerate = SR_KHZ(200);
|
|
|
|
devc->limit_samples = 0;
|
|
|
|
devc->limit_msec = 0;
|
|
|
|
devc->step = 0;
|
|
|
|
devc->num_logic_probes = num_logic_probes;
|
|
|
|
devc->logic_unitsize = (devc->num_logic_probes + 7) / 8;
|
|
|
|
devc->logic_pattern = PATTERN_SIGROK;
|
|
|
|
devc->num_analog_probes = num_analog_probes;
|
2014-03-14 20:09:37 +00:00
|
|
|
devc->analog_channel_groups = NULL;
|
2013-12-27 22:52:23 +00:00
|
|
|
|
2014-03-14 20:09:37 +00:00
|
|
|
/* Logic probes, all in one channel group. */
|
2014-03-14 20:22:29 +00:00
|
|
|
if (!(cg = g_try_malloc(sizeof(struct sr_channel_group))))
|
2013-12-27 22:52:23 +00:00
|
|
|
return NULL;
|
2014-03-14 20:22:29 +00:00
|
|
|
cg->name = g_strdup("Logic");
|
2014-03-14 20:21:09 +00:00
|
|
|
cg->channels = NULL;
|
2014-03-14 20:22:29 +00:00
|
|
|
cg->priv = NULL;
|
2013-12-24 10:27:40 +00:00
|
|
|
for (i = 0; i < num_logic_probes; i++) {
|
2013-12-22 17:46:45 +00:00
|
|
|
sprintf(probe_name, "D%d", i);
|
|
|
|
if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, probe_name)))
|
2012-07-24 17:10:09 +00:00
|
|
|
return NULL;
|
|
|
|
sdi->probes = g_slist_append(sdi->probes, probe);
|
2014-03-14 20:21:09 +00:00
|
|
|
cg->channels = g_slist_append(cg->channels, probe);
|
2012-07-24 17:10:09 +00:00
|
|
|
}
|
2014-03-14 20:22:29 +00:00
|
|
|
sdi->channel_groups = g_slist_append(NULL, cg);
|
2012-07-24 17:10:09 +00:00
|
|
|
|
2014-03-14 20:09:37 +00:00
|
|
|
/* Analog probes, channel groups and pattern generators. */
|
2014-01-21 17:25:50 +00:00
|
|
|
|
|
|
|
pattern = 0;
|
2013-12-24 10:27:40 +00:00
|
|
|
for (i = 0; i < num_analog_probes; i++) {
|
|
|
|
sprintf(probe_name, "A%d", i);
|
2014-01-21 17:19:57 +00:00
|
|
|
if (!(probe = sr_probe_new(i + num_logic_probes,
|
|
|
|
SR_PROBE_ANALOG, TRUE, probe_name)))
|
2013-12-24 10:27:40 +00:00
|
|
|
return NULL;
|
|
|
|
sdi->probes = g_slist_append(sdi->probes, probe);
|
|
|
|
|
2014-03-14 20:09:37 +00:00
|
|
|
/* Every analog probe gets its own channel group. */
|
2014-03-14 20:22:29 +00:00
|
|
|
if (!(cg = g_try_malloc(sizeof(struct sr_channel_group))))
|
2013-12-27 22:52:23 +00:00
|
|
|
return NULL;
|
2014-03-14 20:22:29 +00:00
|
|
|
cg->name = g_strdup(probe_name);
|
2014-03-14 20:21:09 +00:00
|
|
|
cg->channels = g_slist_append(NULL, probe);
|
2011-01-08 17:29:10 +00:00
|
|
|
|
2014-03-14 20:09:37 +00:00
|
|
|
/* Every channel group gets a generator struct. */
|
2013-12-27 22:52:23 +00:00
|
|
|
if (!(ag = g_try_malloc(sizeof(struct analog_gen))))
|
|
|
|
return NULL;
|
2014-03-14 20:21:09 +00:00
|
|
|
ag->packet.probes = cg->channels;
|
2013-12-27 22:52:23 +00:00
|
|
|
ag->packet.mq = 0;
|
|
|
|
ag->packet.mqflags = 0;
|
|
|
|
ag->packet.unit = SR_UNIT_VOLT;
|
|
|
|
ag->packet.data = ag->pattern_data;
|
2014-01-21 17:25:50 +00:00
|
|
|
ag->pattern = pattern;
|
2014-03-14 20:22:29 +00:00
|
|
|
cg->priv = ag;
|
2013-12-27 22:52:23 +00:00
|
|
|
|
2014-03-14 20:22:29 +00:00
|
|
|
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
|
|
|
|
devc->analog_channel_groups = g_slist_append(devc->analog_channel_groups, cg);
|
2014-01-21 17:25:50 +00:00
|
|
|
|
|
|
|
if (++pattern == ARRAY_SIZE(analog_pattern_str))
|
|
|
|
pattern = 0;
|
2013-04-14 14:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sdi->priv = devc;
|
2013-12-27 22:52:23 +00:00
|
|
|
devices = g_slist_append(devices, sdi);
|
|
|
|
drvc->instances = g_slist_append(drvc->instances, sdi);
|
2013-04-14 14:46:15 +00:00
|
|
|
|
2012-07-14 13:49:30 +00:00
|
|
|
return devices;
|
2011-01-06 18:16:47 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static GSList *dev_list(void)
|
2012-08-05 22:59:25 +00:00
|
|
|
{
|
2013-02-02 18:52:26 +00:00
|
|
|
return ((struct drv_context *)(di->priv))->instances;
|
2012-08-05 22:59:25 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int dev_open(struct sr_dev_inst *sdi)
|
2011-01-06 18:16:47 +00:00
|
|
|
{
|
2013-04-23 13:14:42 +00:00
|
|
|
sdi->status = SR_ST_ACTIVE;
|
2011-05-04 17:34:12 +00:00
|
|
|
|
2011-01-29 15:23:12 +00:00
|
|
|
return SR_OK;
|
2011-01-06 18:16:47 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int dev_close(struct sr_dev_inst *sdi)
|
2011-01-06 18:16:47 +00:00
|
|
|
{
|
2013-05-10 16:30:32 +00:00
|
|
|
sdi->status = SR_ST_INACTIVE;
|
2011-05-04 17:34:12 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
2011-01-06 18:16:47 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int cleanup(void)
|
2011-01-06 18:16:47 +00:00
|
|
|
{
|
2014-02-26 20:37:18 +00:00
|
|
|
return std_dev_clear(di, NULL);
|
2011-01-06 18:16:47 +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-14 20:09:37 +00:00
|
|
|
const struct sr_channel_group *channel_group)
|
2011-01-06 18:16:47 +00:00
|
|
|
{
|
2013-12-24 10:27:40 +00:00
|
|
|
struct dev_context *devc;
|
2014-01-12 22:31:23 +00:00
|
|
|
struct sr_probe *probe;
|
|
|
|
struct analog_gen *ag;
|
|
|
|
int pattern;
|
2012-07-24 22:33:38 +00:00
|
|
|
|
2014-01-12 22:31:23 +00:00
|
|
|
if (!sdi)
|
|
|
|
return SR_ERR_ARG;
|
2013-04-20 00:00:49 +00:00
|
|
|
|
2013-12-24 10:27:40 +00:00
|
|
|
devc = sdi->priv;
|
2013-01-24 18:19:09 +00:00
|
|
|
switch (id) {
|
2013-01-25 02:17:36 +00:00
|
|
|
case SR_CONF_SAMPLERATE:
|
2013-04-14 16:00:47 +00:00
|
|
|
*data = g_variant_new_uint64(devc->cur_samplerate);
|
2011-01-06 18:16:47 +00:00
|
|
|
break;
|
2013-03-03 20:17:48 +00:00
|
|
|
case SR_CONF_LIMIT_SAMPLES:
|
2013-04-14 16:00:47 +00:00
|
|
|
*data = g_variant_new_uint64(devc->limit_samples);
|
2013-03-03 20:17:48 +00:00
|
|
|
break;
|
|
|
|
case SR_CONF_LIMIT_MSEC:
|
2013-04-14 16:00:47 +00:00
|
|
|
*data = g_variant_new_uint64(devc->limit_msec);
|
2013-03-03 20:17:48 +00:00
|
|
|
break;
|
|
|
|
case SR_CONF_PATTERN_MODE:
|
2014-03-14 20:09:37 +00:00
|
|
|
if (!channel_group)
|
|
|
|
return SR_ERR_CHANNEL_GROUP;
|
2014-03-14 20:21:09 +00:00
|
|
|
probe = channel_group->channels->data;
|
2014-01-12 22:31:23 +00:00
|
|
|
if (probe->type == SR_PROBE_LOGIC) {
|
|
|
|
pattern = devc->logic_pattern;
|
|
|
|
*data = g_variant_new_string(logic_pattern_str[pattern]);
|
|
|
|
} else if (probe->type == SR_PROBE_ANALOG) {
|
2014-03-14 20:09:37 +00:00
|
|
|
ag = channel_group->priv;
|
2014-01-12 22:31:23 +00:00
|
|
|
pattern = ag->pattern;
|
|
|
|
*data = g_variant_new_string(analog_pattern_str[pattern]);
|
|
|
|
} else
|
|
|
|
return SR_ERR_BUG;
|
2013-12-24 10:27:40 +00:00
|
|
|
break;
|
|
|
|
case SR_CONF_NUM_LOGIC_PROBES:
|
|
|
|
*data = g_variant_new_int32(devc->num_logic_probes);
|
|
|
|
break;
|
|
|
|
case SR_CONF_NUM_ANALOG_PROBES:
|
|
|
|
*data = g_variant_new_int32(devc->num_analog_probes);
|
2013-03-03 20:17:48 +00:00
|
|
|
break;
|
2012-07-15 02:07:51 +00:00
|
|
|
default:
|
2013-04-16 00:33:03 +00:00
|
|
|
return SR_ERR_NA;
|
2011-01-06 18:16:47 +00:00
|
|
|
}
|
|
|
|
|
2012-07-15 01:52:37 +00:00
|
|
|
return SR_OK;
|
2011-01-06 18:16:47 +00:00
|
|
|
}
|
|
|
|
|
2013-04-20 00:00:49 +00:00
|
|
|
static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
|
2014-03-14 20:09:37 +00:00
|
|
|
const struct sr_channel_group *channel_group)
|
2011-01-06 18:16:47 +00:00
|
|
|
{
|
2013-12-27 22:52:23 +00:00
|
|
|
struct dev_context *devc;
|
2014-01-14 22:03:08 +00:00
|
|
|
struct analog_gen *ag;
|
2014-01-12 22:31:23 +00:00
|
|
|
struct sr_probe *probe;
|
|
|
|
int pattern, ret;
|
2013-12-22 17:46:45 +00:00
|
|
|
unsigned int i;
|
2012-05-07 14:02:02 +00:00
|
|
|
const char *stropt;
|
2011-01-06 18:16:47 +00:00
|
|
|
|
2013-12-27 22:52:23 +00:00
|
|
|
devc = sdi->priv;
|
2011-01-06 18:16:47 +00:00
|
|
|
|
2013-04-23 13:14:42 +00:00
|
|
|
if (sdi->status != SR_ST_ACTIVE)
|
|
|
|
return SR_ERR_DEV_CLOSED;
|
|
|
|
|
2014-01-12 22:31:23 +00:00
|
|
|
ret = SR_OK;
|
|
|
|
switch (id) {
|
|
|
|
case SR_CONF_SAMPLERATE:
|
2013-04-14 16:00:47 +00:00
|
|
|
devc->cur_samplerate = g_variant_get_uint64(data);
|
2013-12-22 17:46:45 +00:00
|
|
|
sr_dbg("Setting samplerate to %" PRIu64, devc->cur_samplerate);
|
2014-01-12 22:31:23 +00:00
|
|
|
break;
|
|
|
|
case SR_CONF_LIMIT_SAMPLES:
|
2013-04-14 16:00:47 +00:00
|
|
|
devc->limit_msec = 0;
|
|
|
|
devc->limit_samples = g_variant_get_uint64(data);
|
2013-12-27 22:52:23 +00:00
|
|
|
sr_dbg("Setting sample limit to %" PRIu64, devc->limit_samples);
|
2014-01-12 22:31:23 +00:00
|
|
|
break;
|
|
|
|
case SR_CONF_LIMIT_MSEC:
|
2013-04-14 16:00:47 +00:00
|
|
|
devc->limit_msec = g_variant_get_uint64(data);
|
|
|
|
devc->limit_samples = 0;
|
2013-12-27 22:52:23 +00:00
|
|
|
sr_dbg("Setting time limit to %" PRIu64"ms", devc->limit_msec);
|
2014-01-12 22:31:23 +00:00
|
|
|
break;
|
|
|
|
case SR_CONF_PATTERN_MODE:
|
2014-03-14 20:09:37 +00:00
|
|
|
if (!channel_group)
|
|
|
|
return SR_ERR_CHANNEL_GROUP;
|
2013-03-26 21:02:45 +00:00
|
|
|
stropt = g_variant_get_string(data, NULL);
|
2014-03-14 20:21:09 +00:00
|
|
|
probe = channel_group->channels->data;
|
2014-01-12 22:31:23 +00:00
|
|
|
pattern = -1;
|
|
|
|
if (probe->type == SR_PROBE_LOGIC) {
|
|
|
|
for (i = 0; i < ARRAY_SIZE(logic_pattern_str); i++) {
|
|
|
|
if (!strcmp(stropt, logic_pattern_str[i])) {
|
|
|
|
pattern = i;
|
2013-12-27 22:52:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-01-12 22:31:23 +00:00
|
|
|
if (pattern == -1)
|
|
|
|
return SR_ERR_ARG;
|
|
|
|
devc->logic_pattern = pattern;
|
|
|
|
|
|
|
|
/* Might as well do this now, these are static. */
|
|
|
|
if (pattern == PATTERN_ALL_LOW)
|
2013-12-27 22:52:23 +00:00
|
|
|
memset(devc->logic_data, 0x00, LOGIC_BUFSIZE);
|
2014-01-12 22:31:23 +00:00
|
|
|
else if (pattern == PATTERN_ALL_HIGH)
|
2013-12-27 22:52:23 +00:00
|
|
|
memset(devc->logic_data, 0xff, LOGIC_BUFSIZE);
|
2014-01-12 22:31:23 +00:00
|
|
|
sr_dbg("Setting logic pattern to %s",
|
|
|
|
logic_pattern_str[pattern]);
|
|
|
|
} else if (probe->type == SR_PROBE_ANALOG) {
|
|
|
|
for (i = 0; i < ARRAY_SIZE(analog_pattern_str); i++) {
|
|
|
|
if (!strcmp(stropt, analog_pattern_str[i])) {
|
|
|
|
pattern = i;
|
|
|
|
break;
|
2013-12-27 22:52:23 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-12 22:31:23 +00:00
|
|
|
if (pattern == -1)
|
|
|
|
return SR_ERR_ARG;
|
2014-03-14 20:09:37 +00:00
|
|
|
sr_dbg("Setting analog pattern for channel group %s to %s",
|
|
|
|
channel_group->name,
|
2014-01-12 22:31:23 +00:00
|
|
|
analog_pattern_str[pattern]);
|
2014-03-14 20:09:37 +00:00
|
|
|
ag = channel_group->priv;
|
2014-01-14 22:03:08 +00:00
|
|
|
ag->pattern = pattern;
|
2014-01-12 22:31:23 +00:00
|
|
|
} else
|
|
|
|
return SR_ERR_BUG;
|
|
|
|
break;
|
|
|
|
default:
|
2013-04-16 00:33:03 +00:00
|
|
|
ret = SR_ERR_NA;
|
2011-01-06 18:16:47 +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-14 20:09:37 +00:00
|
|
|
const struct sr_channel_group *channel_group)
|
2013-01-25 01:32:05 +00:00
|
|
|
{
|
2014-01-12 21:36:39 +00:00
|
|
|
struct sr_probe *probe;
|
2013-03-26 21:02:45 +00:00
|
|
|
GVariant *gvar;
|
|
|
|
GVariantBuilder gvb;
|
2013-01-25 01:32:05 +00:00
|
|
|
|
|
|
|
(void)sdi;
|
|
|
|
|
2014-01-12 21:36:39 +00:00
|
|
|
if (key == SR_CONF_SCAN_OPTIONS) {
|
2013-12-24 10:27:40 +00:00
|
|
|
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
|
2014-01-12 21:36:39 +00:00
|
|
|
scanopts, ARRAY_SIZE(scanopts), sizeof(int32_t));
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sdi)
|
|
|
|
return SR_ERR_ARG;
|
|
|
|
|
2014-03-14 20:09:37 +00:00
|
|
|
if (!channel_group) {
|
2014-01-12 21:36:39 +00:00
|
|
|
switch (key) {
|
|
|
|
case SR_CONF_DEVICE_OPTIONS:
|
|
|
|
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
|
|
|
|
devopts, ARRAY_SIZE(devopts), sizeof(int32_t));
|
|
|
|
break;
|
|
|
|
case SR_CONF_SAMPLERATE:
|
|
|
|
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);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return SR_ERR_NA;
|
|
|
|
}
|
|
|
|
} else {
|
2014-03-14 20:21:09 +00:00
|
|
|
probe = channel_group->channels->data;
|
2014-01-12 21:36:39 +00:00
|
|
|
switch (key) {
|
|
|
|
case SR_CONF_DEVICE_OPTIONS:
|
|
|
|
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
|
2014-03-14 20:22:29 +00:00
|
|
|
devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(int32_t));
|
2014-01-12 21:36:39 +00:00
|
|
|
break;
|
|
|
|
case SR_CONF_PATTERN_MODE:
|
|
|
|
if (probe->type == SR_PROBE_LOGIC)
|
|
|
|
*data = g_variant_new_strv(logic_pattern_str,
|
|
|
|
ARRAY_SIZE(logic_pattern_str));
|
2014-01-12 22:31:23 +00:00
|
|
|
else if (probe->type == SR_PROBE_ANALOG)
|
2014-01-12 21:36:39 +00:00
|
|
|
*data = g_variant_new_strv(analog_pattern_str,
|
|
|
|
ARRAY_SIZE(analog_pattern_str));
|
2014-01-12 22:31:23 +00:00
|
|
|
else
|
|
|
|
return SR_ERR_BUG;
|
2014-01-12 21:36:39 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return SR_ERR_NA;
|
|
|
|
}
|
2013-01-25 01:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-12-24 10:27:40 +00:00
|
|
|
static void logic_generator(struct sr_dev_inst *sdi, uint64_t size)
|
2011-01-08 17:29:10 +00:00
|
|
|
{
|
2013-12-22 17:46:45 +00:00
|
|
|
struct dev_context *devc;
|
2013-12-24 10:27:40 +00:00
|
|
|
uint64_t i, j;
|
|
|
|
uint8_t pat;
|
2011-01-08 17:29:10 +00:00
|
|
|
|
2013-12-22 17:46:45 +00:00
|
|
|
devc = sdi->priv;
|
2011-01-08 17:29:10 +00:00
|
|
|
|
2013-12-24 10:27:40 +00:00
|
|
|
switch (devc->logic_pattern) {
|
2013-12-22 17:46:45 +00:00
|
|
|
case PATTERN_SIGROK:
|
2013-12-24 10:27:40 +00:00
|
|
|
memset(devc->logic_data, 0x00, size);
|
|
|
|
for (i = 0; i < size; i += devc->logic_unitsize) {
|
|
|
|
for (j = 0; j < devc->logic_unitsize; j++) {
|
|
|
|
pat = pattern_sigrok[(devc->step + j) % sizeof(pattern_sigrok)] >> 1;
|
|
|
|
devc->logic_data[i + j] = ~pat;
|
|
|
|
}
|
|
|
|
devc->step++;
|
2011-01-15 13:28:03 +00:00
|
|
|
}
|
|
|
|
break;
|
2013-12-22 17:46:45 +00:00
|
|
|
case PATTERN_RANDOM:
|
2011-01-08 18:01:07 +00:00
|
|
|
for (i = 0; i < size; i++)
|
2013-12-22 17:46:45 +00:00
|
|
|
devc->logic_data[i] = (uint8_t)(rand() & 0xff);
|
2011-01-08 17:29:10 +00:00
|
|
|
break;
|
2013-12-22 17:46:45 +00:00
|
|
|
case PATTERN_INC:
|
2013-12-24 10:27:40 +00:00
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
for (j = 0; j < devc->logic_unitsize; j++) {
|
|
|
|
devc->logic_data[i + j] = devc->step;
|
|
|
|
}
|
|
|
|
devc->step++;
|
|
|
|
}
|
2011-05-06 18:34:12 +00:00
|
|
|
break;
|
2013-12-22 17:46:45 +00:00
|
|
|
case PATTERN_ALL_LOW:
|
|
|
|
case PATTERN_ALL_HIGH:
|
|
|
|
/* These were set when the pattern mode was selected. */
|
2011-05-06 18:34:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-12-24 10:27:40 +00:00
|
|
|
sr_err("Unknown pattern: %d.", devc->logic_pattern);
|
2011-05-06 18:34:12 +00:00
|
|
|
break;
|
2011-01-08 17:29:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback handling data */
|
2013-12-22 17:46:45 +00:00
|
|
|
static int prepare_data(int fd, int revents, void *cb_data)
|
2011-01-08 17:29:10 +00:00
|
|
|
{
|
2013-12-22 17:46:45 +00:00
|
|
|
struct sr_dev_inst *sdi;
|
|
|
|
struct dev_context *devc;
|
2011-01-29 16:03:26 +00:00
|
|
|
struct sr_datafeed_packet packet;
|
2011-06-19 12:28:50 +00:00
|
|
|
struct sr_datafeed_logic logic;
|
2014-03-14 20:22:29 +00:00
|
|
|
struct sr_channel_group *cg;
|
2013-12-27 22:52:23 +00:00
|
|
|
struct analog_gen *ag;
|
|
|
|
GSList *l;
|
2014-01-25 19:39:50 +00:00
|
|
|
uint64_t logic_todo, analog_todo, expected_samplenum, analog_samples, sending_now;
|
2012-12-02 00:07:10 +00:00
|
|
|
int64_t time, elapsed;
|
2011-01-19 22:14:17 +00:00
|
|
|
|
2011-11-24 21:57:48 +00:00
|
|
|
(void)fd;
|
|
|
|
(void)revents;
|
2011-01-19 22:14:17 +00:00
|
|
|
|
2013-12-22 17:46:45 +00:00
|
|
|
sdi = cb_data;
|
|
|
|
devc = sdi->priv;
|
|
|
|
|
2012-12-02 00:07:10 +00:00
|
|
|
/* How many "virtual" samples should we have collected by now? */
|
|
|
|
time = g_get_monotonic_time();
|
|
|
|
elapsed = time - devc->starttime;
|
2013-04-14 16:00:47 +00:00
|
|
|
expected_samplenum = elapsed * devc->cur_samplerate / 1000000;
|
2014-01-25 19:39:50 +00:00
|
|
|
|
2012-12-02 00:07:10 +00:00
|
|
|
/* Of those, how many do we still have to send? */
|
2014-01-25 20:20:29 +00:00
|
|
|
logic_todo = MIN(expected_samplenum, devc->limit_samples) - devc->logic_counter;
|
|
|
|
analog_todo = MIN(expected_samplenum, devc->limit_samples) - devc->analog_counter;
|
2011-01-08 17:29:10 +00:00
|
|
|
|
2014-01-25 19:39:50 +00:00
|
|
|
while (logic_todo || analog_todo) {
|
2013-12-24 10:27:40 +00:00
|
|
|
/* Logic */
|
2014-01-25 19:39:50 +00:00
|
|
|
if (devc->num_logic_probes > 0 && logic_todo > 0) {
|
|
|
|
sending_now = MIN(logic_todo,
|
2013-12-27 22:52:23 +00:00
|
|
|
LOGIC_BUFSIZE / devc->logic_unitsize);
|
|
|
|
logic_generator(sdi, sending_now * devc->logic_unitsize);
|
|
|
|
packet.type = SR_DF_LOGIC;
|
|
|
|
packet.payload = &logic;
|
|
|
|
logic.length = sending_now * devc->logic_unitsize;
|
|
|
|
logic.unitsize = devc->logic_unitsize;
|
|
|
|
logic.data = devc->logic_data;
|
|
|
|
sr_session_send(sdi, &packet);
|
2014-01-25 19:39:50 +00:00
|
|
|
logic_todo -= sending_now;
|
|
|
|
devc->logic_counter += sending_now;
|
2013-12-27 22:52:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Analog, one probe at a time */
|
2014-01-25 19:39:50 +00:00
|
|
|
if (devc->num_analog_probes > 0 && analog_todo > 0) {
|
2013-12-27 22:52:23 +00:00
|
|
|
sending_now = 0;
|
2014-03-14 20:09:37 +00:00
|
|
|
for (l = devc->analog_channel_groups; l; l = l->next) {
|
2014-03-14 20:22:29 +00:00
|
|
|
cg = l->data;
|
|
|
|
ag = cg->priv;
|
2013-12-27 22:52:23 +00:00
|
|
|
packet.type = SR_DF_ANALOG;
|
|
|
|
packet.payload = &ag->packet;
|
2014-01-14 22:03:08 +00:00
|
|
|
|
|
|
|
/* FIXME we should make sure we output a whole
|
|
|
|
* period of data before we send out again the
|
|
|
|
* beginning of our buffer. A ring buffer would
|
|
|
|
* help here as well */
|
|
|
|
|
2014-01-25 19:39:50 +00:00
|
|
|
analog_samples = MIN(analog_todo, ag->num_samples);
|
2014-03-14 20:09:37 +00:00
|
|
|
/* Whichever channel group gets there first. */
|
2013-12-27 22:52:23 +00:00
|
|
|
sending_now = MAX(sending_now, analog_samples);
|
|
|
|
ag->packet.num_samples = analog_samples;
|
|
|
|
sr_session_send(sdi, &packet);
|
|
|
|
}
|
2014-01-25 19:39:50 +00:00
|
|
|
analog_todo -= sending_now;
|
|
|
|
devc->analog_counter += sending_now;
|
2013-12-27 22:52:23 +00:00
|
|
|
}
|
2012-12-02 00:07:10 +00:00
|
|
|
}
|
|
|
|
|
2014-01-25 20:20:29 +00:00
|
|
|
if (devc->logic_counter >= devc->limit_samples &&
|
2014-01-25 19:39:50 +00:00
|
|
|
devc->analog_counter >= devc->limit_samples) {
|
|
|
|
sr_dbg("Requested number of samples reached.");
|
2013-12-22 17:46:45 +00:00
|
|
|
dev_acquisition_stop(sdi, cb_data);
|
2012-12-01 18:49:15 +00:00
|
|
|
return TRUE;
|
2011-01-08 17:29:10 +00:00
|
|
|
}
|
2011-01-19 22:14:17 +00:00
|
|
|
|
2011-01-08 17:29:10 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
|
2011-01-06 18:16:47 +00:00
|
|
|
{
|
2014-01-14 22:03:08 +00:00
|
|
|
GSList *l;
|
2013-12-22 17:46:45 +00:00
|
|
|
struct dev_context *devc;
|
2011-01-08 17:29:10 +00:00
|
|
|
|
2013-04-23 13:14:42 +00:00
|
|
|
if (sdi->status != SR_ST_ACTIVE)
|
|
|
|
return SR_ERR_DEV_CLOSED;
|
|
|
|
|
2013-12-22 17:46:45 +00:00
|
|
|
devc = sdi->priv;
|
2014-01-25 20:20:29 +00:00
|
|
|
if (devc->limit_samples == 0)
|
|
|
|
return SR_ERR;
|
2014-01-25 19:39:50 +00:00
|
|
|
devc->logic_counter = devc->analog_counter = 0;
|
2011-01-08 17:29:10 +00:00
|
|
|
|
2012-12-02 00:07:10 +00:00
|
|
|
/*
|
|
|
|
* Setting two channels connected by a pipe is a remnant from when the
|
|
|
|
* demo driver generated data in a thread, and collected and sent the
|
|
|
|
* data in the main program loop.
|
|
|
|
* They are kept here because it provides a convenient way of setting
|
|
|
|
* up a timeout-based polling mechanism.
|
|
|
|
*/
|
2012-08-02 21:53:31 +00:00
|
|
|
if (pipe(devc->pipe_fds)) {
|
2012-11-10 17:24:05 +00:00
|
|
|
sr_err("%s: pipe() failed", __func__);
|
2011-01-29 15:23:12 +00:00
|
|
|
return SR_ERR;
|
2011-05-06 18:34:12 +00:00
|
|
|
}
|
2011-01-08 17:29:10 +00:00
|
|
|
|
2014-03-14 20:09:37 +00:00
|
|
|
for (l = devc->analog_channel_groups; l; l = l->next) {
|
2014-01-14 22:03:08 +00:00
|
|
|
generate_analog_pattern(l->data, devc->cur_samplerate);
|
|
|
|
}
|
|
|
|
|
2013-04-13 15:43:16 +00:00
|
|
|
devc->channel = g_io_channel_unix_new(devc->pipe_fds[0]);
|
2011-01-16 13:12:52 +00:00
|
|
|
|
2013-04-13 15:43:16 +00:00
|
|
|
g_io_channel_set_flags(devc->channel, G_IO_FLAG_NONBLOCK, NULL);
|
2012-07-06 21:23:30 +00:00
|
|
|
|
2011-01-16 13:12:52 +00:00
|
|
|
/* Set channel encoding to binary (default is UTF-8). */
|
2013-04-13 15:43:16 +00:00
|
|
|
g_io_channel_set_encoding(devc->channel, NULL, NULL);
|
2011-01-16 13:12:52 +00:00
|
|
|
|
|
|
|
/* Make channels to unbuffered. */
|
2013-04-13 15:43:16 +00:00
|
|
|
g_io_channel_set_buffered(devc->channel, FALSE);
|
2011-01-16 13:12:52 +00:00
|
|
|
|
2013-04-13 15:43:16 +00:00
|
|
|
sr_session_source_add_channel(devc->channel, G_IO_IN | G_IO_ERR,
|
2013-12-22 17:46:45 +00:00
|
|
|
40, prepare_data, (void *)sdi);
|
2011-01-08 17:29:10 +00:00
|
|
|
|
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);
|
2012-04-22 18:06:19 +00:00
|
|
|
|
2012-12-02 00:07:10 +00:00
|
|
|
/* We use this timestamp to decide how many more samples to send. */
|
|
|
|
devc->starttime = g_get_monotonic_time();
|
|
|
|
|
2011-01-29 15:23:12 +00:00
|
|
|
return SR_OK;
|
2011-01-06 18:16:47 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
|
2011-01-06 18:16:47 +00:00
|
|
|
{
|
2013-12-27 22:52:23 +00:00
|
|
|
struct dev_context *devc;
|
2012-12-01 18:49:15 +00:00
|
|
|
struct sr_datafeed_packet packet;
|
2012-08-03 08:09:02 +00:00
|
|
|
|
2013-04-14 14:46:15 +00:00
|
|
|
(void)cb_data;
|
2012-08-03 08:09:02 +00:00
|
|
|
|
2013-12-27 22:52:23 +00:00
|
|
|
devc = sdi->priv;
|
2014-03-05 19:48:54 +00:00
|
|
|
sr_dbg("Stopping acquisition.");
|
2012-12-01 18:03:45 +00:00
|
|
|
|
2013-04-13 15:43:16 +00:00
|
|
|
sr_session_source_remove_channel(devc->channel);
|
|
|
|
g_io_channel_shutdown(devc->channel, FALSE, NULL);
|
2013-04-14 18:19:35 +00:00
|
|
|
g_io_channel_unref(devc->channel);
|
|
|
|
devc->channel = NULL;
|
2012-12-01 18:49:15 +00:00
|
|
|
|
|
|
|
/* Send last packet. */
|
|
|
|
packet.type = SR_DF_END;
|
2013-12-24 10:27:40 +00:00
|
|
|
sr_session_send(sdi, &packet);
|
2012-08-03 08:09:02 +00:00
|
|
|
|
2012-02-12 12:31:58 +00:00
|
|
|
return SR_OK;
|
2011-01-06 18:16:47 +00:00
|
|
|
}
|
|
|
|
|
2012-02-28 22:52:30 +00:00
|
|
|
SR_PRIV struct sr_dev_driver demo_driver_info = {
|
2011-04-18 22:14:15 +00:00
|
|
|
.name = "demo",
|
|
|
|
.longname = "Demo driver and pattern generator",
|
|
|
|
.api_version = 1,
|
2013-05-10 17:37:54 +00:00
|
|
|
.init = init,
|
|
|
|
.cleanup = cleanup,
|
|
|
|
.scan = scan,
|
|
|
|
.dev_list = dev_list,
|
2014-02-26 20:37:18 +00:00
|
|
|
.dev_clear = NULL,
|
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,
|
|
|
|
.dev_close = dev_close,
|
|
|
|
.dev_acquisition_start = dev_acquisition_start,
|
|
|
|
.dev_acquisition_stop = dev_acquisition_stop,
|
2012-08-02 21:53:31 +00:00
|
|
|
.priv = NULL,
|
2011-01-06 18:16:47 +00:00
|
|
|
};
|