2 * This file is part of the libsigrok project.
4 * Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
5 * Copyright (C) 2011 Olivier Fauchon <olivier@aixmarseille.com>
6 * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
7 * Copyright (C) 2015 Bartosz Golaszewski <bgolaszewski@baylibre.com>
8 * Copyright (C) 2019 Frank Stettner <frank-stettner@gmx.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
24 #ifndef LIBSIGROK_HARDWARE_DEMO_PROTOCOL_H
25 #define LIBSIGROK_HARDWARE_DEMO_PROTOCOL_H
28 #include <libsigrok/libsigrok.h>
29 #include "libsigrok-internal.h"
31 #define LOG_PREFIX "demo"
33 /* The size in bytes of chunks to send through the session bus. */
34 #define LOGIC_BUFSIZE 4096
35 /* Size of the analog pattern space per channel. */
36 #define ANALOG_BUFSIZE 4096
37 /* This is a development feature: it starts a new frame every n samples. */
38 #define SAMPLES_PER_FRAME 1000UL
39 #define DEFAULT_LIMIT_FRAMES 0
41 /* Logic patterns we can generate. */
42 enum logic_pattern_type {
44 * Spells "sigrok" across 8 channels using '0's (with '1's as
45 * "background") when displayed using the 'bits' output format.
46 * The pattern is repeated every 8 channels, shifted to the right
51 /** Pseudo-random values on all channels. */
55 * Incrementing number across 8 channels. The pattern is repeated
56 * every 8 channels, shifted to the right in time by one bit.
61 * Single bit "walking" across all logic channels by being
62 * shifted across data lines, restarting after the last line
63 * was used. An all-zero (all-one) state is inserted to prevent
64 * repetitive patterns (e.g. with 8 data lines, every 8th state
65 * would show the same line state)
70 /** All channels have a low logic state. */
73 /** All channels have a high logic state. */
77 * Mimics a cable squid. Derived from the "works with" logo
78 * to occupy a larger number of channels yet "painting"
79 * something that can get recognized.
83 /** Gray encoded data, like rotary encoder signals. */
87 /* Analog patterns we can generate. */
88 enum analog_pattern_type {
96 uint64_t cur_samplerate;
97 uint64_t limit_samples;
99 uint64_t limit_frames;
100 uint64_t sent_samples;
101 uint64_t sent_frame_samples; /* Number of samples that were sent for current frame. */
106 int32_t num_logic_channels;
107 size_t logic_unitsize;
108 uint64_t all_logic_channels_mask;
109 /* There is only ever one logic channel group, so its pattern goes here. */
110 enum logic_pattern_type logic_pattern;
111 uint8_t logic_data[LOGIC_BUFSIZE];
113 int32_t num_analog_channels;
115 gboolean avg; /* True if averaging is enabled */
116 uint64_t avg_samples;
117 size_t enabled_logic_channels;
118 size_t enabled_analog_channels;
119 size_t first_partial_logic_index;
120 uint8_t first_partial_logic_mask;
122 uint64_t capture_ratio;
123 gboolean trigger_fired;
124 struct soft_trigger_logic *stl;
127 static const char *analog_pattern_str[] = {
135 struct sr_channel *ch;
137 enum sr_mqflag mq_flags;
139 enum analog_pattern_type pattern;
141 float pattern_data[ANALOG_BUFSIZE];
142 unsigned int num_samples;
143 struct sr_datafeed_analog packet;
144 struct sr_analog_encoding encoding;
145 struct sr_analog_meaning meaning;
146 struct sr_analog_spec spec;
147 float avg_val; /* Average value */
148 unsigned int num_avgs; /* Number of samples averaged */
151 SR_PRIV void demo_generate_analog_pattern(struct analog_gen *ag, uint64_t sample_rate);
152 SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data);