]> sigrok.org Git - libsigrok.git/blame - src/hardware/siglent-sds/protocol.h
siglent-sds: initial driver implementation for Siglent SDS
[libsigrok.git] / src / hardware / siglent-sds / protocol.h
CommitLineData
89f5fab9 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
b3360671 23#include <stdbool.h>
89f5fab9 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
b3360671 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
45enum protocol_version {
46 SPO_MODEL,
47 NON_SPO_MODEL,
48};
49
50enum data_format {
51 FORMAT_IEEE488_2,
52};
53
54enum data_source {
55 DATA_SOURCE_SCREEN,
56 DATA_SOURCE_HISTORY,
57};
58
59struct siglent_sds_vendor {
60 const char *name;
61 const char *full_name;
62 const char *usb_name;
63};
64
65struct 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
76struct 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
85enum 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/** Private, per-device-instance driver context. */
89f5fab9 93struct dev_context {
b3360671 94 /* Device model */
95 const struct siglent_sds_model *model;
96
97 /* Device properties */
98 const uint64_t (*timebases)[2];
99 uint64_t num_timebases;
100 const uint64_t (*vdivs)[2];
101 uint64_t num_vdivs;
102
103 /* Channel groups */
104 struct sr_channel_group **analog_groups;
105 struct sr_channel_group *digital_group;
106
107 /* Acquisition settings */
108 GSList *enabled_channels;
109 uint64_t limit_frames;
110 enum data_source data_source;
111 uint64_t analog_frame_size;
112 uint64_t digital_frame_size;
113 uint64_t num_samples;
114 long blockHeaderSize;
115 float sampleRate;
116
117 /* Device settings */
118 gboolean analog_channels[MAX_ANALOG_CHANNELS];
119 gboolean digital_channels[MAX_DIGITAL_CHANNELS];
120 gboolean la_enabled;
121 float timebase;
122 float attenuation[MAX_ANALOG_CHANNELS];
123 float vdiv[MAX_ANALOG_CHANNELS];
124 int vert_reference[MAX_ANALOG_CHANNELS];
125 float vert_offset[MAX_ANALOG_CHANNELS];
126 char *trigger_source;
127 float horiz_triggerpos;
128 char *trigger_slope;
129 float trigger_level;
130 char *coupling[MAX_ANALOG_CHANNELS];
131
132 /* Operational state */
133
134 /* Number of frames received in total. */
135 uint64_t num_frames;
136 /* GSList entry for the current channel. */
137 GSList *channel_entry;
138 /* Number of bytes received for current channel. */
139 uint64_t num_channel_bytes;
140 /* Number of bytes of block header read */
141 uint64_t num_header_bytes;
142 /* Number of bytes in current data block, if 0 block header expected */
143 uint64_t num_block_bytes;
144 /* Number of data block bytes already read */
145 uint64_t num_block_read;
146 /* What to wait for in *_receive */
147 enum wait_events wait_event;
148 /* Trigger/block copying/stop waiting status */
149 int wait_status;
150 /* Acq buffers used for reading from the scope and sending data to app */
151 unsigned char *buffer;
152 float *data;
89f5fab9 153};
154
b3360671 155SR_PRIV int siglent_sds_config_set(const struct sr_dev_inst *sdi,
156 const char *format, ...);
157SR_PRIV int siglent_sds_capture_start(const struct sr_dev_inst *sdi);
158SR_PRIV int siglent_sds_channel_start(const struct sr_dev_inst *sdi);
159SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data);
160SR_PRIV int siglent_sds_get_dev_cfg(const struct sr_dev_inst *sdi);
161SR_PRIV int siglent_sds_get_dev_cfg_vertical(const struct sr_dev_inst *sdi);
162SR_PRIV int siglent_sds_get_dev_cfg_horizontal(const struct sr_dev_inst *sdi);
89f5fab9 163
164#endif