]> sigrok.org Git - libsigrok.git/blob - hardware/rigol-ds/protocol.h
rigol-ds: Enable/disable LA pod when (de)selecting digital channels.
[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 #define DS1000_ANALOG_LIVE_WAVEFORM_SIZE 600
32 #define DS2000_ANALOG_LIVE_WAVEFORM_SIZE 1400
33 #define VS5000_ANALOG_LIVE_WAVEFORM_SIZE 2048
34 #define DSO1000_ANALOG_LIVE_WAVEFORM_SIZE 600
35 /* Needs to be made configurable later */
36 #define DS2000_ANALOG_MEM_WAVEFORM_SIZE_1C 14000
37 #define DS2000_ANALOG_MEM_WAVEFORM_SIZE_2C 7000
38 #define DIGITAL_WAVEFORM_SIZE 1210
39 /* Size of acquisition buffers */
40 #define ACQ_BUFFER_SIZE 32768
41
42 #define MAX_ANALOG_PROBES 4
43 #define MAX_DIGITAL_PROBES 16
44
45 enum rigol_ds_series {
46         RIGOL_DS1000,
47         RIGOL_DS1000Z,
48         RIGOL_DS2000,
49         RIGOL_DS4000,
50         RIGOL_DS6000,
51         RIGOL_VS5000,
52         AGILENT_DSO1000,
53 };
54
55 enum rigol_protocol_flavor {
56         /* Used by DS1000 and VS5000 series */
57         PROTOCOL_LEGACY,
58         /* Used by DS2000, DS4000, DS6000, ... series */
59         PROTOCOL_IEEE488_2,
60 };
61
62 enum data_source {
63         DATA_SOURCE_LIVE,
64         DATA_SOURCE_MEMORY,
65         DATA_SOURCE_SEGMENTED,
66 };
67
68 struct rigol_ds_model {
69         char *vendor;
70         char *name;
71         enum rigol_ds_series series;
72         enum rigol_protocol_flavor protocol;
73         uint64_t min_timebase[2];
74         uint64_t max_timebase[2];
75         uint64_t min_vdiv[2];
76         unsigned int analog_channels;
77         bool has_digital;
78         int num_horizontal_divs;
79 };
80
81 enum wait_events {
82         WAIT_NONE,    /* Don't wait */
83         WAIT_TRIGGER, /* Wait for trigger (only live capture) */
84         WAIT_BLOCK,   /* Wait for block data (only when reading sample mem) */
85         WAIT_STOP,    /* Wait for scope stopping (only single shots) */
86 };
87
88 /** Private, per-device-instance driver context. */
89 struct dev_context {
90         /* Device model */
91         const struct rigol_ds_model *model;
92
93         /* Device properties */
94         const uint64_t (*timebases)[2];
95         uint64_t num_timebases;
96         const uint64_t (*vdivs)[2];
97         uint64_t num_vdivs;
98
99         /* Probe groups */
100         struct sr_probe_group analog_groups[MAX_ANALOG_PROBES];
101         struct sr_probe_group digital_group;
102
103         /* Acquisition settings */
104         GSList *enabled_analog_probes;
105         GSList *enabled_digital_probes;
106         uint64_t limit_frames;
107         void *cb_data;
108         enum data_source data_source;
109         uint64_t analog_frame_size;
110
111         /* Device settings */
112         gboolean analog_channels[MAX_ANALOG_PROBES];
113         gboolean digital_channels[MAX_DIGITAL_PROBES];
114         gboolean la_enabled;
115         float timebase;
116         float vdiv[MAX_ANALOG_PROBES];
117         int vert_reference[MAX_ANALOG_PROBES];
118         float vert_offset[MAX_ANALOG_PROBES];
119         char *trigger_source;
120         float horiz_triggerpos;
121         char *trigger_slope;
122         char *coupling[MAX_ANALOG_PROBES];
123
124         /* Operational state */
125
126         /* Number of frames received in total. */
127         uint64_t num_frames;
128         /* GSList entry for the current channel. */
129         GSList *channel_entry;
130         /* Number of samples received in current frame. */
131         uint64_t num_frame_samples;
132         /* Number of bytes in current data block, if 0 block header expected */
133         uint64_t num_block_bytes;
134         /* Number of data block bytes already read */
135         uint64_t num_block_read;
136         /* What to wait for in *_receive */
137         enum wait_events wait_event;
138         /* Trigger/block copying/stop waiting status */
139         int wait_status;
140         /* Acq buffers used for reading from the scope and sending data to app */
141         unsigned char *buffer;
142         float *data;
143 };
144
145 SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi);
146 SR_PRIV int rigol_ds_channel_start(const struct sr_dev_inst *sdi);
147 SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data);
148 SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi);
149
150 #endif