]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2018 mhooijboer <marchelh@gmail.com> | |
5 | * | |
6 | * This program is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #ifndef LIBSIGROK_HARDWARE_SIGLENT_SDS_PROTOCOL_H | |
21 | #define LIBSIGROK_HARDWARE_SIGLENT_SDS_PROTOCOL_H | |
22 | ||
23 | #include <stdint.h> | |
24 | #include <glib.h> | |
25 | #include <libsigrok/libsigrok.h> | |
26 | #include "libsigrok-internal.h" | |
27 | ||
28 | #define LOG_PREFIX "siglent-sds" | |
29 | ||
30 | /* Size of acquisition buffers */ | |
31 | //#define ACQ_BUFFER_SIZE (6000000) | |
32 | #define ACQ_BUFFER_SIZE (18000000) | |
33 | ||
34 | #define SIGLENT_HEADER_SIZE 363 | |
35 | #define SIGLENT_DIG_HEADER_SIZE 346 | |
36 | ||
37 | /* Maximum number of samples to retrieve at once. */ | |
38 | #define ACQ_BLOCK_SIZE (30 * 1000) | |
39 | ||
40 | #define MAX_ANALOG_CHANNELS 4 | |
41 | #define MAX_DIGITAL_CHANNELS 16 | |
42 | ||
43 | #define DEVICE_STATE_STOPPED 0 /* Scope is in stopped state bit */ | |
44 | #define DEVICE_STATE_DATA_ACQ 1 /* A new signal has been acquired bit */ | |
45 | #define DEVICE_STATE_TRIG_RDY 8192 /* Trigger is ready bit */ | |
46 | #define DEVICE_STATE_DATA_TRIG_RDY 8193 /* Trigger is ready bit */ | |
47 | ||
48 | enum protocol_version { | |
49 | SPO_MODEL, | |
50 | NON_SPO_MODEL, | |
51 | ESERIES, | |
52 | }; | |
53 | ||
54 | enum data_source { | |
55 | DATA_SOURCE_SCREEN, | |
56 | DATA_SOURCE_HISTORY, | |
57 | }; | |
58 | ||
59 | struct siglent_sds_vendor { | |
60 | const char *name; | |
61 | const char *full_name; | |
62 | }; | |
63 | ||
64 | struct siglent_sds_series { | |
65 | const struct siglent_sds_vendor *vendor; | |
66 | const char *name; | |
67 | enum protocol_version protocol; | |
68 | uint64_t max_timebase[2]; | |
69 | uint64_t min_vdiv[2]; | |
70 | int num_horizontal_divs; | |
71 | int num_vertical_divs; | |
72 | int buffer_samples; | |
73 | }; | |
74 | ||
75 | struct siglent_sds_model { | |
76 | const struct siglent_sds_series *series; | |
77 | const char *name; | |
78 | uint64_t min_timebase[2]; | |
79 | unsigned int analog_channels; | |
80 | gboolean has_digital; | |
81 | unsigned int digital_channels; | |
82 | }; | |
83 | ||
84 | enum wait_events { | |
85 | WAIT_NONE, /* Don't wait */ | |
86 | WAIT_TRIGGER, /* Wait for trigger */ | |
87 | WAIT_BLOCK, /* Wait for block data (only when reading sample mem) */ | |
88 | WAIT_STOP, /* Wait for scope stopping (only single shots) */ | |
89 | }; | |
90 | ||
91 | struct dev_context { | |
92 | /* Device model */ | |
93 | const struct siglent_sds_model *model; | |
94 | ||
95 | /* Device properties */ | |
96 | const uint64_t (*timebases)[2]; | |
97 | uint64_t num_timebases; | |
98 | const uint64_t (*vdivs)[2]; | |
99 | uint64_t num_vdivs; | |
100 | ||
101 | /* Channel groups */ | |
102 | struct sr_channel_group **analog_groups; | |
103 | struct sr_channel_group *digital_group; | |
104 | ||
105 | /* Acquisition settings */ | |
106 | GSList *enabled_channels; | |
107 | uint64_t limit_frames; | |
108 | uint64_t average_samples; | |
109 | gboolean average_enabled; | |
110 | enum data_source data_source; | |
111 | uint64_t analog_frame_size; | |
112 | uint64_t digital_frame_size; | |
113 | uint64_t num_samples; | |
114 | uint64_t memory_depth_analog; | |
115 | uint64_t memory_depth_digital; | |
116 | long block_header_size; | |
117 | float samplerate; | |
118 | ||
119 | /* Device settings */ | |
120 | gboolean analog_channels[MAX_ANALOG_CHANNELS]; | |
121 | gboolean digital_channels[MAX_DIGITAL_CHANNELS]; | |
122 | gboolean la_enabled; | |
123 | float timebase; | |
124 | float attenuation[MAX_ANALOG_CHANNELS]; | |
125 | float vdiv[MAX_ANALOG_CHANNELS]; | |
126 | int vert_reference[MAX_ANALOG_CHANNELS]; | |
127 | float vert_offset[MAX_ANALOG_CHANNELS]; | |
128 | char *trigger_source; | |
129 | float horiz_triggerpos; | |
130 | char *trigger_slope; | |
131 | float trigger_level; | |
132 | char *coupling[MAX_ANALOG_CHANNELS]; | |
133 | ||
134 | /* Operational state */ | |
135 | ||
136 | /* Number of frames received in total. */ | |
137 | uint64_t num_frames; | |
138 | /* GSList entry for the current channel. */ | |
139 | GSList *channel_entry; | |
140 | /* Number of bytes received for current channel. */ | |
141 | uint64_t num_channel_bytes; | |
142 | /* Number of bytes of block header read. */ | |
143 | uint64_t num_header_bytes; | |
144 | /* Number of data blocks bytes already read. */ | |
145 | uint64_t num_block_bytes; | |
146 | /* Number of data blocks read. */ | |
147 | int num_block_read; | |
148 | /* What to wait for in *_receive. */ | |
149 | enum wait_events wait_event; | |
150 | /* Trigger/block copying/stop waiting status. */ | |
151 | int wait_status; | |
152 | /* Acq buffers used for reading from the scope and sending data to app. */ | |
153 | unsigned char *buffer; | |
154 | float *data; | |
155 | GArray *dig_buffer; | |
156 | }; | |
157 | ||
158 | SR_PRIV int siglent_sds_config_set(const struct sr_dev_inst *sdi, | |
159 | const char *format, ...); | |
160 | SR_PRIV int siglent_sds_capture_start(const struct sr_dev_inst *sdi); | |
161 | SR_PRIV int siglent_sds_channel_start(const struct sr_dev_inst *sdi); | |
162 | SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data); | |
163 | SR_PRIV int siglent_sds_get_dev_cfg(const struct sr_dev_inst *sdi); | |
164 | SR_PRIV int siglent_sds_get_dev_cfg_vertical(const struct sr_dev_inst *sdi); | |
165 | SR_PRIV int siglent_sds_get_dev_cfg_horizontal(const struct sr_dev_inst *sdi); | |
166 | ||
167 | #endif |