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