]> sigrok.org Git - libsigrok.git/blob - hardware/rigol-ds/protocol.h
Replace rigol_ds_send() function with sr_scpi_send().
[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 /* Message logging helpers with subsystem-specific prefix string. */
30 #define LOG_PREFIX "rigol-ds: "
31 #define sr_log(l, s, args...) sr_log(l, LOG_PREFIX s, ## args)
32 #define sr_spew(s, args...) sr_spew(LOG_PREFIX s, ## args)
33 #define sr_dbg(s, args...) sr_dbg(LOG_PREFIX s, ## args)
34 #define sr_info(s, args...) sr_info(LOG_PREFIX s, ## args)
35 #define sr_warn(s, args...) sr_warn(LOG_PREFIX s, ## args)
36 #define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args)
37
38 #define DS1000_ANALOG_LIVE_WAVEFORM_SIZE 600
39 #define DS2000_ANALOG_LIVE_WAVEFORM_SIZE 1400
40 /* Needs to be made configurable later */
41 #define DS2000_ANALOG_MEM_WAVEFORM_SIZE_1C 14000
42 #define DS2000_ANALOG_MEM_WAVEFORM_SIZE_2C 7000
43 #define DIGITAL_WAVEFORM_SIZE 1210
44 /* Size of acquisition buffers */
45 #define ACQ_BUFFER_SIZE 32768
46
47 enum rigol_ds_series {
48         RIGOL_DS1000,
49         RIGOL_DS1000Z,
50         RIGOL_DS2000,
51         RIGOL_DS4000,
52         RIGOL_DS6000,
53 };
54
55 enum rigol_protocol_flavor {
56         /* Used by DS1000 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 *name;
70         enum rigol_ds_series series;
71         enum rigol_protocol_flavor protocol;
72         uint64_t min_timebase[2];
73         uint64_t max_timebase[2];
74         uint64_t min_vdiv[2];
75         bool has_digital;
76         int num_horizontal_divs;
77 };
78
79 enum wait_events {
80         WAIT_NONE,    /* Don't wait */
81         WAIT_TRIGGER, /* Wait for trigger (only live capture) */
82         WAIT_BLOCK,   /* Wait for block data (only when reading sample mem) */
83         WAIT_STOP,    /* Wait for scope stopping (only single shots) */
84 };
85
86 /** Private, per-device-instance driver context. */
87 struct dev_context {
88         /* Device model */
89         const struct rigol_ds_model *model;
90
91         /* Device properties */
92         const uint64_t (*timebases)[2];
93         uint64_t num_timebases;
94         const uint64_t (*vdivs)[2];
95         uint64_t num_vdivs;
96
97         /* Probe groups */
98         struct sr_probe_group analog_groups[2];
99         struct sr_probe_group digital_group;
100
101         /* Acquisition settings */
102         GSList *enabled_analog_probes;
103         GSList *enabled_digital_probes;
104         uint64_t limit_frames;
105         void *cb_data;
106         enum data_source data_source;
107         uint64_t analog_frame_size;
108
109         /* Device settings */
110         gboolean analog_channels[2];
111         gboolean digital_channels[16];
112         float timebase;
113         float vdiv[2];
114         int vert_reference[2];
115         float vert_offset[2];
116         char *trigger_source;
117         float horiz_triggerpos;
118         char *trigger_slope;
119         char *coupling[2];
120
121         /* Operational state */
122         uint64_t num_frames;
123         /* FIXME: misnomer, actually this is number of frame samples? */
124         uint64_t num_frame_bytes;
125         struct sr_probe *channel_frame;
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_receive(int fd, int revents, void *cb_data);
141 SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi);
142
143 #endif