]> sigrok.org Git - libsigrok.git/blame - src/input/vcd.c
Set DSLogic in logic analyzer mode.
[libsigrok.git] / src / input / vcd.c
CommitLineData
99eaa206 1/*
50985c20 2 * This file is part of the libsigrok project.
99eaa206 3 *
0157808d 4 * Copyright (C) 2012 Petteri Aimonen <jpa@sr.mail.kapsi.fi>
7db06394 5 * Copyright (C) 2014 Bert Vermeulen <bert@biot.com>
99eaa206
PA
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
0157808d
PA
21/* The VCD input module has the following options:
22 *
ba7dd8bb 23 * numchannels: Maximum number of channels to use. The channels are
0157808d
PA
24 * detected in the same order as they are listed
25 * in the $var sections of the VCD file.
26 *
27 * skip: Allows skipping until given timestamp in the file.
28 * This can speed up analyzing of long captures.
29 *
30 * Value < 0: Skip until first timestamp listed in
31 * the file. (default)
32 *
33 * Value = 0: Do not skip, instead generate samples
34 * beginning from timestamp 0.
35 *
36 * Value > 0: Start at the given timestamp.
37 *
38 * downsample: Divide the samplerate by the given factor.
39 * This can speed up analyzing of long captures.
40 *
6b7ace48
PA
41 * compress: Compress idle periods longer than this value.
42 * This can speed up analyzing of long captures.
43 * Default 0 = don't compress.
44 *
0157808d
PA
45 * Based on Verilog standard IEEE Std 1364-2001 Version C
46 *
47 * Supported features:
48 * - $var with 'wire' and 'reg' types of scalar variables
49 * - $timescale definition for samplerate
50 * - multiple character variable identifiers
51 *
52 * Most important unsupported features:
53 * - vector variables (bit vectors etc.)
54 * - analog, integer and real number variables
55 * - $dumpvars initial value declaration
8be87469 56 * - $scope namespaces
ba7dd8bb 57 * - more than 64 channels
0157808d
PA
58 */
59
6ec6c43b 60#include <config.h>
99eaa206
PA
61#include <stdlib.h>
62#include <glib.h>
63#include <stdio.h>
61a429c9 64#include <string.h>
c1aae900 65#include <libsigrok/libsigrok.h>
99eaa206
PA
66#include "libsigrok-internal.h"
67
3544f848 68#define LOG_PREFIX "input/vcd"
99eaa206 69
db0e5c99 70#define CHUNKSIZE (1024 * 1024)
e4c8a4d7
BV
71
72struct context {
c10ef17c 73 gboolean started;
7db06394 74 gboolean got_header;
e4c8a4d7 75 uint64_t samplerate;
7db06394
BV
76 unsigned int maxchannels;
77 unsigned int channelcount;
e4c8a4d7
BV
78 int downsample;
79 unsigned compress;
80 int64_t skip;
7db06394 81 gboolean skip_until_end;
ba7dd8bb 82 GSList *channels;
db0e5c99
PA
83 size_t bytes_per_sample;
84 size_t samples_in_buffer;
85 uint8_t *buffer;
86 uint8_t *current_levels;
e4c8a4d7
BV
87};
88
ba7dd8bb 89struct vcd_channel {
e4c8a4d7
BV
90 gchar *name;
91 gchar *identifier;
92};
93
e4c8a4d7 94/*
7db06394 95 * Reads a single VCD section from input file and parses it to name/contents.
99eaa206
PA
96 * e.g. $timescale 1ps $end => "timescale" "1ps"
97 */
7db06394 98static gboolean parse_section(GString *buf, gchar **name, gchar **contents)
99eaa206 99{
7db06394 100 GString *sname, *scontent;
99eaa206 101 gboolean status;
7db06394
BV
102 unsigned int pos;
103
104 *name = *contents = NULL;
105 status = FALSE;
106 pos = 0;
cd1b0e8f 107
7db06394
BV
108 /* Skip any initial white-space. */
109 while (pos < buf->len && g_ascii_isspace(buf->str[pos]))
110 pos++;
cd1b0e8f 111
99eaa206 112 /* Section tag should start with $. */
7db06394 113 if (buf->str[pos++] != '$')
99eaa206 114 return FALSE;
cd1b0e8f 115
99eaa206 116 sname = g_string_sized_new(32);
7db06394
BV
117 scontent = g_string_sized_new(128);
118
119 /* Read the section tag. */
120 while (pos < buf->len && !g_ascii_isspace(buf->str[pos]))
121 g_string_append_c(sname, buf->str[pos++]);
122
123 /* Skip whitespace before content. */
124 while (pos < buf->len && g_ascii_isspace(buf->str[pos]))
125 pos++;
126
127 /* Read the content. */
128 while (pos < buf->len - 4 && strncmp(buf->str + pos, "$end", 4))
129 g_string_append_c(scontent, buf->str[pos++]);
130
131 if (sname->len && pos < buf->len - 4 && !strncmp(buf->str + pos, "$end", 4)) {
132 status = TRUE;
133 pos += 4;
134 while (pos < buf->len && g_ascii_isspace(buf->str[pos]))
135 pos++;
136 g_string_erase(buf, 0, pos);
137 }
99eaa206 138
99eaa206 139 *name = g_string_free(sname, !status);
7db06394
BV
140 *contents = g_string_free(scontent, !status);
141 if (*contents)
142 g_strchomp(*contents);
143
99eaa206
PA
144 return status;
145}
146
ba7dd8bb 147static void free_channel(void *data)
db9679af 148{
ba7dd8bb
UH
149 struct vcd_channel *vcd_ch = data;
150 g_free(vcd_ch->name);
151 g_free(vcd_ch->identifier);
152 g_free(vcd_ch);
db9679af
ML
153}
154
99eaa206
PA
155/* Remove empty parts from an array returned by g_strsplit. */
156static void remove_empty_parts(gchar **parts)
157{
158 gchar **src = parts;
159 gchar **dest = parts;
e4c8a4d7 160 while (*src != NULL) {
99eaa206 161 if (**src != '\0')
99eaa206 162 *dest++ = *src;
99eaa206
PA
163 src++;
164 }
cd1b0e8f 165
99eaa206
PA
166 *dest = NULL;
167}
168
e4c8a4d7
BV
169/*
170 * Parse VCD header to get values for context structure.
99eaa206
PA
171 * The context structure should be zeroed before calling this.
172 */
7db06394 173static gboolean parse_header(const struct sr_input *in, GString *buf)
99eaa206 174{
ba7dd8bb 175 struct vcd_channel *vcd_ch;
7db06394
BV
176 uint64_t p, q;
177 struct context *inc;
178 gboolean status;
179 gchar *name, *contents, **parts;
99eaa206 180
7db06394
BV
181 inc = in->priv;
182 name = contents = NULL;
183 status = FALSE;
184 while (parse_section(buf, &name, &contents)) {
99eaa206 185 sr_dbg("Section '%s', contents '%s'.", name, contents);
cd1b0e8f 186
e4c8a4d7 187 if (g_strcmp0(name, "enddefinitions") == 0) {
99eaa206
PA
188 status = TRUE;
189 break;
e4c8a4d7
BV
190 } else if (g_strcmp0(name, "timescale") == 0) {
191 /*
192 * The standard allows for values 1, 10 or 100
193 * and units s, ms, us, ns, ps and fs.
7db06394 194 */
e4c8a4d7 195 if (sr_parse_period(contents, &p, &q) == SR_OK) {
7db06394 196 inc->samplerate = q / p;
e4c8a4d7 197 if (q % p != 0) {
99eaa206 198 /* Does not happen unless time value is non-standard */
0157808d 199 sr_warn("Inexact rounding of samplerate, %" PRIu64 " / %" PRIu64 " to %" PRIu64 " Hz.",
7db06394 200 q, p, inc->samplerate);
99eaa206 201 }
cd1b0e8f 202
7db06394 203 sr_dbg("Samplerate: %" PRIu64, inc->samplerate);
e4c8a4d7 204 } else {
99eaa206
PA
205 sr_err("Parsing timescale failed.");
206 }
e4c8a4d7 207 } else if (g_strcmp0(name, "var") == 0) {
e85e550d
WS
208 /* Format: $var type size identifier reference [opt. index] $end */
209 unsigned int length;
210
7db06394 211 parts = g_strsplit_set(contents, " \r\n\t", 0);
99eaa206 212 remove_empty_parts(parts);
e85e550d 213 length = g_strv_length(parts);
cd1b0e8f 214
e85e550d
WS
215 if (length != 4 && length != 5)
216 sr_warn("$var section should have 4 or 5 items");
99eaa206 217 else if (g_strcmp0(parts[0], "reg") != 0 && g_strcmp0(parts[0], "wire") != 0)
8be87469 218 sr_info("Unsupported signal type: '%s'", parts[0]);
99eaa206 219 else if (strtol(parts[1], NULL, 10) != 1)
8be87469 220 sr_info("Unsupported signal size: '%s'", parts[1]);
3f48fc82 221 else if (inc->maxchannels && inc->channelcount >= inc->maxchannels)
e85e550d
WS
222 sr_warn("Skipping '%s%s' because only %d channels requested.",
223 parts[3], parts[4] ? : "", inc->maxchannels);
e4c8a4d7 224 else {
ba7dd8bb
UH
225 vcd_ch = g_malloc(sizeof(struct vcd_channel));
226 vcd_ch->identifier = g_strdup(parts[2]);
e85e550d
WS
227 if (length == 4)
228 vcd_ch->name = g_strdup(parts[3]);
229 else
230 vcd_ch->name = g_strconcat(parts[3], parts[4], NULL);
231
232 sr_info("Channel %d is '%s' identified by '%s'.",
233 inc->channelcount, vcd_ch->name, vcd_ch->identifier);
234
ab464eb3 235 sr_channel_new(in->sdi, inc->channelcount++, SR_CHANNEL_LOGIC, TRUE, vcd_ch->name);
7db06394 236 inc->channels = g_slist_append(inc->channels, vcd_ch);
99eaa206 237 }
cd1b0e8f 238
99eaa206
PA
239 g_strfreev(parts);
240 }
cd1b0e8f 241
db0e5c99
PA
242 g_free(name);
243 name = NULL;
244 g_free(contents);
245 contents = NULL;
99eaa206 246 }
99eaa206
PA
247 g_free(name);
248 g_free(contents);
cd1b0e8f 249
db0e5c99
PA
250 /*
251 * Compute how many bytes each sample will have and initialize the
252 * current levels. The current levels will be updated whenever VCD
253 * has changes.
254 */
255 inc->bytes_per_sample = (inc->channelcount + 7) / 8;
256 inc->current_levels = g_malloc0(inc->bytes_per_sample);
257
7db06394
BV
258 inc->got_header = status;
259
99eaa206
PA
260 return status;
261}
262
7db06394 263static int format_match(GHashTable *metadata)
99eaa206 264{
7db06394 265 GString *buf, *tmpbuf;
99eaa206 266 gboolean status;
7db06394 267 gchar *name, *contents;
cd1b0e8f 268
7db06394
BV
269 buf = g_hash_table_lookup(metadata, GINT_TO_POINTER(SR_INPUT_META_HEADER));
270 tmpbuf = g_string_new_len(buf->str, buf->len);
99eaa206 271
e4c8a4d7
BV
272 /*
273 * If we can parse the first section correctly,
99eaa206
PA
274 * then it is assumed to be a VCD file.
275 */
7db06394
BV
276 status = parse_section(tmpbuf, &name, &contents);
277 g_string_free(tmpbuf, TRUE);
99eaa206
PA
278 g_free(name);
279 g_free(contents);
cd1b0e8f 280
4f979115 281 return status ? SR_OK : SR_ERR;
99eaa206
PA
282}
283
db0e5c99
PA
284/* Send all accumulated bytes from inc->buffer. */
285static void send_buffer(const struct sr_input *in)
61a429c9 286{
db0e5c99 287 struct context *inc;
61a429c9
PA
288 struct sr_datafeed_packet packet;
289 struct sr_datafeed_logic logic;
cd1b0e8f 290
db0e5c99 291 inc = in->priv;
61a429c9 292
db0e5c99
PA
293 if (inc->samples_in_buffer == 0)
294 return;
cd1b0e8f 295
61a429c9 296 packet.type = SR_DF_LOGIC;
cd1b0e8f 297 packet.payload = &logic;
db0e5c99
PA
298 logic.unitsize = inc->bytes_per_sample;
299 logic.data = inc->buffer;
300 logic.length = inc->bytes_per_sample * inc->samples_in_buffer;
301 sr_session_send(in->sdi, &packet);
302 inc->samples_in_buffer = 0;
303}
304
305/*
306 * Add N copies of the current sample to buffer.
307 * When the buffer fills up, automatically send it.
308 */
309static void add_samples(const struct sr_input *in, size_t count)
310{
311 struct context *inc;
312 size_t samples_per_chunk;
313 size_t space_left, i;
314 uint8_t *p;
315
316 inc = in->priv;
317 samples_per_chunk = CHUNKSIZE / inc->bytes_per_sample;
cd1b0e8f 318
e4c8a4d7 319 while (count) {
db0e5c99
PA
320 space_left = samples_per_chunk - inc->samples_in_buffer;
321
322 if (space_left > count)
323 space_left = count;
cd1b0e8f 324
db0e5c99
PA
325 p = inc->buffer + inc->samples_in_buffer * inc->bytes_per_sample;
326 for (i = 0; i < space_left; i++) {
327 memcpy(p, inc->current_levels, inc->bytes_per_sample);
328 p += inc->bytes_per_sample;
329 inc->samples_in_buffer++;
330 count--;
331 }
cd1b0e8f 332
db0e5c99
PA
333 if (inc->samples_in_buffer == samples_per_chunk)
334 send_buffer(in);
61a429c9
PA
335 }
336}
337
36dacf17
WS
338/* Set the channel level depending on the identifier and parsed value. */
339static void process_bit(struct context *inc, char *identifier, unsigned int bit)
340{
341 GSList *l;
342 struct vcd_channel *vcd_ch;
343 unsigned int j;
344
345 for (j = 0, l = inc->channels; j < inc->channelcount && l; j++, l = l->next) {
346 vcd_ch = l->data;
347 if (g_strcmp0(identifier, vcd_ch->identifier) == 0) {
348 /* Found our channel. */
349 size_t byte_idx = (j / 8);
350 size_t bit_idx = j - 8 * byte_idx;
351 if (bit)
352 inc->current_levels[byte_idx] |= (uint8_t)1 << bit_idx;
353 else
354 inc->current_levels[byte_idx] &= ~((uint8_t)1 << bit_idx);
355 break;
356 }
357 }
358 if (j == inc->channelcount)
359 sr_dbg("Did not find channel for identifier '%s'.", identifier);
360}
361
7db06394
BV
362/* Parse a set of lines from the data section. */
363static void parse_contents(const struct sr_input *in, char *data)
61a429c9 364{
7db06394 365 struct context *inc;
db0e5c99 366 uint64_t timestamp, prev_timestamp;
36dacf17 367 unsigned int bit, i;
7db06394 368 char **tokens;
cd1b0e8f 369
7db06394 370 inc = in->priv;
db0e5c99 371 prev_timestamp = 0;
cd1b0e8f 372
61a429c9 373 /* Read one space-delimited token at a time. */
7db06394
BV
374 tokens = g_strsplit_set(data, " \t\r\n", 0);
375 remove_empty_parts(tokens);
376 for (i = 0; tokens[i]; i++) {
377 if (inc->skip_until_end) {
378 if (!strcmp(tokens[i], "$end")) {
379 /* Done with unhandled/unknown section. */
380 inc->skip_until_end = FALSE;
381 break;
382 }
383 }
384 if (tokens[i][0] == '#' && g_ascii_isdigit(tokens[i][1])) {
61a429c9 385 /* Numeric value beginning with # is a new timestamp value */
7db06394 386 timestamp = strtoull(tokens[i] + 1, NULL, 10);
cd1b0e8f 387
7db06394
BV
388 if (inc->downsample > 1)
389 timestamp /= inc->downsample;
cd1b0e8f 390
e4c8a4d7
BV
391 /*
392 * Skip < 0 => skip until first timestamp.
0157808d
PA
393 * Skip = 0 => don't skip
394 * Skip > 0 => skip until timestamp >= skip.
395 */
7db06394
BV
396 if (inc->skip < 0) {
397 inc->skip = timestamp;
8be87469 398 prev_timestamp = timestamp;
7db06394
BV
399 } else if (inc->skip > 0 && timestamp < (uint64_t)inc->skip) {
400 prev_timestamp = inc->skip;
401 } else if (timestamp == prev_timestamp) {
8be87469 402 /* Ignore repeated timestamps (e.g. sigrok outputs these) */
7db06394
BV
403 } else {
404 if (inc->compress != 0 && timestamp - prev_timestamp > inc->compress) {
6b7ace48 405 /* Compress long idle periods */
7db06394 406 prev_timestamp = timestamp - inc->compress;
6b7ace48 407 }
cd1b0e8f 408
61a429c9 409 sr_dbg("New timestamp: %" PRIu64, timestamp);
cd1b0e8f 410
61a429c9 411 /* Generate samples from prev_timestamp up to timestamp - 1. */
db0e5c99 412 add_samples(in, timestamp - prev_timestamp);
0157808d 413 prev_timestamp = timestamp;
61a429c9 414 }
7db06394
BV
415 } else if (tokens[i][0] == '$' && tokens[i][1] != '\0') {
416 /*
417 * This is probably a $dumpvars, $comment or similar.
418 * $dump* contain useful data.
419 */
420 if (g_strcmp0(tokens[i], "$dumpvars") == 0
421 || g_strcmp0(tokens[i], "$dumpon") == 0
422 || g_strcmp0(tokens[i], "$dumpoff") == 0
423 || g_strcmp0(tokens[i], "$end") == 0) {
8be87469 424 /* Ignore, parse contents as normally. */
e4c8a4d7 425 } else {
7db06394
BV
426 /* Ignore this and future lines until $end. */
427 inc->skip_until_end = TRUE;
428 break;
8be87469 429 }
34724ffa
WS
430 } else if (strchr("rR", tokens[i][0]) != NULL) {
431 sr_dbg("Real type vector values not supported yet!");
76bc28c3
WS
432 if (!tokens[++i])
433 /* No tokens left, bail out */
434 break;
435 else
436 /* Process next token */
437 continue;
34724ffa
WS
438 } else if (strchr("bB", tokens[i][0]) != NULL) {
439 bit = (tokens[i][1] == '1');
440
441 /*
442 * Bail out if a) char after 'b' is NUL, or b) there is
443 * a second character after 'b', or c) there is no
444 * identifier.
445 */
446 if (!tokens[i][1] || tokens[i][2] || !tokens[++i]) {
447 sr_dbg("Unexpected vector format!");
448 break;
449 }
450
451 process_bit(inc, tokens[i], bit);
7db06394 452 } else if (strchr("01xXzZ", tokens[i][0]) != NULL) {
a66175c2
WS
453 char *identifier;
454
61a429c9 455 /* A new 1-bit sample value */
7db06394
BV
456 bit = (tokens[i][0] == '1');
457
458 /*
459 * The identifier is either the next character, or, if
460 * there was whitespace after the bit, the next token.
461 */
462 if (tokens[i][1] == '\0') {
73f052d3
WS
463 if (!tokens[++i]) {
464 sr_dbg("Identifier missing!");
465 break;
466 }
a66175c2 467 identifier = tokens[i];
7db06394 468 } else {
a66175c2 469 identifier = tokens[i] + 1;
61a429c9 470 }
36dacf17 471 process_bit(inc, identifier, bit);
e4c8a4d7 472 } else {
7db06394 473 sr_warn("Skipping unknown token '%s'.", tokens[i]);
8be87469 474 }
7db06394
BV
475 }
476 g_strfreev(tokens);
477}
478
479static int init(struct sr_input *in, GHashTable *options)
480{
7db06394
BV
481 struct context *inc;
482
d0181813 483 inc = in->priv = g_malloc0(sizeof(struct context));
cd1b0e8f 484
3f48fc82 485 inc->maxchannels = g_variant_get_int32(g_hash_table_lookup(options, "numchannels"));
7db06394
BV
486 inc->downsample = g_variant_get_int32(g_hash_table_lookup(options, "downsample"));
487 if (inc->downsample < 1)
488 inc->downsample = 1;
489
490 inc->compress = g_variant_get_int32(g_hash_table_lookup(options, "compress"));
491 inc->skip = g_variant_get_int32(g_hash_table_lookup(options, "skip"));
492 inc->skip /= inc->downsample;
493
aac29cc1 494 in->sdi = g_malloc0(sizeof(struct sr_dev_inst));
7db06394
BV
495 in->priv = inc;
496
db0e5c99
PA
497 inc->buffer = g_malloc(CHUNKSIZE);
498
7db06394 499 return SR_OK;
61a429c9
PA
500}
501
7db06394
BV
502static gboolean have_header(GString *buf)
503{
504 unsigned int pos;
505 char *p;
506
507 if (!(p = g_strstr_len(buf->str, buf->len, "$enddefinitions")))
508 return FALSE;
509 pos = p - buf->str + 15;
510 while (pos < buf->len - 4 && g_ascii_isspace(buf->str[pos]))
511 pos++;
512 if (!strncmp(buf->str + pos, "$end", 4))
513 return TRUE;
514
515 return FALSE;
516}
517
7066fd46 518static int process_buffer(struct sr_input *in)
99eaa206 519{
99eaa206 520 struct sr_datafeed_packet packet;
2df1e819
BV
521 struct sr_datafeed_meta meta;
522 struct sr_config *src;
7db06394 523 struct context *inc;
2df1e819 524 uint64_t samplerate;
7db06394
BV
525 char *p;
526
7db06394 527 inc = in->priv;
d0181813 528 if (!inc->started) {
7db06394 529 std_session_send_df_header(in->sdi, LOG_PREFIX);
99eaa206 530
7db06394
BV
531 packet.type = SR_DF_META;
532 packet.payload = &meta;
533 samplerate = inc->samplerate / inc->downsample;
534 src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(samplerate));
535 meta.config = g_slist_append(NULL, src);
536 sr_session_send(in->sdi, &packet);
c01378c9 537 g_slist_free(meta.config);
7db06394 538 sr_config_free(src);
d0181813
BV
539
540 inc->started = TRUE;
99eaa206
PA
541 }
542
7db06394
BV
543 while ((p = g_strrstr_len(in->buf->str, in->buf->len, "\n"))) {
544 *p = '\0';
545 g_strstrip(in->buf->str);
546 if (in->buf->str[0] != '\0')
547 parse_contents(in, in->buf->str);
548 g_string_erase(in->buf, 0, p - in->buf->str + 1);
549 }
99eaa206 550
7db06394
BV
551 return SR_OK;
552}
cd1b0e8f 553
7066fd46
BV
554static int receive(struct sr_input *in, GString *buf)
555{
556 struct context *inc;
557 int ret;
558
559 g_string_append_len(in->buf, buf->str, buf->len);
560
561 inc = in->priv;
562 if (!inc->got_header) {
563 if (!have_header(in->buf))
564 return SR_OK;
73931b7c 565 if (!parse_header(in, in->buf))
7066fd46
BV
566 /* There was a header in there, but it was malformed. */
567 return SR_ERR;
568
569 in->sdi_ready = TRUE;
570 /* sdi is ready, notify frontend. */
571 return SR_OK;
572 }
573
574 ret = process_buffer(in);
575
576 return ret;
577}
578
579static int end(struct sr_input *in)
7db06394 580{
c10ef17c 581 struct sr_datafeed_packet packet;
7db06394 582 struct context *inc;
7066fd46
BV
583 int ret;
584
db0e5c99
PA
585 inc = in->priv;
586
7066fd46
BV
587 if (in->sdi_ready)
588 ret = process_buffer(in);
589 else
590 ret = SR_OK;
99eaa206 591
db0e5c99
PA
592 /* Send any samples that haven't been sent yet. */
593 send_buffer(in);
594
c10ef17c 595 if (inc->started) {
c10ef17c
BV
596 packet.type = SR_DF_END;
597 sr_session_send(in->sdi, &packet);
598 }
599
7066fd46
BV
600 return ret;
601}
602
d5cc282f 603static void cleanup(struct sr_input *in)
7066fd46
BV
604{
605 struct context *inc;
606
607 inc = in->priv;
7db06394 608 g_slist_free_full(inc->channels, free_channel);
db0e5c99
PA
609 g_free(inc->buffer);
610 inc->buffer = NULL;
611 g_free(inc->current_levels);
612 inc->current_levels = NULL;
99eaa206
PA
613}
614
7db06394 615static struct sr_option options[] = {
5e83cd74 616 { "numchannels", "Number of channels", "Number of channels", NULL, NULL },
7db06394
BV
617 { "skip", "Skip", "Skip until timestamp", NULL, NULL },
618 { "downsample", "Downsample", "Divide samplerate by factor", NULL, NULL },
619 { "compress", "Compress", "Compress idle periods longer than this value", NULL, NULL },
06ad20be 620 ALL_ZERO
7db06394
BV
621};
622
2c240774 623static const struct sr_option *get_options(void)
7db06394
BV
624{
625 if (!options[0].def) {
3f48fc82 626 options[0].def = g_variant_ref_sink(g_variant_new_int32(0));
7db06394
BV
627 options[1].def = g_variant_ref_sink(g_variant_new_int32(-1));
628 options[2].def = g_variant_ref_sink(g_variant_new_int32(1));
629 options[3].def = g_variant_ref_sink(g_variant_new_int32(0));
630 }
631
632 return options;
633}
634
d4c93774 635SR_PRIV struct sr_input_module input_vcd = {
99eaa206 636 .id = "vcd",
7db06394 637 .name = "VCD",
17bfaca6 638 .desc = "Value Change Dump",
c7bc82ff 639 .exts = (const char*[]){"vcd", NULL},
7db06394
BV
640 .metadata = { SR_INPUT_META_HEADER | SR_INPUT_META_REQUIRED },
641 .options = get_options,
99eaa206
PA
642 .format_match = format_match,
643 .init = init,
7db06394 644 .receive = receive,
7066fd46 645 .end = end,
7db06394 646 .cleanup = cleanup,
99eaa206 647};