· 6 years ago · Apr 28, 2020, 09:00 AM
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2013 Bert Vermeulen <bert@biot.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_SIGROK_H
21#define LIBSIGROK_SIGROK_H
22
23#include <sys/time.h>
24
25#include <stdio.h>
26#include <sys/time.h>
27#include <stdint.h>
28#include <inttypes.h>
29#include <glib.h>
30#include <zip.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/**
37 * @file
38 *
39 * The public libsigrok header file to be used by frontends.
40 *
41 * This is the only file that libsigrok users (frontends) are supposed to
42 * use and \#include. There are other header files which get installed with
43 * libsigrok, but those are not meant to be used directly by frontends.
44 *
45 * The correct way to get/use the libsigrok API functions is:
46 *
47 * @code{.c}
48 * #include <libsigrok/libsigrok.h>
49 * @endcode
50 */
51
52/*
53 * All possible return codes of libsigrok functions must be listed here.
54 * Functions should never return hardcoded numbers as status, but rather
55 * use these enum values. All error codes are negative numbers.
56 *
57 * The error codes are globally unique in libsigrok, i.e. if one of the
58 * libsigrok functions returns a "malloc error" it must be exactly the same
59 * return value as used by all other functions to indicate "malloc error".
60 * There must be no functions which indicate two different errors via the
61 * same return code.
62 *
63 * Also, for compatibility reasons, no defined return codes are ever removed
64 * or reused for different errors later. You can only add new entries and
65 * return codes, but never remove or redefine existing ones.
66 */
67
68/** Status/error codes returned by libsigrok functions. */
69enum {
70 SR_OK = 0, /**< No error. */
71 SR_ERR = -1, /**< Generic/unspecified error. */
72 SR_ERR_MALLOC = -2, /**< Malloc/calloc/realloc error. */
73 SR_ERR_ARG = -3, /**< Function argument error. */
74 SR_ERR_BUG = -4, /**< Errors hinting at internal bugs. */
75 SR_ERR_SAMPLERATE = -5, /**< Incorrect samplerate. */
76 SR_ERR_NA = -6, /**< Not applicable. */
77 SR_ERR_DEV_CLOSED = -7, /**< Device is closed, but needs to be open. */
78
79 /*
80 * Note: When adding entries here, don't forget to also update the
81 * sr_strerror() and sr_strerror_name() functions in error.c.
82 */
83};
84
85/* Handy little macros */
86#define SR_HZ(n) (n)
87#define SR_KHZ(n) ((n) * (uint64_t)(1000ULL))
88#define SR_MHZ(n) ((n) * (uint64_t)(1000000ULL))
89#define SR_GHZ(n) ((n) * (uint64_t)(1000000000ULL))
90
91#define SR_HZ_TO_NS(n) ((uint64_t)(1000000000ULL) / (n))
92
93#define SR_NS(n) (n)
94#define SR_US(n) ((n) * (uint64_t)(1000ULL))
95#define SR_MS(n) ((n) * (uint64_t)(1000000ULL))
96#define SR_SEC(n) ((n) * (uint64_t)(1000000000ULL))
97#define SR_MIN(n) ((n) * (uint64_t)(60000000000ULL))
98#define SR_HOUR(n) ((n) * (uint64_t)(3600000000000ULL))
99#define SR_DAY(n) ((n) * (uint64_t)(86400000000000ULL))
100
101#define SR_n(n) (n)
102#define SR_Kn(n) ((n) * (uint64_t)(1000ULL))
103#define SR_Mn(n) ((n) * (uint64_t)(1000000ULL))
104#define SR_Gn(n) ((n) * (uint64_t)(1000000000ULL))
105
106#define SR_B(n) (n)
107#define SR_KB(n) ((n) * (uint64_t)(1024ULL))
108#define SR_MB(n) ((n) * (uint64_t)(1048576ULL))
109#define SR_GB(n) ((n) * (uint64_t)(1073741824ULL))
110
111#define SR_mV(n) (n)
112#define SR_V(n) ((n) * (uint64_t)(1000ULL))
113#define SR_KV(n) ((n) * (uint64_t)(1000000ULL))
114#define SR_MV(n) ((n) * (uint64_t)(1000000000ULL))
115
116#define SR_MAX_PROBENAME_LEN 32
117#define DS_MAX_ANALOG_PROBES_NUM 4
118#define DS_MAX_DSO_PROBES_NUM 2
119#define TriggerStages 16
120#define TriggerProbes 16
121#define MaxTriggerProbes 32
122#define TriggerCountBits 16
123#define STriggerDataStage 3
124
125#define DS_CONF_DSO_HDIVS 10
126#define DS_CONF_DSO_VDIVS 10
127
128#define DS_MAX_TRIG_PERCENT 90
129
130#define SAMPLES_ALIGN 1023ULL
131/*
132 * Oscilloscope
133 */
134#define MAX_TIMEBASE SR_SEC(10)
135#define MIN_TIMEBASE SR_NS(10)
136
137extern char DS_RES_PATH[256];
138
139/** libsigrok loglevels. */
140enum {
141 SR_LOG_NONE = 0, /**< Output no messages at all. */
142 SR_LOG_ERR = 1, /**< Output error messages. */
143 SR_LOG_WARN = 2, /**< Output warnings. */
144 SR_LOG_INFO = 3, /**< Output informational messages. */
145 SR_LOG_DBG = 4, /**< Output debug messages. */
146 SR_LOG_SPEW = 5, /**< Output very noisy debug messages. */
147};
148
149/*
150 * Use SR_API to mark public API symbols, and SR_PRIV for private symbols.
151 *
152 * Variables and functions marked 'static' are private already and don't
153 * need SR_PRIV. However, functions which are not static (because they need
154 * to be used in other libsigrok-internal files) but are also not meant to
155 * be part of the public libsigrok API, must use SR_PRIV.
156 *
157 * This uses the 'visibility' feature of gcc (requires gcc >= 4.0).
158 *
159 * This feature is not available on MinGW/Windows, as it is a feature of
160 * ELF files and MinGW/Windows uses PE files.
161 *
162 * Details: http://gcc.gnu.org/wiki/Visibility
163 */
164
165/* Marks public libsigrok API symbols. */
166#ifndef _WIN32
167#define SR_API __attribute__((visibility("default")))
168#else
169#define SR_API
170#endif
171
172/* Marks private, non-public libsigrok symbols (not part of the API). */
173#ifndef _WIN32
174#define SR_PRIV __attribute__((visibility("hidden")))
175#else
176#define SR_PRIV
177#endif
178
179/** Data types used by sr_config_info(). */
180enum {
181 SR_T_UINT64 = 10000,
182 SR_T_UINT8,
183 SR_T_CHAR,
184 SR_T_BOOL,
185 SR_T_FLOAT,
186 SR_T_RATIONAL_PERIOD,
187 SR_T_RATIONAL_VOLT,
188 SR_T_KEYVALUE,
189};
190
191/** Value for sr_datafeed_packet.type. */
192enum {
193 SR_DF_HEADER = 10000,
194 SR_DF_END,
195 SR_DF_META,
196 SR_DF_TRIGGER,
197 SR_DF_LOGIC,
198 SR_DF_DSO,
199 SR_DF_ANALOG,
200 SR_DF_FRAME_BEGIN,
201 SR_DF_FRAME_END,
202 SR_DF_OVERFLOW,
203};
204
205/** Values for sr_datafeed_analog.mq. */
206enum {
207 SR_MQ_VOLTAGE = 10000,
208 SR_MQ_CURRENT,
209 SR_MQ_RESISTANCE,
210 SR_MQ_CAPACITANCE,
211 SR_MQ_TEMPERATURE,
212 SR_MQ_FREQUENCY,
213 SR_MQ_DUTY_CYCLE,
214 SR_MQ_CONTINUITY,
215 SR_MQ_PULSE_WIDTH,
216 SR_MQ_CONDUCTANCE,
217 /** Electrical power, usually in W, or dBm. */
218 SR_MQ_POWER,
219 /** Gain (a transistor's gain, or hFE, for example). */
220 SR_MQ_GAIN,
221 /** Logarithmic representation of sound pressure relative to a
222 * reference value. */
223 SR_MQ_SOUND_PRESSURE_LEVEL,
224 SR_MQ_CARBON_MONOXIDE,
225 SR_MQ_RELATIVE_HUMIDITY,
226};
227
228/** Values for sr_datafeed_analog.unit. */
229enum {
230 SR_UNIT_VOLT = 10000,
231 SR_UNIT_AMPERE,
232 SR_UNIT_OHM,
233 SR_UNIT_FARAD,
234 SR_UNIT_KELVIN,
235 SR_UNIT_CELSIUS,
236 SR_UNIT_FAHRENHEIT,
237 SR_UNIT_HERTZ,
238 SR_UNIT_PERCENTAGE,
239 SR_UNIT_BOOLEAN,
240 SR_UNIT_SECOND,
241 /** Unit of conductance, the inverse of resistance. */
242 SR_UNIT_SIEMENS,
243 /**
244 * An absolute measurement of power, in decibels, referenced to
245 * 1 milliwatt (dBu).
246 */
247 SR_UNIT_DECIBEL_MW,
248 /** Voltage in decibel, referenced to 1 volt (dBV). */
249 SR_UNIT_DECIBEL_VOLT,
250 /**
251 * Measurements that intrinsically do not have units attached, such
252 * as ratios, gains, etc. Specifically, a transistor's gain (hFE) is
253 * a unitless quantity, for example.
254 */
255 SR_UNIT_UNITLESS,
256 /** Sound pressure level relative so 20 micropascals. */
257 SR_UNIT_DECIBEL_SPL,
258 /**
259 * Normalized (0 to 1) concentration of a substance or compound with 0
260 * representing a concentration of 0%, and 1 being 100%. This is
261 * represented as the fraction of number of particles of the substance.
262 */
263 SR_UNIT_CONCENTRATION,
264};
265
266/** Values for sr_datafeed_analog.flags. */
267enum {
268 /** Voltage measurement is alternating current (AC). */
269 SR_MQFLAG_AC = 0x01,
270 /** Voltage measurement is direct current (DC). */
271 SR_MQFLAG_DC = 0x02,
272 /** This is a true RMS measurement. */
273 SR_MQFLAG_RMS = 0x04,
274 /** Value is voltage drop across a diode, or NAN. */
275 SR_MQFLAG_DIODE = 0x08,
276 /** Device is in "hold" mode (repeating the last measurement). */
277 SR_MQFLAG_HOLD = 0x10,
278 /** Device is in "max" mode, only updating upon a new max value. */
279 SR_MQFLAG_MAX = 0x20,
280 /** Device is in "min" mode, only updating upon a new min value. */
281 SR_MQFLAG_MIN = 0x40,
282 /** Device is in autoranging mode. */
283 SR_MQFLAG_AUTORANGE = 0x80,
284 /** Device is in relative mode. */
285 SR_MQFLAG_RELATIVE = 0x100,
286 /** Sound pressure level is A-weighted in the frequency domain,
287 * according to IEC 61672:2003. */
288 SR_MQFLAG_SPL_FREQ_WEIGHT_A = 0x200,
289 /** Sound pressure level is C-weighted in the frequency domain,
290 * according to IEC 61672:2003. */
291 SR_MQFLAG_SPL_FREQ_WEIGHT_C = 0x400,
292 /** Sound pressure level is Z-weighted (i.e. not at all) in the
293 * frequency domain, according to IEC 61672:2003. */
294 SR_MQFLAG_SPL_FREQ_WEIGHT_Z = 0x800,
295 /** Sound pressure level is not weighted in the frequency domain,
296 * albeit without standards-defined low and high frequency limits. */
297 SR_MQFLAG_SPL_FREQ_WEIGHT_FLAT = 0x1000,
298 /** Sound pressure level measurement is S-weighted (1s) in the
299 * time domain. */
300 SR_MQFLAG_SPL_TIME_WEIGHT_S = 0x2000,
301 /** Sound pressure level measurement is F-weighted (125ms) in the
302 * time domain. */
303 SR_MQFLAG_SPL_TIME_WEIGHT_F = 0x4000,
304 /** Sound pressure level is time-averaged (LAT), also known as
305 * Equivalent Continuous A-weighted Sound Level (LEQ). */
306 SR_MQFLAG_SPL_LAT = 0x8000,
307 /** Sound pressure level represented as a percentage of measurements
308 * that were over a preset alarm level. */
309 SR_MQFLAG_SPL_PCT_OVER_ALARM = 0x10000,
310};
311
312enum DSO_MEASURE_TYPE {
313 DSO_MS_BEGIN = 0,
314 DSO_MS_FREQ,
315 DSO_MS_PERD,
316 DSO_MS_PDUT,
317 DSO_MS_NDUT,
318 DSO_MS_PCNT,
319 DSO_MS_RISE,
320 DSO_MS_FALL,
321 DSO_MS_PWDT,
322 DSO_MS_NWDT,
323 DSO_MS_BRST,
324 DSO_MS_AMPT,
325 DSO_MS_VHIG,
326 DSO_MS_VLOW,
327 DSO_MS_VRMS,
328 DSO_MS_VMEA,
329 DSO_MS_VP2P,
330 DSO_MS_VMAX,
331 DSO_MS_VMIN,
332 DSO_MS_POVR,
333 DSO_MS_NOVR,
334 DSO_MS_END,
335};
336
337enum {
338 SR_PKT_OK,
339 SR_PKT_SOURCE_ERROR,
340 SR_PKT_DATA_ERROR,
341};
342
343struct sr_context;
344
345struct sr_datafeed_packet {
346 uint16_t type;
347 uint16_t status;
348 const void *payload;
349};
350
351struct sr_datafeed_header {
352 int feed_version;
353 struct timeval starttime;
354};
355
356struct sr_datafeed_meta {
357 GSList *config;
358};
359
360enum LA_DATA_FORMAT {
361 LA_CROSS_DATA,
362 LA_SPLIT_DATA,
363};
364
365struct sr_datafeed_logic {
366 uint64_t length;
367 /** data format */
368 int format;
369 /** for LA_SPLIT_DATA, indicate the channel index */
370 uint16_t index;
371 uint16_t order;
372 uint16_t unitsize;
373 uint16_t data_error;
374 uint64_t error_pattern;
375 void *data;
376};
377
378struct sr_datafeed_dso {
379 /** The probes for which data is included in this packet. */
380 GSList *probes;
381 int num_samples;
382 /** Measured quantity (voltage, current, temperature, and so on). */
383 int mq;
384 /** Unit in which the MQ is measured. */
385 int unit;
386 /** Bitmap with extra information about the MQ. */
387 uint64_t mqflags;
388 /** samplerate different from last packet */
389 gboolean samplerate_tog;
390 /** trig flag */
391 gboolean trig_flag;
392 /** trig channel */
393 uint8_t trig_ch;
394 /** The analog value(s). The data is interleaved according to
395 * the probes list. */
396 void *data;
397};
398
399struct sr_datafeed_analog {
400 /** The probes for which data is included in this packet. */
401 GSList *probes;
402 int num_samples;
403 /** How many bits for each sample */
404 uint8_t unit_bits;
405 /** Interval between two valid samples */
406 uint16_t unit_pitch;
407 /** Measured quantity (voltage, current, temperature, and so on). */
408 int mq;
409 /** Unit in which the MQ is measured. */
410 int unit;
411 /** Bitmap with extra information about the MQ. */
412 uint64_t mqflags;
413 /** The analog value(s). The data is interleaved according to
414 * the probes list. */
415 void *data;
416};
417
418/** Input (file) format struct. */
419struct sr_input {
420 /**
421 * A pointer to this input format's 'struct sr_input_format'.
422 * The frontend can use this to call the module's callbacks.
423 */
424 struct sr_input_format *format;
425
426 GHashTable *param;
427
428 struct sr_dev_inst *sdi;
429
430 void *internal;
431};
432
433struct sr_input_format {
434 /** The unique ID for this input format. Must not be NULL. */
435 char *id;
436
437 /**
438 * A short description of the input format, which can (for example)
439 * be displayed to the user by frontends. Must not be NULL.
440 */
441 char *description;
442
443 /**
444 * Check if this input module can load and parse the specified file.
445 *
446 * @param filename The name (and path) of the file to check.
447 *
448 * @return TRUE if this module knows the format, FALSE if it doesn't.
449 */
450 int (*format_match) (const char *filename);
451
452 /**
453 * Initialize the input module.
454 *
455 * @param in A pointer to a valid 'struct sr_input' that the caller
456 * has to allocate and provide to this function. It is also
457 * the responsibility of the caller to free it later.
458 * @param filename The name (and path) of the file to use.
459 *
460 * @return SR_OK upon success, a negative error code upon failure.
461 */
462 int (*init) (struct sr_input *in, const char *filename);
463
464 /**
465 * Load a file, parsing the input according to the file's format.
466 *
467 * This function will send datafeed packets to the session bus, so
468 * the calling frontend must have registered its session callbacks
469 * beforehand.
470 *
471 * The packet types sent across the session bus by this function must
472 * include at least SR_DF_HEADER, SR_DF_END, and an appropriate data
473 * type such as SR_DF_LOGIC. It may also send a SR_DF_TRIGGER packet
474 * if appropriate.
475 *
476 * @param in A pointer to a valid 'struct sr_input' that the caller
477 * has to allocate and provide to this function. It is also
478 * the responsibility of the caller to free it later.
479 * @param filename The name (and path) of the file to use.
480 *
481 * @return SR_OK upon succcess, a negative error code upon failure.
482 */
483 int (*loadfile) (struct sr_input *in, const char *filename);
484};
485
486/** Output (file) format struct. */
487struct sr_output {
488 /**
489 * A pointer to this output format's 'struct sr_output_format'.
490 * The frontend can use this to call the module's callbacks.
491 */
492 const struct sr_output_module *module;
493
494 /**
495 * The device for which this output module is creating output. This
496 * can be used by the module to find out probe names and numbers.
497 */
498 const struct sr_dev_inst *sdi;
499
500 /**
501 * An optional parameter which the frontend can pass in to the
502 * output module. How the string is interpreted is entirely up to
503 * the module.
504 */
505 char *param;
506
507 /**
508 * A generic pointer which can be used by the module to keep internal
509 * state between calls into its callback functions.
510 *
511 * For example, the module might store a pointer to a chunk of output
512 * there, and only flush it when it reaches a certain size.
513 */
514 void *priv;
515};
516
517/** Generic option struct used by various subsystems. */
518struct sr_option {
519 /* Short name suitable for commandline usage, [a-z0-9-]. */
520 char *id;
521 /* Short name suitable for GUI usage, can contain UTF-8. */
522 char *name;
523 /* Description of the option, in a sentence. */
524 char *desc;
525 /* Default value for this option. */
526 GVariant *def;
527 /* List of possible values, if this is an option with few values. */
528 GSList *values;
529};
530
531/** Output module driver. */
532struct sr_output_module {
533 /**
534 * A unique ID for this output module, suitable for use in command-line
535 * clients, [a-z0-9-]. Must not be NULL.
536 */
537 char *id;
538
539 /**
540 * A unique name for this output module, suitable for use in GUI
541 * clients, can contain UTF-8. Must not be NULL.
542 */
543 const char *name;
544
545 /**
546 * A short description of the output module. Must not be NULL.
547 *
548 * This can be displayed by frontends, e.g. when selecting the output
549 * module for saving a file.
550 */
551 char *desc;
552
553 /**
554 * A NULL terminated array of strings containing a list of file name
555 * extensions typical for the input file format, or NULL if there is
556 * no typical extension for this file format.
557 */
558 const char *const *exts;
559
560 /**
561 * Returns a NULL-terminated list of options this module can take.
562 * Can be NULL, if the module has no options.
563 */
564 const struct sr_option *(*options) (void);
565
566 /**
567 * This function is called once, at the beginning of an output stream.
568 *
569 * The device struct will be available in the output struct passed in,
570 * as well as the param field -- which may be NULL or an empty string,
571 * if no parameter was passed.
572 *
573 * The module can use this to initialize itself, create a struct for
574 * keeping state and storing it in the <code>internal</code> field.
575 *
576 * @param o Pointer to the respective 'struct sr_output'.
577 *
578 * @retval SR_OK Success
579 * @retval other Negative error code.
580 */
581 int (*init) (struct sr_output *o, GHashTable *options);
582
583 /**
584 * This function is passed a copy of every packed in the data feed.
585 * Any output generated by the output module in response to the
586 * packet should be returned in a newly allocated GString
587 * <code>out</code>, which will be freed by the caller.
588 *
589 * Packets not of interest to the output module can just be ignored,
590 * and the <code>out</code> parameter set to NULL.
591 *
592 * @param o Pointer to the respective 'struct sr_output'.
593 * @param sdi The device instance that generated the packet.
594 * @param packet The complete packet.
595 * @param out A pointer where a GString * should be stored if
596 * the module generates output, or NULL if not.
597 *
598 * @retval SR_OK Success
599 * @retval other Negative error code.
600 */
601 int (*receive) (const struct sr_output *o,
602 const struct sr_datafeed_packet *packet, GString **out);
603
604 /**
605 * This function is called after the caller is finished using
606 * the output module, and can be used to free any internal
607 * resources the module may keep.
608 *
609 * @retval SR_OK Success
610 * @retval other Negative error code.
611 */
612 int (*cleanup) (struct sr_output *o);
613};
614
615
616enum CHANNEL_TYPE {
617 SR_CHANNEL_DECODER = 9998,
618 SR_CHANNEL_GROUP = 9999,
619 SR_CHANNEL_LOGIC = 10000,
620 SR_CHANNEL_DSO,
621 SR_CHANNEL_ANALOG,
622 SR_CHANNEL_FFT,
623 SR_CHANNEL_LISSAJOUS,
624 SR_CHANNEL_MATH,
625};
626
627enum OPERATION_MODE {
628 LOGIC = 0,
629 DSO = 1,
630 ANALOG = 2,
631};
632
633struct sr_channel {
634 /* The index field will go: use g_slist_length(sdi->channels) instead. */
635 uint16_t index;
636 int type;
637 gboolean enabled;
638 char *name;
639 char *trigger;
640 uint8_t bits;
641 uint64_t vdiv;
642 uint64_t vfactor;
643 uint16_t offset;
644 uint16_t zero_offset;
645 uint16_t hw_offset;
646 uint16_t vpos_trans;
647 uint8_t coupling;
648 uint8_t trig_value;
649 int8_t comb_diff_top;
650 int8_t comb_diff_bom;
651 int8_t comb_comp;
652 uint16_t digi_fgain;
653
654 double cali_fgain0;
655 double cali_fgain1;
656 double cali_fgain2;
657 double cali_fgain3;
658 double cali_comb_fgain0;
659 double cali_comb_fgain1;
660 double cali_comb_fgain2;
661 double cali_comb_fgain3;
662
663 gboolean map_default;
664 const char *map_unit;
665 double map_min;
666 double map_max;
667 struct DSL_vga *vga_ptr;
668};
669
670/** Structure for groups of channels that have common properties. */
671struct sr_channel_group {
672 /** Name of the channel group. */
673 char *name;
674 /** List of sr_channel structs of the channels belonging to this group. */
675 GSList *channels;
676 /** Private data for driver use. */
677 void *priv;
678};
679
680struct sr_config {
681 int key;
682 GVariant *data;
683};
684
685struct sr_config_info {
686 int key;
687 int datatype;
688 char *id;
689 char *name;
690 char *label;
691 char *label_cn;
692 char *description;
693};
694
695struct sr_status {
696 uint8_t trig_hit;
697 uint8_t captured_cnt3;
698 uint8_t captured_cnt2;
699 uint8_t captured_cnt1;
700 uint8_t captured_cnt0;
701
702 uint16_t pkt_id;
703 uint32_t vlen;
704 gboolean stream_mode;
705 gboolean measure_valid;
706 uint32_t sample_divider;
707 gboolean sample_divider_tog;
708 gboolean trig_flag;
709 uint8_t trig_ch;
710 uint8_t trig_offset;
711
712 uint8_t ch0_max;
713 uint8_t ch0_min;
714 uint32_t ch0_cyc_cnt;
715 uint32_t ch0_cyc_tlen;
716 uint32_t ch0_cyc_plen;
717 uint32_t ch0_cyc_llen;
718 gboolean ch0_level_valid;
719 gboolean ch0_plevel;
720 uint8_t ch0_low_level;
721 uint8_t ch0_high_level;
722 uint32_t ch0_cyc_rlen;
723 uint32_t ch0_cyc_flen;
724 uint64_t ch0_acc_square;
725 uint32_t ch0_acc_mean;
726 uint32_t ch0_acc_mean_p1;
727 uint32_t ch0_acc_mean_p2;
728 uint32_t ch0_acc_mean_p3;
729
730 uint8_t ch1_max;
731 uint8_t ch1_min;
732 uint32_t ch1_cyc_cnt;
733 uint32_t ch1_cyc_tlen;
734 uint32_t ch1_cyc_plen;
735 uint32_t ch1_cyc_llen;
736 gboolean ch1_level_valid;
737 gboolean ch1_plevel;
738 uint8_t ch1_low_level;
739 uint8_t ch1_high_level;
740 uint32_t ch1_cyc_rlen;
741 uint32_t ch1_cyc_flen;
742 uint64_t ch1_acc_square;
743 uint32_t ch1_acc_mean;
744 uint32_t ch1_acc_mean_p1;
745 uint32_t ch1_acc_mean_p2;
746 uint32_t ch1_acc_mean_p3;
747};
748
749enum {
750 /*--- Device classes ------------------------------------------------*/
751
752 /** The device can act as logic analyzer. */
753 SR_CONF_LOGIC_ANALYZER = 10000,
754
755 /** The device can act as an oscilloscope. */
756 SR_CONF_OSCILLOSCOPE,
757
758 /** The device can act as a multimeter. */
759 SR_CONF_MULTIMETER,
760
761 /** The device is a demo device. */
762 SR_CONF_DEMO_DEV,
763
764 /** The device can act as a sound level meter. */
765 SR_CONF_SOUNDLEVELMETER,
766
767 /** The device can measure temperature. */
768 SR_CONF_THERMOMETER,
769
770 /** The device can measure humidity. */
771 SR_CONF_HYGROMETER,
772
773 /*--- Driver scan options -------------------------------------------*/
774
775 /**
776 * Specification on how to connect to a device.
777 *
778 * In combination with SR_CONF_SERIALCOMM, this is a serial port in
779 * the form which makes sense to the OS (e.g., /dev/ttyS0).
780 * Otherwise this specifies a USB device, either in the form of
781 * @verbatim <bus>.<address> @endverbatim (decimal, e.g. 1.65) or
782 * @verbatim <vendorid>.<productid> @endverbatim
783 * (hexadecimal, e.g. 1d6b.0001).
784 */
785 SR_CONF_CONN = 20000,
786
787 /**
788 * Serial communication specification, in the form:
789 *
790 * @verbatim <baudrate>/<databits><parity><stopbits> @endverbatim
791 *
792 * Example: 9600/8n1
793 *
794 * The string may also be followed by one or more special settings,
795 * in the form "/key=value". Supported keys and their values are:
796 *
797 * rts 0,1 set the port's RTS pin to low or high
798 * dtr 0,1 set the port's DTR pin to low or high
799 * flow 0 no flow control
800 * 1 hardware-based (RTS/CTS) flow control
801 * 2 software-based (XON/XOFF) flow control
802 *
803 * This is always an optional parameter, since a driver typically
804 * knows the speed at which the device wants to communicate.
805 */
806 SR_CONF_SERIALCOMM,
807
808 /*--- Device configuration ------------------------------------------*/
809
810 /** The device supports setting its samplerate, in Hz. */
811 SR_CONF_SAMPLERATE = 30000,
812
813 /** The device supports setting a pre/post-trigger capture ratio. */
814 SR_CONF_CAPTURE_RATIO,
815
816 /** */
817 SR_CONF_USB_SPEED,
818 SR_CONF_USB30_SUPPORT,
819 SR_CONF_DEVICE_MODE,
820 SR_CONF_INSTANT,
821 SR_CONF_STATUS,
822
823 /** The device supports setting a pattern (pattern generator mode). */
824 SR_CONF_PATTERN_MODE,
825
826 /** The device supports Run Length Encoding. */
827 SR_CONF_RLE,
828
829 /** Need wait to uplad captured data */
830 SR_CONF_WAIT_UPLOAD,
831
832 /** The device supports setting trigger slope. */
833 SR_CONF_TRIGGER_SLOPE,
834
835 /** Trigger source. */
836 SR_CONF_TRIGGER_SOURCE,
837
838 /** Trigger channel */
839 SR_CONF_TRIGGER_CHANNEL,
840
841 /** Trigger Value. */
842 SR_CONF_TRIGGER_VALUE,
843
844 /** Horizontal trigger position. */
845 SR_CONF_HORIZ_TRIGGERPOS,
846
847 /** Trigger hold off time */
848 SR_CONF_TRIGGER_HOLDOFF,
849
850 /** Trigger Margin */
851 SR_CONF_TRIGGER_MARGIN,
852
853 /** Buffer size. */
854 SR_CONF_BUFFERSIZE,
855
856 /** Time base. */
857 SR_CONF_MAX_TIMEBASE,
858 SR_CONF_MIN_TIMEBASE,
859 SR_CONF_TIMEBASE,
860
861 /** Filter. */
862 SR_CONF_FILTER,
863
864 /** DSO configure sync */
865 SR_CONF_DSO_SYNC,
866
867 /** How many bits for each sample */
868 SR_CONF_UNIT_BITS,
869 SR_CONF_REF_MIN,
870 SR_CONF_REF_MAX,
871
872 /** Valid channel number */
873 SR_CONF_TOTAL_CH_NUM,
874
875 /** Valid channel number */
876 SR_CONF_VLD_CH_NUM,
877
878 /** 32 channel support */
879 SR_CONF_LA_CH32,
880
881 /** Zero */
882 SR_CONF_HAVE_ZERO,
883 SR_CONF_ZERO,
884 SR_CONF_ZERO_SET,
885 SR_CONF_ZERO_LOAD,
886 SR_CONF_ZERO_DEFAULT,
887 SR_CONF_ZERO_COMB_FGAIN,
888 SR_CONF_ZERO_COMB,
889 SR_CONF_VOCM,
890 SR_CONF_CALI,
891
892 /** status for dso channel */
893 SR_CONF_STATUS_PERIOD,
894 SR_CONF_STATUS_PCNT,
895 SR_CONF_STATUS_MAX,
896 SR_CONF_STATUS_MIN,
897 SR_CONF_STATUS_PLEN,
898 SR_CONF_STATUS_LLEN,
899 SR_CONF_STATUS_LEVEL,
900 SR_CONF_STATUS_PLEVEL,
901 SR_CONF_STATUS_LOW,
902 SR_CONF_STATUS_HIGH,
903 SR_CONF_STATUS_RLEN,
904 SR_CONF_STATUS_FLEN,
905 SR_CONF_STATUS_RMS,
906 SR_CONF_STATUS_MEAN,
907
908 /** Stream */
909 SR_CONF_STREAM,
910
911 /** DSO Roll */
912 SR_CONF_ROLL,
913
914 /** Test */
915 SR_CONF_TEST,
916 SR_CONF_EEPROM,
917 SR_CONF_TUNE,
918 SR_CONF_TUNE_SEL,
919 SR_CONF_EXTEND_ID,
920 SR_CONF_EXTEND_DATA,
921
922 /** The device supports setting its sample interval, in ms. */
923 SR_CONF_SAMPLE_INTERVAL,
924
925 /** Number of timebases, as related to SR_CONF_TIMEBASE. */
926 SR_CONF_NUM_TIMEBASE,
927
928 /** Number of vertical divisions, as related to SR_CONF_PROBE_VDIV. */
929 SR_CONF_NUM_VDIV,
930
931 /** clock type (internal/external) */
932 SR_CONF_CLOCK_TYPE,
933
934 /** clock edge (posedge/negedge) */
935 SR_CONF_CLOCK_EDGE,
936
937 /** Device operation mode */
938 SR_CONF_OPERATION_MODE,
939
940 /** Device buffer options */
941 SR_CONF_BUFFER_OPTIONS,
942
943 /** Device channel mode */
944 SR_CONF_CHANNEL_MODE,
945
946 /** RLE compress support */
947 SR_CONF_RLE_SUPPORT,
948
949 /** Signal max height **/
950 SR_CONF_MAX_HEIGHT,
951 SR_CONF_MAX_HEIGHT_VALUE,
952
953 /** Device sample threshold */
954 SR_CONF_THRESHOLD,
955 SR_CONF_VTH,
956
957 /** Hardware capacity **/
958 SR_CONF_MAX_DSO_SAMPLERATE,
959 SR_CONF_MAX_DSO_SAMPLELIMITS,
960 SR_CONF_HW_DEPTH,
961
962 /** bandwidth */
963 SR_CONF_BANDWIDTH,
964 SR_CONF_BANDWIDTH_LIMIT,
965
966 /*--- Probe configuration -------------------------------------------*/
967 /** Probe options */
968 SR_CONF_PROBE_CONFIGS,
969
970 /** Probe options */
971 SR_CONF_PROBE_SESSIONS,
972
973 /** Enable */
974 SR_CONF_PROBE_EN,
975
976 /** Coupling */
977 SR_CONF_PROBE_COUPLING,
978
979 /** Volts/div */
980 SR_CONF_PROBE_VDIV,
981
982 /** Factor */
983 SR_CONF_PROBE_FACTOR,
984
985 /** Mapping */
986 SR_CONF_PROBE_MAP_DEFAULT,
987 SR_CONF_PROBE_MAP_UNIT,
988 SR_CONF_PROBE_MAP_MIN,
989 SR_CONF_PROBE_MAP_MAX,
990
991 /** Vertical offset */
992 SR_CONF_PROBE_OFFSET,
993 SR_CONF_PROBE_HW_OFFSET,
994 SR_CONF_PROBE_PREOFF,
995 SR_CONF_PROBE_PREOFF_DEFAULT,
996 SR_CONF_PROBE_PREOFF_MARGIN,
997
998 /** VGain */
999 SR_CONF_PROBE_VGAIN,
1000 SR_CONF_PROBE_VGAIN_DEFAULT,
1001 SR_CONF_PROBE_VGAIN_RANGE,
1002 SR_CONF_PROBE_COMB_COMP_EN,
1003 SR_CONF_PROBE_COMB_COMP,
1004
1005 /*--- Special stuff -------------------------------------------------*/
1006
1007 /** Device options for a particular device. */
1008 SR_CONF_DEVICE_OPTIONS,
1009
1010 /** Sessions */
1011 SR_CONF_DEVICE_SESSIONS,
1012
1013 /** Session filename. */
1014 SR_CONF_SESSIONFILE,
1015
1016 /** The device supports specifying a capturefile to inject. */
1017 SR_CONF_CAPTUREFILE,
1018
1019 /** Session file version */
1020 SR_CONF_FILE_VERSION,
1021
1022 /** The device supports setting the number of probes. */
1023 SR_CONF_CAPTURE_NUM_PROBES,
1024
1025 /** The device supports setting the number of data blocks. */
1026 SR_CONF_NUM_BLOCKS,
1027
1028 /** language (string code) **/
1029 SR_CONF_LANGUAGE,
1030
1031 /*--- Acquisition modes ---------------------------------------------*/
1032
1033 /**
1034 * The device supports setting a sample time limit (how long
1035 * the sample acquisition should run, in ms).
1036 */
1037 SR_CONF_LIMIT_MSEC = 50000,
1038
1039 /**
1040 * The device supports setting a sample number limit (how many
1041 * samples should be acquired).
1042 */
1043 SR_CONF_LIMIT_SAMPLES,
1044
1045 /**
1046 * Absolute time record for session driver
1047 */
1048 SR_CONF_TRIGGER_TIME,
1049
1050 /**
1051 * Trigger position for session driver
1052 */
1053 SR_CONF_TRIGGER_POS,
1054
1055 /**
1056 * The actual sample count received
1057 */
1058 SR_CONF_ACTUAL_SAMPLES,
1059
1060 /**
1061 * The device supports setting a frame limit (how many
1062 * frames should be acquired).
1063 */
1064 SR_CONF_LIMIT_FRAMES,
1065
1066 /**
1067 * The device supports continuous sampling. Neither a time limit
1068 * nor a sample number limit has to be supplied, it will just acquire
1069 * samples continuously, until explicitly stopped by a certain command.
1070 */
1071 SR_CONF_CONTINUOUS,
1072
1073 /** The device has internal storage, into which data is logged. This
1074 * starts or stops the internal logging. */
1075 SR_CONF_DATALOG,
1076};
1077
1078struct sr_dev_inst {
1079 /** Device driver. */
1080 struct sr_dev_driver *driver;
1081 /** Index of device in driver. */
1082 int index;
1083 /** Device instance status. SR_ST_NOT_FOUND, etc. */
1084 int status;
1085 /** Device instance type. SR_INST_USB, etc. */
1086 int inst_type;
1087 /** Device mode. LA/DAQ/OSC, etc. */
1088 int mode;
1089 /** Device vendor. */
1090 char *vendor;
1091 /** Device model. */
1092 char *model;
1093 /** Device version. */
1094 char *version;
1095 /** List of channels. */
1096 GSList *channels;
1097 /** List of sr_channel_group structs */
1098 GSList *channel_groups;
1099 /** Device instance connection data (used?) */
1100 void *conn;
1101 /** Device instance private data (used?) */
1102 void *priv;
1103};
1104
1105/** Types of device instances (sr_dev_inst). */
1106enum {
1107 /** Device instance type for USB devices. */
1108 SR_INST_USB = 10000,
1109 /** Device instance type for serial port devices. */
1110 SR_INST_SERIAL,
1111};
1112
1113/** Device instance status. */
1114enum {
1115 /** The device instance was not found. */
1116 SR_ST_NOT_FOUND = 10000,
1117 /** The device instance was found, but is still booting. */
1118 SR_ST_INITIALIZING,
1119 /** The device instance is live, but not in use. */
1120 SR_ST_INACTIVE,
1121 /** The device instance has an imcompatible firmware */
1122 SR_ST_INCOMPATIBLE,
1123 /** The device instance is actively in use in a session. */
1124 SR_ST_ACTIVE,
1125 /** The device is winding down its session. */
1126 SR_ST_STOPPING,
1127};
1128
1129/** Device test modes. */
1130enum {
1131 /** No test mode */
1132 SR_TEST_NONE,
1133 /** Internal pattern test mode */
1134 SR_TEST_INTERNAL,
1135 /** External pattern test mode */
1136 SR_TEST_EXTERNAL,
1137 /** SDRAM loopback test mode */
1138 SR_TEST_LOOPBACK,
1139};
1140
1141/** Device buffer mode */
1142enum {
1143 /** Stop immediately */
1144 SR_BUF_STOP = 0,
1145 /** Upload captured data */
1146 SR_BUF_UPLOAD = 1,
1147};
1148
1149/** Device threshold level. */
1150enum {
1151 /** 1.8/2.5/3.3 level */
1152 SR_TH_3V3 = 0,
1153 /** 5.0 level */
1154 SR_TH_5V0 = 1,
1155};
1156
1157/** Device input filter. */
1158enum {
1159 /** None */
1160 SR_FILTER_NONE = 0,
1161 /** One clock cycle */
1162 SR_FILTER_1T = 1,
1163};
1164
1165/** Coupling. */
1166enum {
1167 /** DC */
1168 SR_DC_COUPLING = 0,
1169 /** AC */
1170 SR_AC_COUPLING = 1,
1171 /** Ground */
1172 SR_GND_COUPLING = 2,
1173};
1174
1175struct sr_dev_mode {
1176 int mode;
1177 char *name;
1178 char *name_cn;
1179 char *acronym;
1180 char *icon;
1181};
1182
1183struct sr_dev_driver {
1184 /* Driver-specific */
1185 char *name;
1186 char *longname;
1187 int api_version;
1188 int (*init) (struct sr_context *sr_ctx);
1189 int (*cleanup) (void);
1190 GSList *(*scan) (GSList *options);
1191 GSList *(*dev_list) (void);
1192 const GSList *(*dev_mode_list) (const struct sr_dev_inst *sdi);
1193 int (*dev_clear) (void);
1194
1195 int (*config_get) (int id, GVariant **data,
1196 const struct sr_dev_inst *sdi,
1197 const struct sr_channel *ch,
1198 const struct sr_channel_group *cg);
1199 int (*config_set) (int id, GVariant *data,
1200 struct sr_dev_inst *sdi,
1201 struct sr_channel *ch,
1202 struct sr_channel_group *cg);
1203 int (*config_list) (int info_id, GVariant **data,
1204 const struct sr_dev_inst *sdi,
1205 const struct sr_channel_group *cg);
1206
1207 /* Device-specific */
1208 int (*dev_open) (struct sr_dev_inst *sdi);
1209 int (*dev_close) (struct sr_dev_inst *sdi);
1210 int (*dev_status_get) (const struct sr_dev_inst *sdi,
1211 struct sr_status *status, gboolean prg);
1212 int (*dev_acquisition_start) (struct sr_dev_inst *sdi,
1213 void *cb_data);
1214 int (*dev_acquisition_stop) (const struct sr_dev_inst *sdi,
1215 void *cb_data);
1216
1217 /* Dynamic */
1218 void *priv;
1219};
1220
1221struct sr_session {
1222 /** List of struct sr_dev pointers. */
1223 GSList *devs;
1224 /** List of struct datafeed_callback pointers. */
1225 GSList *datafeed_callbacks;
1226 gboolean running;
1227
1228 unsigned int num_sources;
1229
1230 /*
1231 * Both "sources" and "pollfds" are of the same size and contain pairs
1232 * of descriptor and callback function. We can not embed the GPollFD
1233 * into the source struct since we want to be able to pass the array
1234 * of all poll descriptors to g_poll().
1235 */
1236 struct source *sources;
1237 GPollFD *pollfds;
1238 int source_timeout;
1239
1240 /*
1241 * These are our synchronization primitives for stopping the session in
1242 * an async fashion. We need to make sure the session is stopped from
1243 * within the session thread itself.
1244 */
1245 GMutex stop_mutex;
1246 gboolean abort_session;
1247};
1248
1249enum {
1250 SIMPLE_TRIGGER = 0,
1251 ADV_TRIGGER,
1252 SERIAL_TRIGGER,
1253};
1254
1255enum {
1256 DSO_TRIGGER_AUTO = 0,
1257 DSO_TRIGGER_CH0,
1258 DSO_TRIGGER_CH1,
1259 DSO_TRIGGER_CH0A1,
1260 DSO_TRIGGER_CH0O1,
1261};
1262enum {
1263 DSO_TRIGGER_RISING = 0,
1264 DSO_TRIGGER_FALLING,
1265};
1266
1267struct ds_trigger {
1268 uint16_t trigger_en;
1269 uint16_t trigger_mode;
1270 uint16_t trigger_pos;
1271 uint16_t trigger_stages;
1272 unsigned char trigger_logic[TriggerStages+1];
1273 unsigned char trigger0_inv[TriggerStages+1];
1274 unsigned char trigger1_inv[TriggerStages+1];
1275 char trigger0[TriggerStages+1][MaxTriggerProbes];
1276 char trigger1[TriggerStages+1][MaxTriggerProbes];
1277 uint32_t trigger0_count[TriggerStages+1];
1278 uint32_t trigger1_count[TriggerStages+1];
1279};
1280
1281struct ds_trigger_pos {
1282 uint32_t check_id;
1283 uint32_t real_pos;
1284 uint32_t ram_saddr;
1285 uint32_t remain_cnt_l;
1286 uint32_t remain_cnt_h;
1287 uint32_t status;
1288};
1289
1290typedef int (*sr_receive_data_callback_t)(int fd, int revents, const struct sr_dev_inst *sdi);
1291
1292#include "proto.h"
1293#include "version.h"
1294
1295#ifdef __cplusplus
1296}
1297#endif
1298
1299#endif