27 #include "sigrok-internal.h"
40 static const char *vcd_header_comment =
"\
41 $comment\n Acquisition with %d/%d probes at %s\n$end\n";
49 char *samplerate_s, *frequency_s, *timestamp;
52 if (!(ctx = g_try_malloc0(
sizeof(
struct context)))) {
53 sr_err(
"vcd out: %s: ctx malloc failed", __func__);
60 for (l = o->
dev->
probes; l; l = l->next) {
67 sr_err(
"vcd out: VCD only supports 94 probes.");
73 ctx->
header = g_string_sized_new(512);
74 num_probes = g_slist_length(o->
dev->
probes);
78 timestamp = g_strdup(ctime(&t));
79 timestamp[strlen(timestamp)-1] = 0;
80 g_string_printf(ctx->
header,
"$date %s $end\n", timestamp);
84 g_string_append_printf(ctx->
header,
"$version %s %s $end\n",
91 g_string_free(ctx->
header, TRUE);
95 g_string_append_printf(ctx->
header, vcd_header_comment,
109 g_string_free(ctx->
header, TRUE);
113 g_string_append_printf(ctx->
header,
"$timescale %s $end\n", frequency_s);
117 g_string_append_printf(ctx->
header,
"$scope module %s $end\n",
PACKAGE);
121 g_string_append_printf(ctx->
header,
"$var wire 1 %c %s $end\n",
125 g_string_append(ctx->
header,
"$upscope $end\n"
126 "$enddefinitions $end\n$dumpvars\n");
128 if (!(ctx->
prevbits = g_try_malloc0(
sizeof(
int) * num_probes))) {
129 g_string_free(ctx->
header, TRUE);
131 sr_err(
"vcd out: %s: ctx->prevbits malloc failed", __func__);
138 static int event(
struct sr_output *o,
int event_type, uint8_t **data_out,
139 uint64_t *length_out)
143 switch (event_type) {
145 outbuf = (uint8_t *)g_strdup(
"$dumpoff\n$end\n");
147 *length_out = strlen((
const char *)outbuf);
160 static int data(
struct sr_output *o,
const uint8_t *data_in,
161 uint64_t length_in, uint8_t **data_out, uint64_t *length_out)
165 int p, curbit, prevbit;
167 static uint64_t samplecount = 0;
169 int first_sample = 0;
172 out = g_string_sized_new(512);
176 g_string_append(out, ctx->
header->str);
177 g_string_free(ctx->
header, TRUE);
185 memcpy(&sample, data_in + i, ctx->
unitsize);
194 curbit = (sample & ((uint64_t) (1 << p))) >> p;
195 prevbit = (ctx->
prevsample & ((uint64_t) (1 << p))) >> p;
198 if (prevbit == curbit)
202 g_string_append_printf(out,
"#%" PRIu64
"\n%i%c\n",
203 (uint64_t)(((
float)samplecount / ctx->
samplerate)
204 * ctx->
period), curbit, (
char)(
'!' + p));
210 *data_out = (uint8_t *)out->str;
211 *length_out = out->len;
212 g_string_free(out, FALSE);
219 .description =
"Value Change Dump (VCD)",