From: HÃ¥vard Espeland Date: Sun, 16 Jan 2011 16:34:49 +0000 (+0100) Subject: output_vcd: Remember samples between packets. X-Git-Tag: libsigrok-0.1.0~418 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=08b488b84896d0e29c401c67f7bda7fed968f9ca;p=libsigrok.git output_vcd: Remember samples between packets. Fixes two bugs in vcd output: 1) Waveform did not match original input when viewed in gtkwave. 2) No vcd output when using 1 MHz sampling on Sigma. --- diff --git a/output/output_vcd.c b/output/output_vcd.c index 2157c1ba..2ea64538 100644 --- a/output/output_vcd.c +++ b/output/output_vcd.c @@ -31,6 +31,7 @@ struct context { char *probelist[65]; int *prevbits; GString *header; + uint64_t prevsample; }; const char *vcd_header = "\ @@ -169,9 +170,10 @@ static int data(struct output *o, char *data_in, uint64_t length_in, struct context *ctx; unsigned int i; int p, curbit, prevbit; - uint64_t sample, prevsample; + uint64_t sample; static uint64_t samplecount = 0; GString *out; + int first_sample = 0; ctx = o->internal; out = g_string_sized_new(512); @@ -181,19 +183,24 @@ static int data(struct output *o, char *data_in, uint64_t length_in, g_string_append(out, ctx->header->str); g_string_free(ctx->header, TRUE); ctx->header = NULL; + first_sample = 1; } for (i = 0; i <= length_in - ctx->unitsize; i += ctx->unitsize) { samplecount++; + memcpy(&sample, data_in + i, ctx->unitsize); - if (i == 0) - prevsample = sample; - else - memcpy(&prevsample, data_in + i - 1, ctx->unitsize); + + if (first_sample) { + /* First packet. We neg to make sure sample is stored. */ + ctx->prevsample = ~sample; + first_sample = 0; + } + for (p = 0; p < ctx->num_enabled_probes; p++) { curbit = (sample & ((uint64_t) (1 << p))) >> p; - prevbit = (prevsample & ((uint64_t) (1 << p))) >> p; + prevbit = (ctx->prevsample & ((uint64_t) (1 << p))) >> p; /* VCD only contains deltas/changes of signals. */ if (prevbit == curbit) @@ -203,6 +210,8 @@ static int data(struct output *o, char *data_in, uint64_t length_in, g_string_append_printf(out, "#%" PRIu64 "\n%i%c\n", samplecount, curbit, (char)('!' + p)); } + + ctx->prevsample = sample; } *data_out = out->str;