]>
Commit | Line | Data |
---|---|---|
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 | /* Size of acquisition buffers */ | |
32 | #define ACQ_BUFFER_SIZE 32768 | |
33 | ||
34 | /* Maximum number of samples to retrieve at once. */ | |
35 | #define ACQ_BLOCK_SIZE 30000 | |
36 | ||
37 | #define MAX_ANALOG_CHANNELS 4 | |
38 | #define MAX_DIGITAL_CHANNELS 16 | |
39 | ||
40 | enum protocol_version { | |
41 | PROTOCOL_V1, /* VS5000 */ | |
42 | PROTOCOL_V2, /* DS1000 */ | |
43 | PROTOCOL_V3, /* DS2000, DSO1000 */ | |
44 | PROTOCOL_V4, /* DS1000Z */ | |
45 | }; | |
46 | ||
47 | enum data_format { | |
48 | /* Used by DS1000 versions up to 2.02, and VS5000 series */ | |
49 | FORMAT_RAW, | |
50 | /* Used by DS1000 versions from 2.04 onwards and all later series */ | |
51 | FORMAT_IEEE488_2, | |
52 | }; | |
53 | ||
54 | enum data_source { | |
55 | DATA_SOURCE_LIVE, | |
56 | DATA_SOURCE_MEMORY, | |
57 | DATA_SOURCE_SEGMENTED, | |
58 | }; | |
59 | ||
60 | struct rigol_ds_vendor { | |
61 | const char *name; | |
62 | const char *full_name; | |
63 | }; | |
64 | ||
65 | struct rigol_ds_series { | |
66 | const struct rigol_ds_vendor *vendor; | |
67 | const char *name; | |
68 | enum protocol_version protocol; | |
69 | enum data_format format; | |
70 | uint64_t max_timebase[2]; | |
71 | uint64_t min_vdiv[2]; | |
72 | int num_horizontal_divs; | |
73 | int live_samples; | |
74 | int buffer_samples; | |
75 | }; | |
76 | ||
77 | struct rigol_ds_model { | |
78 | const struct rigol_ds_series *series; | |
79 | const char *name; | |
80 | uint64_t min_timebase[2]; | |
81 | unsigned int analog_channels; | |
82 | bool has_digital; | |
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 data_format format; | |
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 | /* Channel groups */ | |
105 | struct sr_channel_group **analog_groups; | |
106 | struct sr_channel_group *digital_group; | |
107 | ||
108 | /* Acquisition settings */ | |
109 | GSList *enabled_channels; | |
110 | uint64_t limit_frames; | |
111 | void *cb_data; | |
112 | enum data_source data_source; | |
113 | uint64_t analog_frame_size; | |
114 | uint64_t digital_frame_size; | |
115 | ||
116 | /* Device settings */ | |
117 | gboolean analog_channels[MAX_ANALOG_CHANNELS]; | |
118 | gboolean digital_channels[MAX_DIGITAL_CHANNELS]; | |
119 | gboolean la_enabled; | |
120 | float timebase; | |
121 | float vdiv[MAX_ANALOG_CHANNELS]; | |
122 | int vert_reference[MAX_ANALOG_CHANNELS]; | |
123 | float vert_offset[MAX_ANALOG_CHANNELS]; | |
124 | char *trigger_source; | |
125 | float horiz_triggerpos; | |
126 | char *trigger_slope; | |
127 | char *coupling[MAX_ANALOG_CHANNELS]; | |
128 | ||
129 | /* Operational state */ | |
130 | ||
131 | /* Number of frames received in total. */ | |
132 | uint64_t num_frames; | |
133 | /* GSList entry for the current channel. */ | |
134 | GSList *channel_entry; | |
135 | /* Number of bytes received for current channel. */ | |
136 | uint64_t num_channel_bytes; | |
137 | /* Number of bytes of block header read */ | |
138 | uint64_t num_header_bytes; | |
139 | /* Number of bytes in current data block, if 0 block header expected */ | |
140 | uint64_t num_block_bytes; | |
141 | /* Number of data block bytes already read */ | |
142 | uint64_t num_block_read; | |
143 | /* What to wait for in *_receive */ | |
144 | enum wait_events wait_event; | |
145 | /* Trigger/block copying/stop waiting status */ | |
146 | int wait_status; | |
147 | /* Acq buffers used for reading from the scope and sending data to app */ | |
148 | unsigned char *buffer; | |
149 | float *data; | |
150 | }; | |
151 | ||
152 | SR_PRIV int rigol_ds_config_set(const struct sr_dev_inst *sdi, const char *format, ...); | |
153 | SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi); | |
154 | SR_PRIV int rigol_ds_channel_start(const struct sr_dev_inst *sdi); | |
155 | SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data); | |
156 | SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi); | |
157 | ||
158 | #endif |