]> sigrok.org Git - libsigrok.git/blame - src/hardware/demo/protocol.h
demo: add convenient bit mask for "all logic channels"
[libsigrok.git] / src / hardware / demo / protocol.h
CommitLineData
ba508e22
UH
1/*
2 * This file is part of the libsigrok project.
3 *
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 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
2ea1fdf1 20 * along with this program; if not, see <http://www.gnu.org/licenses/>.
ba508e22
UH
21 */
22
23#ifndef LIBSIGROK_HARDWARE_DEMO_PROTOCOL_H
24#define LIBSIGROK_HARDWARE_DEMO_PROTOCOL_H
25
26#include <stdint.h>
27#include <libsigrok/libsigrok.h>
28#include "libsigrok-internal.h"
29
30#define LOG_PREFIX "demo"
31
32/* The size in bytes of chunks to send through the session bus. */
33#define LOGIC_BUFSIZE 4096
34/* Size of the analog pattern space per channel. */
35#define ANALOG_BUFSIZE 4096
f55bea76
SA
36/* This is a development feature: it starts a new frame every n samples. */
37#define SAMPLES_PER_FRAME 0
ba508e22 38
ba508e22 39/* Logic patterns we can generate. */
817e759d 40enum logic_pattern_type {
ba508e22
UH
41 /**
42 * Spells "sigrok" across 8 channels using '0's (with '1's as
43 * "background") when displayed using the 'bits' output format.
44 * The pattern is repeated every 8 channels, shifted to the right
45 * in time by one bit.
46 */
47 PATTERN_SIGROK,
48
49 /** Pseudo-random values on all channels. */
50 PATTERN_RANDOM,
51
52 /**
53 * Incrementing number across 8 channels. The pattern is repeated
54 * every 8 channels, shifted to the right in time by one bit.
55 */
56 PATTERN_INC,
57
845060fa
SA
58 /**
59 * Single bit "walking" across all logic channels by being
60 * shifted across data lines, restarting after the last line
61 * was used. An all-zero (all-one) state is inserted to prevent
62 * repetitive patterns (e.g. with 8 data lines, every 8th state
63 * would show the same line state)
64 */
65 PATTERN_WALKING_ONE,
66 PATTERN_WALKING_ZERO,
67
ba508e22
UH
68 /** All channels have a low logic state. */
69 PATTERN_ALL_LOW,
70
71 /** All channels have a high logic state. */
72 PATTERN_ALL_HIGH,
81d53a29
GS
73
74 /**
75 * Mimics a cable squid. Derived from the "works with" logo
76 * to occupy a larger number of channels yet "painting"
77 * something that can get recognized.
78 */
79 PATTERN_SQUID,
ba508e22
UH
80};
81
82/* Analog patterns we can generate. */
817e759d 83enum analog_pattern_type {
ba508e22
UH
84 PATTERN_SQUARE,
85 PATTERN_SINE,
86 PATTERN_TRIANGLE,
87 PATTERN_SAWTOOTH,
88};
89
817e759d
GS
90struct dev_context {
91 uint64_t cur_samplerate;
92 uint64_t limit_samples;
93 uint64_t limit_msec;
94 uint64_t sent_samples;
95 uint64_t sent_frame_samples; /* Number of samples that were sent for current frame. */
96 int64_t start_us;
97 int64_t spent_us;
98 uint64_t step;
99 /* Logic */
100 int32_t num_logic_channels;
101 size_t logic_unitsize;
015f0970 102 uint64_t all_logic_channels_mask;
817e759d
GS
103 /* There is only ever one logic channel group, so its pattern goes here. */
104 enum logic_pattern_type logic_pattern;
105 uint8_t logic_data[LOGIC_BUFSIZE];
106 /* Analog */
107 int32_t num_analog_channels;
108 GHashTable *ch_ag;
109 gboolean avg; /* True if averaging is enabled */
110 uint64_t avg_samples;
111 size_t enabled_logic_channels;
112 size_t enabled_analog_channels;
113 size_t first_partial_logic_index;
114 uint8_t first_partial_logic_mask;
115};
116
ba508e22
UH
117static const char *analog_pattern_str[] = {
118 "square",
119 "sine",
120 "triangle",
121 "sawtooth",
122};
123
124struct analog_gen {
01f2adb0 125 struct sr_channel *ch;
817e759d 126 enum analog_pattern_type pattern;
ba508e22
UH
127 float amplitude;
128 float pattern_data[ANALOG_BUFSIZE];
129 unsigned int num_samples;
130 struct sr_datafeed_analog packet;
131 struct sr_analog_encoding encoding;
132 struct sr_analog_meaning meaning;
133 struct sr_analog_spec spec;
134 float avg_val; /* Average value */
817e759d 135 unsigned int num_avgs; /* Number of samples averaged */
ba508e22
UH
136};
137
138SR_PRIV void demo_generate_analog_pattern(struct analog_gen *ag, uint64_t sample_rate);
139SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data);
140
141#endif