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