2 * This file is part of the sigrok project.
4 * Copyright (C) 2011 Bert Vermeulen <bert@biot.com>
5 * Copyright (C) 2011 HÃ¥vard Espeland <gus@ping.uio.no>
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.
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.
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/>.
27 int init_bits(struct sr_output *o)
29 return init(o, DEFAULT_BPL_BITS, MODE_BITS);
32 int data_bits(struct sr_output *o, const char *data_in, uint64_t length_in,
33 char **data_out, uint64_t *length_out)
36 unsigned int outsize, offset, p;
42 max_linelen = SR_MAX_PROBENAME_LEN + 3 + ctx->samples_per_line
43 + ctx->samples_per_line / 8;
45 * Calculate space needed for probes. Set aside 512 bytes for
46 * extra output, e.g. trigger.
48 outsize = 512 + (1 + (length_in / ctx->unitsize) / ctx->samples_per_line)
49 * (ctx->num_enabled_probes * max_linelen);
51 if (!(outbuf = calloc(1, outsize + 1)))
56 /* The header is still here, this must be the first packet. */
57 strncpy(outbuf, ctx->header, outsize);
61 /* Ensure first transition. */
62 memcpy(&ctx->prevsample, data_in, ctx->unitsize);
63 ctx->prevsample = ~ctx->prevsample;
66 if (length_in >= ctx->unitsize) {
67 for (offset = 0; offset <= length_in - ctx->unitsize;
68 offset += ctx->unitsize) {
69 memcpy(&sample, data_in + offset, ctx->unitsize);
70 for (p = 0; p < ctx->num_enabled_probes; p++) {
71 c = (sample & ((uint64_t) 1 << p)) ? '1' : '0';
72 ctx->linebuf[p * ctx->linebuf_len +
73 ctx->line_offset] = c;
78 /* Add a space every 8th bit. */
79 if ((ctx->spl_cnt & 7) == 0) {
80 for (p = 0; p < ctx->num_enabled_probes; p++)
81 ctx->linebuf[p * ctx->linebuf_len +
82 ctx->line_offset] = ' ';
87 if (ctx->spl_cnt >= ctx->samples_per_line) {
88 flush_linebufs(ctx, outbuf);
89 ctx->line_offset = ctx->spl_cnt = 0;
90 ctx->mark_trigger = -1;
94 g_message("short buffer (length_in=%" PRIu64 ")", length_in);
98 *length_out = strlen(outbuf);
103 struct sr_output_format output_text_bits = {
105 .description = "Bits (takes argument, default 64)",
106 .df_type = SR_DF_LOGIC,