]> sigrok.org Git - libsigrok.git/blob - src/hardware/demo/api.c
demo: Get/Set measurement quantity for the analog channels.
[libsigrok.git] / src / hardware / demo / api.c
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
5  * Copyright (C) 2011 Olivier Fauchon <olivier@aixmarseille.com>
6  * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
7  * Copyright (C) 2015 Bartosz Golaszewski <bgolaszewski@baylibre.com>
8  * Copyright (C) 2019 Frank Stettner <frank-stettner@gmx.net>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, see <http://www.gnu.org/licenses/>.
22  */
23
24 #include <config.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <math.h>
28 #include <libsigrok/libsigrok.h>
29 #include "libsigrok-internal.h"
30 #include "protocol.h"
31
32 #define DEFAULT_NUM_LOGIC_CHANNELS              8
33 #define DEFAULT_LOGIC_PATTERN                   PATTERN_SIGROK
34
35 #define DEFAULT_NUM_ANALOG_CHANNELS             4
36 #define DEFAULT_ANALOG_ENCODING_DIGITS  4
37 #define DEFAULT_ANALOG_SPEC_DIGITS              4
38 #define DEFAULT_ANALOG_AMPLITUDE                10
39
40 /* Note: No spaces allowed because of sigrok-cli. */
41 static const char *logic_pattern_str[] = {
42         "sigrok",
43         "random",
44         "incremental",
45         "walking-one",
46         "walking-zero",
47         "all-low",
48         "all-high",
49         "squid",
50         "graycode",
51 };
52
53 static const uint32_t scanopts[] = {
54         SR_CONF_NUM_LOGIC_CHANNELS,
55         SR_CONF_NUM_ANALOG_CHANNELS,
56         SR_CONF_LIMIT_FRAMES,
57 };
58
59 static const uint32_t drvopts[] = {
60         SR_CONF_DEMO_DEV,
61         SR_CONF_LOGIC_ANALYZER,
62         SR_CONF_OSCILLOSCOPE,
63 };
64
65 static const uint32_t devopts[] = {
66         SR_CONF_CONTINUOUS,
67         SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
68         SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
69         SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET,
70         SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
71         SR_CONF_AVERAGING | SR_CONF_GET | SR_CONF_SET,
72         SR_CONF_AVG_SAMPLES | SR_CONF_GET | SR_CONF_SET,
73         SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
74         SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET,
75 };
76
77 static const uint32_t devopts_cg_logic[] = {
78         SR_CONF_PATTERN_MODE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
79 };
80
81 static const uint32_t devopts_cg_analog_group[] = {
82         SR_CONF_AMPLITUDE | SR_CONF_GET | SR_CONF_SET,
83 };
84
85 static const uint32_t devopts_cg_analog_channel[] = {
86         SR_CONF_MEASURED_QUANTITY | SR_CONF_GET | SR_CONF_SET,
87         SR_CONF_PATTERN_MODE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
88         SR_CONF_AMPLITUDE | SR_CONF_GET | SR_CONF_SET,
89 };
90
91 static const int32_t trigger_matches[] = {
92         SR_TRIGGER_ZERO,
93         SR_TRIGGER_ONE,
94         SR_TRIGGER_RISING,
95         SR_TRIGGER_FALLING,
96         SR_TRIGGER_EDGE,
97 };
98
99 static const uint64_t samplerates[] = {
100         SR_HZ(1),
101         SR_GHZ(1),
102         SR_HZ(1),
103 };
104
105 static GSList *scan(struct sr_dev_driver *di, GSList *options)
106 {
107         struct dev_context *devc;
108         struct sr_dev_inst *sdi;
109         struct sr_channel *ch;
110         struct sr_channel_group *cg, *acg;
111         struct sr_config *src;
112         struct analog_gen *ag;
113         GSList *l;
114         int num_logic_channels, num_analog_channels, pattern, i;
115         uint64_t limit_frames;
116         char channel_name[16];
117
118         num_logic_channels = DEFAULT_NUM_LOGIC_CHANNELS;
119         num_analog_channels = DEFAULT_NUM_ANALOG_CHANNELS;
120         limit_frames = DEFAULT_LIMIT_FRAMES;
121         for (l = options; l; l = l->next) {
122                 src = l->data;
123                 switch (src->key) {
124                 case SR_CONF_NUM_LOGIC_CHANNELS:
125                         num_logic_channels = g_variant_get_int32(src->data);
126                         break;
127                 case SR_CONF_NUM_ANALOG_CHANNELS:
128                         num_analog_channels = g_variant_get_int32(src->data);
129                         break;
130                 case SR_CONF_LIMIT_FRAMES:
131                         limit_frames = g_variant_get_uint64(src->data);
132                         break;
133                 }
134         }
135
136         sdi = g_malloc0(sizeof(struct sr_dev_inst));
137         sdi->status = SR_ST_INACTIVE;
138         sdi->model = g_strdup("Demo device");
139
140         devc = g_malloc0(sizeof(struct dev_context));
141         devc->cur_samplerate = SR_KHZ(200);
142         devc->num_logic_channels = num_logic_channels;
143         devc->logic_unitsize = (devc->num_logic_channels + 7) / 8;
144         devc->all_logic_channels_mask = 1UL << 0;
145         devc->all_logic_channels_mask <<= devc->num_logic_channels;
146         devc->all_logic_channels_mask--;
147         devc->logic_pattern = DEFAULT_LOGIC_PATTERN;
148         devc->num_analog_channels = num_analog_channels;
149         devc->limit_frames = limit_frames;
150         devc->capture_ratio = 20;
151         devc->stl = NULL;
152
153         if (num_logic_channels > 0) {
154                 /* Logic channels, all in one channel group. */
155                 cg = g_malloc0(sizeof(struct sr_channel_group));
156                 cg->name = g_strdup("Logic");
157                 for (i = 0; i < num_logic_channels; i++) {
158                         sprintf(channel_name, "D%d", i);
159                         ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name);
160                         cg->channels = g_slist_append(cg->channels, ch);
161                 }
162                 sdi->channel_groups = g_slist_append(NULL, cg);
163         }
164
165         /* Analog channels, channel groups and pattern generators. */
166         devc->ch_ag = g_hash_table_new(g_direct_hash, g_direct_equal);
167         if (num_analog_channels > 0) {
168                 pattern = 0;
169                 /* An "Analog" channel group with all analog channels in it. */
170                 acg = g_malloc0(sizeof(struct sr_channel_group));
171                 acg->name = g_strdup("Analog");
172                 sdi->channel_groups = g_slist_append(sdi->channel_groups, acg);
173
174                 for (i = 0; i < num_analog_channels; i++) {
175                         snprintf(channel_name, 16, "A%d", i);
176                         ch = sr_channel_new(sdi, i + num_logic_channels, SR_CHANNEL_ANALOG,
177                                         TRUE, channel_name);
178                         acg->channels = g_slist_append(acg->channels, ch);
179
180                         /* Every analog channel gets its own channel group as well. */
181                         cg = g_malloc0(sizeof(struct sr_channel_group));
182                         cg->name = g_strdup(channel_name);
183                         cg->channels = g_slist_append(NULL, ch);
184                         sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
185
186                         /* Every channel gets a generator struct. */
187                         ag = g_malloc(sizeof(struct analog_gen));
188                         ag->ch = ch;
189                         ag->mq = SR_MQ_VOLTAGE;
190                         ag->mq_flags = SR_MQFLAG_DC;
191                         ag->unit = SR_UNIT_VOLT;
192                         ag->amplitude = DEFAULT_ANALOG_AMPLITUDE;
193                         sr_analog_init(&ag->packet, &ag->encoding, &ag->meaning, &ag->spec, 2);
194                         ag->packet.meaning->channels = cg->channels;
195                         ag->packet.meaning->mq = ag->mq;
196                         ag->packet.meaning->mqflags = ag->mq_flags;
197                         ag->packet.meaning->unit = ag->unit;
198                         ag->packet.encoding->digits = DEFAULT_ANALOG_ENCODING_DIGITS;
199                         ag->packet.spec->spec_digits = DEFAULT_ANALOG_SPEC_DIGITS;
200                         ag->packet.data = ag->pattern_data;
201                         ag->pattern = pattern;
202                         ag->avg_val = 0.0f;
203                         ag->num_avgs = 0;
204                         g_hash_table_insert(devc->ch_ag, ch, ag);
205
206                         if (++pattern == ARRAY_SIZE(analog_pattern_str))
207                                 pattern = 0;
208                 }
209         }
210
211         sdi->priv = devc;
212
213         return std_scan_complete(di, g_slist_append(NULL, sdi));
214 }
215
216 static void clear_helper(struct dev_context *devc)
217 {
218         GHashTableIter iter;
219         void *value;
220
221         /* Analog generators. */
222         g_hash_table_iter_init(&iter, devc->ch_ag);
223         while (g_hash_table_iter_next(&iter, NULL, &value))
224                 g_free(value);
225         g_hash_table_unref(devc->ch_ag);
226 }
227
228 static int dev_clear(const struct sr_dev_driver *di)
229 {
230         return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper);
231 }
232
233 static int config_get(uint32_t key, GVariant **data,
234         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
235 {
236         struct dev_context *devc;
237         struct sr_channel *ch;
238         struct analog_gen *ag;
239         GVariant *mq_arr[2];
240         int pattern;
241
242         if (!sdi)
243                 return SR_ERR_ARG;
244
245         devc = sdi->priv;
246         switch (key) {
247         case SR_CONF_SAMPLERATE:
248                 *data = g_variant_new_uint64(devc->cur_samplerate);
249                 break;
250         case SR_CONF_LIMIT_SAMPLES:
251                 *data = g_variant_new_uint64(devc->limit_samples);
252                 break;
253         case SR_CONF_LIMIT_MSEC:
254                 *data = g_variant_new_uint64(devc->limit_msec);
255                 break;
256         case SR_CONF_LIMIT_FRAMES:
257                 *data = g_variant_new_uint64(devc->limit_frames);
258                 break;
259         case SR_CONF_AVERAGING:
260                 *data = g_variant_new_boolean(devc->avg);
261                 break;
262         case SR_CONF_AVG_SAMPLES:
263                 *data = g_variant_new_uint64(devc->avg_samples);
264                 break;
265         case SR_CONF_MEASURED_QUANTITY:
266                 if (!cg)
267                         return SR_ERR_CHANNEL_GROUP;
268                 /* Any channel in the group will do. */
269                 ch = cg->channels->data;
270                 if (ch->type != SR_CHANNEL_ANALOG)
271                         return SR_ERR_ARG;
272                 ag = g_hash_table_lookup(devc->ch_ag, ch);
273                 mq_arr[0] = g_variant_new_uint32(ag->mq);
274                 mq_arr[1] = g_variant_new_uint64(ag->mq_flags);
275                 *data = g_variant_new_tuple(mq_arr, 2);
276                 break;
277         case SR_CONF_PATTERN_MODE:
278                 if (!cg)
279                         return SR_ERR_CHANNEL_GROUP;
280                 /* Any channel in the group will do. */
281                 ch = cg->channels->data;
282                 if (ch->type == SR_CHANNEL_LOGIC) {
283                         pattern = devc->logic_pattern;
284                         *data = g_variant_new_string(logic_pattern_str[pattern]);
285                 } else if (ch->type == SR_CHANNEL_ANALOG) {
286                         ag = g_hash_table_lookup(devc->ch_ag, ch);
287                         pattern = ag->pattern;
288                         *data = g_variant_new_string(analog_pattern_str[pattern]);
289                 } else
290                         return SR_ERR_BUG;
291                 break;
292         case SR_CONF_AMPLITUDE:
293                 if (!cg)
294                         return SR_ERR_CHANNEL_GROUP;
295                 /* Any channel in the group will do. */
296                 ch = cg->channels->data;
297                 if (ch->type != SR_CHANNEL_ANALOG)
298                         return SR_ERR_ARG;
299                 ag = g_hash_table_lookup(devc->ch_ag, ch);
300                 *data = g_variant_new_double(ag->amplitude);
301                 break;
302         case SR_CONF_CAPTURE_RATIO:
303                 *data = g_variant_new_uint64(devc->capture_ratio);
304                 break;
305         default:
306                 return SR_ERR_NA;
307         }
308
309         return SR_OK;
310 }
311
312 static int config_set(uint32_t key, GVariant *data,
313         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
314 {
315         struct dev_context *devc;
316         struct analog_gen *ag;
317         struct sr_channel *ch;
318         GVariant *mq_tuple_child;
319         GSList *l;
320         int logic_pattern, analog_pattern;
321
322         devc = sdi->priv;
323
324         switch (key) {
325         case SR_CONF_SAMPLERATE:
326                 devc->cur_samplerate = g_variant_get_uint64(data);
327                 break;
328         case SR_CONF_LIMIT_SAMPLES:
329                 devc->limit_msec = 0;
330                 devc->limit_samples = g_variant_get_uint64(data);
331                 break;
332         case SR_CONF_LIMIT_MSEC:
333                 devc->limit_msec = g_variant_get_uint64(data);
334                 devc->limit_samples = 0;
335                 break;
336         case SR_CONF_LIMIT_FRAMES:
337                 devc->limit_frames = g_variant_get_uint64(data);
338                 break;
339         case SR_CONF_AVERAGING:
340                 devc->avg = g_variant_get_boolean(data);
341                 sr_dbg("%s averaging", devc->avg ? "Enabling" : "Disabling");
342                 break;
343         case SR_CONF_AVG_SAMPLES:
344                 devc->avg_samples = g_variant_get_uint64(data);
345                 sr_dbg("Setting averaging rate to %" PRIu64, devc->avg_samples);
346                 break;
347         case SR_CONF_MEASURED_QUANTITY:
348                 if (!cg)
349                         return SR_ERR_CHANNEL_GROUP;
350                 for (l = cg->channels; l; l = l->next) {
351                         ch = l->data;
352                         if (ch->type != SR_CHANNEL_ANALOG)
353                                 return SR_ERR_ARG;
354                         ag = g_hash_table_lookup(devc->ch_ag, ch);
355                         mq_tuple_child = g_variant_get_child_value(data, 0);
356                         ag->mq = g_variant_get_uint32(mq_tuple_child);
357                         mq_tuple_child = g_variant_get_child_value(data, 1);
358                         ag->mq_flags = g_variant_get_uint64(mq_tuple_child);
359                         g_variant_unref(mq_tuple_child);
360                 }
361                 break;
362         case SR_CONF_PATTERN_MODE:
363                 if (!cg)
364                         return SR_ERR_CHANNEL_GROUP;
365                 logic_pattern = std_str_idx(data, ARRAY_AND_SIZE(logic_pattern_str));
366                 analog_pattern = std_str_idx(data, ARRAY_AND_SIZE(analog_pattern_str));
367                 if (logic_pattern < 0 && analog_pattern < 0)
368                         return SR_ERR_ARG;
369                 for (l = cg->channels; l; l = l->next) {
370                         ch = l->data;
371                         if (ch->type == SR_CHANNEL_LOGIC) {
372                                 if (logic_pattern == -1)
373                                         return SR_ERR_ARG;
374                                 sr_dbg("Setting logic pattern to %s",
375                                                 logic_pattern_str[logic_pattern]);
376                                 devc->logic_pattern = logic_pattern;
377                                 /* Might as well do this now, these are static. */
378                                 if (logic_pattern == PATTERN_ALL_LOW)
379                                         memset(devc->logic_data, 0x00, LOGIC_BUFSIZE);
380                                 else if (logic_pattern == PATTERN_ALL_HIGH)
381                                         memset(devc->logic_data, 0xff, LOGIC_BUFSIZE);
382                         } else if (ch->type == SR_CHANNEL_ANALOG) {
383                                 if (analog_pattern == -1)
384                                         return SR_ERR_ARG;
385                                 sr_dbg("Setting analog pattern for channel %s to %s",
386                                                 ch->name, analog_pattern_str[analog_pattern]);
387                                 ag = g_hash_table_lookup(devc->ch_ag, ch);
388                                 ag->pattern = analog_pattern;
389                         } else
390                                 return SR_ERR_BUG;
391                 }
392                 break;
393         case SR_CONF_AMPLITUDE:
394                 if (!cg)
395                         return SR_ERR_CHANNEL_GROUP;
396                 for (l = cg->channels; l; l = l->next) {
397                         ch = l->data;
398                         if (ch->type != SR_CHANNEL_ANALOG)
399                                 return SR_ERR_ARG;
400                         ag = g_hash_table_lookup(devc->ch_ag, ch);
401                         ag->amplitude = g_variant_get_double(data);
402                 }
403                 break;
404         case SR_CONF_CAPTURE_RATIO:
405                 devc->capture_ratio = g_variant_get_uint64(data);
406                 break;
407         default:
408                 return SR_ERR_NA;
409         }
410
411         return SR_OK;
412 }
413
414 static int config_list(uint32_t key, GVariant **data,
415         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
416 {
417         struct sr_channel *ch;
418
419         if (!cg) {
420                 switch (key) {
421                 case SR_CONF_SCAN_OPTIONS:
422                 case SR_CONF_DEVICE_OPTIONS:
423                         return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
424                 case SR_CONF_SAMPLERATE:
425                         *data = std_gvar_samplerates_steps(ARRAY_AND_SIZE(samplerates));
426                         break;
427                 case SR_CONF_TRIGGER_MATCH:
428                         *data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches));
429                         break;
430                 default:
431                         return SR_ERR_NA;
432                 }
433         } else {
434                 ch = cg->channels->data;
435                 switch (key) {
436                 case SR_CONF_DEVICE_OPTIONS:
437                         if (ch->type == SR_CHANNEL_LOGIC)
438                                 *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_logic));
439                         else if (ch->type == SR_CHANNEL_ANALOG) {
440                                 if (strcmp(cg->name, "Analog") == 0)
441                                         *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_analog_group));
442                                 else
443                                         *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_analog_channel));
444                         }
445                         else
446                                 return SR_ERR_BUG;
447                         break;
448                 case SR_CONF_PATTERN_MODE:
449                         /* The analog group (with all 4 channels) shall not have a pattern property. */
450                         if (strcmp(cg->name, "Analog") == 0)
451                                 return SR_ERR_NA;
452
453                         if (ch->type == SR_CHANNEL_LOGIC)
454                                 *data = g_variant_new_strv(ARRAY_AND_SIZE(logic_pattern_str));
455                         else if (ch->type == SR_CHANNEL_ANALOG)
456                                 *data = g_variant_new_strv(ARRAY_AND_SIZE(analog_pattern_str));
457                         else
458                                 return SR_ERR_BUG;
459                         break;
460                 default:
461                         return SR_ERR_NA;
462                 }
463         }
464
465         return SR_OK;
466 }
467
468 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
469 {
470         struct dev_context *devc;
471         GSList *l;
472         struct sr_channel *ch;
473         int bitpos;
474         uint8_t mask;
475         GHashTableIter iter;
476         void *value;
477         struct sr_trigger *trigger;
478
479         devc = sdi->priv;
480         devc->sent_samples = 0;
481         devc->sent_frame_samples = 0;
482
483         /* Setup triggers */
484         if ((trigger = sr_session_trigger_get(sdi->session))) {
485                 int pre_trigger_samples = 0;
486                 if (devc->limit_samples > 0)
487                         pre_trigger_samples = (devc->capture_ratio * devc->limit_samples) / 100;
488                 devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
489                 if (!devc->stl)
490                         return SR_ERR_MALLOC;
491
492                 /* Disable all analog channels since using them when there are logic
493                  * triggers set up would require having pre-trigger sample buffers
494                  * for analog sample data.
495                  */
496                 for (l = sdi->channels; l; l = l->next) {
497                         ch = l->data;
498                         if (ch->type == SR_CHANNEL_ANALOG)
499                                 ch->enabled = FALSE;
500                 }
501         }
502         devc->trigger_fired = FALSE;
503
504         /*
505          * Determine the numbers of logic and analog channels that are
506          * involved in the acquisition. Determine an offset and a mask to
507          * remove excess logic data content before datafeed submission.
508          */
509         devc->enabled_logic_channels = 0;
510         devc->enabled_analog_channels = 0;
511         for (l = sdi->channels; l; l = l->next) {
512                 ch = l->data;
513                 if (!ch->enabled)
514                         continue;
515                 if (ch->type == SR_CHANNEL_ANALOG) {
516                         devc->enabled_analog_channels++;
517                         continue;
518                 }
519                 if (ch->type != SR_CHANNEL_LOGIC)
520                         continue;
521                 /*
522                  * TODO: Need we create a channel map here, such that the
523                  * session datafeed packets will have a dense representation
524                  * of the enabled channels' data? For example store channels
525                  * D3 and D5 in bit positions 0 and 1 respectively, when all
526                  * other channels are disabled? The current implementation
527                  * generates a sparse layout, might provide data for logic
528                  * channels that are disabled while it might suppress data
529                  * from enabled channels at the same time.
530                  */
531                 devc->enabled_logic_channels++;
532         }
533         devc->first_partial_logic_index = devc->enabled_logic_channels / 8;
534         bitpos = devc->enabled_logic_channels % 8;
535         mask = (1 << bitpos) - 1;
536         devc->first_partial_logic_mask = mask;
537         sr_dbg("num logic %zu, partial off %zu, mask 0x%02x.",
538                 devc->enabled_logic_channels,
539                 devc->first_partial_logic_index,
540                 devc->first_partial_logic_mask);
541
542         /*
543          * Have the waveform for analog patterns pre-generated. It's
544          * supposed to be periodic, so the generator just needs to
545          * access the prepared sample data (DDS style).
546          */
547         g_hash_table_iter_init(&iter, devc->ch_ag);
548         while (g_hash_table_iter_next(&iter, NULL, &value))
549                 demo_generate_analog_pattern(value, devc->cur_samplerate);
550
551         sr_session_source_add(sdi->session, -1, 0, 100,
552                         demo_prepare_data, (struct sr_dev_inst *)sdi);
553
554         std_session_send_df_header(sdi);
555
556         if (devc->limit_frames > 0)
557                 std_session_send_frame_begin(sdi);
558
559         /* We use this timestamp to decide how many more samples to send. */
560         devc->start_us = g_get_monotonic_time();
561         devc->spent_us = 0;
562         devc->step = 0;
563
564         return SR_OK;
565 }
566
567 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
568 {
569         struct dev_context *devc;
570
571         sr_session_source_remove(sdi->session, -1);
572
573         devc = sdi->priv;
574         if (devc->limit_frames > 0)
575                 std_session_send_frame_end(sdi);
576
577         std_session_send_df_end(sdi);
578
579         if (devc->stl) {
580                 soft_trigger_logic_free(devc->stl);
581                 devc->stl = NULL;
582         }
583
584         return SR_OK;
585 }
586
587 static struct sr_dev_driver demo_driver_info = {
588         .name = "demo",
589         .longname = "Demo driver and pattern generator",
590         .api_version = 1,
591         .init = std_init,
592         .cleanup = std_cleanup,
593         .scan = scan,
594         .dev_list = std_dev_list,
595         .dev_clear = dev_clear,
596         .config_get = config_get,
597         .config_set = config_set,
598         .config_list = config_list,
599         .dev_open = std_dummy_dev_open,
600         .dev_close = std_dummy_dev_close,
601         .dev_acquisition_start = dev_acquisition_start,
602         .dev_acquisition_stop = dev_acquisition_stop,
603         .context = NULL,
604 };
605 SR_REGISTER_DEV_DRIVER(demo_driver_info);