]> sigrok.org Git - libsigrok.git/blame - src/hardware/demo/protocol.h
Add std_session_send_frame_begin/end helpers
[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
36
ba508e22
UH
37struct dev_context {
38 uint64_t cur_samplerate;
39 uint64_t limit_samples;
40 uint64_t limit_msec;
41 uint64_t sent_samples;
42 int64_t start_us;
43 int64_t spent_us;
44 uint64_t step;
45 /* Logic */
46 int32_t num_logic_channels;
47 unsigned int logic_unitsize;
48 /* There is only ever one logic channel group, so its pattern goes here. */
49 uint8_t logic_pattern;
50 unsigned char logic_data[LOGIC_BUFSIZE];
51 /* Analog */
52 int32_t num_analog_channels;
53 GHashTable *ch_ag;
54 gboolean avg; /* True if averaging is enabled */
55 uint64_t avg_samples;
1b7b72d4
GS
56 size_t enabled_logic_channels;
57 size_t enabled_analog_channels;
4a465510
GS
58 size_t first_partial_logic_index;
59 uint8_t first_partial_logic_mask;
ba508e22
UH
60};
61
62/* Logic patterns we can generate. */
63enum {
64 /**
65 * Spells "sigrok" across 8 channels using '0's (with '1's as
66 * "background") when displayed using the 'bits' output format.
67 * The pattern is repeated every 8 channels, shifted to the right
68 * in time by one bit.
69 */
70 PATTERN_SIGROK,
71
72 /** Pseudo-random values on all channels. */
73 PATTERN_RANDOM,
74
75 /**
76 * Incrementing number across 8 channels. The pattern is repeated
77 * every 8 channels, shifted to the right in time by one bit.
78 */
79 PATTERN_INC,
80
845060fa
SA
81 /**
82 * Single bit "walking" across all logic channels by being
83 * shifted across data lines, restarting after the last line
84 * was used. An all-zero (all-one) state is inserted to prevent
85 * repetitive patterns (e.g. with 8 data lines, every 8th state
86 * would show the same line state)
87 */
88 PATTERN_WALKING_ONE,
89 PATTERN_WALKING_ZERO,
90
ba508e22
UH
91 /** All channels have a low logic state. */
92 PATTERN_ALL_LOW,
93
94 /** All channels have a high logic state. */
95 PATTERN_ALL_HIGH,
81d53a29
GS
96
97 /**
98 * Mimics a cable squid. Derived from the "works with" logo
99 * to occupy a larger number of channels yet "painting"
100 * something that can get recognized.
101 */
102 PATTERN_SQUID,
ba508e22
UH
103};
104
105/* Analog patterns we can generate. */
106enum {
ba508e22
UH
107 PATTERN_SQUARE,
108 PATTERN_SINE,
109 PATTERN_TRIANGLE,
110 PATTERN_SAWTOOTH,
111};
112
113static const char *analog_pattern_str[] = {
114 "square",
115 "sine",
116 "triangle",
117 "sawtooth",
118};
119
120struct analog_gen {
01f2adb0 121 struct sr_channel *ch;
ba508e22
UH
122 int pattern;
123 float amplitude;
124 float pattern_data[ANALOG_BUFSIZE];
125 unsigned int num_samples;
126 struct sr_datafeed_analog packet;
127 struct sr_analog_encoding encoding;
128 struct sr_analog_meaning meaning;
129 struct sr_analog_spec spec;
130 float avg_val; /* Average value */
131 unsigned num_avgs; /* Number of samples averaged */
132};
133
134SR_PRIV void demo_generate_analog_pattern(struct analog_gen *ag, uint64_t sample_rate);
135SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data);
136
137#endif