]>
Commit | Line | Data |
---|---|---|
a1bb33af | 1 | /* |
50985c20 | 2 | * This file is part of the libsigrok project. |
a1bb33af | 3 | * |
13d8e03c | 4 | * Copyright (C) 2013 Bert Vermeulen <bert@biot.com> |
a1bb33af UH |
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 | ||
0f8522bf UH |
20 | #ifndef LIBSIGROK_SIGROK_H |
21 | #define LIBSIGROK_SIGROK_H | |
a1bb33af UH |
22 | |
23 | #include <stdio.h> | |
24 | #include <sys/time.h> | |
25 | #include <stdint.h> | |
26 | #include <inttypes.h> | |
27 | #include <glib.h> | |
a1bb33af | 28 | |
f1b296fc BV |
29 | #ifdef WIN32 |
30 | #define WINVER 0x0500 | |
31 | #define _WIN32_WINNT WINVER | |
32 | #include <Winsock2.h> | |
33 | #else | |
34 | #include <sys/time.h> | |
35 | #endif | |
36 | ||
a00b530c UH |
37 | #ifdef __cplusplus |
38 | extern "C" { | |
39 | #endif | |
40 | ||
393fb9cb UH |
41 | /** |
42 | * @file | |
43 | * | |
44 | * The public libsigrok header file to be used by frontends. | |
1f345a21 UH |
45 | * |
46 | * This is the only file that libsigrok users (frontends) are supposed to | |
ca0938c5 | 47 | * use and \#include. There are other header files which get installed with |
1f345a21 UH |
48 | * libsigrok, but those are not meant to be used directly by frontends. |
49 | * | |
50 | * The correct way to get/use the libsigrok API functions is: | |
51 | * | |
52 | * @code{.c} | |
53 | * #include <libsigrok/libsigrok.h> | |
54 | * @endcode | |
393fb9cb UH |
55 | */ |
56 | ||
e31b636d | 57 | /* |
e31b636d UH |
58 | * All possible return codes of libsigrok functions must be listed here. |
59 | * Functions should never return hardcoded numbers as status, but rather | |
3c0839d5 | 60 | * use these enum values. All error codes are negative numbers. |
e31b636d UH |
61 | * |
62 | * The error codes are globally unique in libsigrok, i.e. if one of the | |
2b3414a4 UH |
63 | * libsigrok functions returns a "malloc error" it must be exactly the same |
64 | * return value as used by all other functions to indicate "malloc error". | |
e31b636d UH |
65 | * There must be no functions which indicate two different errors via the |
66 | * same return code. | |
67 | * | |
68 | * Also, for compatibility reasons, no defined return codes are ever removed | |
3c0839d5 | 69 | * or reused for different errors later. You can only add new entries and |
e31b636d UH |
70 | * return codes, but never remove or redefine existing ones. |
71 | */ | |
3c0839d5 UH |
72 | |
73 | /** Status/error codes returned by libsigrok functions. */ | |
74 | enum { | |
75 | SR_OK = 0, /**< No error. */ | |
76 | SR_ERR = -1, /**< Generic/unspecified error. */ | |
77 | SR_ERR_MALLOC = -2, /**< Malloc/calloc/realloc error. */ | |
78 | SR_ERR_ARG = -3, /**< Function argument error. */ | |
79 | SR_ERR_BUG = -4, /**< Errors hinting at internal bugs. */ | |
80 | SR_ERR_SAMPLERATE = -5, /**< Incorrect samplerate. */ | |
bd6fbf62 | 81 | SR_ERR_NA = -6, /**< Not applicable. */ |
e73ffd42 | 82 | SR_ERR_DEV_CLOSED = -7, /**< Device is closed, but needs to be open. */ |
409a811b UH |
83 | |
84 | /* | |
85 | * Note: When adding entries here, don't forget to also update the | |
86 | * sr_strerror() and sr_strerror_name() functions in error.c. | |
87 | */ | |
3c0839d5 | 88 | }; |
a1bb33af | 89 | |
b2ff9506 | 90 | #define SR_MAX_PROBENAME_LEN 32 |
f1b296fc BV |
91 | #define DS_MAX_ANALOG_PROBES_NUM 8 |
92 | #define TriggerStages 16 | |
93 | #define TriggerProbes 16 | |
94 | #define TriggerCountBits 16 | |
2a3f9541 | 95 | |
a1bb33af | 96 | /* Handy little macros */ |
c9140419 | 97 | #define SR_HZ(n) (n) |
0b4b41ee UH |
98 | #define SR_KHZ(n) ((n) * (uint64_t)(1000ULL)) |
99 | #define SR_MHZ(n) ((n) * (uint64_t)(1000000ULL)) | |
100 | #define SR_GHZ(n) ((n) * (uint64_t)(1000000000ULL)) | |
a1bb33af | 101 | |
0b4b41ee | 102 | #define SR_HZ_TO_NS(n) ((uint64_t)(1000000000ULL) / (n)) |
3677f3ec | 103 | |
3c0839d5 UH |
104 | /** libsigrok loglevels. */ |
105 | enum { | |
106 | SR_LOG_NONE = 0, /**< Output no messages at all. */ | |
107 | SR_LOG_ERR = 1, /**< Output error messages. */ | |
108 | SR_LOG_WARN = 2, /**< Output warnings. */ | |
109 | SR_LOG_INFO = 3, /**< Output informational messages. */ | |
110 | SR_LOG_DBG = 4, /**< Output debug messages. */ | |
111 | SR_LOG_SPEW = 5, /**< Output very noisy debug messages. */ | |
112 | }; | |
1352eedd | 113 | |
1a081ca6 UH |
114 | /* |
115 | * Use SR_API to mark public API symbols, and SR_PRIV for private symbols. | |
116 | * | |
117 | * Variables and functions marked 'static' are private already and don't | |
118 | * need SR_PRIV. However, functions which are not static (because they need | |
119 | * to be used in other libsigrok-internal files) but are also not meant to | |
120 | * be part of the public libsigrok API, must use SR_PRIV. | |
121 | * | |
122 | * This uses the 'visibility' feature of gcc (requires gcc >= 4.0). | |
123 | * | |
69e70c23 UH |
124 | * This feature is not available on MinGW/Windows, as it is a feature of |
125 | * ELF files and MinGW/Windows uses PE files. | |
126 | * | |
1a081ca6 UH |
127 | * Details: http://gcc.gnu.org/wiki/Visibility |
128 | */ | |
129 | ||
130 | /* Marks public libsigrok API symbols. */ | |
69e70c23 | 131 | #ifndef _WIN32 |
1a081ca6 | 132 | #define SR_API __attribute__((visibility("default"))) |
69e70c23 UH |
133 | #else |
134 | #define SR_API | |
135 | #endif | |
1a081ca6 UH |
136 | |
137 | /* Marks private, non-public libsigrok symbols (not part of the API). */ | |
69e70c23 | 138 | #ifndef _WIN32 |
1a081ca6 | 139 | #define SR_PRIV __attribute__((visibility("hidden"))) |
69e70c23 UH |
140 | #else |
141 | #define SR_PRIV | |
142 | #endif | |
1a081ca6 | 143 | |
f1b296fc | 144 | typedef int (*sr_receive_data_callback_t)(int fd, int revents, const struct sr_dev_inst *sdi); |
882e2075 | 145 | |
08a9260b | 146 | /** Data types used by sr_config_info(). */ |
a1bb33af | 147 | enum { |
24d04d1e | 148 | SR_T_UINT64 = 10000, |
5a2326a7 | 149 | SR_T_CHAR, |
4d436e71 | 150 | SR_T_BOOL, |
0fe11789 | 151 | SR_T_FLOAT, |
c1e48618 | 152 | SR_T_RATIONAL_PERIOD, |
bd8db307 | 153 | SR_T_RATIONAL_VOLT, |
45edd0b2 | 154 | SR_T_KEYVALUE, |
0fe11789 BV |
155 | }; |
156 | ||
3c0839d5 | 157 | /** Value for sr_datafeed_packet.type. */ |
a1bb33af | 158 | enum { |
24d04d1e | 159 | SR_DF_HEADER = 10000, |
5a2326a7 | 160 | SR_DF_END, |
9a5693a5 | 161 | SR_DF_META, |
5a2326a7 UH |
162 | SR_DF_TRIGGER, |
163 | SR_DF_LOGIC, | |
ee7489d2 | 164 | SR_DF_ANALOG, |
6ea7669c BV |
165 | SR_DF_FRAME_BEGIN, |
166 | SR_DF_FRAME_END, | |
a1bb33af UH |
167 | }; |
168 | ||
3c0839d5 | 169 | /** Values for sr_datafeed_analog.mq. */ |
9956f285 | 170 | enum { |
24d04d1e | 171 | SR_MQ_VOLTAGE = 10000, |
9956f285 UH |
172 | SR_MQ_CURRENT, |
173 | SR_MQ_RESISTANCE, | |
174 | SR_MQ_CAPACITANCE, | |
175 | SR_MQ_TEMPERATURE, | |
176 | SR_MQ_FREQUENCY, | |
177 | SR_MQ_DUTY_CYCLE, | |
64591be2 | 178 | SR_MQ_CONTINUITY, |
aa839a5c | 179 | SR_MQ_PULSE_WIDTH, |
96b3b3d5 | 180 | SR_MQ_CONDUCTANCE, |
3c0839d5 | 181 | /** Electrical power, usually in W, or dBm. */ |
b82a17d3 | 182 | SR_MQ_POWER, |
a02d77bc | 183 | /** Gain (a transistor's gain, or hFE, for example). */ |
b82a17d3 | 184 | SR_MQ_GAIN, |
fc19c288 BV |
185 | /** Logarithmic representation of sound pressure relative to a |
186 | * reference value. */ | |
187 | SR_MQ_SOUND_PRESSURE_LEVEL, | |
4f3bd685 | 188 | SR_MQ_CARBON_MONOXIDE, |
ef4344e7 | 189 | SR_MQ_RELATIVE_HUMIDITY, |
9956f285 UH |
190 | }; |
191 | ||
3c0839d5 | 192 | /** Values for sr_datafeed_analog.unit. */ |
aff5a729 | 193 | enum { |
24d04d1e | 194 | SR_UNIT_VOLT = 10000, |
9956f285 UH |
195 | SR_UNIT_AMPERE, |
196 | SR_UNIT_OHM, | |
197 | SR_UNIT_FARAD, | |
9956f285 | 198 | SR_UNIT_KELVIN, |
edb000eb BV |
199 | SR_UNIT_CELSIUS, |
200 | SR_UNIT_FAHRENHEIT, | |
9956f285 UH |
201 | SR_UNIT_HERTZ, |
202 | SR_UNIT_PERCENTAGE, | |
edb000eb | 203 | SR_UNIT_BOOLEAN, |
aa839a5c | 204 | SR_UNIT_SECOND, |
3c0839d5 | 205 | /** Unit of conductance, the inverse of resistance. */ |
96b3b3d5 | 206 | SR_UNIT_SIEMENS, |
3c0839d5 UH |
207 | /** |
208 | * An absolute measurement of power, in decibels, referenced to | |
209 | * 1 milliwatt (dBu). | |
210 | */ | |
b82a17d3 | 211 | SR_UNIT_DECIBEL_MW, |
6b869234 BV |
212 | /** Voltage in decibel, referenced to 1 volt (dBV). */ |
213 | SR_UNIT_DECIBEL_VOLT, | |
3c0839d5 UH |
214 | /** |
215 | * Measurements that intrinsically do not have units attached, such | |
6b869234 | 216 | * as ratios, gains, etc. Specifically, a transistor's gain (hFE) is |
3c0839d5 UH |
217 | * a unitless quantity, for example. |
218 | */ | |
b82a17d3 | 219 | SR_UNIT_UNITLESS, |
fc19c288 BV |
220 | /** Sound pressure level relative so 20 micropascals. */ |
221 | SR_UNIT_DECIBEL_SPL, | |
801c7800 AG |
222 | /** |
223 | * Normalized (0 to 1) concentration of a substance or compound with 0 | |
224 | * representing a concentration of 0%, and 1 being 100%. This is | |
225 | * represented as the fraction of number of particles of the substance. | |
226 | */ | |
4f3bd685 | 227 | SR_UNIT_CONCENTRATION, |
aff5a729 BV |
228 | }; |
229 | ||
3c0839d5 | 230 | /** Values for sr_datafeed_analog.flags. */ |
02e864d0 | 231 | enum { |
3c0839d5 | 232 | /** Voltage measurement is alternating current (AC). */ |
02e864d0 | 233 | SR_MQFLAG_AC = 0x01, |
3c0839d5 | 234 | /** Voltage measurement is direct current (DC). */ |
02e864d0 BV |
235 | SR_MQFLAG_DC = 0x02, |
236 | /** This is a true RMS measurement. */ | |
237 | SR_MQFLAG_RMS = 0x04, | |
238 | /** Value is voltage drop across a diode, or NAN. */ | |
239 | SR_MQFLAG_DIODE = 0x08, | |
a02d77bc | 240 | /** Device is in "hold" mode (repeating the last measurement). */ |
02e864d0 | 241 | SR_MQFLAG_HOLD = 0x10, |
3c0839d5 | 242 | /** Device is in "max" mode, only updating upon a new max value. */ |
02e864d0 | 243 | SR_MQFLAG_MAX = 0x20, |
3c0839d5 | 244 | /** Device is in "min" mode, only updating upon a new min value. */ |
02e864d0 BV |
245 | SR_MQFLAG_MIN = 0x40, |
246 | /** Device is in autoranging mode. */ | |
247 | SR_MQFLAG_AUTORANGE = 0x80, | |
248 | /** Device is in relative mode. */ | |
249 | SR_MQFLAG_RELATIVE = 0x100, | |
fc19c288 | 250 | /** Sound pressure level is A-weighted in the frequency domain, |
2244356d | 251 | * according to IEC 61672:2003. */ |
fc19c288 BV |
252 | SR_MQFLAG_SPL_FREQ_WEIGHT_A = 0x200, |
253 | /** Sound pressure level is C-weighted in the frequency domain, | |
2244356d | 254 | * according to IEC 61672:2003. */ |
fc19c288 BV |
255 | SR_MQFLAG_SPL_FREQ_WEIGHT_C = 0x400, |
256 | /** Sound pressure level is Z-weighted (i.e. not at all) in the | |
2244356d | 257 | * frequency domain, according to IEC 61672:2003. */ |
fc19c288 BV |
258 | SR_MQFLAG_SPL_FREQ_WEIGHT_Z = 0x800, |
259 | /** Sound pressure level is not weighted in the frequency domain, | |
260 | * albeit without standards-defined low and high frequency limits. */ | |
261 | SR_MQFLAG_SPL_FREQ_WEIGHT_FLAT = 0x1000, | |
262 | /** Sound pressure level measurement is S-weighted (1s) in the | |
263 | * time domain. */ | |
264 | SR_MQFLAG_SPL_TIME_WEIGHT_S = 0x2000, | |
265 | /** Sound pressure level measurement is F-weighted (125ms) in the | |
266 | * time domain. */ | |
267 | SR_MQFLAG_SPL_TIME_WEIGHT_F = 0x4000, | |
268 | /** Sound pressure level is time-averaged (LAT), also known as | |
269 | * Equivalent Continuous A-weighted Sound Level (LEQ). */ | |
270 | SR_MQFLAG_SPL_LAT = 0x8000, | |
271 | /** Sound pressure level represented as a percentage of measurements | |
272 | * that were over a preset alarm level. */ | |
273 | SR_MQFLAG_SPL_PCT_OVER_ALARM = 0x10000, | |
02e864d0 BV |
274 | }; |
275 | ||
b8072700 PS |
276 | struct sr_context; |
277 | ||
b9c735a2 | 278 | struct sr_datafeed_packet { |
a1bb33af | 279 | uint16_t type; |
bf53457d | 280 | const void *payload; |
a1bb33af UH |
281 | }; |
282 | ||
b9c735a2 | 283 | struct sr_datafeed_header { |
a1bb33af UH |
284 | int feed_version; |
285 | struct timeval starttime; | |
ee7489d2 BV |
286 | }; |
287 | ||
9a5693a5 BV |
288 | struct sr_datafeed_meta { |
289 | GSList *config; | |
290 | }; | |
291 | ||
38ab3ee7 BV |
292 | struct sr_datafeed_logic { |
293 | uint64_t length; | |
294 | uint16_t unitsize; | |
f1b296fc | 295 | uint16_t data_error; |
9c939c51 | 296 | void *data; |
38ab3ee7 BV |
297 | }; |
298 | ||
f1b296fc BV |
299 | struct sr_datafeed_trigger { |
300 | ||
301 | }; | |
302 | ||
ee7489d2 | 303 | struct sr_datafeed_analog { |
aeba33ba | 304 | /** The probes for which data is included in this packet. */ |
69e19dd7 | 305 | GSList *probes; |
ee7489d2 | 306 | int num_samples; |
a02d77bc | 307 | /** Measured quantity (voltage, current, temperature, and so on). */ |
02e864d0 BV |
308 | int mq; |
309 | /** Unit in which the MQ is measured. */ | |
310 | int unit; | |
311 | /** Bitmap with extra information about the MQ. */ | |
312 | uint64_t mqflags; | |
aeba33ba BV |
313 | /** The analog value(s). The data is interleaved according to |
314 | * the probes list. */ | |
ee7489d2 BV |
315 | float *data; |
316 | }; | |
317 | ||
83687343 | 318 | /** Input (file) format struct. */ |
f50f3f40 | 319 | struct sr_input { |
83687343 UH |
320 | /** |
321 | * A pointer to this input format's 'struct sr_input_format'. | |
322 | * The frontend can use this to call the module's callbacks. | |
323 | */ | |
f50f3f40 | 324 | struct sr_input_format *format; |
83687343 | 325 | |
3dafb92b | 326 | GHashTable *param; |
83687343 | 327 | |
5c3c1241 | 328 | struct sr_dev_inst *sdi; |
83687343 | 329 | |
3dafb92b | 330 | void *internal; |
34e4813f BV |
331 | }; |
332 | ||
f50f3f40 | 333 | struct sr_input_format { |
83687343 | 334 | /** The unique ID for this input format. Must not be NULL. */ |
cdb3573c | 335 | char *id; |
83687343 UH |
336 | |
337 | /** | |
338 | * A short description of the input format, which can (for example) | |
339 | * be displayed to the user by frontends. Must not be NULL. | |
340 | */ | |
34e4813f | 341 | char *description; |
83687343 UH |
342 | |
343 | /** | |
344 | * Check if this input module can load and parse the specified file. | |
345 | * | |
346 | * @param filename The name (and path) of the file to check. | |
347 | * | |
348 | * @return TRUE if this module knows the format, FALSE if it doesn't. | |
349 | */ | |
757b8c62 | 350 | int (*format_match) (const char *filename); |
83687343 UH |
351 | |
352 | /** | |
353 | * Initialize the input module. | |
354 | * | |
355 | * @param in A pointer to a valid 'struct sr_input' that the caller | |
356 | * has to allocate and provide to this function. It is also | |
357 | * the responsibility of the caller to free it later. | |
358 | * @param filename The name (and path) of the file to use. | |
359 | * | |
360 | * @return SR_OK upon success, a negative error code upon failure. | |
361 | */ | |
543d45c5 | 362 | int (*init) (struct sr_input *in, const char *filename); |
83687343 UH |
363 | |
364 | /** | |
365 | * Load a file, parsing the input according to the file's format. | |
366 | * | |
367 | * This function will send datafeed packets to the session bus, so | |
368 | * the calling frontend must have registered its session callbacks | |
369 | * beforehand. | |
370 | * | |
371 | * The packet types sent across the session bus by this function must | |
372 | * include at least SR_DF_HEADER, SR_DF_END, and an appropriate data | |
373 | * type such as SR_DF_LOGIC. It may also send a SR_DF_TRIGGER packet | |
374 | * if appropriate. | |
375 | * | |
376 | * @param in A pointer to a valid 'struct sr_input' that the caller | |
377 | * has to allocate and provide to this function. It is also | |
378 | * the responsibility of the caller to free it later. | |
379 | * @param filename The name (and path) of the file to use. | |
380 | * | |
381 | * @return SR_OK upon success, a negative error code upon failure. | |
382 | */ | |
f50f3f40 | 383 | int (*loadfile) (struct sr_input *in, const char *filename); |
34e4813f BV |
384 | }; |
385 | ||
07e1aad5 | 386 | /** Output (file) format struct. */ |
f50f3f40 | 387 | struct sr_output { |
07e1aad5 UH |
388 | /** |
389 | * A pointer to this output format's 'struct sr_output_format'. | |
390 | * The frontend can use this to call the module's callbacks. | |
391 | */ | |
f50f3f40 | 392 | struct sr_output_format *format; |
07e1aad5 UH |
393 | |
394 | /** | |
395 | * The device for which this output module is creating output. This | |
396 | * can be used by the module to find out probe names and numbers. | |
397 | */ | |
5c3c1241 | 398 | struct sr_dev_inst *sdi; |
07e1aad5 UH |
399 | |
400 | /** | |
401 | * An optional parameter which the frontend can pass in to the | |
402 | * output module. How the string is interpreted is entirely up to | |
403 | * the module. | |
404 | */ | |
a1bb33af | 405 | char *param; |
07e1aad5 UH |
406 | |
407 | /** | |
408 | * A generic pointer which can be used by the module to keep internal | |
409 | * state between calls into its callback functions. | |
410 | * | |
411 | * For example, the module might store a pointer to a chunk of output | |
412 | * there, and only flush it when it reaches a certain size. | |
413 | */ | |
a1bb33af UH |
414 | void *internal; |
415 | }; | |
416 | ||
f50f3f40 | 417 | struct sr_output_format { |
07e1aad5 UH |
418 | /** |
419 | * A unique ID for this output format. Must not be NULL. | |
420 | * | |
421 | * It can be used by frontends to select this output format for use. | |
422 | * | |
423 | * For example, calling sigrok-cli with <code>-O hex</code> will | |
424 | * select the hexadecimal text output format. | |
425 | */ | |
cdb3573c | 426 | char *id; |
07e1aad5 UH |
427 | |
428 | /** | |
429 | * A short description of the output format. Must not be NULL. | |
430 | * | |
431 | * This can be displayed by frontends, e.g. when selecting the output | |
432 | * format for saving a file. | |
433 | */ | |
a1bb33af | 434 | char *description; |
07e1aad5 | 435 | |
f0411b1d | 436 | int df_type; |
07e1aad5 UH |
437 | |
438 | /** | |
439 | * This function is called once, at the beginning of an output stream. | |
440 | * | |
441 | * The device struct will be available in the output struct passed in, | |
442 | * as well as the param field -- which may be NULL or an empty string, | |
443 | * if no parameter was passed. | |
444 | * | |
445 | * The module can use this to initialize itself, create a struct for | |
446 | * keeping state and storing it in the <code>internal</code> field. | |
447 | * | |
448 | * @param o Pointer to the respective 'struct sr_output'. | |
449 | * | |
450 | * @return SR_OK upon success, a negative error code otherwise. | |
451 | */ | |
f50f3f40 | 452 | int (*init) (struct sr_output *o); |
07e1aad5 UH |
453 | |
454 | /** | |
455 | * Whenever a chunk of data comes in, it will be passed to the | |
456 | * output module via this function. The <code>data_in</code> and | |
457 | * <code>length_in</code> values refers to this data; the module | |
458 | * must not alter or g_free() this buffer. | |
459 | * | |
460 | * The function must allocate a buffer for storing its output, and | |
461 | * pass along a pointer to this buffer in the <code>data_out</code> | |
462 | * parameter, as well as storing the length of the buffer in | |
463 | * <code>length_out</code>. The calling frontend will g_free() | |
464 | * this buffer when it's done with it. | |
465 | * | |
466 | * IMPORTANT: The memory allocation much happen using a glib memory | |
467 | * allocation call (not a "normal" malloc) since g_free() will be | |
468 | * used to free the memory! | |
469 | * | |
470 | * If there is no output, this function MUST store NULL in the | |
471 | * <code>data_out</code> parameter, so the caller knows not to try | |
472 | * and g_free() it. | |
473 | * | |
17f63de6 | 474 | * Note: This API call is obsolete, use receive() instead. |
07e1aad5 UH |
475 | * |
476 | * @param o Pointer to the respective 'struct sr_output'. | |
477 | * @param data_in Pointer to the input data buffer. | |
478 | * @param length_in Length of the input. | |
479 | * @param data_out Pointer to the allocated output buffer. | |
480 | * @param length_out Length (in bytes) of the output. | |
481 | * | |
482 | * @return SR_OK upon success, a negative error code otherwise. | |
483 | */ | |
054e6709 UH |
484 | int (*data) (struct sr_output *o, const uint8_t *data_in, |
485 | uint64_t length_in, uint8_t **data_out, | |
486 | uint64_t *length_out); | |
07e1aad5 UH |
487 | |
488 | /** | |
489 | * This function is called when an event occurs in the datafeed | |
490 | * which the output module may need to be aware of. No data is | |
491 | * passed in, only the fact that the event occurs. The following | |
492 | * events can currently be passed in: | |
493 | * | |
494 | * - SR_DF_TRIGGER: At this point in the datafeed, the trigger | |
495 | * matched. The output module may mark this in some way, e.g. by | |
496 | * plotting a red line on a graph. | |
497 | * | |
498 | * - SR_DF_END: This marks the end of the datafeed. No more calls | |
499 | * into the output module will be done, so this is a good time to | |
500 | * free up any memory used to keep state, for example. | |
501 | * | |
502 | * Any output generated by this function must have a reference to | |
503 | * it stored in the <code>data_out</code> and <code>length_out</code> | |
504 | * parameters, or NULL if no output was generated. | |
505 | * | |
17f63de6 | 506 | * Note: This API call is obsolete, use receive() instead. |
07e1aad5 UH |
507 | * |
508 | * @param o Pointer to the respective 'struct sr_output'. | |
509 | * @param event_type Type of event that occured. | |
510 | * @param data_out Pointer to the allocated output buffer. | |
511 | * @param length_out Length (in bytes) of the output. | |
512 | * | |
513 | * @return SR_OK upon success, a negative error code otherwise. | |
514 | */ | |
054e6709 | 515 | int (*event) (struct sr_output *o, int event_type, uint8_t **data_out, |
17f63de6 | 516 | uint64_t *length_out); |
07e1aad5 | 517 | |
17f63de6 BV |
518 | /** |
519 | * This function is passed a copy of every packed in the data feed. | |
520 | * Any output generated by the output module in response to the | |
521 | * packet should be returned in a newly allocated GString | |
522 | * <code>out</code>, which will be freed by the caller. | |
523 | * | |
524 | * Packets not of interest to the output module can just be ignored, | |
525 | * and the <code>out</code> parameter set to NULL. | |
526 | * | |
527 | * @param o Pointer to the respective 'struct sr_output'. | |
528 | * @param sdi The device instance that generated the packet. | |
529 | * @param packet The complete packet. | |
530 | * @param out A pointer where a GString * should be stored if | |
531 | * the module generates output, or NULL if not. | |
532 | * | |
533 | * @return SR_OK upon success, a negative error code otherwise. | |
534 | */ | |
535 | int (*receive) (struct sr_output *o, const struct sr_dev_inst *sdi, | |
536 | const struct sr_datafeed_packet *packet, GString **out); | |
07e1aad5 | 537 | |
17f63de6 BV |
538 | /** |
539 | * This function is called after the caller is finished using | |
540 | * the output module, and can be used to free any internal | |
541 | * resources the module may keep. | |
542 | * | |
543 | * @return SR_OK upon success, a negative error code otherwise. | |
544 | */ | |
f45b7590 | 545 | int (*cleanup) (struct sr_output *o); |
a1bb33af UH |
546 | }; |
547 | ||
921e753f | 548 | enum { |
24d04d1e | 549 | SR_PROBE_LOGIC = 10000, |
87ca93c5 | 550 | SR_PROBE_ANALOG, |
921e753f DR |
551 | }; |
552 | ||
f1b296fc BV |
553 | enum { |
554 | LOGIC = 0, | |
555 | ANALOG = 1, | |
556 | }; | |
557 | ||
558 | static const char *mode_strings[] = { | |
559 | "Logic Analyzer", | |
560 | "Oscilloscope", | |
561 | }; | |
562 | ||
1afe8989 | 563 | struct sr_probe { |
08a9260b | 564 | /* The index field will go: use g_slist_length(sdi->probes) instead. */ |
a1bb33af | 565 | int index; |
6ea7e235 | 566 | int type; |
a1bb33af UH |
567 | gboolean enabled; |
568 | char *name; | |
569 | char *trigger; | |
570 | }; | |
571 | ||
9a5693a5 BV |
572 | struct sr_config { |
573 | int key; | |
bc1c2f00 | 574 | GVariant *data; |
b159add3 BV |
575 | }; |
576 | ||
9a5693a5 BV |
577 | struct sr_config_info { |
578 | int key; | |
fbf394c6 | 579 | int datatype; |
9a5693a5 BV |
580 | char *id; |
581 | char *name; | |
582 | char *description; | |
9a5693a5 BV |
583 | }; |
584 | ||
a1bb33af | 585 | enum { |
e88dadd7 UH |
586 | /*--- Device classes ------------------------------------------------*/ |
587 | ||
588 | /** The device can act as logic analyzer. */ | |
1953564a | 589 | SR_CONF_LOGIC_ANALYZER = 10000, |
925dbf9f | 590 | |
ee7489d2 | 591 | /** The device can act as an oscilloscope. */ |
1953564a | 592 | SR_CONF_OSCILLOSCOPE, |
e88dadd7 | 593 | |
ca3d84cc | 594 | /** The device can act as a multimeter. */ |
1953564a | 595 | SR_CONF_MULTIMETER, |
a141db8c | 596 | |
ca3d84cc | 597 | /** The device is a demo device. */ |
1953564a | 598 | SR_CONF_DEMO_DEV, |
a141db8c | 599 | |
fc19c288 | 600 | /** The device can act as a sound level meter. */ |
1953564a | 601 | SR_CONF_SOUNDLEVELMETER, |
ca3d84cc | 602 | |
40270444 | 603 | /** The device can measure temperature. */ |
1953564a | 604 | SR_CONF_THERMOMETER, |
40270444 BV |
605 | |
606 | /** The device can measure humidity. */ | |
1953564a | 607 | SR_CONF_HYGROMETER, |
40270444 | 608 | |
9a6517d1 | 609 | /*--- Driver scan options -------------------------------------------*/ |
c89c1c9c BV |
610 | |
611 | /** | |
612 | * Specification on how to connect to a device. | |
613 | * | |
1953564a | 614 | * In combination with SR_CONF_SERIALCOMM, this is a serial port in |
c89c1c9c BV |
615 | * the form which makes sense to the OS (e.g., /dev/ttyS0). |
616 | * Otherwise this specifies a USB device, either in the form of | |
617 | * @verbatim <bus>.<address> @endverbatim (decimal, e.g. 1.65) or | |
618 | * @verbatim <vendorid>.<productid> @endverbatim | |
619 | * (hexadecimal, e.g. 1d6b.0001). | |
620 | */ | |
1953564a | 621 | SR_CONF_CONN = 20000, |
c89c1c9c BV |
622 | |
623 | /** | |
624 | * Serial communication specification, in the form: | |
625 | * | |
626 | * @verbatim <baudrate>/<databits><parity><stopbits> @endverbatim | |
627 | * | |
628 | * Example: 9600/8n1 | |
629 | * | |
630 | * The string may also be followed by one or more special settings, | |
631 | * in the form "/key=value". Supported keys and their values are: | |
632 | * | |
633 | * rts 0,1 set the port's RTS pin to low or high | |
634 | * dtr 0,1 set the port's DTR pin to low or high | |
635 | * flow 0 no flow control | |
636 | * 1 hardware-based (RTS/CTS) flow control | |
637 | * 2 software-based (XON/XOFF) flow control | |
638 | * | |
639 | * This is always an optional parameter, since a driver typically | |
640 | * knows the speed at which the device wants to communicate. | |
641 | */ | |
1953564a | 642 | SR_CONF_SERIALCOMM, |
c89c1c9c | 643 | |
ca3d84cc | 644 | /*--- Device configuration ------------------------------------------*/ |
e88dadd7 | 645 | |
7231a145 | 646 | /** The device supports setting its samplerate, in Hz. */ |
1953564a | 647 | SR_CONF_SAMPLERATE = 30000, |
e88dadd7 | 648 | |
e88dadd7 | 649 | /** The device supports setting a pre/post-trigger capture ratio. */ |
1953564a | 650 | SR_CONF_CAPTURE_RATIO, |
e88dadd7 | 651 | |
f1b296fc BV |
652 | /** */ |
653 | SR_CONF_DEVICE_MODE, | |
654 | ||
e88dadd7 | 655 | /** The device supports setting a pattern (pattern generator mode). */ |
1953564a | 656 | SR_CONF_PATTERN_MODE, |
e88dadd7 | 657 | |
3a4d09c0 | 658 | /** The device supports Run Length Encoding. */ |
1953564a | 659 | SR_CONF_RLE, |
3a4d09c0 | 660 | |
ee7489d2 | 661 | /** The device supports setting trigger slope. */ |
1953564a | 662 | SR_CONF_TRIGGER_SLOPE, |
0fe11789 BV |
663 | |
664 | /** Trigger source. */ | |
1953564a | 665 | SR_CONF_TRIGGER_SOURCE, |
0fe11789 | 666 | |
3c0839d5 | 667 | /** Horizontal trigger position. */ |
1953564a | 668 | SR_CONF_HORIZ_TRIGGERPOS, |
0fe11789 BV |
669 | |
670 | /** Buffer size. */ | |
1953564a | 671 | SR_CONF_BUFFERSIZE, |
0fe11789 BV |
672 | |
673 | /** Time base. */ | |
1953564a | 674 | SR_CONF_TIMEBASE, |
ee7489d2 | 675 | |
3c4976c9 | 676 | /** Filter. */ |
1953564a | 677 | SR_CONF_FILTER, |
3c4976c9 | 678 | |
bd8db307 | 679 | /** Volts/div. */ |
1953564a | 680 | SR_CONF_VDIV, |
bd8db307 | 681 | |
e1c8b2ab | 682 | /** Coupling. */ |
1953564a | 683 | SR_CONF_COUPLING, |
e1c8b2ab | 684 | |
c50277a6 BV |
685 | /** Trigger types. */ |
686 | SR_CONF_TRIGGER_TYPE, | |
687 | ||
7231a145 BV |
688 | /** The device supports setting its sample interval, in ms. */ |
689 | SR_CONF_SAMPLE_INTERVAL, | |
690 | ||
2efa699f BV |
691 | /** Number of timebases, as related to SR_CONF_TIMEBASE. */ |
692 | SR_CONF_NUM_TIMEBASE, | |
693 | ||
694 | /** Number of vertical divisions, as related to SR_CONF_VDIV. */ | |
695 | SR_CONF_NUM_VDIV, | |
696 | ||
f1b296fc BV |
697 | /** clock type (internal/external) */ |
698 | SR_CONF_CLOCK_TYPE, | |
699 | ||
e88dadd7 UH |
700 | /*--- Special stuff -------------------------------------------------*/ |
701 | ||
9a6517d1 | 702 | /** Scan options supported by the driver. */ |
aeba33ba | 703 | SR_CONF_SCAN_OPTIONS = 40000, |
9a6517d1 BV |
704 | |
705 | /** Device options for a particular device. */ | |
706 | SR_CONF_DEVICE_OPTIONS, | |
f1b296fc | 707 | SR_CONF_DEVICE_CONFIGS, |
9a6517d1 | 708 | |
3c0839d5 | 709 | /** Session filename. */ |
aeba33ba | 710 | SR_CONF_SESSIONFILE, |
40dda2c3 | 711 | |
e88dadd7 | 712 | /** The device supports specifying a capturefile to inject. */ |
1953564a | 713 | SR_CONF_CAPTUREFILE, |
925dbf9f | 714 | |
e88dadd7 | 715 | /** The device supports specifying the capturefile unit size. */ |
1953564a | 716 | SR_CONF_CAPTURE_UNITSIZE, |
7d658874 | 717 | |
e88dadd7 | 718 | /** The device supports setting the number of probes. */ |
1953564a | 719 | SR_CONF_CAPTURE_NUM_PROBES, |
e88dadd7 UH |
720 | |
721 | /*--- Acquisition modes ---------------------------------------------*/ | |
722 | ||
723 | /** | |
a02d77bc UH |
724 | * The device supports setting a sample time limit (how long |
725 | * the sample acquisition should run, in ms). | |
e88dadd7 | 726 | */ |
1953564a | 727 | SR_CONF_LIMIT_MSEC = 50000, |
e88dadd7 UH |
728 | |
729 | /** | |
a02d77bc UH |
730 | * The device supports setting a sample number limit (how many |
731 | * samples should be acquired). | |
e88dadd7 | 732 | */ |
1953564a | 733 | SR_CONF_LIMIT_SAMPLES, |
e88dadd7 | 734 | |
6ea7669c | 735 | /** |
a02d77bc UH |
736 | * The device supports setting a frame limit (how many |
737 | * frames should be acquired). | |
6ea7669c | 738 | */ |
1953564a | 739 | SR_CONF_LIMIT_FRAMES, |
6ea7669c | 740 | |
e88dadd7 | 741 | /** |
a02d77bc | 742 | * The device supports continuous sampling. Neither a time limit |
e88dadd7 UH |
743 | * nor a sample number limit has to be supplied, it will just acquire |
744 | * samples continuously, until explicitly stopped by a certain command. | |
745 | */ | |
1953564a | 746 | SR_CONF_CONTINUOUS, |
e6551ea6 BV |
747 | |
748 | /** The device has internal storage, into which data is logged. This | |
749 | * starts or stops the internal logging. */ | |
750 | SR_CONF_DATALOG, | |
a1bb33af UH |
751 | }; |
752 | ||
d68e2d1a | 753 | struct sr_dev_inst { |
9e41fdba | 754 | struct sr_dev_driver *driver; |
a1bb33af UH |
755 | int index; |
756 | int status; | |
1d9a8a5f | 757 | int inst_type; |
f1b296fc | 758 | int mode; |
a1bb33af UH |
759 | char *vendor; |
760 | char *model; | |
761 | char *version; | |
47211d65 | 762 | GSList *probes; |
9e2e9864 | 763 | void *conn; |
8d672550 | 764 | void *priv; |
a1bb33af UH |
765 | }; |
766 | ||
3c0839d5 | 767 | /** Types of device instances (sr_dev_inst). */ |
a1bb33af | 768 | enum { |
4101f961 | 769 | /** Device instance type for USB devices. */ |
24d04d1e | 770 | SR_INST_USB = 10000, |
4101f961 UH |
771 | /** Device instance type for serial port devices. */ |
772 | SR_INST_SERIAL, | |
a1bb33af UH |
773 | }; |
774 | ||
3c0839d5 | 775 | /** Device instance status. */ |
a1bb33af | 776 | enum { |
3c0839d5 | 777 | /** The device instance was not found. */ |
24d04d1e | 778 | SR_ST_NOT_FOUND = 10000, |
3c0839d5 | 779 | /** The device instance was found, but is still booting. */ |
5a2326a7 | 780 | SR_ST_INITIALIZING, |
3c0839d5 | 781 | /** The device instance is live, but not in use. */ |
5a2326a7 | 782 | SR_ST_INACTIVE, |
3c0839d5 | 783 | /** The device instance is actively in use in a session. */ |
5a2326a7 | 784 | SR_ST_ACTIVE, |
69b07d14 BV |
785 | /** The device is winding down its session. */ |
786 | SR_ST_STOPPING, | |
a1bb33af UH |
787 | }; |
788 | ||
c09f0b57 UH |
789 | struct sr_dev_driver { |
790 | /* Driver-specific */ | |
a1bb33af | 791 | char *name; |
9f8274a5 | 792 | char *longname; |
a1bb33af | 793 | int api_version; |
34f06b90 | 794 | int (*init) (struct sr_context *sr_ctx); |
57ab7d9f | 795 | int (*cleanup) (void); |
80bf0426 | 796 | GSList *(*scan) (GSList *options); |
811deee4 BV |
797 | GSList *(*dev_list) (void); |
798 | int (*dev_clear) (void); | |
bc1c2f00 | 799 | int (*config_get) (int id, GVariant **data, |
035a1078 | 800 | const struct sr_dev_inst *sdi); |
bc1c2f00 | 801 | int (*config_set) (int id, GVariant *data, |
035a1078 | 802 | const struct sr_dev_inst *sdi); |
bc1c2f00 | 803 | int (*config_list) (int info_id, GVariant **data, |
c5fb502f | 804 | const struct sr_dev_inst *sdi); |
a1bb33af | 805 | |
1b452b85 | 806 | /* Device-specific */ |
25a0f108 BV |
807 | int (*dev_open) (struct sr_dev_inst *sdi); |
808 | int (*dev_close) (struct sr_dev_inst *sdi); | |
f1b296fc | 809 | int (*dev_test) (struct sr_dev_inst *sdi); |
3ffb6964 BV |
810 | int (*dev_acquisition_start) (const struct sr_dev_inst *sdi, |
811 | void *cb_data); | |
69b07d14 | 812 | int (*dev_acquisition_stop) (struct sr_dev_inst *sdi, |
3ffb6964 | 813 | void *cb_data); |
dd34b8d3 BV |
814 | |
815 | /* Dynamic */ | |
c259726a | 816 | void *priv; |
a1bb33af UH |
817 | }; |
818 | ||
2872d21e | 819 | struct sr_session { |
3c0839d5 | 820 | /** List of struct sr_dev pointers. */ |
bb7ef793 | 821 | GSList *devs; |
2726474a | 822 | /** List of struct datafeed_callback pointers. */ |
a1bb33af UH |
823 | GSList *datafeed_callbacks; |
824 | GTimeVal starttime; | |
b7e94111 LPC |
825 | |
826 | unsigned int num_sources; | |
827 | ||
3c0839d5 UH |
828 | /* |
829 | * Both "sources" and "pollfds" are of the same size and contain pairs | |
830 | * of descriptor and callback function. We can not embed the GPollFD | |
831 | * into the source struct since we want to be able to pass the array | |
832 | * of all poll descriptors to g_poll(). | |
b7e94111 LPC |
833 | */ |
834 | struct source *sources; | |
835 | GPollFD *pollfds; | |
836 | int source_timeout; | |
33c6e4c5 AG |
837 | |
838 | /* | |
839 | * These are our synchronization primitives for stopping the session in | |
840 | * an async fashion. We need to make sure the session is stopped from | |
841 | * within the session thread itself. | |
842 | */ | |
f1b296fc | 843 | // GMutex stop_mutex; |
33c6e4c5 | 844 | gboolean abort_session; |
a1bb33af UH |
845 | }; |
846 | ||
f1b296fc BV |
847 | enum { |
848 | SIMPLE_TRIGGER = 0, | |
849 | ADV_TRIGGER, | |
850 | }; | |
851 | ||
852 | struct ds_trigger { | |
853 | uint16_t trigger_en; | |
854 | uint16_t trigger_mode; | |
855 | uint16_t trigger_pos; | |
856 | uint16_t trigger_stages; | |
857 | unsigned char trigger_logic[TriggerStages+1]; | |
858 | unsigned char trigger0_inv[TriggerStages+1]; | |
859 | unsigned char trigger1_inv[TriggerStages+1]; | |
860 | char trigger0[TriggerStages+1][TriggerProbes]; | |
861 | char trigger1[TriggerStages+1][TriggerProbes]; | |
862 | uint16_t trigger0_count[TriggerStages+1]; | |
863 | uint16_t trigger1_count[TriggerStages+1]; | |
864 | }; | |
865 | ||
866 | struct ds_trigger_pos { | |
867 | uint32_t real_pos; | |
868 | uint32_t ram_saddr; | |
869 | unsigned char first_block[504]; | |
870 | }; | |
871 | ||
872 | //struct libusbhp_t; | |
873 | typedef void (*libusbhp_hotplug_cb_fn)(struct libusbhp_device_t *device, | |
874 | void *user_data); | |
875 | #ifdef __linux__ | |
876 | #include <libudev.h> | |
877 | ||
878 | struct dev_list_t { | |
879 | char *path; | |
880 | unsigned short vid; | |
881 | unsigned short pid; | |
882 | struct dev_list_t *next; | |
883 | }; | |
884 | #endif/*__linux__*/ | |
885 | ||
886 | struct libusbhp_t { | |
887 | #ifdef __linux__ | |
888 | struct udev* hotplug; | |
889 | struct udev_monitor* hotplug_monitor; | |
890 | struct dev_list_t *devlist; | |
891 | #endif/*__linux__*/ | |
892 | #ifdef _WIN32 | |
893 | HWND hwnd; | |
894 | HDEVNOTIFY hDeviceNotify; | |
895 | WNDCLASSEX wcex; | |
896 | #endif/*_WIN32*/ | |
897 | libusbhp_hotplug_cb_fn attach; | |
898 | libusbhp_hotplug_cb_fn detach; | |
899 | void *user_data; | |
900 | }; | |
901 | ||
902 | struct libusbhp_device_t { | |
903 | unsigned short idVendor; | |
904 | unsigned short idProduct; | |
905 | }; | |
906 | ||
45c59c8b BV |
907 | #include "proto.h" |
908 | #include "version.h" | |
c2bd92ec | 909 | |
a00b530c UH |
910 | #ifdef __cplusplus |
911 | } | |
912 | #endif | |
913 | ||
a1bb33af | 914 | #endif |