]> sigrok.org Git - libsigrok.git/blob - src/hardware/siglent-sds/protocol.h
091652054df2178dc6c9046817f58c0c4696258a
[libsigrok.git] / src / hardware / siglent-sds / protocol.h
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 <stdbool.h>
24 #include <stdint.h>
25 #include <glib.h>
26 #include <libsigrok/libsigrok.h>
27 #include "libsigrok-internal.h"
28
29 #define LOG_PREFIX "siglent-sds"
30
31 /* Size of acquisition buffers */
32 //#define ACQ_BUFFER_SIZE (6000000)
33 #define ACQ_BUFFER_SIZE (18000000)
34
35 #define SIGLENT_HEADER_SIZE 363
36 #define SIGLENT_DIG_HEADER_SIZE 346
37
38 /* Maximum number of samples to retrieve at once. */
39 #define ACQ_BLOCK_SIZE (30 * 1000)
40
41 #define MAX_ANALOG_CHANNELS 4
42 #define MAX_DIGITAL_CHANNELS 16
43
44 #define DEVICE_STATE_STOPPED 0          /* Scope is in stopped state bit */
45 #define DEVICE_STATE_DATA_ACQ 1         /* A new signal has been acquired bit */
46 #define DEVICE_STATE_TRIG_RDY 8192      /* Trigger is ready bit */
47 #define DEVICE_STATE_DATA_TRIG_RDY 8193 /* Trigger is ready bit */
48
49 enum protocol_version {
50         SPO_MODEL,
51         NON_SPO_MODEL,
52         ESERIES,
53 };
54
55 enum data_source {
56         DATA_SOURCE_SCREEN,
57         DATA_SOURCE_HISTORY,
58 };
59
60 struct siglent_sds_vendor {
61         const char *name;
62         const char *full_name;
63 };
64
65 struct siglent_sds_series {
66         const struct siglent_sds_vendor *vendor;
67         const char *name;
68         enum protocol_version protocol;
69         uint64_t max_timebase[2];
70         uint64_t min_vdiv[2];
71         int num_horizontal_divs;
72         int num_vertical_divs;
73         int buffer_samples;
74 };
75
76 struct siglent_sds_model {
77         const struct siglent_sds_series *series;
78         const char *name;
79         uint64_t min_timebase[2];
80         unsigned int analog_channels;
81         bool has_digital;
82         unsigned int digital_channels;
83 };
84
85 enum wait_events {
86         WAIT_NONE,      /* Don't wait */
87         WAIT_TRIGGER,   /* Wait for trigger */
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 struct dev_context {
93         /* Device model */
94         const struct siglent_sds_model *model;
95
96         /* Device properties */
97         const uint64_t (*timebases)[2];
98         uint64_t num_timebases;
99         const uint64_t (*vdivs)[2];
100         uint64_t num_vdivs;
101
102         /* Channel groups */
103         struct sr_channel_group **analog_groups;
104         struct sr_channel_group *digital_group;
105
106         /* Acquisition settings */
107         GSList *enabled_channels;
108         uint64_t limit_frames;
109         uint64_t average_samples;
110         gboolean average_enabled;
111         enum data_source data_source;
112         uint64_t analog_frame_size;
113         uint64_t digital_frame_size;
114         uint64_t num_samples;
115         uint64_t memory_depth_analog;
116         uint64_t memory_depth_digital;
117         long block_header_size;
118         float samplerate;
119
120         /* Device settings */
121         gboolean analog_channels[MAX_ANALOG_CHANNELS];
122         gboolean digital_channels[MAX_DIGITAL_CHANNELS];
123         gboolean la_enabled;
124         float timebase;
125         float attenuation[MAX_ANALOG_CHANNELS];
126         float vdiv[MAX_ANALOG_CHANNELS];
127         int vert_reference[MAX_ANALOG_CHANNELS];
128         float vert_offset[MAX_ANALOG_CHANNELS];
129         char *trigger_source;
130         float horiz_triggerpos;
131         char *trigger_slope;
132         float trigger_level;
133         char *coupling[MAX_ANALOG_CHANNELS];
134
135         /* Operational state */
136
137         /* Number of frames received in total. */
138         uint64_t num_frames;
139         /* GSList entry for the current channel. */
140         GSList *channel_entry;
141         /* Number of bytes received for current channel. */
142         uint64_t num_channel_bytes;
143         /* Number of bytes of block header read. */
144         uint64_t num_header_bytes;
145         /* Number of data blocks bytes already read. */
146         uint64_t num_block_bytes;
147         /* Number of data blocks read. */
148         int num_block_read;
149         /* What to wait for in *_receive. */
150         enum wait_events wait_event;
151         /* Trigger/block copying/stop waiting status. */
152         int wait_status;
153         /* Acq buffers used for reading from the scope and sending data to app. */
154         unsigned char *buffer;
155         float *data;
156         GArray *dig_buffer;
157 };
158
159 SR_PRIV int siglent_sds_config_set(const struct sr_dev_inst *sdi,
160         const char *format, ...);
161 SR_PRIV int siglent_sds_capture_start(const struct sr_dev_inst *sdi);
162 SR_PRIV int siglent_sds_channel_start(const struct sr_dev_inst *sdi);
163 SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data);
164 SR_PRIV int siglent_sds_get_dev_cfg(const struct sr_dev_inst *sdi);
165 SR_PRIV int siglent_sds_get_dev_cfg_vertical(const struct sr_dev_inst *sdi);
166 SR_PRIV int siglent_sds_get_dev_cfg_horizontal(const struct sr_dev_inst *sdi);
167
168 #endif