]> sigrok.org Git - libsigrok.git/blob - src/hardware/demo/protocol.h
demo: File naming consistency changes.
[libsigrok.git] / src / hardware / demo / protocol.h
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
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
22  */
23
24 #ifndef LIBSIGROK_HARDWARE_DEMO_PROTOCOL_H
25 #define LIBSIGROK_HARDWARE_DEMO_PROTOCOL_H
26
27 #include <stdint.h>
28 #include <libsigrok/libsigrok.h>
29 #include "libsigrok-internal.h"
30
31 #define LOG_PREFIX "demo"
32
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
38 /* Private, per-device-instance driver context. */
39 struct dev_context {
40         uint64_t cur_samplerate;
41         uint64_t limit_samples;
42         uint64_t limit_msec;
43         uint64_t sent_samples;
44         int64_t start_us;
45         int64_t spent_us;
46         uint64_t step;
47         /* Logic */
48         int32_t num_logic_channels;
49         unsigned int logic_unitsize;
50         /* There is only ever one logic channel group, so its pattern goes here. */
51         uint8_t logic_pattern;
52         unsigned char logic_data[LOGIC_BUFSIZE];
53         /* Analog */
54         int32_t num_analog_channels;
55         GHashTable *ch_ag;
56         gboolean avg; /* True if averaging is enabled */
57         uint64_t avg_samples;
58 };
59
60 /* Logic patterns we can generate. */
61 enum {
62         /**
63          * Spells "sigrok" across 8 channels using '0's (with '1's as
64          * "background") when displayed using the 'bits' output format.
65          * The pattern is repeated every 8 channels, shifted to the right
66          * in time by one bit.
67          */
68         PATTERN_SIGROK,
69
70         /** Pseudo-random values on all channels. */
71         PATTERN_RANDOM,
72
73         /**
74          * Incrementing number across 8 channels. The pattern is repeated
75          * every 8 channels, shifted to the right in time by one bit.
76          */
77         PATTERN_INC,
78
79         /** All channels have a low logic state. */
80         PATTERN_ALL_LOW,
81
82         /** All channels have a high logic state. */
83         PATTERN_ALL_HIGH,
84 };
85
86 /* Analog patterns we can generate. */
87 enum {
88         /**
89          * Square wave.
90          */
91         PATTERN_SQUARE,
92         PATTERN_SINE,
93         PATTERN_TRIANGLE,
94         PATTERN_SAWTOOTH,
95 };
96
97 static const char *analog_pattern_str[] = {
98         "square",
99         "sine",
100         "triangle",
101         "sawtooth",
102 };
103
104 struct analog_gen {
105         int pattern;
106         float amplitude;
107         float pattern_data[ANALOG_BUFSIZE];
108         unsigned int num_samples;
109         struct sr_datafeed_analog packet;
110         struct sr_analog_encoding encoding;
111         struct sr_analog_meaning meaning;
112         struct sr_analog_spec spec;
113         float avg_val; /* Average value */
114         unsigned num_avgs; /* Number of samples averaged */
115 };
116
117 SR_PRIV void demo_generate_analog_pattern(struct analog_gen *ag, uint64_t sample_rate);
118 SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data);
119
120 #endif