]>
Commit | Line | Data |
---|---|---|
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 | ||
45 | enum protocol_version { | |
46 | SPO_MODEL, | |
47 | NON_SPO_MODEL, | |
48 | }; | |
49 | ||
b3360671 | 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; | |
b3360671 | 58 | }; |
59 | ||
60 | struct siglent_sds_series { | |
61 | const struct siglent_sds_vendor *vendor; | |
62 | const char *name; | |
63 | enum protocol_version protocol; | |
64 | uint64_t max_timebase[2]; | |
65 | uint64_t min_vdiv[2]; | |
66 | int num_horizontal_divs; | |
67 | int num_vertical_divs; | |
68 | int buffer_samples; | |
69 | }; | |
70 | ||
71 | struct siglent_sds_model { | |
72 | const struct siglent_sds_series *series; | |
73 | const char *name; | |
74 | uint64_t min_timebase[2]; | |
75 | unsigned int analog_channels; | |
76 | bool has_digital; | |
77 | unsigned int digital_channels; | |
78 | }; | |
79 | ||
80 | enum wait_events { | |
81 | WAIT_NONE, /* Don't wait */ | |
82 | WAIT_TRIGGER, /* Wait for trigger */ | |
83 | WAIT_BLOCK, /* Wait for block data (only when reading sample mem) */ | |
84 | WAIT_STOP, /* Wait for scope stopping (only single shots) */ | |
85 | }; | |
86 | ||
89f5fab9 | 87 | struct dev_context { |
b3360671 | 88 | /* Device model */ |
89 | const struct siglent_sds_model *model; | |
90 | ||
91 | /* Device properties */ | |
92 | const uint64_t (*timebases)[2]; | |
93 | uint64_t num_timebases; | |
94 | const uint64_t (*vdivs)[2]; | |
95 | uint64_t num_vdivs; | |
96 | ||
97 | /* Channel groups */ | |
98 | struct sr_channel_group **analog_groups; | |
99 | struct sr_channel_group *digital_group; | |
100 | ||
101 | /* Acquisition settings */ | |
102 | GSList *enabled_channels; | |
103 | uint64_t limit_frames; | |
fe1aa536 | 104 | uint64_t average_samples; |
105 | gboolean average_enabled; | |
b3360671 | 106 | enum data_source data_source; |
107 | uint64_t analog_frame_size; | |
108 | uint64_t digital_frame_size; | |
109 | uint64_t num_samples; | |
e5896840 UH |
110 | long block_header_size; |
111 | float samplerate; | |
b3360671 | 112 | |
113 | /* Device settings */ | |
114 | gboolean analog_channels[MAX_ANALOG_CHANNELS]; | |
115 | gboolean digital_channels[MAX_DIGITAL_CHANNELS]; | |
116 | gboolean la_enabled; | |
117 | float timebase; | |
118 | float attenuation[MAX_ANALOG_CHANNELS]; | |
119 | float vdiv[MAX_ANALOG_CHANNELS]; | |
120 | int vert_reference[MAX_ANALOG_CHANNELS]; | |
121 | float vert_offset[MAX_ANALOG_CHANNELS]; | |
122 | char *trigger_source; | |
123 | float horiz_triggerpos; | |
124 | char *trigger_slope; | |
125 | float trigger_level; | |
126 | char *coupling[MAX_ANALOG_CHANNELS]; | |
127 | ||
128 | /* Operational state */ | |
129 | ||
130 | /* Number of frames received in total. */ | |
131 | uint64_t num_frames; | |
132 | /* GSList entry for the current channel. */ | |
133 | GSList *channel_entry; | |
134 | /* Number of bytes received for current channel. */ | |
135 | uint64_t num_channel_bytes; | |
3e7fb88f | 136 | /* Number of bytes of block header read. */ |
b3360671 | 137 | uint64_t num_header_bytes; |
3e7fb88f | 138 | /* Number of bytes in current data block, if 0 block header expected. */ |
b3360671 | 139 | uint64_t num_block_bytes; |
3e7fb88f | 140 | /* Number of data block bytes already read. */ |
b3360671 | 141 | uint64_t num_block_read; |
3e7fb88f | 142 | /* What to wait for in *_receive. */ |
b3360671 | 143 | enum wait_events wait_event; |
3e7fb88f | 144 | /* Trigger/block copying/stop waiting status. */ |
b3360671 | 145 | int wait_status; |
3e7fb88f | 146 | /* Acq buffers used for reading from the scope and sending data to app. */ |
b3360671 | 147 | unsigned char *buffer; |
148 | float *data; | |
89f5fab9 | 149 | }; |
150 | ||
b3360671 | 151 | SR_PRIV int siglent_sds_config_set(const struct sr_dev_inst *sdi, |
152 | const char *format, ...); | |
153 | SR_PRIV int siglent_sds_capture_start(const struct sr_dev_inst *sdi); | |
154 | SR_PRIV int siglent_sds_channel_start(const struct sr_dev_inst *sdi); | |
155 | SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data); | |
156 | SR_PRIV int siglent_sds_get_dev_cfg(const struct sr_dev_inst *sdi); | |
157 | SR_PRIV int siglent_sds_get_dev_cfg_vertical(const struct sr_dev_inst *sdi); | |
158 | SR_PRIV int siglent_sds_get_dev_cfg_horizontal(const struct sr_dev_inst *sdi); | |
89f5fab9 | 159 | |
160 | #endif |