]> sigrok.org Git - libsigrok.git/blob - hardware/rigol-ds/protocol.h
rigol-ds: On DS1000 with firmware < 0.2.4, use legacy protocol.
[libsigrok.git] / hardware / rigol-ds / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2012 Martin Ling <martin-git@earth.li>
5  * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
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
21 #ifndef LIBSIGROK_HARDWARE_RIGOL_DS_PROTOCOL_H
22 #define LIBSIGROK_HARDWARE_RIGOL_DS_PROTOCOL_H
23
24 #include <stdint.h>
25 #include <stdbool.h>
26 #include "libsigrok.h"
27 #include "libsigrok-internal.h"
28
29 #define LOG_PREFIX "rigol-ds"
30
31 /* Analog waveform block sizes */
32 #define DS1000_ANALOG_LIVE_WAVEFORM_SIZE 600
33 #define DS2000_ANALOG_LIVE_WAVEFORM_SIZE 1400
34 #define VS5000_ANALOG_LIVE_WAVEFORM_SIZE 2048
35 #define DSO1000_ANALOG_LIVE_WAVEFORM_SIZE 600
36 #define DS2000_ANALOG_MEM_WAVEFORM_SIZE_1C 14000
37 #define DS2000_ANALOG_MEM_WAVEFORM_SIZE_2C 7000
38
39 /* Digital waveform block size */
40 #define DS1000_DIGITAL_WAVEFORM_SIZE 1200
41 #define VS5000_DIGITAL_WAVEFORM_SIZE 4096
42
43 /* Size of acquisition buffers */
44 #define ACQ_BUFFER_SIZE 32768
45
46 #define MAX_ANALOG_PROBES 4
47 #define MAX_DIGITAL_PROBES 16
48
49 enum rigol_ds_series {
50         RIGOL_VS5000,
51         RIGOL_DS1000,
52         RIGOL_DS1000Z,
53         RIGOL_DS2000,
54         RIGOL_DS4000,
55         RIGOL_DS6000,
56         AGILENT_DSO1000,
57 };
58
59 enum rigol_protocol_flavor {
60         /* Used by DS1000 and VS5000 series */
61         PROTOCOL_LEGACY,
62         /* Used by DS2000, DS4000, DS6000, ... series */
63         PROTOCOL_IEEE488_2,
64 };
65
66 enum data_source {
67         DATA_SOURCE_LIVE,
68         DATA_SOURCE_MEMORY,
69         DATA_SOURCE_SEGMENTED,
70 };
71
72 struct rigol_ds_model {
73         char *vendor;
74         char *name;
75         enum rigol_ds_series series;
76         enum rigol_protocol_flavor protocol;
77         uint64_t min_timebase[2];
78         uint64_t max_timebase[2];
79         uint64_t min_vdiv[2];
80         unsigned int analog_channels;
81         bool has_digital;
82         int num_horizontal_divs;
83 };
84
85 enum wait_events {
86         WAIT_NONE,    /* Don't wait */
87         WAIT_TRIGGER, /* Wait for trigger (only live capture) */
88         WAIT_BLOCK,   /* Wait for block data (only when reading sample mem) */
89         WAIT_STOP,    /* Wait for scope stopping (only single shots) */
90 };
91
92 /** Private, per-device-instance driver context. */
93 struct dev_context {
94         /* Device model */
95         const struct rigol_ds_model *model;
96         enum rigol_protocol_flavor protocol;
97
98         /* Device properties */
99         const uint64_t (*timebases)[2];
100         uint64_t num_timebases;
101         const uint64_t (*vdivs)[2];
102         uint64_t num_vdivs;
103
104         /* Probe groups */
105         struct sr_probe_group analog_groups[MAX_ANALOG_PROBES];
106         struct sr_probe_group digital_group;
107
108         /* Acquisition settings */
109         GSList *enabled_analog_probes;
110         GSList *enabled_digital_probes;
111         uint64_t limit_frames;
112         void *cb_data;
113         enum data_source data_source;
114         uint64_t analog_frame_size;
115         uint64_t digital_frame_size;
116
117         /* Device settings */
118         gboolean analog_channels[MAX_ANALOG_PROBES];
119         gboolean digital_channels[MAX_DIGITAL_PROBES];
120         gboolean la_enabled;
121         float timebase;
122         float vdiv[MAX_ANALOG_PROBES];
123         int vert_reference[MAX_ANALOG_PROBES];
124         float vert_offset[MAX_ANALOG_PROBES];
125         char *trigger_source;
126         float horiz_triggerpos;
127         char *trigger_slope;
128         char *coupling[MAX_ANALOG_PROBES];
129
130         /* Operational state */
131
132         /* Number of frames received in total. */
133         uint64_t num_frames;
134         /* GSList entry for the current channel. */
135         GSList *channel_entry;
136         /* Number of bytes received for current channel. */
137         uint64_t num_channel_bytes;
138         /* Number of bytes in current data block, if 0 block header expected */
139         uint64_t num_block_bytes;
140         /* Number of data block bytes already read */
141         uint64_t num_block_read;
142         /* What to wait for in *_receive */
143         enum wait_events wait_event;
144         /* Trigger/block copying/stop waiting status */
145         int wait_status;
146         /* Acq buffers used for reading from the scope and sending data to app */
147         unsigned char *buffer;
148         float *data;
149 };
150
151 SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi);
152 SR_PRIV int rigol_ds_channel_start(const struct sr_dev_inst *sdi);
153 SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data);
154 SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi);
155
156 #endif