X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=output%2Fvcd.c;h=ffc753281a53f0f0b45c1bea8f2a53ae95da4546;hb=563080a8d1f1737578a313b89995a9da6ec1077c;hp=d1526c1b6587e076732b343b07a9c81c692df156;hpb=3544f848e0d7f67af8e11ce7ec344b34cd797df3;p=libsigrok.git diff --git a/output/vcd.c b/output/vcd.c index d1526c1b..ffc75328 100644 --- a/output/vcd.c +++ b/output/vcd.c @@ -35,6 +35,7 @@ struct context { uint8_t *prevsample; int period; uint64_t samplerate; + uint64_t samplecount; unsigned int unitsize; }; @@ -62,6 +63,8 @@ static int init(struct sr_output *o) for (l = o->sdi->probes; l; l = l->next) { probe = l->data; + if (probe->type != SR_PROBE_LOGIC) + continue; if (!probe->enabled) continue; ctx->probeindices = g_array_append_val( @@ -124,6 +127,8 @@ static int init(struct sr_output *o) /* Wires / channels */ for (i = 0, l = o->sdi->probes; l; l = l->next, i++) { probe = l->data; + if (probe->type != SR_PROBE_LOGIC) + continue; if (!probe->enabled) continue; g_string_append_printf(ctx->header, "$var wire 1 %c %s $end\n", @@ -151,7 +156,6 @@ static int receive(struct sr_output *o, const struct sr_dev_inst *sdi, unsigned int i; int p, curbit, prevbit, index; uint8_t *sample; - static uint64_t samplecount = 0; (void)sdi; @@ -170,31 +174,31 @@ static int receive(struct sr_output *o, const struct sr_dev_inst *sdi, /* The header is still here, this must be the first packet. */ *out = ctx->header; ctx->header = NULL; + ctx->samplecount = 0; } else { *out = g_string_sized_new(512); } logic = packet->payload; for (i = 0; i <= logic->length - logic->unitsize; i += logic->unitsize) { - samplecount++; - sample = logic->data + i; for (p = 0; p < ctx->num_enabled_probes; p++) { index = g_array_index(ctx->probeindices, int, p); - curbit = (sample[p / 8] & (((uint8_t) 1) << index)) >> index; - prevbit = (ctx->prevsample[p / 8] & (((uint8_t) 1) << index)) >> index; + curbit = ((unsigned)sample[index / 8] >> (index % 8)) & 1; + prevbit = ((unsigned)ctx->prevsample[index / 8] >> (index % 8)) & 1; /* VCD only contains deltas/changes of signals. */ - if (prevbit == curbit) + if (prevbit == curbit && ctx->samplecount > 0) continue; /* Output which signal changed to which value. */ - g_string_append_printf(*out, "#%" PRIu64 "\n%i%c\n", - (uint64_t)(((float)samplecount / ctx->samplerate) - * ctx->period), curbit, (char)('!' + p)); + g_string_append_printf(*out, "#%.0f\n%i%c\n", + (double)ctx->samplecount / ctx->samplerate * ctx->period, + curbit, (char)('!' + p)); } + ctx->samplecount++; memcpy(ctx->prevsample, sample, ctx->unitsize); }