X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=output%2Fvcd.c;h=48bd4bb11148c86a3d085eb8ed544fe1f1755f81;hb=3a581560f1288b4cecc4ab885c85ac7603dd21db;hp=e1661e5c08cfc7367eecfd63315638f4f9fe9d32;hpb=d5585e32dd856b09d78acab2aac3ba6c78ad7752;p=libsigrok.git diff --git a/output/vcd.c b/output/vcd.c index e1661e5c..48bd4bb1 100644 --- a/output/vcd.c +++ b/output/vcd.c @@ -1,8 +1,8 @@ /* - * This file is part of the sigrok project. + * This file is part of the libsigrok project. * * Copyright (C) 2010 Uwe Hermann - * Copyright (C) 2010-2012 Bert Vermeulen + * Copyright (C) 2013 Bert Vermeulen * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -38,6 +38,7 @@ struct context { int num_enabled_probes; char *probelist[SR_MAX_NUM_PROBES + 1]; + int probeindices[SR_MAX_NUM_PROBES + 1]; int *prevbits; GString *header; uint64_t prevsample; @@ -53,7 +54,7 @@ static int init(struct sr_output *o) struct context *ctx; struct sr_probe *probe; GSList *l; - uint64_t *samplerate; + GVariant *gvar; int num_probes, i; char *samplerate_s, *frequency_s, *timestamp; time_t t; @@ -70,7 +71,9 @@ static int init(struct sr_output *o) probe = l->data; if (!probe->enabled) continue; - ctx->probelist[ctx->num_enabled_probes++] = probe->name; + ctx->probelist[ctx->num_enabled_probes] = probe->name; + ctx->probeindices[ctx->num_enabled_probes] = probe->index; + ctx->num_enabled_probes++; } if (ctx->num_enabled_probes > 94) { sr_err("VCD only supports 94 probes."); @@ -93,17 +96,18 @@ static int init(struct sr_output *o) PACKAGE, PACKAGE_VERSION); if (o->sdi->driver && sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) { - o->sdi->driver->config_get(SR_CONF_SAMPLERATE, - (const void **)&samplerate, o->sdi); - ctx->samplerate = *samplerate; + o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi); + ctx->samplerate = g_variant_get_uint64(gvar); if (!((samplerate_s = sr_samplerate_string(ctx->samplerate)))) { g_string_free(ctx->header, TRUE); g_free(ctx); + g_variant_unref(gvar); return SR_ERR; } g_string_append_printf(ctx->header, vcd_header_comment, ctx->num_enabled_probes, num_probes, samplerate_s); g_free(samplerate_s); + g_variant_unref(gvar); } /* timescale */ @@ -144,14 +148,14 @@ static int init(struct sr_output *o) return SR_OK; } -static GString *recv(struct sr_output *o, const struct sr_dev_inst *sdi, +static GString *receive(struct sr_output *o, const struct sr_dev_inst *sdi, const struct sr_datafeed_packet *packet) { const struct sr_datafeed_logic *logic; struct context *ctx; GString *text; unsigned int i; - int p, curbit, prevbit; + int p, curbit, prevbit, index; uint64_t sample; static uint64_t samplecount = 0; gboolean first_sample; @@ -192,8 +196,9 @@ static GString *recv(struct sr_output *o, const struct sr_dev_inst *sdi, } for (p = 0; p < ctx->num_enabled_probes; p++) { - curbit = (sample & ((uint64_t) (1 << p))) >> p; - prevbit = (ctx->prevsample & ((uint64_t) (1 << p))) >> p; + index = ctx->probeindices[p]; + curbit = (sample & (((uint64_t) 1) << index)) >> index; + prevbit = (ctx->prevsample & (((uint64_t) 1) << index)) >> index; /* VCD only contains deltas/changes of signals. */ if (prevbit == curbit) @@ -229,6 +234,6 @@ struct sr_output_format output_vcd = { .description = "Value Change Dump (VCD)", .df_type = SR_DF_LOGIC, .init = init, - .recv = recv, - .cleanup = cleanup + .recv = receive, + .cleanup = cleanup, };