2 * This file is part of the libsigrok project.
4 * Copyright (C) 2012 Martin Ling <martin-git@earth.li>
5 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
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.
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.
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/>.
21 #ifndef LIBSIGROK_HARDWARE_RIGOL_DS_PROTOCOL_H
22 #define LIBSIGROK_HARDWARE_RIGOL_DS_PROTOCOL_H
26 #include <libsigrok/libsigrok.h>
27 #include "libsigrok-internal.h"
29 #define LOG_PREFIX "rigol-ds"
31 /* Size of acquisition buffers */
32 #define ACQ_BUFFER_SIZE (32 * 1024)
34 /* Maximum number of samples to retrieve at once. */
35 #define ACQ_BLOCK_SIZE (30 * 1000)
37 #define MAX_ANALOG_CHANNELS 4
38 #define MAX_DIGITAL_CHANNELS 16
40 enum protocol_version {
41 PROTOCOL_V1, /* VS5000 */
42 PROTOCOL_V2, /* DS1000 */
43 PROTOCOL_V3, /* DS2000, DSO1000 */
44 PROTOCOL_V4, /* DS1000Z */
45 PROTOCOL_V5, /* MSO5000 */
49 /* Used by DS1000 versions up to 2.02, and VS5000 series */
51 /* Used by DS1000 versions from 2.04 onwards and all later series */
58 DATA_SOURCE_SEGMENTED,
61 struct rigol_ds_vendor {
63 const char *full_name;
66 struct rigol_ds_series {
67 const struct rigol_ds_vendor *vendor;
69 enum protocol_version protocol;
70 enum data_format format;
71 uint64_t max_timebase[2];
73 int num_horizontal_divs;
79 CMD_GET_HORIZ_TRIGGERPOS,
80 CMD_SET_HORIZ_TRIGGERPOS,
83 struct rigol_ds_command {
88 struct rigol_ds_model {
89 const struct rigol_ds_series *series;
91 uint64_t min_timebase[2];
92 unsigned int analog_channels;
94 const char **trigger_sources;
95 unsigned int num_trigger_sources;
96 const struct rigol_ds_command *cmds;
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) */
107 const struct rigol_ds_model *model;
108 enum data_format format;
110 /* Device properties */
111 const uint64_t (*timebases)[2];
112 uint64_t num_timebases;
113 const uint64_t (*vdivs)[2];
117 struct sr_channel_group **analog_groups;
118 struct sr_channel_group *digital_group;
120 /* Acquisition settings */
121 GSList *enabled_channels;
122 uint64_t limit_frames;
123 enum data_source data_source;
124 uint64_t analog_frame_size;
125 uint64_t digital_frame_size;
127 /* Device settings */
128 gboolean analog_channels[MAX_ANALOG_CHANNELS];
129 gboolean digital_channels[MAX_DIGITAL_CHANNELS];
132 float attenuation[MAX_ANALOG_CHANNELS];
133 float vdiv[MAX_ANALOG_CHANNELS];
134 int vert_reference[MAX_ANALOG_CHANNELS];
135 float vert_origin[MAX_ANALOG_CHANNELS];
136 float vert_offset[MAX_ANALOG_CHANNELS];
137 float vert_inc[MAX_ANALOG_CHANNELS];
138 char *trigger_source;
139 float horiz_triggerpos;
142 char *coupling[MAX_ANALOG_CHANNELS];
144 /* Number of frames received in total. */
146 /* GSList entry for the current channel. */
147 GSList *channel_entry;
148 /* Number of bytes received for current channel. */
149 uint64_t num_channel_bytes;
150 /* Number of bytes of block header read */
151 uint64_t num_header_bytes;
152 /* Number of bytes in current data block, if 0 block header expected */
153 uint64_t num_block_bytes;
154 /* Number of data block bytes already read */
155 uint64_t num_block_read;
156 /* What to wait for in *_receive */
157 enum wait_events wait_event;
158 /* Trigger/block copying/stop waiting status */
160 /* Acq buffers used for reading from the scope and sending data to app */
161 unsigned char *buffer;
165 SR_PRIV int rigol_ds_config_set(const struct sr_dev_inst *sdi, const char *format, ...);
166 SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi);
167 SR_PRIV int rigol_ds_channel_start(const struct sr_dev_inst *sdi);
168 SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data);
169 SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi);
170 SR_PRIV int rigol_ds_get_dev_cfg_vertical(const struct sr_dev_inst *sdi);