]> sigrok.org Git - libsigrok.git/blame - src/hardware/rigol-ds/protocol.h
output/csv: use intermediate time_t var, silence compiler warning
[libsigrok.git] / src / hardware / rigol-ds / protocol.h
CommitLineData
f4816ac6
ML
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2012 Martin Ling <martin-git@earth.li>
88e429c9 5 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
f4816ac6
ML
6 *
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.
11 *
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.
16 *
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/>.
19 */
20
3086efdd
ML
21#ifndef LIBSIGROK_HARDWARE_RIGOL_DS_PROTOCOL_H
22#define LIBSIGROK_HARDWARE_RIGOL_DS_PROTOCOL_H
f4816ac6
ML
23
24#include <stdint.h>
bafd4890 25#include <stdbool.h>
c1aae900 26#include <libsigrok/libsigrok.h>
f4816ac6
ML
27#include "libsigrok-internal.h"
28
3544f848 29#define LOG_PREFIX "rigol-ds"
f4816ac6 30
babab622 31/* Size of acquisition buffers */
1a46cc62 32#define ACQ_BUFFER_SIZE (32 * 1024)
babab622 33
702f42e8 34/* Maximum number of samples to retrieve at once. */
1a46cc62 35#define ACQ_BLOCK_SIZE (30 * 1000)
702f42e8 36
3f239f08
UH
37#define MAX_ANALOG_CHANNELS 4
38#define MAX_DIGITAL_CHANNELS 16
821fbcad 39
569d4dbd
ML
40enum protocol_version {
41 PROTOCOL_V1, /* VS5000 */
42 PROTOCOL_V2, /* DS1000 */
43 PROTOCOL_V3, /* DS2000, DSO1000 */
702f42e8 44 PROTOCOL_V4, /* DS1000Z */
f6129c8f 45 PROTOCOL_V5, /* MSO5000 */
babab622
ML
46};
47
569d4dbd
ML
48enum data_format {
49 /* Used by DS1000 versions up to 2.02, and VS5000 series */
50 FORMAT_RAW,
51 /* Used by DS1000 versions from 2.04 onwards and all later series */
52 FORMAT_IEEE488_2,
babab622
ML
53};
54
55enum data_source {
56 DATA_SOURCE_LIVE,
57 DATA_SOURCE_MEMORY,
58 DATA_SOURCE_SEGMENTED,
59};
e0b7d23c 60
569d4dbd
ML
61struct rigol_ds_vendor {
62 const char *name;
63 const char *full_name;
64};
65
66struct rigol_ds_series {
67 const struct rigol_ds_vendor *vendor;
68 const char *name;
69 enum protocol_version protocol;
70 enum data_format format;
bafd4890
ML
71 uint64_t max_timebase[2];
72 uint64_t min_vdiv[2];
569d4dbd
ML
73 int num_horizontal_divs;
74 int live_samples;
75 int buffer_samples;
76};
77
0f523f2b
UH
78enum cmds {
79 CMD_GET_HORIZ_TRIGGERPOS,
80 CMD_SET_HORIZ_TRIGGERPOS,
81};
82
83struct rigol_ds_command {
84 int cmd;
85 const char *str;
86};
87
569d4dbd
ML
88struct rigol_ds_model {
89 const struct rigol_ds_series *series;
90 const char *name;
91 uint64_t min_timebase[2];
821fbcad 92 unsigned int analog_channels;
bafd4890 93 bool has_digital;
6bcc81ac
VO
94 const char **trigger_sources;
95 unsigned int num_trigger_sources;
0f523f2b 96 const struct rigol_ds_command *cmds;
babab622
ML
97};
98
99enum wait_events {
100 WAIT_NONE, /* Don't wait */
101 WAIT_TRIGGER, /* Wait for trigger (only live capture) */
102 WAIT_BLOCK, /* Wait for block data (only when reading sample mem) */
103 WAIT_STOP, /* Wait for scope stopping (only single shots) */
bafd4890
ML
104};
105
f4816ac6 106struct dev_context {
bafd4890 107 const struct rigol_ds_model *model;
569d4dbd 108 enum data_format format;
bafd4890
ML
109
110 /* Device properties */
111 const uint64_t (*timebases)[2];
112 uint64_t num_timebases;
113 const uint64_t (*vdivs)[2];
114 uint64_t num_vdivs;
6bb192bc 115
660e398f 116 /* Channel groups */
562b7ae5
SA
117 struct sr_channel_group **analog_groups;
118 struct sr_channel_group *digital_group;
3d3a601e 119
254dd102 120 /* Acquisition settings */
702f42e8 121 GSList *enabled_channels;
e0b7d23c 122 uint64_t limit_frames;
babab622
ML
123 enum data_source data_source;
124 uint64_t analog_frame_size;
d22250a9 125 uint64_t digital_frame_size;
f4816ac6 126
254dd102 127 /* Device settings */
3f239f08
UH
128 gboolean analog_channels[MAX_ANALOG_CHANNELS];
129 gboolean digital_channels[MAX_DIGITAL_CHANNELS];
04e8e01e 130 gboolean la_enabled;
254dd102 131 float timebase;
1cbb3b1c 132 float sample_rate;
934cf6cf 133 float attenuation[MAX_ANALOG_CHANNELS];
3f239f08
UH
134 float vdiv[MAX_ANALOG_CHANNELS];
135 int vert_reference[MAX_ANALOG_CHANNELS];
6b04525b 136 float vert_origin[MAX_ANALOG_CHANNELS];
3f239f08 137 float vert_offset[MAX_ANALOG_CHANNELS];
6b04525b 138 float vert_inc[MAX_ANALOG_CHANNELS];
254dd102
BV
139 char *trigger_source;
140 float horiz_triggerpos;
141 char *trigger_slope;
9ea62f2e 142 float trigger_level;
3f239f08 143 char *coupling[MAX_ANALOG_CHANNELS];
254dd102 144
0d87bd93 145 /* Number of frames received in total. */
254dd102 146 uint64_t num_frames;
8cbe5339
VO
147 /* Number of frames available from the Segmented data source */
148 uint64_t num_frames_segmented;
821fbcad
ML
149 /* GSList entry for the current channel. */
150 GSList *channel_entry;
f76c24f6
ML
151 /* Number of bytes received for current channel. */
152 uint64_t num_channel_bytes;
aff00e40
ML
153 /* Number of bytes of block header read */
154 uint64_t num_header_bytes;
bafd4890
ML
155 /* Number of bytes in current data block, if 0 block header expected */
156 uint64_t num_block_bytes;
157 /* Number of data block bytes already read */
158 uint64_t num_block_read;
babab622
ML
159 /* What to wait for in *_receive */
160 enum wait_events wait_event;
161 /* Trigger/block copying/stop waiting status */
162 int wait_status;
163 /* Acq buffers used for reading from the scope and sending data to app */
164 unsigned char *buffer;
165 float *data;
f4816ac6
ML
166};
167
38354d9d 168SR_PRIV int rigol_ds_config_set(const struct sr_dev_inst *sdi, const char *format, ...);
babab622 169SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi);
677f85d0 170SR_PRIV int rigol_ds_channel_start(const struct sr_dev_inst *sdi);
3086efdd 171SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data);
3086efdd 172SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi);
8719638f 173SR_PRIV int rigol_ds_get_dev_cfg_vertical(const struct sr_dev_inst *sdi);
e0b7d23c 174
f4816ac6 175#endif