]> sigrok.org Git - libsigrok.git/blame - src/hardware/demo/api.c
sr_dev_close(): Set status to SR_ST_INACTIVE.
[libsigrok.git] / src / hardware / demo / api.c
CommitLineData
6239c175 1/*
50985c20 2 * This file is part of the libsigrok project.
6239c175
UH
3 *
4 * Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
fc96e6f8 5 * Copyright (C) 2011 Olivier Fauchon <olivier@aixmarseille.com>
c216d623 6 * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
7a8a1aba 7 * Copyright (C) 2015 Bartosz Golaszewski <bgolaszewski@baylibre.com>
6239c175
UH
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
2ea1fdf1 20 * along with this program; if not, see <http://www.gnu.org/licenses/>.
6239c175
UH
21 */
22
6ec6c43b 23#include <config.h>
6239c175
UH
24#include <stdlib.h>
25#include <string.h>
4374219b 26#include <math.h>
c1aae900 27#include <libsigrok/libsigrok.h>
45c59c8b 28#include "libsigrok-internal.h"
ba508e22 29#include "protocol.h"
92bcedf6 30
7db90279 31#define DEFAULT_NUM_LOGIC_CHANNELS 8
b1e6eec6 32#define DEFAULT_LOGIC_PATTERN PATTERN_SIGROK
c03ed397 33
b1e6eec6 34#define DEFAULT_NUM_ANALOG_CHANNELS 4
d9251a2c 35#define DEFAULT_ANALOG_AMPLITUDE 10
85b5af06 36
77463bd3 37/* Note: No spaces allowed because of sigrok-cli. */
8b2d41ed 38static const char *logic_pattern_str[] = {
61c39f54
BV
39 "sigrok",
40 "random",
41 "incremental",
77463bd3
SA
42 "walking-one",
43 "walking-zero",
61c39f54
BV
44 "all-low",
45 "all-high",
81d53a29 46 "squid",
61c39f54
BV
47};
48
1e4a7cac
BV
49static const uint32_t drvopts[] = {
50 SR_CONF_DEMO_DEV,
51 SR_CONF_LOGIC_ANALYZER,
52 SR_CONF_OSCILLOSCOPE,
53};
54
584560f1 55static const uint32_t scanopts[] = {
3f239f08
UH
56 SR_CONF_NUM_LOGIC_CHANNELS,
57 SR_CONF_NUM_ANALOG_CHANNELS,
e15f48c2 58};
85b5af06 59
390795c0 60static const uint32_t devopts[] = {
e91bb0a6 61 SR_CONF_CONTINUOUS,
5827f61b
BV
62 SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
63 SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
390795c0 64 SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
7a8a1aba
BG
65 SR_CONF_AVERAGING | SR_CONF_GET | SR_CONF_SET,
66 SR_CONF_AVG_SAMPLES | SR_CONF_GET | SR_CONF_SET,
390795c0
BV
67};
68
69static const uint32_t devopts_cg_logic[] = {
f12d9979 70 SR_CONF_PATTERN_MODE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
49224c28
BV
71};
72
e2b99f04
SA
73static const uint32_t devopts_cg_analog_group[] = {
74 SR_CONF_AMPLITUDE | SR_CONF_GET | SR_CONF_SET,
75};
76
77static const uint32_t devopts_cg_analog_channel[] = {
f12d9979
BV
78 SR_CONF_PATTERN_MODE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
79 SR_CONF_AMPLITUDE | SR_CONF_GET | SR_CONF_SET,
7a1da331
BV
80};
81
d00088ca
BV
82static const uint64_t samplerates[] = {
83 SR_HZ(1),
84 SR_GHZ(1),
85 SR_HZ(1),
4bfbf9fc
BV
86};
87
4f840ce9 88static GSList *scan(struct sr_dev_driver *di, GSList *options)
6239c175 89{
33ef7573 90 struct dev_context *devc;
c07f60e7 91 struct sr_dev_inst *sdi;
ba7dd8bb 92 struct sr_channel *ch;
49224c28 93 struct sr_channel_group *cg, *acg;
c07f60e7 94 struct sr_config *src;
8b2d41ed 95 struct analog_gen *ag;
43376f33 96 GSList *l;
ba7dd8bb
UH
97 int num_logic_channels, num_analog_channels, pattern, i;
98 char channel_name[16];
067d0716 99
3f239f08
UH
100 num_logic_channels = DEFAULT_NUM_LOGIC_CHANNELS;
101 num_analog_channels = DEFAULT_NUM_ANALOG_CHANNELS;
c07f60e7
BV
102 for (l = options; l; l = l->next) {
103 src = l->data;
104 switch (src->key) {
3f239f08 105 case SR_CONF_NUM_LOGIC_CHANNELS:
ba7dd8bb 106 num_logic_channels = g_variant_get_int32(src->data);
c07f60e7 107 break;
3f239f08 108 case SR_CONF_NUM_ANALOG_CHANNELS:
ba7dd8bb 109 num_analog_channels = g_variant_get_int32(src->data);
c07f60e7
BV
110 break;
111 }
112 }
85b5af06 113
aac29cc1 114 sdi = g_malloc0(sizeof(struct sr_dev_inst));
45884333 115 sdi->status = SR_ST_INACTIVE;
4b664cd6 116 sdi->model = g_strdup("Demo device");
e15f48c2 117
a49a320d 118 devc = g_malloc0(sizeof(struct dev_context));
8b2d41ed 119 devc->cur_samplerate = SR_KHZ(200);
ba7dd8bb
UH
120 devc->num_logic_channels = num_logic_channels;
121 devc->logic_unitsize = (devc->num_logic_channels + 7) / 8;
b1e6eec6 122 devc->logic_pattern = DEFAULT_LOGIC_PATTERN;
ba7dd8bb 123 devc->num_analog_channels = num_analog_channels;
8b2d41ed 124
f18e0db3
LPC
125 if (num_logic_channels > 0) {
126 /* Logic channels, all in one channel group. */
127 cg = g_malloc0(sizeof(struct sr_channel_group));
128 cg->name = g_strdup("Logic");
129 for (i = 0; i < num_logic_channels; i++) {
130 sprintf(channel_name, "D%d", i);
f1c79a6a 131 ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name);
f18e0db3
LPC
132 cg->channels = g_slist_append(cg->channels, ch);
133 }
134 sdi->channel_groups = g_slist_append(NULL, cg);
87ca93c5
BV
135 }
136
ba7dd8bb 137 /* Analog channels, channel groups and pattern generators. */
d91d0b12 138 devc->ch_ag = g_hash_table_new(g_direct_hash, g_direct_equal);
f18e0db3
LPC
139 if (num_analog_channels > 0) {
140 pattern = 0;
141 /* An "Analog" channel group with all analog channels in it. */
142 acg = g_malloc0(sizeof(struct sr_channel_group));
143 acg->name = g_strdup("Analog");
144 sdi->channel_groups = g_slist_append(sdi->channel_groups, acg);
145
f18e0db3
LPC
146 for (i = 0; i < num_analog_channels; i++) {
147 snprintf(channel_name, 16, "A%d", i);
148 ch = sr_channel_new(sdi, i + num_logic_channels, SR_CHANNEL_ANALOG,
f1c79a6a 149 TRUE, channel_name);
f18e0db3
LPC
150 acg->channels = g_slist_append(acg->channels, ch);
151
152 /* Every analog channel gets its own channel group as well. */
153 cg = g_malloc0(sizeof(struct sr_channel_group));
154 cg->name = g_strdup(channel_name);
155 cg->channels = g_slist_append(NULL, ch);
156 sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
157
158 /* Every channel gets a generator struct. */
159 ag = g_malloc(sizeof(struct analog_gen));
01f2adb0 160 ag->ch = ch;
f18e0db3 161 ag->amplitude = DEFAULT_ANALOG_AMPLITUDE;
3be044aa 162 sr_analog_init(&ag->packet, &ag->encoding, &ag->meaning, &ag->spec, 2);
4b770103
UH
163 ag->packet.meaning->channels = cg->channels;
164 ag->packet.meaning->mq = 0;
165 ag->packet.meaning->mqflags = 0;
166 ag->packet.meaning->unit = SR_UNIT_VOLT;
f18e0db3
LPC
167 ag->packet.data = ag->pattern_data;
168 ag->pattern = pattern;
169 ag->avg_val = 0.0f;
170 ag->num_avgs = 0;
171 g_hash_table_insert(devc->ch_ag, ch, ag);
172
173 if (++pattern == ARRAY_SIZE(analog_pattern_str))
174 pattern = 0;
175 }
33ef7573 176 }
33ef7573
JH
177
178 sdi->priv = devc;
179
43376f33 180 return std_scan_complete(di, g_slist_append(NULL, sdi));
6239c175
UH
181}
182
6078d2c9 183static int dev_open(struct sr_dev_inst *sdi)
6239c175 184{
7e463623 185 (void)sdi;
697785d1 186
e46b8fb1 187 return SR_OK;
6239c175
UH
188}
189
6078d2c9 190static int dev_close(struct sr_dev_inst *sdi)
6239c175 191{
f1ba6b4b 192 (void)sdi;
697785d1
UH
193
194 return SR_OK;
6239c175
UH
195}
196
ed0b7fed
BV
197static void clear_helper(void *priv)
198{
199 struct dev_context *devc;
49224c28
BV
200 GHashTableIter iter;
201 void *value;
ed0b7fed
BV
202
203 devc = priv;
49224c28
BV
204
205 /* Analog generators. */
206 g_hash_table_iter_init(&iter, devc->ch_ag);
207 while (g_hash_table_iter_next(&iter, NULL, &value))
208 g_free(value);
209 g_hash_table_unref(devc->ch_ag);
ed0b7fed
BV
210 g_free(devc);
211}
212
6ab68731 213static int dev_clear(const struct sr_dev_driver *di)
6239c175 214{
ed0b7fed 215 return std_dev_clear(di, clear_helper);
6239c175
UH
216}
217
584560f1 218static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
53b4680f 219 const struct sr_channel_group *cg)
6239c175 220{
c07f60e7 221 struct dev_context *devc;
ba7dd8bb 222 struct sr_channel *ch;
2388ae86
BV
223 struct analog_gen *ag;
224 int pattern;
6f57fd96 225
2388ae86
BV
226 if (!sdi)
227 return SR_ERR_ARG;
8f996b89 228
c07f60e7 229 devc = sdi->priv;
584560f1 230 switch (key) {
123e1313 231 case SR_CONF_SAMPLERATE:
a7684294 232 *data = g_variant_new_uint64(devc->cur_samplerate);
6239c175 233 break;
2474d87e 234 case SR_CONF_LIMIT_SAMPLES:
a7684294 235 *data = g_variant_new_uint64(devc->limit_samples);
2474d87e
BV
236 break;
237 case SR_CONF_LIMIT_MSEC:
a7684294 238 *data = g_variant_new_uint64(devc->limit_msec);
2474d87e 239 break;
7a8a1aba
BG
240 case SR_CONF_AVERAGING:
241 *data = g_variant_new_boolean(devc->avg);
242 break;
243 case SR_CONF_AVG_SAMPLES:
244 *data = g_variant_new_uint64(devc->avg_samples);
245 break;
2474d87e 246 case SR_CONF_PATTERN_MODE:
53b4680f 247 if (!cg)
660e398f 248 return SR_ERR_CHANNEL_GROUP;
49224c28 249 /* Any channel in the group will do. */
ba7dd8bb 250 ch = cg->channels->data;
3f239f08 251 if (ch->type == SR_CHANNEL_LOGIC) {
2388ae86
BV
252 pattern = devc->logic_pattern;
253 *data = g_variant_new_string(logic_pattern_str[pattern]);
3f239f08 254 } else if (ch->type == SR_CHANNEL_ANALOG) {
49224c28 255 ag = g_hash_table_lookup(devc->ch_ag, ch);
2388ae86
BV
256 pattern = ag->pattern;
257 *data = g_variant_new_string(analog_pattern_str[pattern]);
258 } else
259 return SR_ERR_BUG;
c07f60e7 260 break;
dddabe37
BV
261 case SR_CONF_AMPLITUDE:
262 if (!cg)
263 return SR_ERR_CHANNEL_GROUP;
49224c28 264 /* Any channel in the group will do. */
dddabe37
BV
265 ch = cg->channels->data;
266 if (ch->type != SR_CHANNEL_ANALOG)
267 return SR_ERR_ARG;
49224c28 268 ag = g_hash_table_lookup(devc->ch_ag, ch);
dddabe37
BV
269 *data = g_variant_new_double(ag->amplitude);
270 break;
7dfcf010 271 default:
bd6fbf62 272 return SR_ERR_NA;
6239c175
UH
273 }
274
dfb0fa1a 275 return SR_OK;
6239c175
UH
276}
277
584560f1 278static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
53b4680f 279 const struct sr_channel_group *cg)
6239c175 280{
8b2d41ed 281 struct dev_context *devc;
4374219b 282 struct analog_gen *ag;
ba7dd8bb 283 struct sr_channel *ch;
49224c28
BV
284 GSList *l;
285 int logic_pattern, analog_pattern, ret;
61c39f54 286 unsigned int i;
1b79df2f 287 const char *stropt;
6239c175 288
8b2d41ed 289 devc = sdi->priv;
6239c175 290
2388ae86 291 ret = SR_OK;
584560f1 292 switch (key) {
2388ae86 293 case SR_CONF_SAMPLERATE:
a7684294 294 devc->cur_samplerate = g_variant_get_uint64(data);
2388ae86
BV
295 break;
296 case SR_CONF_LIMIT_SAMPLES:
a7684294
JH
297 devc->limit_msec = 0;
298 devc->limit_samples = g_variant_get_uint64(data);
2388ae86
BV
299 break;
300 case SR_CONF_LIMIT_MSEC:
a7684294
JH
301 devc->limit_msec = g_variant_get_uint64(data);
302 devc->limit_samples = 0;
2388ae86 303 break;
7a8a1aba
BG
304 case SR_CONF_AVERAGING:
305 devc->avg = g_variant_get_boolean(data);
306 sr_dbg("%s averaging", devc->avg ? "Enabling" : "Disabling");
307 break;
308 case SR_CONF_AVG_SAMPLES:
309 devc->avg_samples = g_variant_get_uint64(data);
310 sr_dbg("Setting averaging rate to %" PRIu64, devc->avg_samples);
311 break;
2388ae86 312 case SR_CONF_PATTERN_MODE:
53b4680f 313 if (!cg)
660e398f 314 return SR_ERR_CHANNEL_GROUP;
d00088ca 315 stropt = g_variant_get_string(data, NULL);
49224c28
BV
316 logic_pattern = analog_pattern = -1;
317 for (i = 0; i < ARRAY_SIZE(logic_pattern_str); i++) {
318 if (!strcmp(stropt, logic_pattern_str[i])) {
319 logic_pattern = i;
320 break;
8b2d41ed 321 }
49224c28
BV
322 }
323 for (i = 0; i < ARRAY_SIZE(analog_pattern_str); i++) {
324 if (!strcmp(stropt, analog_pattern_str[i])) {
325 analog_pattern = i;
326 break;
8b2d41ed 327 }
49224c28
BV
328 }
329 if (logic_pattern == -1 && analog_pattern == -1)
330 return SR_ERR_ARG;
331 for (l = cg->channels; l; l = l->next) {
332 ch = l->data;
333 if (ch->type == SR_CHANNEL_LOGIC) {
334 if (logic_pattern == -1)
335 return SR_ERR_ARG;
336 sr_dbg("Setting logic pattern to %s",
337 logic_pattern_str[logic_pattern]);
338 devc->logic_pattern = logic_pattern;
339 /* Might as well do this now, these are static. */
340 if (logic_pattern == PATTERN_ALL_LOW)
341 memset(devc->logic_data, 0x00, LOGIC_BUFSIZE);
342 else if (logic_pattern == PATTERN_ALL_HIGH)
343 memset(devc->logic_data, 0xff, LOGIC_BUFSIZE);
344 } else if (ch->type == SR_CHANNEL_ANALOG) {
345 if (analog_pattern == -1)
346 return SR_ERR_ARG;
347 sr_dbg("Setting analog pattern for channel %s to %s",
348 ch->name, analog_pattern_str[analog_pattern]);
349 ag = g_hash_table_lookup(devc->ch_ag, ch);
350 ag->pattern = analog_pattern;
351 } else
352 return SR_ERR_BUG;
353 }
2388ae86 354 break;
dddabe37
BV
355 case SR_CONF_AMPLITUDE:
356 if (!cg)
357 return SR_ERR_CHANNEL_GROUP;
49224c28
BV
358 for (l = cg->channels; l; l = l->next) {
359 ch = l->data;
360 if (ch->type != SR_CHANNEL_ANALOG)
361 return SR_ERR_ARG;
362 ag = g_hash_table_lookup(devc->ch_ag, ch);
363 ag->amplitude = g_variant_get_double(data);
364 }
dddabe37 365 break;
2388ae86 366 default:
bd6fbf62 367 ret = SR_ERR_NA;
6239c175
UH
368 }
369
370 return ret;
371}
372
584560f1 373static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
53b4680f 374 const struct sr_channel_group *cg)
a1c743fc 375{
ba7dd8bb 376 struct sr_channel *ch;
d00088ca
BV
377 GVariant *gvar;
378 GVariantBuilder gvb;
a1c743fc 379
7a1da331 380 if (key == SR_CONF_SCAN_OPTIONS) {
584560f1
BV
381 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
382 scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
7a1da331
BV
383 return SR_OK;
384 }
385
390795c0
BV
386 if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
387 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
1e4a7cac 388 drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
390795c0
BV
389 return SR_OK;
390 }
391
7a1da331
BV
392 if (!sdi)
393 return SR_ERR_ARG;
394
53b4680f 395 if (!cg) {
7a1da331
BV
396 switch (key) {
397 case SR_CONF_DEVICE_OPTIONS:
584560f1 398 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
1e4a7cac 399 devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
7a1da331
BV
400 break;
401 case SR_CONF_SAMPLERATE:
402 g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
403 gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,
404 ARRAY_SIZE(samplerates), sizeof(uint64_t));
405 g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar);
406 *data = g_variant_builder_end(&gvb);
407 break;
408 default:
409 return SR_ERR_NA;
410 }
411 } else {
ba7dd8bb 412 ch = cg->channels->data;
7a1da331
BV
413 switch (key) {
414 case SR_CONF_DEVICE_OPTIONS:
49224c28 415 if (ch->type == SR_CHANNEL_LOGIC)
8249889d 416 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
49224c28 417 devopts_cg_logic, ARRAY_SIZE(devopts_cg_logic),
584560f1 418 sizeof(uint32_t));
e2b99f04
SA
419 else if (ch->type == SR_CHANNEL_ANALOG) {
420 if (strcmp(cg->name, "Analog") == 0)
421 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
422 devopts_cg_analog_group, ARRAY_SIZE(devopts_cg_analog_group),
423 sizeof(uint32_t));
424 else
425 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
426 devopts_cg_analog_channel, ARRAY_SIZE(devopts_cg_analog_channel),
427 sizeof(uint32_t));
428 }
49224c28
BV
429 else
430 return SR_ERR_BUG;
7a1da331
BV
431 break;
432 case SR_CONF_PATTERN_MODE:
e2b99f04
SA
433 /* The analog group (with all 4 channels) shall not have a pattern property. */
434 if (strcmp(cg->name, "Analog") == 0)
435 return SR_ERR_NA;
436
3f239f08 437 if (ch->type == SR_CHANNEL_LOGIC)
7a1da331
BV
438 *data = g_variant_new_strv(logic_pattern_str,
439 ARRAY_SIZE(logic_pattern_str));
3f239f08 440 else if (ch->type == SR_CHANNEL_ANALOG)
7a1da331
BV
441 *data = g_variant_new_strv(analog_pattern_str,
442 ARRAY_SIZE(analog_pattern_str));
2388ae86
BV
443 else
444 return SR_ERR_BUG;
7a1da331
BV
445 break;
446 default:
447 return SR_ERR_NA;
448 }
a1c743fc
BV
449 }
450
451 return SR_OK;
452}
453
695dc859 454static int dev_acquisition_start(const struct sr_dev_inst *sdi)
6239c175 455{
61c39f54 456 struct dev_context *devc;
1b7b72d4
GS
457 GSList *l;
458 struct sr_channel *ch;
4a465510
GS
459 int bitpos;
460 uint8_t mask;
49224c28
BV
461 GHashTableIter iter;
462 void *value;
85b5af06 463
61c39f54 464 devc = sdi->priv;
a49a320d 465 devc->sent_samples = 0;
85b5af06 466
4a465510
GS
467 /*
468 * Determine the numbers of logic and analog channels that are
469 * involved in the acquisition. Determine an offset and a mask to
470 * remove excess logic data content before datafeed submission.
471 */
1b7b72d4
GS
472 devc->enabled_logic_channels = 0;
473 devc->enabled_analog_channels = 0;
474 for (l = sdi->channels; l; l = l->next) {
475 ch = l->data;
476 if (!ch->enabled)
477 continue;
478 if (ch->type == SR_CHANNEL_ANALOG) {
479 devc->enabled_analog_channels++;
480 continue;
481 }
4a465510 482 if (ch->type != SR_CHANNEL_LOGIC)
1b7b72d4 483 continue;
4a465510
GS
484 /*
485 * TODO: Need we create a channel map here, such that the
486 * session datafeed packets will have a dense representation
487 * of the enabled channels' data? For example store channels
488 * D3 and D5 in bit positions 0 and 1 respectively, when all
489 * other channels are disabled? The current implementation
490 * generates a sparse layout, might provide data for logic
491 * channels that are disabled while it might suppress data
492 * from enabled channels at the same time.
493 */
494 devc->enabled_logic_channels++;
1b7b72d4 495 }
4a465510
GS
496 devc->first_partial_logic_index = devc->enabled_logic_channels / 8;
497 bitpos = devc->enabled_logic_channels % 8;
498 mask = (1 << bitpos) - 1;
499 devc->first_partial_logic_mask = mask;
500 sr_dbg("DBG: %s(), num logic %zu, partial off %zu, mask 0x%02x",
501 __func__, devc->enabled_logic_channels,
502 devc->first_partial_logic_index,
503 devc->first_partial_logic_mask);
504
505 /*
506 * Have the waveform for analog patterns pre-generated. It's
507 * supposed to be periodic, so the generator just needs to
508 * access the prepared sample data (DDS style).
509 */
49224c28
BV
510 g_hash_table_iter_init(&iter, devc->ch_ag);
511 while (g_hash_table_iter_next(&iter, NULL, &value))
ba508e22 512 demo_generate_analog_pattern(value, devc->cur_samplerate);
4374219b 513
98c01fe1 514 sr_session_source_add(sdi->session, -1, 0, 100,
ba508e22 515 demo_prepare_data, (struct sr_dev_inst *)sdi);
85b5af06 516
bee2b016 517 std_session_send_df_header(sdi);
f366e86c 518
3b203673 519 /* We use this timestamp to decide how many more samples to send. */
a49a320d
DE
520 devc->start_us = g_get_monotonic_time();
521 devc->spent_us = 0;
471ac344 522 devc->step = 0;
3b203673 523
e46b8fb1 524 return SR_OK;
6239c175
UH
525}
526
695dc859 527static int dev_acquisition_stop(struct sr_dev_inst *sdi)
6239c175 528{
027bf077 529 sr_session_source_remove(sdi->session, -1);
bee2b016 530 std_session_send_df_end(sdi);
7fd3e859 531
3010f21c 532 return SR_OK;
6239c175
UH
533}
534
dd5c48a6 535static struct sr_dev_driver demo_driver_info = {
e519ba86
UH
536 .name = "demo",
537 .longname = "Demo driver and pattern generator",
538 .api_version = 1,
c2fdcc25 539 .init = std_init,
700d6b64 540 .cleanup = std_cleanup,
6078d2c9 541 .scan = scan,
c01bf34c 542 .dev_list = std_dev_list,
6ab68731 543 .dev_clear = dev_clear,
035a1078
BV
544 .config_get = config_get,
545 .config_set = config_set,
a1c743fc 546 .config_list = config_list,
6078d2c9
UH
547 .dev_open = dev_open,
548 .dev_close = dev_close,
549 .dev_acquisition_start = dev_acquisition_start,
550 .dev_acquisition_stop = dev_acquisition_stop,
41812aca 551 .context = NULL,
6239c175 552};
dd5c48a6 553SR_REGISTER_DEV_DRIVER(demo_driver_info);