]> sigrok.org Git - libsigrok.git/blame - src/libsigrok-internal.h
kingst-la2016: coding style, separate declaration from instructions
[libsigrok.git] / src / libsigrok-internal.h
CommitLineData
1483577e 1/*
50985c20 2 * This file is part of the libsigrok project.
1483577e 3 *
13d8e03c 4 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
1483577e
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
a5827886
UH
20#ifndef LIBSIGROK_LIBSIGROK_INTERNAL_H
21#define LIBSIGROK_LIBSIGROK_INTERNAL_H
1483577e 22
1df81f4b
GS
23#include "config.h"
24
cc8a7d25 25#include <glib.h>
4417074c
GS
26#ifdef HAVE_LIBHIDAPI
27#include <hidapi.h>
28#endif
c4f2dfd0 29#ifdef HAVE_LIBSERIALPORT
dc991353 30#include <libserialport.h>
c4f2dfd0 31#endif
fdcdfe53
GS
32#ifdef HAVE_LIBUSB_1_0
33#include <libusb.h>
34#endif
e1a712ca
GS
35#ifdef HAVE_LIBFTDI
36#include <ftdi.h>
37#endif
fdcdfe53 38#include <stdarg.h>
ad5aa993 39#include <stdint.h>
fdcdfe53 40#include <stdio.h>
ae4c1fb6 41#include <stdlib.h>
b08024a8 42
98654c99
DE
43struct zip;
44struct zip_stat;
45
393fb9cb
UH
46/**
47 * @file
48 *
49 * libsigrok private header file, only to be used internally.
50 */
51
4cea9eb2
UH
52/*--- Macros ----------------------------------------------------------------*/
53
54#ifndef ARRAY_SIZE
55#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
56#endif
57
58#ifndef ARRAY_AND_SIZE
59#define ARRAY_AND_SIZE(a) (a), ARRAY_SIZE(a)
60#endif
61
6cfc6c5c
UH
62#ifndef G_SOURCE_FUNC
63#define G_SOURCE_FUNC(f) ((GSourceFunc) (void (*)(void)) (f)) /* Since 2.58. */
64#endif
65
66#define SR_RECEIVE_DATA_CALLBACK(f) \
67 ((sr_receive_data_callback) (void (*)(void)) (f))
68
a4f9c35b 69/**
5bf0dd6a 70 * Read a 8 bits unsigned integer out of memory.
a4f9c35b 71 * @param x a pointer to the input memory
5bf0dd6a 72 * @return the corresponding unsigned integer
a4f9c35b 73 */
f1833600
GS
74static inline uint8_t read_u8(const uint8_t *p)
75{
76 return p[0];
77}
78#define R8(x) read_u8((const uint8_t *)(x))
a4f9c35b 79
e4bcc63d
GS
80/**
81 * Read an 8 bits signed integer out of memory.
82 * @param x a pointer to the input memory
83 * @return the corresponding signed integer
84 */
85static inline int8_t read_i8(const uint8_t *p)
86{
87 return (int8_t)p[0];
88}
89
e28ef28a 90/**
5bf0dd6a 91 * Read a 16 bits big endian unsigned integer out of memory.
e28ef28a 92 * @param x a pointer to the input memory
5bf0dd6a 93 * @return the corresponding unsigned integer
e28ef28a 94 */
f1833600
GS
95static inline uint16_t read_u16be(const uint8_t *p)
96{
97 uint16_t u;
98
99 u = 0;
100 u <<= 8; u |= p[0];
101 u <<= 8; u |= p[1];
102
103 return u;
104}
105#define RB16(x) read_u16be((const uint8_t *)(x))
e28ef28a
AJ
106
107/**
5bf0dd6a 108 * Read a 16 bits little endian unsigned integer out of memory.
e28ef28a 109 * @param x a pointer to the input memory
5bf0dd6a 110 * @return the corresponding unsigned integer
e28ef28a 111 */
f1833600
GS
112static inline uint16_t read_u16le(const uint8_t *p)
113{
114 uint16_t u;
115
116 u = 0;
117 u <<= 8; u |= p[1];
118 u <<= 8; u |= p[0];
119
120 return u;
121}
122#define RL16(x) read_u16le((const uint8_t *)(x))
e28ef28a 123
4d376e08
SB
124/**
125 * Read a 16 bits big endian signed integer out of memory.
126 * @param x a pointer to the input memory
127 * @return the corresponding signed integer
128 */
f1833600
GS
129static inline int16_t read_i16be(const uint8_t *p)
130{
131 uint16_t u;
132 int16_t i;
133
134 u = read_u16be(p);
135 i = (int16_t)u;
136
137 return i;
138}
139#define RB16S(x) read_i16be((const uint8_t *)(x))
4d376e08 140
e28ef28a 141/**
5bf0dd6a 142 * Read a 16 bits little endian signed integer out of memory.
e28ef28a 143 * @param x a pointer to the input memory
5bf0dd6a
BV
144 * @return the corresponding signed integer
145 */
f1833600
GS
146static inline int16_t read_i16le(const uint8_t *p)
147{
148 uint16_t u;
149 int16_t i;
150
151 u = read_u16le(p);
152 i = (int16_t)u;
153
154 return i;
155}
156#define RL16S(x) read_i16le((const uint8_t *)(x))
5bf0dd6a 157
080b6bcf
GS
158/**
159 * Read a 24 bits little endian unsigned integer out of memory.
160 * @param x a pointer to the input memory
161 * @return the corresponding unsigned integer
162 */
163static inline uint32_t read_u24le(const uint8_t *p)
164{
165 uint32_t u;
166
167 u = 0;
168 u <<= 8; u |= p[2];
169 u <<= 8; u |= p[1];
170 u <<= 8; u |= p[0];
171
172 return u;
173}
174
5bf0dd6a
BV
175/**
176 * Read a 32 bits big endian unsigned integer out of memory.
177 * @param x a pointer to the input memory
178 * @return the corresponding unsigned integer
e28ef28a 179 */
f1833600
GS
180static inline uint32_t read_u32be(const uint8_t *p)
181{
182 uint32_t u;
183
184 u = 0;
185 u <<= 8; u |= p[0];
186 u <<= 8; u |= p[1];
187 u <<= 8; u |= p[2];
188 u <<= 8; u |= p[3];
189
190 return u;
191}
192#define RB32(x) read_u32be((const uint8_t *)(x))
e28ef28a
AJ
193
194/**
5bf0dd6a 195 * Read a 32 bits little endian unsigned integer out of memory.
e28ef28a 196 * @param x a pointer to the input memory
5bf0dd6a 197 * @return the corresponding unsigned integer
e28ef28a 198 */
f1833600
GS
199static inline uint32_t read_u32le(const uint8_t *p)
200{
201 uint32_t u;
202
203 u = 0;
204 u <<= 8; u |= p[3];
205 u <<= 8; u |= p[2];
206 u <<= 8; u |= p[1];
207 u <<= 8; u |= p[0];
208
209 return u;
210}
211#define RL32(x) read_u32le((const uint8_t *)(x))
e28ef28a 212
4d376e08
SB
213/**
214 * Read a 32 bits big endian signed integer out of memory.
215 * @param x a pointer to the input memory
216 * @return the corresponding signed integer
217 */
f1833600
GS
218static inline int32_t read_i32be(const uint8_t *p)
219{
220 uint32_t u;
221 int32_t i;
222
223 u = read_u32be(p);
224 i = (int32_t)u;
225
226 return i;
227}
228#define RB32S(x) read_i32be((const uint8_t *)(x))
4d376e08 229
ea2d6d99 230/**
5bf0dd6a
BV
231 * Read a 32 bits little endian signed integer out of memory.
232 * @param x a pointer to the input memory
233 * @return the corresponding signed integer
234 */
f1833600
GS
235static inline int32_t read_i32le(const uint8_t *p)
236{
237 uint32_t u;
238 int32_t i;
239
240 u = read_u32le(p);
241 i = (int32_t)u;
242
243 return i;
244}
245#define RL32S(x) read_i32le((const uint8_t *)(x))
5bf0dd6a 246
17b93fd7
TS
247/**
248 * Read a 64 bits big endian unsigned integer out of memory.
249 * @param x a pointer to the input memory
250 * @return the corresponding unsigned integer
251 */
f1833600
GS
252static inline uint64_t read_u64be(const uint8_t *p)
253{
254 uint64_t u;
255
256 u = 0;
257 u <<= 8; u |= p[0];
258 u <<= 8; u |= p[1];
259 u <<= 8; u |= p[2];
260 u <<= 8; u |= p[3];
261 u <<= 8; u |= p[4];
262 u <<= 8; u |= p[5];
263 u <<= 8; u |= p[6];
264 u <<= 8; u |= p[7];
265
266 return u;
267}
268#define RB64(x) read_u64be((const uint8_t *)(x))
17b93fd7 269
8a66b077
SA
270/**
271 * Read a 64 bits little endian unsigned integer out of memory.
272 * @param x a pointer to the input memory
273 * @return the corresponding unsigned integer
274 */
f1833600
GS
275static inline uint64_t read_u64le(const uint8_t *p)
276{
277 uint64_t u;
278
279 u = 0;
280 u <<= 8; u |= p[7];
281 u <<= 8; u |= p[6];
282 u <<= 8; u |= p[5];
283 u <<= 8; u |= p[4];
284 u <<= 8; u |= p[3];
285 u <<= 8; u |= p[2];
286 u <<= 8; u |= p[1];
287 u <<= 8; u |= p[0];
288
289 return u;
290}
291#define RL64(x) read_u64le((const uint8_t *)(x))
292
293/**
294 * Read a 64 bits big endian signed integer out of memory.
295 * @param x a pointer to the input memory
296 * @return the corresponding unsigned integer
297 */
298static inline int64_t read_i64be(const uint8_t *p)
299{
300 uint64_t u;
301 int64_t i;
302
303 u = read_u64be(p);
304 i = (int64_t)u;
305
306 return i;
307}
308#define RB64S(x) read_i64be((const uint8_t *)(x))
8a66b077
SA
309
310/**
311 * Read a 64 bits little endian signed integer out of memory.
312 * @param x a pointer to the input memory
313 * @return the corresponding unsigned integer
314 */
f1833600
GS
315static inline int64_t read_i64le(const uint8_t *p)
316{
317 uint64_t u;
318 int64_t i;
319
320 u = read_u64le(p);
321 i = (int64_t)u;
322
323 return i;
324}
325#define RL64S(x) read_i64le((const uint8_t *)(x))
8a66b077 326
a2632bca 327/**
daa895cb 328 * Read a 32 bits big endian float out of memory (single precision).
a2632bca
AJ
329 * @param x a pointer to the input memory
330 * @return the corresponding float
331 */
f1833600
GS
332static inline float read_fltbe(const uint8_t *p)
333{
334 /*
335 * Implementor's note: Strictly speaking the "union" trick
336 * is not portable. But this phrase was found to work on the
337 * project's supported platforms, and serve well until a more
338 * appropriate phrase is found.
339 */
340 union { uint32_t u32; float flt; } u;
341 float f;
342
343 u.u32 = read_u32be(p);
344 f = u.flt;
345
346 return f;
347}
348#define RBFL(x) read_fltbe((const uint8_t *)(x))
a2632bca
AJ
349
350/**
daa895cb 351 * Read a 32 bits little endian float out of memory (single precision).
a2632bca
AJ
352 * @param x a pointer to the input memory
353 * @return the corresponding float
354 */
f1833600
GS
355static inline float read_fltle(const uint8_t *p)
356{
357 /*
358 * Implementor's note: Strictly speaking the "union" trick
359 * is not portable. But this phrase was found to work on the
360 * project's supported platforms, and serve well until a more
361 * appropriate phrase is found.
362 */
363 union { uint32_t u32; float flt; } u;
364 float f;
365
366 u.u32 = read_u32le(p);
367 f = u.flt;
368
369 return f;
370}
371#define RLFL(x) read_fltle((const uint8_t *)(x))
a2632bca 372
e4bcc63d
GS
373/**
374 * Read a 64 bits big endian float out of memory (double precision).
375 * @param x a pointer to the input memory
376 * @return the corresponding floating point value
377 */
378static inline double read_dblbe(const uint8_t *p)
379{
380 /*
381 * Implementor's note: Strictly speaking the "union" trick
382 * is not portable. But this phrase was found to work on the
383 * project's supported platforms, and serve well until a more
384 * appropriate phrase is found.
385 */
386 union { uint64_t u64; double flt; } u;
387 double f;
388
389 u.u64 = read_u64be(p);
390 f = u.flt;
391
392 return f;
393}
394
daa895cb
GS
395/**
396 * Read a 64 bits little endian float out of memory (double precision).
397 * @param x a pointer to the input memory
398 * @return the corresponding floating point value
399 */
400static inline double read_dblle(const uint8_t *p)
401{
402 /*
403 * Implementor's note: Strictly speaking the "union" trick
404 * is not portable. But this phrase was found to work on the
405 * project's supported platforms, and serve well until a more
406 * appropriate phrase is found.
407 */
408 union { uint64_t u64; double flt; } u;
409 double f;
410
411 u.u64 = read_u64le(p);
412 f = u.flt;
413
414 return f;
415}
416#define RLDB(x) read_dblle((const uint8_t *)(x))
417
5bf0dd6a
BV
418/**
419 * Write a 8 bits unsigned integer to memory.
ea2d6d99 420 * @param p a pointer to the output memory
5bf0dd6a 421 * @param x the input unsigned integer
ea2d6d99 422 */
f1833600
GS
423static inline void write_u8(uint8_t *p, uint8_t x)
424{
425 p[0] = x;
426}
427#define W8(p, x) write_u8((uint8_t *)(p), (uint8_t)(x))
ea2d6d99
AJ
428
429/**
5bf0dd6a 430 * Write a 16 bits unsigned integer to memory stored as big endian.
ea2d6d99 431 * @param p a pointer to the output memory
5bf0dd6a 432 * @param x the input unsigned integer
ea2d6d99 433 */
f1833600
GS
434static inline void write_u16be(uint8_t *p, uint16_t x)
435{
436 p[1] = x & 0xff; x >>= 8;
437 p[0] = x & 0xff; x >>= 8;
438}
439#define WB16(p, x) write_u16be((uint8_t *)(p), (uint16_t)(x))
ea2d6d99
AJ
440
441/**
5bf0dd6a 442 * Write a 16 bits unsigned integer to memory stored as little endian.
ea2d6d99 443 * @param p a pointer to the output memory
5bf0dd6a 444 * @param x the input unsigned integer
ea2d6d99 445 */
f1833600
GS
446static inline void write_u16le(uint8_t *p, uint16_t x)
447{
448 p[0] = x & 0xff; x >>= 8;
449 p[1] = x & 0xff; x >>= 8;
450}
451#define WL16(p, x) write_u16le((uint8_t *)(p), (uint16_t)(x))
ea2d6d99 452
15526343
GS
453/**
454 * Write a 24 bits unsigned integer to memory stored as little endian.
455 * @param p a pointer to the output memory
456 * @param x the input unsigned integer
457 */
458static inline void write_u24le(uint8_t *p, uint32_t x)
459{
460 p[0] = x & 0xff; x >>= 8;
461 p[1] = x & 0xff; x >>= 8;
462 p[2] = x & 0xff; x >>= 8;
463}
464#define WL24(p, x) write_u24le((uint8_t *)(p), (uint32_t)(x))
465
ea2d6d99 466/**
5bf0dd6a 467 * Write a 32 bits unsigned integer to memory stored as big endian.
ea2d6d99 468 * @param p a pointer to the output memory
5bf0dd6a 469 * @param x the input unsigned integer
ea2d6d99 470 */
f1833600
GS
471static inline void write_u32be(uint8_t *p, uint32_t x)
472{
473 p[3] = x & 0xff; x >>= 8;
474 p[2] = x & 0xff; x >>= 8;
475 p[1] = x & 0xff; x >>= 8;
476 p[0] = x & 0xff; x >>= 8;
477}
478#define WB32(p, x) write_u32be((uint8_t *)(p), (uint32_t)(x))
ea2d6d99
AJ
479
480/**
5bf0dd6a 481 * Write a 32 bits unsigned integer to memory stored as little endian.
ea2d6d99 482 * @param p a pointer to the output memory
5bf0dd6a 483 * @param x the input unsigned integer
ea2d6d99 484 */
f1833600
GS
485static inline void write_u32le(uint8_t *p, uint32_t x)
486{
487 p[0] = x & 0xff; x >>= 8;
488 p[1] = x & 0xff; x >>= 8;
489 p[2] = x & 0xff; x >>= 8;
490 p[3] = x & 0xff; x >>= 8;
491}
492#define WL32(p, x) write_u32le((uint8_t *)(p), (uint32_t)(x))
ea2d6d99 493
15526343
GS
494/**
495 * Write a 40 bits unsigned integer to memory stored as little endian.
496 * @param p a pointer to the output memory
497 * @param x the input unsigned integer
498 */
499static inline void write_u40le(uint8_t *p, uint64_t x)
500{
501 p[0] = x & 0xff; x >>= 8;
502 p[1] = x & 0xff; x >>= 8;
503 p[2] = x & 0xff; x >>= 8;
504 p[3] = x & 0xff; x >>= 8;
505 p[4] = x & 0xff; x >>= 8;
506}
507#define WL40(p, x) write_u40le((uint8_t *)(p), (uint64_t)(x))
508
797c8d90
GS
509/**
510 * Write a 48 bits unsigned integer to memory stored as little endian.
511 * @param p a pointer to the output memory
512 * @param x the input unsigned integer
513 */
514static inline void write_u48le(uint8_t *p, uint64_t x)
515{
516 p[0] = x & 0xff; x >>= 8;
517 p[1] = x & 0xff; x >>= 8;
518 p[2] = x & 0xff; x >>= 8;
519 p[3] = x & 0xff; x >>= 8;
520 p[4] = x & 0xff; x >>= 8;
521 p[5] = x & 0xff; x >>= 8;
522}
523#define WL48(p, x) write_u48le((uint8_t *)(p), (uint64_t)(x))
524
efce57da
GS
525/**
526 * Write a 64 bits unsigned integer to memory stored as big endian.
527 * @param p a pointer to the output memory
528 * @param x the input unsigned integer
529 */
530static inline void write_u64be(uint8_t *p, uint64_t x)
531{
532 p[7] = x & 0xff; x >>= 8;
533 p[6] = x & 0xff; x >>= 8;
534 p[5] = x & 0xff; x >>= 8;
535 p[4] = x & 0xff; x >>= 8;
536 p[3] = x & 0xff; x >>= 8;
537 p[2] = x & 0xff; x >>= 8;
538 p[1] = x & 0xff; x >>= 8;
539 p[0] = x & 0xff; x >>= 8;
540}
541
daa895cb
GS
542/**
543 * Write a 64 bits unsigned integer to memory stored as little endian.
544 * @param p a pointer to the output memory
545 * @param x the input unsigned integer
546 */
547static inline void write_u64le(uint8_t *p, uint64_t x)
548{
549 p[0] = x & 0xff; x >>= 8;
550 p[1] = x & 0xff; x >>= 8;
551 p[2] = x & 0xff; x >>= 8;
552 p[3] = x & 0xff; x >>= 8;
553 p[4] = x & 0xff; x >>= 8;
554 p[5] = x & 0xff; x >>= 8;
555 p[6] = x & 0xff; x >>= 8;
556 p[7] = x & 0xff; x >>= 8;
557}
558#define WL64(p, x) write_u64le((uint8_t *)(p), (uint64_t)(x))
559
a2632bca
AJ
560/**
561 * Write a 32 bits float to memory stored as big endian.
562 * @param p a pointer to the output memory
563 * @param x the input float
564 */
f1833600
GS
565static inline void write_fltbe(uint8_t *p, float x)
566{
567 union { uint32_t u; float f; } u;
568 u.f = x;
569 write_u32be(p, u.u);
570}
571#define WBFL(p, x) write_fltbe((uint8_t *)(p), (x))
a2632bca
AJ
572
573/**
574 * Write a 32 bits float to memory stored as little endian.
575 * @param p a pointer to the output memory
576 * @param x the input float
577 */
f1833600
GS
578static inline void write_fltle(uint8_t *p, float x)
579{
580 union { uint32_t u; float f; } u;
581 u.f = x;
582 write_u32le(p, u.u);
583}
584#define WLFL(p, x) write_fltle((uint8_t *)(p), float (x))
585
daa895cb
GS
586/**
587 * Write a 64 bits float to memory stored as little endian.
588 * @param p a pointer to the output memory
589 * @param x the input floating point value
590 */
591static inline void write_dblle(uint8_t *p, double x)
592{
593 union { uint64_t u; double f; } u;
594 u.f = x;
595 write_u64le(p, u.u);
596}
597#define WLDB(p, x) write_dblle((uint8_t *)(p), float (x))
598
f1833600
GS
599/* Endianess conversion helpers with read/write position increment. */
600
601/**
602 * Read unsigned 8bit integer from raw memory, increment read position.
603 * @param[in, out] p Pointer into byte stream.
604 * @return Retrieved integer value, unsigned.
605 */
606static inline uint8_t read_u8_inc(const uint8_t **p)
607{
608 uint8_t v;
609
610 if (!p || !*p)
611 return 0;
612 v = read_u8(*p);
613 *p += sizeof(v);
614
615 return v;
616}
617
e4bcc63d
GS
618/**
619 * Read signed 8bit integer from raw memory, increment read position.
620 * @param[in, out] p Pointer into byte stream.
621 * @return Retrieved integer value, signed.
622 */
623static inline int8_t read_i8_inc(const uint8_t **p)
624{
625 int8_t v;
626
627 if (!p || !*p)
628 return 0;
629 v = read_i8(*p);
630 *p += sizeof(v);
631
632 return v;
633}
634
f1833600
GS
635/**
636 * Read unsigned 16bit integer from raw memory (big endian format), increment read position.
637 * @param[in, out] p Pointer into byte stream.
638 * @return Retrieved integer value, unsigned.
639 */
640static inline uint16_t read_u16be_inc(const uint8_t **p)
641{
642 uint16_t v;
643
644 if (!p || !*p)
645 return 0;
646 v = read_u16be(*p);
647 *p += sizeof(v);
648
649 return v;
650}
651
652/**
653 * Read unsigned 16bit integer from raw memory (little endian format), increment read position.
654 * @param[in, out] p Pointer into byte stream.
655 * @return Retrieved integer value, unsigned.
656 */
657static inline uint16_t read_u16le_inc(const uint8_t **p)
658{
659 uint16_t v;
660
661 if (!p || !*p)
662 return 0;
663 v = read_u16le(*p);
664 *p += sizeof(v);
665
666 return v;
667}
668
669/**
e4bcc63d 670 * Read signed 16bit integer from raw memory (big endian format), increment read position.
f1833600 671 * @param[in, out] p Pointer into byte stream.
e4bcc63d 672 * @return Retrieved integer value, signed.
f1833600 673 */
e4bcc63d 674static inline int16_t read_i16be_inc(const uint8_t **p)
f1833600 675{
e4bcc63d 676 int16_t v;
f1833600
GS
677
678 if (!p || !*p)
679 return 0;
e4bcc63d
GS
680 v = read_i16be(*p);
681 *p += sizeof(v);
682
683 return v;
684}
685
686/**
687 * Read signed 16bit integer from raw memory (little endian format), increment read position.
688 * @param[in, out] p Pointer into byte stream.
689 * @return Retrieved integer value, signed.
690 */
691static inline int16_t read_i16le_inc(const uint8_t **p)
692{
693 int16_t v;
694
695 if (!p || !*p)
696 return 0;
697 v = read_i16le(*p);
f1833600
GS
698 *p += sizeof(v);
699
700 return v;
701}
702
080b6bcf
GS
703/**
704 * Read unsigned 24bit integer from raw memory (little endian format), increment read position.
705 * @param[in, out] p Pointer into byte stream.
706 * @return Retrieved integer value, unsigned.
707 */
708static inline uint32_t read_u24le_inc(const uint8_t **p)
709{
710 uint32_t v;
711
712 if (!p || !*p)
713 return 0;
714 v = read_u24le(*p);
715 *p += 3 * sizeof(uint8_t);
716
717 return v;
718}
719
e4bcc63d
GS
720/**
721 * Read unsigned 32bit integer from raw memory (big endian format), increment read position.
722 * @param[in, out] p Pointer into byte stream.
723 * @return Retrieved integer value, unsigned.
724 */
725static inline uint32_t read_u32be_inc(const uint8_t **p)
726{
727 uint32_t v;
728
729 if (!p || !*p)
730 return 0;
731 v = read_u32be(*p);
732 *p += sizeof(v);
733
734 return v;
735}
736
f1833600
GS
737/**
738 * Read unsigned 32bit integer from raw memory (little endian format), increment read position.
739 * @param[in, out] p Pointer into byte stream.
740 * @return Retrieved integer value, unsigned.
741 */
742static inline uint32_t read_u32le_inc(const uint8_t **p)
743{
744 uint32_t v;
745
746 if (!p || !*p)
747 return 0;
748 v = read_u32le(*p);
749 *p += sizeof(v);
750
751 return v;
752}
753
e4bcc63d
GS
754/**
755 * Read signed 32bit integer from raw memory (big endian format), increment read position.
756 * @param[in, out] p Pointer into byte stream.
757 * @return Retrieved integer value, signed.
758 */
759static inline int32_t read_i32be_inc(const uint8_t **p)
760{
761 int32_t v;
762
763 if (!p || !*p)
764 return 0;
765 v = read_i32be(*p);
766 *p += sizeof(v);
767
768 return v;
769}
770
771/**
772 * Read signed 32bit integer from raw memory (little endian format), increment read position.
773 * @param[in, out] p Pointer into byte stream.
774 * @return Retrieved integer value, signed.
775 */
776static inline int32_t read_i32le_inc(const uint8_t **p)
777{
778 int32_t v;
779
780 if (!p || !*p)
781 return 0;
782 v = read_i32le(*p);
783 *p += sizeof(v);
784
785 return v;
786}
787
f1833600
GS
788/**
789 * Read unsigned 64bit integer from raw memory (big endian format), increment read position.
790 * @param[in, out] p Pointer into byte stream.
791 * @return Retrieved integer value, unsigned.
792 */
793static inline uint64_t read_u64be_inc(const uint8_t **p)
794{
795 uint64_t v;
796
797 if (!p || !*p)
798 return 0;
799 v = read_u64be(*p);
800 *p += sizeof(v);
801
802 return v;
803}
804
805/**
806 * Read unsigned 64bit integer from raw memory (little endian format), increment read position.
807 * @param[in, out] p Pointer into byte stream.
808 * @return Retrieved integer value, unsigned.
809 */
810static inline uint64_t read_u64le_inc(const uint8_t **p)
811{
812 uint64_t v;
813
814 if (!p || !*p)
815 return 0;
816 v = read_u64le(*p);
817 *p += sizeof(v);
818
819 return v;
820}
821
e4bcc63d
GS
822/**
823 * Read 32bit float from raw memory (big endian format), increment read position.
824 * @param[in, out] p Pointer into byte stream.
825 * @return Retrieved float value.
826 */
827static inline float read_fltbe_inc(const uint8_t **p)
828{
829 float v;
830
831 if (!p || !*p)
832 return 0;
833 v = read_fltbe(*p);
834 *p += sizeof(v);
835
836 return v;
837}
838
daa895cb
GS
839/**
840 * Read 32bit float from raw memory (little endian format), increment read position.
841 * @param[in, out] p Pointer into byte stream.
842 * @return Retrieved float value.
843 */
844static inline float read_fltle_inc(const uint8_t **p)
845{
846 float v;
847
848 if (!p || !*p)
849 return 0;
850 v = read_fltle(*p);
851 *p += sizeof(v);
852
853 return v;
854}
855
e4bcc63d
GS
856/**
857 * Read 64bit float from raw memory (big endian format), increment read position.
858 * @param[in, out] p Pointer into byte stream.
859 * @return Retrieved float value.
860 */
861static inline double read_dblbe_inc(const uint8_t **p)
862{
863 double v;
864
865 if (!p || !*p)
866 return 0;
867 v = read_dblbe(*p);
868 *p += sizeof(v);
869
870 return v;
871}
872
daa895cb
GS
873/**
874 * Read 64bit float from raw memory (little endian format), increment read position.
875 * @param[in, out] p Pointer into byte stream.
876 * @return Retrieved float value.
877 */
878static inline double read_dblle_inc(const uint8_t **p)
879{
880 double v;
881
882 if (!p || !*p)
883 return 0;
884 v = read_dblle(*p);
885 *p += sizeof(v);
886
887 return v;
888}
889
f1833600
GS
890/**
891 * Write unsigned 8bit integer to raw memory, increment write position.
892 * @param[in, out] p Pointer into byte stream.
893 * @param[in] x Value to write.
894 */
895static inline void write_u8_inc(uint8_t **p, uint8_t x)
896{
897 if (!p || !*p)
898 return;
899 write_u8(*p, x);
900 *p += sizeof(x);
901}
902
903/**
904 * Write unsigned 16bit big endian integer to raw memory, increment write position.
905 * @param[in, out] p Pointer into byte stream.
906 * @param[in] x Value to write.
907 */
908static inline void write_u16be_inc(uint8_t **p, uint16_t x)
909{
910 if (!p || !*p)
911 return;
912 write_u16be(*p, x);
913 *p += sizeof(x);
914}
915
916/**
917 * Write unsigned 16bit little endian integer to raw memory, increment write position.
918 * @param[in, out] p Pointer into byte stream.
919 * @param[in] x Value to write.
920 */
921static inline void write_u16le_inc(uint8_t **p, uint16_t x)
922{
923 if (!p || !*p)
924 return;
925 write_u16le(*p, x);
926 *p += sizeof(x);
927}
928
15526343
GS
929/**
930 * Write unsigned 24bit liggle endian integer to raw memory, increment write position.
931 * @param[in, out] p Pointer into byte stream.
932 * @param[in] x Value to write.
933 */
934static inline void write_u24le_inc(uint8_t **p, uint32_t x)
935{
936 if (!p || !*p)
937 return;
938 write_u24le(*p, x);
939 *p += 3 * sizeof(uint8_t);
940}
941
f1833600
GS
942/**
943 * Write unsigned 32bit big endian integer to raw memory, increment write position.
944 * @param[in, out] p Pointer into byte stream.
945 * @param[in] x Value to write.
946 */
947static inline void write_u32be_inc(uint8_t **p, uint32_t x)
948{
949 if (!p || !*p)
950 return;
951 write_u32be(*p, x);
952 *p += sizeof(x);
953}
954
955/**
956 * Write unsigned 32bit little endian integer to raw memory, increment write position.
957 * @param[in, out] p Pointer into byte stream.
958 * @param[in] x Value to write.
959 */
960static inline void write_u32le_inc(uint8_t **p, uint32_t x)
961{
962 if (!p || !*p)
963 return;
964 write_u32le(*p, x);
965 *p += sizeof(x);
966}
a2632bca 967
15526343
GS
968/**
969 * Write unsigned 40bit little endian integer to raw memory, increment write position.
970 * @param[in, out] p Pointer into byte stream.
971 * @param[in] x Value to write.
972 */
973static inline void write_u40le_inc(uint8_t **p, uint64_t x)
974{
975 if (!p || !*p)
976 return;
977 write_u40le(*p, x);
978 *p += 5 * sizeof(uint8_t);
979}
980
797c8d90
GS
981/**
982 * Write unsigned 48bit little endian integer to raw memory, increment write position.
983 * @param[in, out] p Pointer into byte stream.
984 * @param[in] x Value to write.
985 */
986static inline void write_u48le_inc(uint8_t **p, uint64_t x)
987{
988 if (!p || !*p)
989 return;
990 write_u48le(*p, x);
991 *p += 48 / 8 * sizeof(uint8_t);
992}
993
daa895cb
GS
994/**
995 * Write unsigned 64bit little endian integer to raw memory, increment write position.
996 * @param[in, out] p Pointer into byte stream.
997 * @param[in] x Value to write.
998 */
999static inline void write_u64le_inc(uint8_t **p, uint64_t x)
1000{
1001 if (!p || !*p)
1002 return;
1003 write_u64le(*p, x);
1004 *p += sizeof(x);
1005}
1006
1007/**
1008 * Write single precision little endian float to raw memory, increment write position.
1009 * @param[in, out] p Pointer into byte stream.
1010 * @param[in] x Value to write.
1011 */
1012static inline void write_fltle_inc(uint8_t **p, float x)
1013{
1014 if (!p || !*p)
1015 return;
1016 write_fltle(*p, x);
1017 *p += sizeof(x);
1018}
1019
1020/**
1021 * Write double precision little endian float to raw memory, increment write position.
1022 * @param[in, out] p Pointer into byte stream.
1023 * @param[in] x Value to write.
1024 */
1025static inline void write_dblle_inc(uint8_t **p, double x)
1026{
1027 if (!p || !*p)
1028 return;
1029 write_dblle(*p, x);
1030 *p += sizeof(x);
1031}
1032
6bf4273e
UH
1033/* Portability fixes for FreeBSD. */
1034#ifdef __FreeBSD__
1035#define LIBUSB_CLASS_APPLICATION 0xfe
15eea61a 1036#define libusb_has_capability(x) 0
6bf4273e
UH
1037#define libusb_handle_events_timeout_completed(ctx, tv, c) \
1038 libusb_handle_events_timeout(ctx, tv)
1039#endif
1040
e1a712ca
GS
1041/*
1042 * Convenience for FTDI library version dependency.
1043 * - Version 1.5 introduced ftdi_tciflush(), ftdi_tcoflush(), and
1044 * ftdi_tcioflush() all within the same commit, and deprecated
1045 * ftdi_usb_purge_buffers() which suffered from inverse semantics.
1046 * The API is drop-in compatible (arguments count and data types are
1047 * identical). The libsigrok source code always flushes RX and TX at
1048 * the same time, never individually.
1049 */
1050#if defined HAVE_FTDI_TCIOFLUSH && HAVE_FTDI_TCIOFLUSH
1051# define PURGE_FTDI_BOTH ftdi_tcioflush
1052#else
1053# define PURGE_FTDI_BOTH ftdi_usb_purge_buffers
1054#endif
1055
1685c276
BV
1056/* Static definitions of structs ending with an all-zero entry are a
1057 * problem when compiling with -Wmissing-field-initializers: GCC
1058 * suppresses the warning only with { 0 }, clang wants { } */
1059#ifdef __clang__
1060#define ALL_ZERO { }
1061#else
1062#define ALL_ZERO { 0 }
1063#endif
1064
dd5c48a6
LPC
1065#ifdef __APPLE__
1066#define SR_DRIVER_LIST_SECTION "__DATA,__sr_driver_list"
1067#else
02a8c07d 1068#define SR_DRIVER_LIST_SECTION "__sr_driver_list"
dd5c48a6
LPC
1069#endif
1070
3decd3b1
GS
1071#if !defined SR_DRIVER_LIST_NOREORDER && defined __has_attribute
1072#if __has_attribute(no_reorder)
1073#define SR_DRIVER_LIST_NOREORDER __attribute__((no_reorder))
1074#endif
1075#endif
1076#if !defined SR_DRIVER_LIST_NOREORDER
1077#define SR_DRIVER_LIST_NOREORDER /* EMPTY */
1078#endif
1079
dd5c48a6
LPC
1080/**
1081 * Register a list of hardware drivers.
1082 *
1083 * This macro can be used to register multiple hardware drivers to the library.
1084 * This is useful when a driver supports multiple similar but slightly
1085 * different devices that require different sr_dev_driver struct definitions.
1086 *
1087 * For registering only a single driver see SR_REGISTER_DEV_DRIVER().
1088 *
1089 * Example:
1090 * @code{c}
1091 * #define MY_DRIVER(_name) \
1092 * &(struct sr_dev_driver){ \
1093 * .name = _name, \
1094 * ...
1095 * };
1096 *
1097 * SR_REGISTER_DEV_DRIVER_LIST(my_driver_infos,
1098 * MY_DRIVER("driver 1"),
1099 * MY_DRIVER("driver 2"),
1100 * ...
1101 * );
1102 * @endcode
1103 *
1104 * @param name Name to use for the driver list identifier.
1105 * @param ... Comma separated list of pointers to sr_dev_driver structs.
1106 */
1107#define SR_REGISTER_DEV_DRIVER_LIST(name, ...) \
1108 static const struct sr_dev_driver *name[] \
3decd3b1 1109 SR_DRIVER_LIST_NOREORDER \
dd5c48a6
LPC
1110 __attribute__((section (SR_DRIVER_LIST_SECTION), used, \
1111 aligned(sizeof(struct sr_dev_driver *)))) \
1112 = { \
1113 __VA_ARGS__ \
1114 };
1115
1116/**
1117 * Register a hardware driver.
1118 *
1119 * This macro is used to register a hardware driver with the library. It has
1120 * to be used in order to make the driver accessible to applications using the
1121 * library.
1122 *
1123 * The macro invocation should be placed directly under the struct
1124 * sr_dev_driver definition.
1125 *
1126 * Example:
1127 * @code{c}
1128 * static struct sr_dev_driver driver_info = {
1129 * .name = "driver",
1130 * ....
1131 * };
1132 * SR_REGISTER_DEV_DRIVER(driver_info);
1133 * @endcode
1134 *
1135 * @param name Identifier name of sr_dev_driver struct to register.
1136 */
1137#define SR_REGISTER_DEV_DRIVER(name) \
1138 SR_REGISTER_DEV_DRIVER_LIST(name##_list, &name);
1139
ced48274 1140SR_API void sr_drivers_init(struct sr_context *context);
5d8b3913 1141
b8072700 1142struct sr_context {
032da34b 1143 struct sr_dev_driver **driver_list;
785b9ff2
PS
1144#ifdef HAVE_LIBUSB_1_0
1145 libusb_context *libusb_ctx;
1146#endif
bee24666
DE
1147 sr_resource_open_callback resource_open_cb;
1148 sr_resource_close_callback resource_close_cb;
1149 sr_resource_read_callback resource_read_cb;
1150 void *resource_cb_data;
b8072700
PS
1151};
1152
20e88821
BV
1153/** Input module metadata keys. */
1154enum sr_input_meta_keys {
1155 /** The input filename, if there is one. */
1156 SR_INPUT_META_FILENAME = 0x01,
1157 /** The input file's size in bytes. */
1158 SR_INPUT_META_FILESIZE = 0x02,
1159 /** The first 128 bytes of the file, provided as a GString. */
1160 SR_INPUT_META_HEADER = 0x04,
20e88821
BV
1161
1162 /** The module cannot identify a file without this metadata. */
1163 SR_INPUT_META_REQUIRED = 0x80,
1164};
1165
d514d35d
BV
1166/** Input (file) module struct. */
1167struct sr_input {
1168 /**
1169 * A pointer to this input module's 'struct sr_input_module'.
d514d35d 1170 */
17bfaca6
BV
1171 const struct sr_input_module *module;
1172 GString *buf;
d514d35d 1173 struct sr_dev_inst *sdi;
d0181813 1174 gboolean sdi_ready;
17bfaca6 1175 void *priv;
d514d35d
BV
1176};
1177
1178/** Input (file) module driver. */
1179struct sr_input_module {
17bfaca6 1180 /**
d65fcbcd 1181 * A unique ID for this input module, suitable for use in command-line
17bfaca6
BV
1182 * clients, [a-z0-9-]. Must not be NULL.
1183 */
1184 const char *id;
d514d35d
BV
1185
1186 /**
d65fcbcd 1187 * A unique name for this input module, suitable for use in GUI
17bfaca6 1188 * clients, can contain UTF-8. Must not be NULL.
d514d35d 1189 */
17bfaca6 1190 const char *name;
d514d35d
BV
1191
1192 /**
d65fcbcd 1193 * A short description of the input module. Must not be NULL.
d514d35d 1194 *
d65fcbcd 1195 * This can be displayed by frontends, e.g. when selecting the input
17bfaca6
BV
1196 * module for saving a file.
1197 */
1198 const char *desc;
1199
c7bc82ff
JH
1200 /**
1201 * A NULL terminated array of strings containing a list of file name
1202 * extensions typical for the input file format, or NULL if there is
1203 * no typical extension for this file format.
1204 */
1205 const char *const *exts;
1206
17bfaca6
BV
1207 /**
1208 * Zero-terminated list of metadata items the module needs to be able
1209 * to identify an input stream. Can be all-zero, if the module cannot
1210 * identify streams at all, i.e. has to be forced into use.
1211 *
1212 * Each item is one of:
1213 * SR_INPUT_META_FILENAME
1214 * SR_INPUT_META_FILESIZE
1215 * SR_INPUT_META_HEADER
17bfaca6
BV
1216 *
1217 * If the high bit (SR_INPUT META_REQUIRED) is set, the module cannot
1218 * identify a stream without the given metadata.
1219 */
1220 const uint8_t metadata[8];
1221
1222 /**
1223 * Returns a NULL-terminated list of options this module can take.
1224 * Can be NULL, if the module has no options.
1225 */
2c240774 1226 const struct sr_option *(*options) (void);
17bfaca6
BV
1227
1228 /**
1229 * Check if this input module can load and parse the specified stream.
1230 *
1231 * @param[in] metadata Metadata the module can use to identify the stream.
54ee427d
GS
1232 * @param[out] confidence "Strength" of the detection.
1233 * Specialized handlers can take precedence over generic/basic support.
d514d35d 1234 *
4f979115 1235 * @retval SR_OK This module knows the format.
753793ef 1236 * @retval SR_ERR_NA There wasn't enough data for this module to
4f979115 1237 * positively identify the format.
d9251a2c
UH
1238 * @retval SR_ERR_DATA This module knows the format, but cannot handle
1239 * it. This means the stream is either corrupt, or indicates a
1240 * feature that the module does not support.
4f979115 1241 * @retval SR_ERR This module does not know the format.
54ee427d
GS
1242 *
1243 * Lower numeric values of 'confidence' mean that the input module
1244 * stronger believes in its capability to handle this specific format.
1245 * This way, multiple input modules can claim support for a format,
1246 * and the application can pick the best match, or try fallbacks
1247 * in case of errors. This approach also copes with formats that
1248 * are unreliable to detect in the absence of magic signatures.
d514d35d 1249 */
54ee427d 1250 int (*format_match) (GHashTable *metadata, unsigned int *confidence);
d514d35d
BV
1251
1252 /**
1253 * Initialize the input module.
1254 *
d514d35d
BV
1255 * @retval SR_OK Success
1256 * @retval other Negative error code.
1257 */
17bfaca6 1258 int (*init) (struct sr_input *in, GHashTable *options);
d514d35d
BV
1259
1260 /**
753793ef 1261 * Send data to the specified input instance.
d514d35d 1262 *
753793ef
BV
1263 * When an input module instance is created with sr_input_new(), this
1264 * function is used to feed data to the instance.
d514d35d 1265 *
753793ef
BV
1266 * As enough data gets fed into this function to completely populate
1267 * the device instance associated with this input instance, this is
1268 * guaranteed to return the moment it's ready. This gives the caller
1269 * the chance to examine the device instance, attach session callbacks
1270 * and so on.
17bfaca6
BV
1271 *
1272 * @retval SR_OK Success
1273 * @retval other Negative error code.
1274 */
d0181813 1275 int (*receive) (struct sr_input *in, GString *buf);
17bfaca6 1276
753793ef
BV
1277 /**
1278 * Signal the input module no more data will come.
1279 *
1280 * This will cause the module to process any data it may have buffered.
1281 * The SR_DF_END packet will also typically be sent at this time.
1282 */
7066fd46
BV
1283 int (*end) (struct sr_input *in);
1284
d9251a2c
UH
1285 /**
1286 * Reset the input module's input handling structures.
1287 *
1288 * Causes the input module to reset its internal state so that we can
1289 * re-send the input data from the beginning without having to
1290 * re-create the entire input module.
1291 *
1292 * @retval SR_OK Success.
1293 * @retval other Negative error code.
1294 */
b6b4f03e
SA
1295 int (*reset) (struct sr_input *in);
1296
17bfaca6
BV
1297 /**
1298 * This function is called after the caller is finished using
1299 * the input module, and can be used to free any internal
1300 * resources the module may keep.
d514d35d 1301 *
753793ef
BV
1302 * This function is optional.
1303 *
d514d35d
BV
1304 * @retval SR_OK Success
1305 * @retval other Negative error code.
1306 */
d5cc282f 1307 void (*cleanup) (struct sr_input *in);
d514d35d
BV
1308};
1309
a755b0e1
BV
1310/** Output module instance. */
1311struct sr_output {
d9251a2c 1312 /** A pointer to this output's module. */
a755b0e1
BV
1313 const struct sr_output_module *module;
1314
1315 /**
1316 * The device for which this output module is creating output. This
1317 * can be used by the module to find out channel names and numbers.
1318 */
1319 const struct sr_dev_inst *sdi;
1320
81b3ce37
SA
1321 /**
1322 * The name of the file that the data should be written to.
1323 */
1324 const char *filename;
1325
a755b0e1
BV
1326 /**
1327 * A generic pointer which can be used by the module to keep internal
1328 * state between calls into its callback functions.
1329 *
1330 * For example, the module might store a pointer to a chunk of output
1331 * there, and only flush it when it reaches a certain size.
1332 */
d686c5ec 1333 void *priv;
a755b0e1
BV
1334};
1335
1336/** Output module driver. */
1337struct sr_output_module {
1338 /**
1339 * A unique ID for this output module, suitable for use in command-line
1340 * clients, [a-z0-9-]. Must not be NULL.
1341 */
2c240774 1342 const char *id;
a755b0e1
BV
1343
1344 /**
1345 * A unique name for this output module, suitable for use in GUI
1346 * clients, can contain UTF-8. Must not be NULL.
1347 */
1348 const char *name;
1349
1350 /**
1351 * A short description of the output module. Must not be NULL.
1352 *
1353 * This can be displayed by frontends, e.g. when selecting the output
1354 * module for saving a file.
1355 */
2c240774 1356 const char *desc;
a755b0e1 1357
8a174d23
JH
1358 /**
1359 * A NULL terminated array of strings containing a list of file name
1360 * extensions typical for the input file format, or NULL if there is
1361 * no typical extension for this file format.
1362 */
1363 const char *const *exts;
1364
3cd4b381
SA
1365 /**
1366 * Bitfield containing flags that describe certain properties
1367 * this output module may or may not have.
1368 * @see sr_output_flags
1369 */
1370 const uint64_t flags;
1371
a755b0e1
BV
1372 /**
1373 * Returns a NULL-terminated list of options this module can take.
1374 * Can be NULL, if the module has no options.
a755b0e1 1375 */
af7d656d 1376 const struct sr_option *(*options) (void);
a755b0e1
BV
1377
1378 /**
1379 * This function is called once, at the beginning of an output stream.
1380 *
1381 * The device struct will be available in the output struct passed in,
1382 * as well as the param field -- which may be NULL or an empty string,
1383 * if no parameter was passed.
1384 *
1385 * The module can use this to initialize itself, create a struct for
1386 * keeping state and storing it in the <code>internal</code> field.
1387 *
1388 * @param o Pointer to the respective 'struct sr_output'.
1389 *
1390 * @retval SR_OK Success
1391 * @retval other Negative error code.
1392 */
1393 int (*init) (struct sr_output *o, GHashTable *options);
1394
1395 /**
f3f19d11 1396 * This function is passed a copy of every packet in the data feed.
a755b0e1
BV
1397 * Any output generated by the output module in response to the
1398 * packet should be returned in a newly allocated GString
1399 * <code>out</code>, which will be freed by the caller.
1400 *
1401 * Packets not of interest to the output module can just be ignored,
1402 * and the <code>out</code> parameter set to NULL.
1403 *
1404 * @param o Pointer to the respective 'struct sr_output'.
1405 * @param sdi The device instance that generated the packet.
1406 * @param packet The complete packet.
1407 * @param out A pointer where a GString * should be stored if
1408 * the module generates output, or NULL if not.
1409 *
1410 * @retval SR_OK Success
1411 * @retval other Negative error code.
1412 */
1413 int (*receive) (const struct sr_output *o,
1414 const struct sr_datafeed_packet *packet, GString **out);
1415
1416 /**
1417 * This function is called after the caller is finished using
1418 * the output module, and can be used to free any internal
1419 * resources the module may keep.
1420 *
1421 * @retval SR_OK Success
1422 * @retval other Negative error code.
1423 */
1424 int (*cleanup) (struct sr_output *o);
1425};
1426
790320f6
UH
1427/** Transform module instance. */
1428struct sr_transform {
d9251a2c 1429 /** A pointer to this transform's module. */
790320f6
UH
1430 const struct sr_transform_module *module;
1431
1432 /**
1433 * The device for which this transform module is used. This
1434 * can be used by the module to find out channel names and numbers.
1435 */
1436 const struct sr_dev_inst *sdi;
1437
1438 /**
1439 * A generic pointer which can be used by the module to keep internal
1440 * state between calls into its callback functions.
1441 */
1442 void *priv;
1443};
1444
1445struct sr_transform_module {
1446 /**
1447 * A unique ID for this transform module, suitable for use in
1448 * command-line clients, [a-z0-9-]. Must not be NULL.
1449 */
2c240774 1450 const char *id;
790320f6
UH
1451
1452 /**
1453 * A unique name for this transform module, suitable for use in GUI
1454 * clients, can contain UTF-8. Must not be NULL.
1455 */
1456 const char *name;
1457
1458 /**
1459 * A short description of the transform module. Must not be NULL.
1460 *
1461 * This can be displayed by frontends, e.g. when selecting
1462 * which transform module(s) to add.
1463 */
2c240774 1464 const char *desc;
790320f6
UH
1465
1466 /**
1467 * Returns a NULL-terminated list of options this transform module
1468 * can take. Can be NULL, if the transform module has no options.
1469 */
1470 const struct sr_option *(*options) (void);
1471
1472 /**
1473 * This function is called once, at the beginning of a stream.
1474 *
1475 * @param t Pointer to the respective 'struct sr_transform'.
1476 * @param options Hash table of options for this transform module.
1477 * Can be NULL if no options are to be used.
1478 *
1479 * @retval SR_OK Success
1480 * @retval other Negative error code.
1481 */
1482 int (*init) (struct sr_transform *t, GHashTable *options);
1483
1484 /**
1485 * This function is passed a pointer to every packet in the data feed.
1486 *
1487 * It can either return (in packet_out) a pointer to another packet
1488 * (possibly the exact same packet it got as input), or NULL.
1489 *
1490 * @param t Pointer to the respective 'struct sr_transform'.
1491 * @param packet_in Pointer to a datafeed packet.
1492 * @param packet_out Pointer to the resulting datafeed packet after
1493 * this function was run. If NULL, the transform
1494 * module intentionally didn't output a new packet.
1495 *
1496 * @retval SR_OK Success
1497 * @retval other Negative error code.
1498 */
1499 int (*receive) (const struct sr_transform *t,
1500 struct sr_datafeed_packet *packet_in,
1501 struct sr_datafeed_packet **packet_out);
1502
1503 /**
1504 * This function is called after the caller is finished using
1505 * the transform module, and can be used to free any internal
1506 * resources the module may keep.
1507 *
1508 * @retval SR_OK Success
1509 * @retval other Negative error code.
1510 */
1511 int (*cleanup) (struct sr_transform *t);
1512};
1513
69890f73 1514#ifdef HAVE_LIBUSB_1_0
04cb9157 1515/** USB device instance */
d68e2d1a 1516struct sr_usb_dev_inst {
98582bf5
BV
1517 /** USB bus */
1518 uint8_t bus;
1519 /** Device address on USB bus */
1520 uint8_t address;
1521 /** libusb device handle */
1522 struct libusb_device_handle *devhdl;
69890f73
UH
1523};
1524#endif
1525
1ac8c218 1526struct sr_serial_dev_inst;
1df81f4b 1527#ifdef HAVE_SERIAL_COMM
a7b8692e 1528struct ser_lib_functions;
edec0436 1529struct ser_hid_chip_functions;
b79c3422 1530struct sr_bt_desc;
d4787248
GS
1531typedef void (*serial_rx_chunk_callback)(struct sr_serial_dev_inst *serial,
1532 void *cb_data, const void *buf, size_t count);
d68e2d1a 1533struct sr_serial_dev_inst {
98582bf5
BV
1534 /** Port name, e.g. '/dev/tty42'. */
1535 char *port;
1536 /** Comm params for serial_set_paramstr(). */
1537 char *serialcomm;
a7b8692e 1538 struct ser_lib_functions *lib_funcs;
639c6f61
GS
1539 struct {
1540 int bit_rate;
1541 int data_bits;
1542 int parity_bits;
1543 int stop_bits;
1544 } comm_params;
ad5aa993 1545 GString *rcv_buffer;
d4787248
GS
1546 serial_rx_chunk_callback rx_chunk_cb_func;
1547 void *rx_chunk_cb_data;
a7b8692e 1548#ifdef HAVE_LIBSERIALPORT
98582bf5 1549 /** libserialport port handle */
271392d9 1550 struct sp_port *sp_data;
a7b8692e 1551#endif
4417074c 1552#ifdef HAVE_LIBHIDAPI
edec0436
GS
1553 enum ser_hid_chip_t {
1554 SER_HID_CHIP_UNKNOWN, /**!< place holder */
a10284cd 1555 SER_HID_CHIP_BTC_BU86X, /**!< Brymen BU86x */
616bc3a1 1556 SER_HID_CHIP_SIL_CP2110, /**!< SiLabs CP2110 */
0cdb72c8 1557 SER_HID_CHIP_VICTOR_DMM, /**!< Victor 70/86 DMM cable */
828eeea2 1558 SER_HID_CHIP_WCH_CH9325, /**!< WCH CH9325 */
edec0436
GS
1559 SER_HID_CHIP_LAST, /**!< sentinel */
1560 } hid_chip;
1561 struct ser_hid_chip_functions *hid_chip_funcs;
1562 char *usb_path;
1563 char *usb_serno;
1564 const char *hid_path;
4417074c 1565 hid_device *hid_dev;
edec0436 1566 GSList *hid_source_args;
4417074c 1567#endif
b79c3422
GS
1568#ifdef HAVE_BLUETOOTH
1569 enum ser_bt_conn_t {
1570 SER_BT_CONN_UNKNOWN, /**!< place holder */
1571 SER_BT_CONN_RFCOMM, /**!< BT classic, RFCOMM channel */
1572 SER_BT_CONN_BLE122, /**!< BLE, BLE122 module, indications */
1573 SER_BT_CONN_NRF51, /**!< BLE, Nordic nRF51, notifications */
1574 SER_BT_CONN_CC254x, /**!< BLE, TI CC254x, notifications */
1575 SER_BT_CONN_MAX, /**!< sentinel */
1576 } bt_conn_type;
1577 char *bt_addr_local;
1578 char *bt_addr_remote;
1579 size_t bt_rfcomm_channel;
1580 uint16_t bt_notify_handle_read;
1581 uint16_t bt_notify_handle_write;
1582 uint16_t bt_notify_handle_cccd;
1583 uint16_t bt_notify_value_cccd;
1584 struct sr_bt_desc *bt_desc;
1585 GSList *bt_source_args;
1586#endif
69890f73 1587};
c4f2dfd0 1588#endif
69890f73 1589
ae67644f
ML
1590struct sr_usbtmc_dev_inst {
1591 char *device;
1592 int fd;
1593};
1594
026c822d
UH
1595/* Private driver context. */
1596struct drv_context {
98582bf5
BV
1597 /** sigrok context */
1598 struct sr_context *sr_ctx;
026c822d
UH
1599 GSList *instances;
1600};
1601
48a486cd
BV
1602/*--- log.c -----------------------------------------------------------------*/
1603
00f0016c 1604#if defined(_WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
7419638d
DE
1605/*
1606 * On MinGW, we need to specify the gnu_printf format flavor or GCC
1607 * will assume non-standard Microsoft printf syntax.
1608 */
1609SR_PRIV int sr_log(int loglevel, const char *format, ...)
1610 __attribute__((__format__ (__gnu_printf__, 2, 3)));
1611#else
be92d5b4 1612SR_PRIV int sr_log(int loglevel, const char *format, ...) G_GNUC_PRINTF(2, 3);
7419638d 1613#endif
48a486cd 1614
3544f848 1615/* Message logging helpers with subsystem-specific prefix string. */
be92d5b4
DE
1616#define sr_spew(...) sr_log(SR_LOG_SPEW, LOG_PREFIX ": " __VA_ARGS__)
1617#define sr_dbg(...) sr_log(SR_LOG_DBG, LOG_PREFIX ": " __VA_ARGS__)
1618#define sr_info(...) sr_log(SR_LOG_INFO, LOG_PREFIX ": " __VA_ARGS__)
1619#define sr_warn(...) sr_log(SR_LOG_WARN, LOG_PREFIX ": " __VA_ARGS__)
1620#define sr_err(...) sr_log(SR_LOG_ERR, LOG_PREFIX ": " __VA_ARGS__)
3544f848 1621
48a486cd
BV
1622/*--- device.c --------------------------------------------------------------*/
1623
cffdc3e6
ML
1624/** Scan options supported by a driver. */
1625#define SR_CONF_SCAN_OPTIONS 0x7FFF0000
1626
1627/** Device options for a particular device. */
1628#define SR_CONF_DEVICE_OPTIONS 0x7FFF0001
1629
e318f01b
ML
1630/** Mask for separating config keys from capabilities. */
1631#define SR_CONF_MASK 0x1fffffff
1632
f3ca73ed 1633/** Values for the changes argument of sr_dev_driver.config_channel_set. */
2a854d71 1634enum {
fca75cbb 1635 /** The enabled state of the channel has been changed. */
3f239f08 1636 SR_CHANNEL_SET_ENABLED = 1 << 0,
2a854d71
DE
1637};
1638
5e23fcab
ML
1639SR_PRIV struct sr_channel *sr_channel_new(struct sr_dev_inst *sdi,
1640 int index, int type, gboolean enabled, const char *name);
fe71c7e4
GS
1641SR_PRIV void sr_channel_free(struct sr_channel *ch);
1642SR_PRIV void sr_channel_free_cb(void *p);
9c24d16a
BV
1643SR_PRIV struct sr_channel *sr_next_enabled_channel(const struct sr_dev_inst *sdi,
1644 struct sr_channel *cur_channel);
712f981d
GS
1645SR_PRIV gboolean sr_channels_differ(struct sr_channel *ch1, struct sr_channel *ch2);
1646SR_PRIV gboolean sr_channel_lists_differ(GSList *l1, GSList *l2);
48a486cd 1647
96727ef0
UH
1648/** Device instance data */
1649struct sr_dev_inst {
1650 /** Device driver. */
1651 struct sr_dev_driver *driver;
1652 /** Device instance status. SR_ST_NOT_FOUND, etc. */
1653 int status;
1654 /** Device instance type. SR_INST_USB, etc. */
1655 int inst_type;
1656 /** Device vendor. */
1657 char *vendor;
1658 /** Device model. */
1659 char *model;
1660 /** Device version. */
1661 char *version;
1662 /** Serial number. */
1663 char *serial_num;
1664 /** Connection string to uniquely identify devices. */
1665 char *connection_id;
1666 /** List of channels. */
1667 GSList *channels;
1668 /** List of sr_channel_group structs */
1669 GSList *channel_groups;
1670 /** Device instance connection data (used?) */
1671 void *conn;
1672 /** Device instance private data (used?) */
1673 void *priv;
1674 /** Session to which this device is currently assigned. */
1675 struct sr_session *session;
1676};
1677
48a486cd 1678/* Generic device instances */
48a486cd 1679SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi);
48a486cd 1680
545f9786 1681#ifdef HAVE_LIBUSB_1_0
69890f73 1682/* USB-specific instances */
d68e2d1a 1683SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus,
69890f73 1684 uint8_t address, struct libusb_device_handle *hdl);
d68e2d1a 1685SR_PRIV void sr_usb_dev_inst_free(struct sr_usb_dev_inst *usb);
69890f73
UH
1686#endif
1687
1df81f4b 1688#ifdef HAVE_SERIAL_COMM
1ac8c218
GS
1689#ifndef HAVE_LIBSERIALPORT
1690/*
1691 * Some identifiers which initially got provided by libserialport are
1692 * used internally within the libsigrok serial layer's implementation,
1693 * while libserialport no longer is the exclusive provider of serial
1694 * communication support. Declare the identifiers here so they remain
1695 * available across all build configurations.
1696 */
1697enum libsp_parity {
1698 SP_PARITY_NONE = 0,
1699 SP_PARITY_ODD = 1,
1700 SP_PARITY_EVEN = 2,
1701 SP_PARITY_MARK = 3,
1702 SP_PARITY_SPACE = 4,
1703};
1704
1705enum libsp_flowcontrol {
1706 SP_FLOWCONTROL_NONE = 0,
1707 SP_FLOWCONTROL_XONXOFF = 1,
1708 SP_FLOWCONTROL_RTSCTS = 2,
1709 SP_FLOWCONTROL_DTRDSR = 3,
1710};
1711#endif
1712
69890f73 1713/* Serial-specific instances */
299bdb24
BV
1714SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(const char *port,
1715 const char *serialcomm);
d68e2d1a 1716SR_PRIV void sr_serial_dev_inst_free(struct sr_serial_dev_inst *serial);
c4f2dfd0 1717#endif
69890f73 1718
ae67644f
ML
1719/* USBTMC-specific instances */
1720SR_PRIV struct sr_usbtmc_dev_inst *sr_usbtmc_dev_inst_new(const char *device);
1721SR_PRIV void sr_usbtmc_dev_inst_free(struct sr_usbtmc_dev_inst *usbtmc);
b08024a8 1722
c09f0b57 1723/*--- hwdriver.c ------------------------------------------------------------*/
996b0c72 1724
13fef1ed 1725SR_PRIV const GVariantType *sr_variant_type_get(int datatype);
584560f1 1726SR_PRIV int sr_variant_type_check(uint32_t key, GVariant *data);
032da34b 1727SR_PRIV void sr_hw_cleanup_all(const struct sr_context *ctx);
584560f1 1728SR_PRIV struct sr_config *sr_config_new(uint32_t key, GVariant *data);
722db131 1729SR_PRIV void sr_config_free(struct sr_config *src);
f670835f 1730SR_PRIV int sr_dev_acquisition_start(struct sr_dev_inst *sdi);
d2f7c417 1731SR_PRIV int sr_dev_acquisition_stop(struct sr_dev_inst *sdi);
996b0c72 1732
a1645fcd
BV
1733/*--- session.c -------------------------------------------------------------*/
1734
e2b23821 1735struct sr_session {
4ed5d21d
ML
1736 /** Context this session exists in. */
1737 struct sr_context *ctx;
c0e3ba4b 1738 /** List of struct sr_dev_inst pointers. */
e2b23821 1739 GSList *devs;
1de3cced
ML
1740 /** List of struct sr_dev_inst pointers owned by this session. */
1741 GSList *owned_devs;
e2b23821
UH
1742 /** List of struct datafeed_callback pointers. */
1743 GSList *datafeed_callbacks;
c0a1e532 1744 GSList *transforms;
7b5e6d29 1745 struct sr_trigger *trigger;
62d7945f 1746
5de0fc55
DE
1747 /** Callback to invoke on session stop. */
1748 sr_session_stopped_callback stopped_callback;
1749 /** User data to be passed to the session stop callback. */
1750 void *stopped_cb_data;
1751
2e5e3df4 1752 /** Mutex protecting the main context pointer. */
c2bf5506
DE
1753 GMutex main_mutex;
1754 /** Context of the session main loop. */
1755 GMainContext *main_context;
e2b23821 1756
c2bf5506
DE
1757 /** Registered event sources for this session. */
1758 GHashTable *event_sources;
1759 /** Session main loop. */
1760 GMainLoop *main_loop;
5de0fc55
DE
1761 /** ID of idle source for dispatching the session stop notification. */
1762 unsigned int stop_check_id;
2e5e3df4
DE
1763 /** Whether the session has been started. */
1764 gboolean running;
e2b23821
UH
1765};
1766
62d7945f 1767SR_PRIV int sr_session_source_add_internal(struct sr_session *session,
c2bf5506 1768 void *key, GSource *source);
92248e78 1769SR_PRIV int sr_session_source_remove_internal(struct sr_session *session,
c2bf5506
DE
1770 void *key);
1771SR_PRIV int sr_session_source_destroyed(struct sr_session *session,
1772 void *key, GSource *source);
cbc1413f
DE
1773SR_PRIV int sr_session_fd_source_add(struct sr_session *session,
1774 void *key, gintptr fd, int events, int timeout,
1775 sr_receive_data_callback cb, void *cb_data);
ee9953ef
DE
1776
1777SR_PRIV int sr_session_source_add(struct sr_session *session, int fd,
1778 int events, int timeout, sr_receive_data_callback cb, void *cb_data);
1779SR_PRIV int sr_session_source_add_pollfd(struct sr_session *session,
1780 GPollFD *pollfd, int timeout, sr_receive_data_callback cb,
1781 void *cb_data);
1782SR_PRIV int sr_session_source_add_channel(struct sr_session *session,
1783 GIOChannel *channel, int events, int timeout,
1784 sr_receive_data_callback cb, void *cb_data);
1785SR_PRIV int sr_session_source_remove(struct sr_session *session, int fd);
1786SR_PRIV int sr_session_source_remove_pollfd(struct sr_session *session,
1787 GPollFD *pollfd);
1788SR_PRIV int sr_session_source_remove_channel(struct sr_session *session,
1789 GIOChannel *channel);
1790
7d1a4a52
FS
1791SR_PRIV int sr_session_send_meta(const struct sr_dev_inst *sdi,
1792 uint32_t key, GVariant *var);
de4d3f99 1793SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
ae5859ff 1794 const struct sr_datafeed_packet *packet);
f438e0c9 1795SR_PRIV int sr_sessionfile_check(const char *filename);
7c69b528
SA
1796SR_PRIV struct sr_dev_inst *sr_session_prepare_sdi(const char *filename,
1797 struct sr_session **session);
a1645fcd 1798
98654c99
DE
1799/*--- session_file.c --------------------------------------------------------*/
1800
a6dc3dac
DE
1801#if !HAVE_ZIP_DISCARD
1802/* Replace zip_discard() if not available. */
1803#define zip_discard(zip) sr_zip_discard(zip)
1804SR_PRIV void sr_zip_discard(struct zip *archive);
1805#endif
1806
98654c99
DE
1807SR_PRIV GKeyFile *sr_sessionfile_read_metadata(struct zip *archive,
1808 const struct zip_stat *entry);
1809
41caa319
AJ
1810/*--- analog.c --------------------------------------------------------------*/
1811
edb691fc 1812SR_PRIV int sr_analog_init(struct sr_datafeed_analog *analog,
41caa319
AJ
1813 struct sr_analog_encoding *encoding,
1814 struct sr_analog_meaning *meaning,
1815 struct sr_analog_spec *spec,
1816 int digits);
1817
063e7aef
UH
1818/*--- std.c -----------------------------------------------------------------*/
1819
144f6660
UH
1820typedef int (*dev_close_callback)(struct sr_dev_inst *sdi);
1821typedef void (*std_dev_clear_callback)(void *priv);
cd2f0fe2 1822
c45c32ce 1823SR_PRIV int std_init(struct sr_dev_driver *di, struct sr_context *sr_ctx);
700d6b64 1824SR_PRIV int std_cleanup(const struct sr_dev_driver *di);
4d67b9d9
UH
1825SR_PRIV int std_dummy_dev_open(struct sr_dev_inst *sdi);
1826SR_PRIV int std_dummy_dev_close(struct sr_dev_inst *sdi);
1827SR_PRIV int std_dummy_dev_acquisition_start(const struct sr_dev_inst *sdi);
1828SR_PRIV int std_dummy_dev_acquisition_stop(struct sr_dev_inst *sdi);
1df81f4b 1829#ifdef HAVE_SERIAL_COMM
23dc6661 1830SR_PRIV int std_serial_dev_open(struct sr_dev_inst *sdi);
1b38775b 1831SR_PRIV int std_serial_dev_acquisition_stop(struct sr_dev_inst *sdi);
c4f2dfd0 1832#endif
bee2b016
LPC
1833SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi);
1834SR_PRIV int std_session_send_df_end(const struct sr_dev_inst *sdi);
10cf8113 1835SR_PRIV int std_session_send_df_trigger(const struct sr_dev_inst *sdi);
7f7702b8
UH
1836SR_PRIV int std_session_send_df_frame_begin(const struct sr_dev_inst *sdi);
1837SR_PRIV int std_session_send_df_frame_end(const struct sr_dev_inst *sdi);
6e43c3d5 1838SR_PRIV int std_dev_clear_with_callback(const struct sr_dev_driver *driver,
144f6660 1839 std_dev_clear_callback clear_private);
f778bf02 1840SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver);
c01bf34c 1841SR_PRIV GSList *std_dev_list(const struct sr_dev_driver *di);
043e899a 1842SR_PRIV int std_serial_dev_close(struct sr_dev_inst *sdi);
15a5bfe4 1843SR_PRIV GSList *std_scan_complete(struct sr_dev_driver *di, GSList *devices);
4afdfd46 1844
e66d1892
UH
1845SR_PRIV int std_opts_config_list(uint32_t key, GVariant **data,
1846 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg,
1847 const uint32_t scanopts[], size_t scansize, const uint32_t drvopts[],
1848 size_t drvsize, const uint32_t devopts[], size_t devsize);
1849
23772462
UH
1850extern SR_PRIV const uint32_t NO_OPTS[1];
1851
e66d1892
UH
1852#define STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts) \
1853 std_opts_config_list(key, data, sdi, cg, ARRAY_AND_SIZE(scanopts), \
1854 ARRAY_AND_SIZE(drvopts), ARRAY_AND_SIZE(devopts))
1855
58ffcf97 1856SR_PRIV GVariant *std_gvar_tuple_array(const uint64_t a[][2], unsigned int n);
db944f16 1857SR_PRIV GVariant *std_gvar_tuple_rational(const struct sr_rational *r, unsigned int n);
463160cb
UH
1858SR_PRIV GVariant *std_gvar_samplerates(const uint64_t samplerates[], unsigned int n);
1859SR_PRIV GVariant *std_gvar_samplerates_steps(const uint64_t samplerates[], unsigned int n);
54d471f4
UH
1860SR_PRIV GVariant *std_gvar_min_max_step(double min, double max, double step);
1861SR_PRIV GVariant *std_gvar_min_max_step_array(const double a[3]);
7bc3cfe6 1862SR_PRIV GVariant *std_gvar_min_max_step_thresholds(const double dmin, const double dmax, const double dstep);
db944f16 1863
a162eeb2 1864SR_PRIV GVariant *std_gvar_tuple_u64(uint64_t low, uint64_t high);
43995cda 1865SR_PRIV GVariant *std_gvar_tuple_double(double low, double high);
a162eeb2 1866
769561cb
UH
1867SR_PRIV GVariant *std_gvar_array_i32(const int32_t a[], unsigned int n);
1868SR_PRIV GVariant *std_gvar_array_u32(const uint32_t a[], unsigned int n);
1869SR_PRIV GVariant *std_gvar_array_u64(const uint64_t a[], unsigned int n);
70635036 1870SR_PRIV GVariant *std_gvar_array_str(const char *a[], unsigned int n);
db944f16 1871
94e64a0b 1872SR_PRIV GVariant *std_gvar_thresholds(const double a[][2], unsigned int n);
9fb9afb5 1873
697fb6dd
UH
1874SR_PRIV int std_str_idx(GVariant *data, const char *a[], unsigned int n);
1875SR_PRIV int std_u64_idx(GVariant *data, const uint64_t a[], unsigned int n);
1876SR_PRIV int std_u8_idx(GVariant *data, const uint8_t a[], unsigned int n);
1877
1878SR_PRIV int std_str_idx_s(const char *s, const char *a[], unsigned int n);
1879SR_PRIV int std_u8_idx_s(uint8_t b, const uint8_t a[], unsigned int n);
1880
1881SR_PRIV int std_u64_tuple_idx(GVariant *data, const uint64_t a[][2], unsigned int n);
1882SR_PRIV int std_double_tuple_idx(GVariant *data, const double a[][2], unsigned int n);
1883SR_PRIV int std_double_tuple_idx_d0(const double d, const double a[][2], unsigned int n);
1884
fcd6a8bd
UH
1885SR_PRIV int std_cg_idx(const struct sr_channel_group *cg, struct sr_channel_group *a[], unsigned int n);
1886
c0aa074e
UH
1887SR_PRIV int std_dummy_set_params(struct sr_serial_dev_inst *serial,
1888 int baudrate, int bits, int parity, int stopbits,
1889 int flowcontrol, int rts, int dtr);
3ad30b4e
GS
1890SR_PRIV int std_dummy_set_handshake(struct sr_serial_dev_inst *serial,
1891 int rts, int dtr);
c0aa074e 1892
bee24666
DE
1893/*--- resource.c ------------------------------------------------------------*/
1894
7d89fd60
DE
1895SR_PRIV int64_t sr_file_get_size(FILE *file);
1896
bee24666
DE
1897SR_PRIV int sr_resource_open(struct sr_context *ctx,
1898 struct sr_resource *res, int type, const char *name)
1899 G_GNUC_WARN_UNUSED_RESULT;
1900SR_PRIV int sr_resource_close(struct sr_context *ctx,
1901 struct sr_resource *res);
32ba0d80 1902SR_PRIV gssize sr_resource_read(struct sr_context *ctx,
bee24666
DE
1903 const struct sr_resource *res, void *buf, size_t count)
1904 G_GNUC_WARN_UNUSED_RESULT;
1905SR_PRIV void *sr_resource_load(struct sr_context *ctx, int type,
1906 const char *name, size_t *size, size_t max_size)
1907 G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
1908
8d558c7a
UH
1909/*--- strutil.c -------------------------------------------------------------*/
1910
1911SR_PRIV int sr_atol(const char *str, long *ret);
97aa41e9 1912SR_PRIV int sr_atol_base(const char *str, long *ret, char **end, int base);
30903c40 1913SR_PRIV int sr_atoul_base(const char *str, unsigned long *ret, char **end, int base);
8d558c7a
UH
1914SR_PRIV int sr_atoi(const char *str, int *ret);
1915SR_PRIV int sr_atod(const char *str, double *ret);
1916SR_PRIV int sr_atof(const char *str, float *ret);
4f0463a0 1917SR_PRIV int sr_atod_ascii(const char *str, double *ret);
91ab2f64 1918SR_PRIV int sr_atod_ascii_digits(const char *str, double *ret, int *digits);
9806c2d5 1919SR_PRIV int sr_atof_ascii(const char *str, float *ret);
8d558c7a 1920
d8bc7ca3
GS
1921SR_PRIV GString *sr_hexdump_new(const uint8_t *data, const size_t len);
1922SR_PRIV void sr_hexdump_free(GString *s);
1923
ac136b57
BV
1924/*--- soft-trigger.c --------------------------------------------------------*/
1925
1926struct soft_trigger_logic {
1927 const struct sr_dev_inst *sdi;
1928 const struct sr_trigger *trigger;
1929 int count;
1930 int unitsize;
1931 int cur_stage;
1932 uint8_t *prev_sample;
fe5a7355
AJ
1933 uint8_t *pre_trigger_buffer;
1934 uint8_t *pre_trigger_head;
1935 int pre_trigger_size;
1936 int pre_trigger_fill;
ac136b57
BV
1937};
1938
d1078180 1939SR_PRIV int logic_channel_unitsize(GSList *channels);
ac136b57 1940SR_PRIV struct soft_trigger_logic *soft_trigger_logic_new(
fe5a7355
AJ
1941 const struct sr_dev_inst *sdi, struct sr_trigger *trigger,
1942 int pre_trigger_samples);
ac136b57
BV
1943SR_PRIV void soft_trigger_logic_free(struct soft_trigger_logic *st);
1944SR_PRIV int soft_trigger_logic_check(struct soft_trigger_logic *st, uint8_t *buf,
fe5a7355 1945 int len, int *pre_trigger_samples);
ac136b57 1946
fcfa36fd 1947/*--- serial.c --------------------------------------------------------------*/
058b7035 1948
1df81f4b 1949#ifdef HAVE_SERIAL_COMM
a54dd31e
UH
1950enum {
1951 SERIAL_RDWR = 1,
1952 SERIAL_RDONLY = 2,
a54dd31e
UH
1953};
1954
144f6660 1955typedef gboolean (*packet_valid_callback)(const uint8_t *buf);
1a7adeac
GS
1956typedef int (*packet_valid_len_callback)(void *st,
1957 const uint8_t *p, size_t l, size_t *pl);
766456be 1958
ae4c1fb6
GS
1959typedef GSList *(*sr_ser_list_append_t)(GSList *devs, const char *name,
1960 const char *desc);
1961typedef GSList *(*sr_ser_find_append_t)(GSList *devs, const char *name);
1962
299bdb24
BV
1963SR_PRIV int serial_open(struct sr_serial_dev_inst *serial, int flags);
1964SR_PRIV int serial_close(struct sr_serial_dev_inst *serial);
1965SR_PRIV int serial_flush(struct sr_serial_dev_inst *serial);
bce75f94 1966SR_PRIV int serial_drain(struct sr_serial_dev_inst *serial);
8c3df6e5 1967SR_PRIV size_t serial_has_receive_data(struct sr_serial_dev_inst *serial);
9a474211 1968SR_PRIV int serial_write_blocking(struct sr_serial_dev_inst *serial,
eead2782 1969 const void *buf, size_t count, unsigned int timeout_ms);
9a474211
ML
1970SR_PRIV int serial_write_nonblocking(struct sr_serial_dev_inst *serial,
1971 const void *buf, size_t count);
9a474211 1972SR_PRIV int serial_read_blocking(struct sr_serial_dev_inst *serial, void *buf,
eead2782 1973 size_t count, unsigned int timeout_ms);
9a474211
ML
1974SR_PRIV int serial_read_nonblocking(struct sr_serial_dev_inst *serial, void *buf,
1975 size_t count);
d4787248
GS
1976SR_PRIV int serial_set_read_chunk_cb(struct sr_serial_dev_inst *serial,
1977 serial_rx_chunk_callback cb, void *cb_data);
299bdb24 1978SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate,
71caaad4 1979 int bits, int parity, int stopbits, int flowcontrol, int rts, int dtr);
3ad30b4e
GS
1980SR_PRIV int serial_set_handshake(struct sr_serial_dev_inst *serial,
1981 int rts, int dtr);
299bdb24
BV
1982SR_PRIV int serial_set_paramstr(struct sr_serial_dev_inst *serial,
1983 const char *paramstr);
1984SR_PRIV int serial_readline(struct sr_serial_dev_inst *serial, char **buf,
1985 int *buflen, gint64 timeout_ms);
766456be 1986SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial,
1a7adeac
GS
1987 uint8_t *buf, size_t *buflen,
1988 size_t packet_size, packet_valid_callback is_valid,
1989 packet_valid_len_callback is_valid_len, size_t *return_size,
1990 uint64_t timeout_ms);
102f1239
BV
1991SR_PRIV int serial_source_add(struct sr_session *session,
1992 struct sr_serial_dev_inst *serial, int events, int timeout,
1993 sr_receive_data_callback cb, void *cb_data);
1994SR_PRIV int serial_source_remove(struct sr_session *session,
1995 struct sr_serial_dev_inst *serial);
b541f837 1996SR_PRIV GSList *sr_serial_find_usb(uint16_t vendor_id, uint16_t product_id);
c5cfc735 1997SR_PRIV int serial_timeout(struct sr_serial_dev_inst *port, int num_bytes);
ae4c1fb6 1998
ad5aa993
GS
1999SR_PRIV void sr_ser_discard_queued_data(struct sr_serial_dev_inst *serial);
2000SR_PRIV size_t sr_ser_has_queued_data(struct sr_serial_dev_inst *serial);
2001SR_PRIV void sr_ser_queue_rx_data(struct sr_serial_dev_inst *serial,
2002 const uint8_t *data, size_t len);
2003SR_PRIV size_t sr_ser_unqueue_rx_data(struct sr_serial_dev_inst *serial,
2004 uint8_t *data, size_t len);
2005
a7b8692e
GS
2006struct ser_lib_functions {
2007 int (*open)(struct sr_serial_dev_inst *serial, int flags);
2008 int (*close)(struct sr_serial_dev_inst *serial);
2009 int (*flush)(struct sr_serial_dev_inst *serial);
2010 int (*drain)(struct sr_serial_dev_inst *serial);
2011 int (*write)(struct sr_serial_dev_inst *serial,
2012 const void *buf, size_t count,
2013 int nonblocking, unsigned int timeout_ms);
2014 int (*read)(struct sr_serial_dev_inst *serial,
2015 void *buf, size_t count,
2016 int nonblocking, unsigned int timeout_ms);
2017 int (*set_params)(struct sr_serial_dev_inst *serial,
2018 int baudrate, int bits, int parity, int stopbits,
2019 int flowcontrol, int rts, int dtr);
3ad30b4e
GS
2020 int (*set_handshake)(struct sr_serial_dev_inst *serial,
2021 int rts, int dtr);
a7b8692e
GS
2022 int (*setup_source_add)(struct sr_session *session,
2023 struct sr_serial_dev_inst *serial,
2024 int events, int timeout,
2025 sr_receive_data_callback cb, void *cb_data);
2026 int (*setup_source_remove)(struct sr_session *session,
2027 struct sr_serial_dev_inst *serial);
2028 GSList *(*list)(GSList *list, sr_ser_list_append_t append);
2029 GSList *(*find_usb)(GSList *list, sr_ser_find_append_t append,
2030 uint16_t vendor_id, uint16_t product_id);
2031 int (*get_frame_format)(struct sr_serial_dev_inst *serial,
2032 int *baud, int *bits);
2033 size_t (*get_rx_avail)(struct sr_serial_dev_inst *serial);
2034};
2035extern SR_PRIV struct ser_lib_functions *ser_lib_funcs_libsp;
4417074c
GS
2036SR_PRIV int ser_name_is_hid(struct sr_serial_dev_inst *serial);
2037extern SR_PRIV struct ser_lib_functions *ser_lib_funcs_hid;
b79c3422
GS
2038SR_PRIV int ser_name_is_bt(struct sr_serial_dev_inst *serial);
2039extern SR_PRIV struct ser_lib_functions *ser_lib_funcs_bt;
edec0436
GS
2040
2041#ifdef HAVE_LIBHIDAPI
2042struct vid_pid_item {
2043 uint16_t vid, pid;
2044};
edec0436
GS
2045
2046struct ser_hid_chip_functions {
2047 const char *chipname;
2048 const char *chipdesc;
2049 const struct vid_pid_item *vid_pid_items;
2050 const int max_bytes_per_request;
2051 int (*set_params)(struct sr_serial_dev_inst *serial,
2052 int baudrate, int bits, int parity, int stopbits,
2053 int flowcontrol, int rts, int dtr);
2054 int (*read_bytes)(struct sr_serial_dev_inst *serial,
2055 uint8_t *data, int space, unsigned int timeout);
2056 int (*write_bytes)(struct sr_serial_dev_inst *serial,
2057 const uint8_t *data, int space);
2058 int (*flush)(struct sr_serial_dev_inst *serial);
2059 int (*drain)(struct sr_serial_dev_inst *serial);
2060};
a10284cd 2061extern SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_bu86x;
828eeea2 2062extern SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_ch9325;
616bc3a1 2063extern SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_cp2110;
0cdb72c8 2064extern SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_victor;
edec0436
GS
2065SR_PRIV const char *ser_hid_chip_find_name_vid_pid(uint16_t vid, uint16_t pid);
2066#endif
c4f2dfd0 2067#endif
1483577e 2068
7fd8a8f7
GS
2069SR_PRIV int sr_serial_extract_options(GSList *options,
2070 const char **serial_device, const char **serial_options);
2071
7c8ae47d
GS
2072/*--- bt/ API ---------------------------------------------------------------*/
2073
2074#ifdef HAVE_BLUETOOTH
2075SR_PRIV const char *sr_bt_adapter_get_address(size_t idx);
2076
2077struct sr_bt_desc;
2078typedef void (*sr_bt_scan_cb)(void *cb_data, const char *addr, const char *name);
2079typedef int (*sr_bt_data_cb)(void *cb_data, uint8_t *data, size_t dlen);
2080
2081SR_PRIV struct sr_bt_desc *sr_bt_desc_new(void);
2082SR_PRIV void sr_bt_desc_free(struct sr_bt_desc *desc);
2083
2084SR_PRIV int sr_bt_config_cb_scan(struct sr_bt_desc *desc,
2085 sr_bt_scan_cb cb, void *cb_data);
2086SR_PRIV int sr_bt_config_cb_data(struct sr_bt_desc *desc,
2087 sr_bt_data_cb cb, void *cb_data);
2088SR_PRIV int sr_bt_config_addr_local(struct sr_bt_desc *desc, const char *addr);
2089SR_PRIV int sr_bt_config_addr_remote(struct sr_bt_desc *desc, const char *addr);
2090SR_PRIV int sr_bt_config_rfcomm(struct sr_bt_desc *desc, size_t channel);
2091SR_PRIV int sr_bt_config_notify(struct sr_bt_desc *desc,
2092 uint16_t read_handle, uint16_t write_handle,
2093 uint16_t cccd_handle, uint16_t cccd_value);
2094
2095SR_PRIV int sr_bt_scan_le(struct sr_bt_desc *desc, int duration);
2096SR_PRIV int sr_bt_scan_bt(struct sr_bt_desc *desc, int duration);
2097
2098SR_PRIV int sr_bt_connect_ble(struct sr_bt_desc *desc);
2099SR_PRIV int sr_bt_connect_rfcomm(struct sr_bt_desc *desc);
2100SR_PRIV void sr_bt_disconnect(struct sr_bt_desc *desc);
2101
2102SR_PRIV ssize_t sr_bt_read(struct sr_bt_desc *desc,
2103 void *data, size_t len);
2104SR_PRIV ssize_t sr_bt_write(struct sr_bt_desc *desc,
2105 const void *data, size_t len);
2106
2107SR_PRIV int sr_bt_start_notify(struct sr_bt_desc *desc);
2108SR_PRIV int sr_bt_check_notify(struct sr_bt_desc *desc);
2109#endif
2110
fcfa36fd 2111/*--- ezusb.c ---------------------------------------------------------------*/
058b7035 2112
22b02383 2113#ifdef HAVE_LIBUSB_1_0
1a081ca6 2114SR_PRIV int ezusb_reset(struct libusb_device_handle *hdl, int set_clear);
8e2d6c9d
DE
2115SR_PRIV int ezusb_install_firmware(struct sr_context *ctx, libusb_device_handle *hdl,
2116 const char *name);
2117SR_PRIV int ezusb_upload_firmware(struct sr_context *ctx, libusb_device *dev,
2118 int configuration, const char *name);
22b02383 2119#endif
058b7035 2120
fcfa36fd 2121/*--- usb.c -----------------------------------------------------------------*/
0c632d36
UH
2122
2123#ifdef HAVE_LIBUSB_1_0
7ae6a758 2124SR_PRIV GSList *sr_usb_find(libusb_context *usb_ctx, const char *conn);
0c632d36 2125SR_PRIV int sr_usb_open(libusb_context *usb_ctx, struct sr_usb_dev_inst *usb);
67e95ed3 2126SR_PRIV void sr_usb_close(struct sr_usb_dev_inst *usb);
102f1239
BV
2127SR_PRIV int usb_source_add(struct sr_session *session, struct sr_context *ctx,
2128 int timeout, sr_receive_data_callback cb, void *cb_data);
2129SR_PRIV int usb_source_remove(struct sr_session *session, struct sr_context *ctx);
76bc5f63 2130SR_PRIV int usb_get_port_path(libusb_device *dev, char *path, int path_len);
69f7d9b4
JH
2131SR_PRIV gboolean usb_match_manuf_prod(libusb_device *dev,
2132 const char *manufacturer, const char *product);
0c632d36
UH
2133#endif
2134
18698b40
AS
2135/*--- binary_helpers.c ------------------------------------------------------*/
2136
2137/** Binary value type */
2138enum binary_value_type {
d65f51bf
GS
2139 BVT_INVALID,
2140
2141 BVT_UINT8,
18698b40
AS
2142 BVT_BE_UINT8 = BVT_UINT8,
2143 BVT_LE_UINT8 = BVT_UINT8,
2144
2145 BVT_BE_UINT16,
2146 BVT_BE_UINT32,
2147 BVT_BE_UINT64,
2148 BVT_BE_FLOAT,
2149
2150 BVT_LE_UINT16,
2151 BVT_LE_UINT32,
2152 BVT_LE_UINT64,
2153 BVT_LE_FLOAT,
2154};
2155
2156/** Binary value specification */
2157struct binary_value_spec {
2158 /** Offset into binary blob */
2159 size_t offset;
2160 /** Data type to decode */
2161 enum binary_value_type type;
2162 /** Scale factor to get native units */
2163 float scale;
2164};
2165
2166/** Binary channel definition */
2167struct binary_analog_channel {
2168 /** Channel name */
2169 const char *name;
2170 /** Binary value in data stream */
2171 struct binary_value_spec spec;
2172 /** Significant digits */
2173 int digits;
2174 /** Measured quantity */
2175 enum sr_mq mq;
2176 /** Measured unit */
2177 enum sr_unit unit;
2178};
2179
2180/**
2181 * Read extract a value from a binary blob.
2182 *
2183 * @param out Pointer to output buffer.
2184 * @param spec Binary value specification
2185 * @param data Pointer to binary blob
2186 * @param length Size of binary blob
2187 * @return SR_OK on success, SR_ERR_* error code on failure.
2188 */
2189SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec, const void *data, size_t length);
2190
2191/**
2192 * Send an analog channel packet based on a binary analog channel
2193 * specification.
2194 *
2195 * @param sdi Device instance
2196 * @param ch Sigrok channel
2197 * @param spec Channel specification
2198 * @param data Pointer to binary blob
2199 * @param length Size of binary blob
2200 * @return SR_OK on success, SR_ERR_* error code on failure.
2201 */
2202SR_PRIV int bv_send_analog_channel(const struct sr_dev_inst *sdi, struct sr_channel *ch,
2203 const struct binary_analog_channel *spec, const void *data, size_t length);
7b9d7320 2204
4ea012bd
AS
2205/*--- crc.c -----------------------------------------------------------------*/
2206
2207#define SR_CRC16_DEFAULT_INIT 0xffffU
2208
2209/**
2210 * Calculate a CRC16 checksum using the 0x8005 polynomial.
2211 *
2212 * This CRC16 flavor is also known as CRC16-ANSI or CRC16-MODBUS.
2213 *
2214 * @param crc Initial value (typically 0xffff)
2215 * @param buffer Input buffer
2216 * @param len Buffer length
2217 * @return Checksum
2218 */
2219SR_PRIV uint16_t sr_crc16(uint16_t crc, const uint8_t *buffer, int len);
2220
daa39012
AJ
2221/*--- modbus/modbus.c -------------------------------------------------------*/
2222
2223struct sr_modbus_dev_inst {
2224 const char *name;
2225 const char *prefix;
2226 int priv_size;
2227 GSList *(*scan)(int modbusaddr);
2228 int (*dev_inst_new)(void *priv, const char *resource,
2229 char **params, const char *serialcomm, int modbusaddr);
2230 int (*open)(void *priv);
2231 int (*source_add)(struct sr_session *session, void *priv, int events,
2232 int timeout, sr_receive_data_callback cb, void *cb_data);
2233 int (*source_remove)(struct sr_session *session, void *priv);
2234 int (*send)(void *priv, const uint8_t *buffer, int buffer_size);
2235 int (*read_begin)(void *priv, uint8_t *function_code);
2236 int (*read_data)(void *priv, uint8_t *buf, int maxlen);
2237 int (*read_end)(void *priv);
2238 int (*close)(void *priv);
2239 void (*free)(void *priv);
2240 unsigned int read_timeout_ms;
2241 void *priv;
2242};
2243
2244SR_PRIV GSList *sr_modbus_scan(struct drv_context *drvc, GSList *options,
2245 struct sr_dev_inst *(*probe_device)(struct sr_modbus_dev_inst *modbus));
2246SR_PRIV struct sr_modbus_dev_inst *modbus_dev_inst_new(const char *resource,
2247 const char *serialcomm, int modbusaddr);
2248SR_PRIV int sr_modbus_open(struct sr_modbus_dev_inst *modbus);
2249SR_PRIV int sr_modbus_source_add(struct sr_session *session,
2250 struct sr_modbus_dev_inst *modbus, int events, int timeout,
2251 sr_receive_data_callback cb, void *cb_data);
2252SR_PRIV int sr_modbus_source_remove(struct sr_session *session,
2253 struct sr_modbus_dev_inst *modbus);
2254SR_PRIV int sr_modbus_request(struct sr_modbus_dev_inst *modbus,
2255 uint8_t *request, int request_size);
2256SR_PRIV int sr_modbus_reply(struct sr_modbus_dev_inst *modbus,
2257 uint8_t *reply, int reply_size);
2258SR_PRIV int sr_modbus_request_reply(struct sr_modbus_dev_inst *modbus,
2259 uint8_t *request, int request_size,
2260 uint8_t *reply, int reply_size);
2261SR_PRIV int sr_modbus_read_coils(struct sr_modbus_dev_inst *modbus,
2262 int address, int nb_coils, uint8_t *coils);
2263SR_PRIV int sr_modbus_read_holding_registers(struct sr_modbus_dev_inst *modbus,
2264 int address, int nb_registers,
2265 uint16_t *registers);
2266SR_PRIV int sr_modbus_write_coil(struct sr_modbus_dev_inst *modbus,
2267 int address, int value);
2268SR_PRIV int sr_modbus_write_multiple_registers(struct sr_modbus_dev_inst*modbus,
2269 int address, int nb_registers,
2270 uint16_t *registers);
2271SR_PRIV int sr_modbus_close(struct sr_modbus_dev_inst *modbus);
2272SR_PRIV void sr_modbus_free(struct sr_modbus_dev_inst *modbus);
2273
fcfa36fd 2274/*--- dmm/es519xx.c ---------------------------------------------------------*/
c01bdebc 2275
bfb926c1
AJ
2276/**
2277 * All 11-byte es519xx chips repeat each block twice for each conversion cycle
2278 * so always read 2 blocks at a time.
2279 */
2280#define ES519XX_11B_PACKET_SIZE (11 * 2)
72e1672f 2281#define ES519XX_14B_PACKET_SIZE 14
c01bdebc
AJ
2282
2283struct es519xx_info {
2284 gboolean is_judge, is_voltage, is_auto, is_micro, is_current;
2285 gboolean is_milli, is_resistance, is_continuity, is_diode;
2286 gboolean is_frequency, is_rpm, is_capacitance, is_duty_cycle;
2287 gboolean is_temperature, is_celsius, is_fahrenheit;
2288 gboolean is_adp0, is_adp1, is_adp2, is_adp3;
2289 gboolean is_sign, is_batt, is_ol, is_pmax, is_pmin, is_apo;
2290 gboolean is_dc, is_ac, is_vahz, is_min, is_max, is_rel, is_hold;
2291 gboolean is_digit4, is_ul, is_vasel, is_vbar, is_lpf1, is_lpf0, is_rmr;
2292 uint32_t baudrate;
2293 int packet_size;
2294 gboolean alt_functions, fivedigits, clampmeter, selectable_lpf;
8cbf5627 2295 int digits;
c01bdebc
AJ
2296};
2297
72e1672f
UH
2298SR_PRIV gboolean sr_es519xx_2400_11b_packet_valid(const uint8_t *buf);
2299SR_PRIV int sr_es519xx_2400_11b_parse(const uint8_t *buf, float *floatval,
8c677240 2300 struct sr_datafeed_analog *analog, void *info);
2588e50c
AJ
2301SR_PRIV gboolean sr_es519xx_2400_11b_altfn_packet_valid(const uint8_t *buf);
2302SR_PRIV int sr_es519xx_2400_11b_altfn_parse(const uint8_t *buf,
8c677240 2303 float *floatval, struct sr_datafeed_analog *analog, void *info);
72e1672f 2304SR_PRIV gboolean sr_es519xx_19200_11b_5digits_packet_valid(const uint8_t *buf);
93d719cd 2305SR_PRIV int sr_es519xx_19200_11b_5digits_parse(const uint8_t *buf,
8c677240 2306 float *floatval, struct sr_datafeed_analog *analog, void *info);
72e1672f
UH
2307SR_PRIV gboolean sr_es519xx_19200_11b_clamp_packet_valid(const uint8_t *buf);
2308SR_PRIV int sr_es519xx_19200_11b_clamp_parse(const uint8_t *buf,
8c677240 2309 float *floatval, struct sr_datafeed_analog *analog, void *info);
72e1672f
UH
2310SR_PRIV gboolean sr_es519xx_19200_11b_packet_valid(const uint8_t *buf);
2311SR_PRIV int sr_es519xx_19200_11b_parse(const uint8_t *buf, float *floatval,
8c677240 2312 struct sr_datafeed_analog *analog, void *info);
72e1672f
UH
2313SR_PRIV gboolean sr_es519xx_19200_14b_packet_valid(const uint8_t *buf);
2314SR_PRIV int sr_es519xx_19200_14b_parse(const uint8_t *buf, float *floatval,
8c677240 2315 struct sr_datafeed_analog *analog, void *info);
72e1672f
UH
2316SR_PRIV gboolean sr_es519xx_19200_14b_sel_lpf_packet_valid(const uint8_t *buf);
2317SR_PRIV int sr_es519xx_19200_14b_sel_lpf_parse(const uint8_t *buf,
8c677240 2318 float *floatval, struct sr_datafeed_analog *analog, void *info);
c01bdebc 2319
fcfa36fd 2320/*--- dmm/fs9922.c ----------------------------------------------------------*/
79081ec8 2321
913abe83
UH
2322#define FS9922_PACKET_SIZE 14
2323
2324struct fs9922_info {
2325 gboolean is_auto, is_dc, is_ac, is_rel, is_hold, is_bpn, is_z1, is_z2;
2326 gboolean is_max, is_min, is_apo, is_bat, is_nano, is_z3, is_micro;
2327 gboolean is_milli, is_kilo, is_mega, is_beep, is_diode, is_percent;
2328 gboolean is_z4, is_volt, is_ampere, is_ohm, is_hfe, is_hertz, is_farad;
2329 gboolean is_celsius, is_fahrenheit;
2330 int bargraph_sign, bargraph_value;
2331};
2332
913abe83
UH
2333SR_PRIV gboolean sr_fs9922_packet_valid(const uint8_t *buf);
2334SR_PRIV int sr_fs9922_parse(const uint8_t *buf, float *floatval,
8c677240
UH
2335 struct sr_datafeed_analog *analog, void *info);
2336SR_PRIV void sr_fs9922_z1_diode(struct sr_datafeed_analog *analog, void *info);
79081ec8 2337
fcfa36fd 2338/*--- dmm/fs9721.c ----------------------------------------------------------*/
6c701476 2339
8c1adf37
UH
2340#define FS9721_PACKET_SIZE 14
2341
2342struct fs9721_info {
2343 gboolean is_ac, is_dc, is_auto, is_rs232, is_micro, is_nano, is_kilo;
2344 gboolean is_diode, is_milli, is_percent, is_mega, is_beep, is_farad;
2345 gboolean is_ohm, is_rel, is_hold, is_ampere, is_volt, is_hz, is_bat;
2346 gboolean is_c2c1_11, is_c2c1_10, is_c2c1_01, is_c2c1_00, is_sign;
2347};
2348
8c1adf37
UH
2349SR_PRIV gboolean sr_fs9721_packet_valid(const uint8_t *buf);
2350SR_PRIV int sr_fs9721_parse(const uint8_t *buf, float *floatval,
8c677240
UH
2351 struct sr_datafeed_analog *analog, void *info);
2352SR_PRIV void sr_fs9721_00_temp_c(struct sr_datafeed_analog *analog, void *info);
2353SR_PRIV void sr_fs9721_01_temp_c(struct sr_datafeed_analog *analog, void *info);
2354SR_PRIV void sr_fs9721_10_temp_c(struct sr_datafeed_analog *analog, void *info);
2355SR_PRIV void sr_fs9721_01_10_temp_f_c(struct sr_datafeed_analog *analog, void *info);
2356SR_PRIV void sr_fs9721_max_c_min(struct sr_datafeed_analog *analog, void *info);
dcd212f7 2357
4c29bba1
PS
2358/*--- dmm/mm38xr.c ---------------------------------------------------------*/
2359
2360#define METERMAN_38XR_PACKET_SIZE 15
2361
2362struct meterman_38xr_info { int dummy; };
2363
2364SR_PRIV gboolean meterman_38xr_packet_valid(const uint8_t *buf);
2365SR_PRIV int meterman_38xr_parse(const uint8_t *buf, float *floatval,
2366 struct sr_datafeed_analog *analog, void *info);
2367
dcd212f7
VV
2368/*--- dmm/ms2115b.c ---------------------------------------------------------*/
2369
2370#define MS2115B_PACKET_SIZE 9
2371
2372enum ms2115b_display {
2373 MS2115B_DISPLAY_MAIN,
2374 MS2115B_DISPLAY_SUB,
2375 MS2115B_DISPLAY_COUNT,
2376};
2377
2378struct ms2115b_info {
2379 /* Selected channel. */
2380 size_t ch_idx;
2381 gboolean is_ac, is_dc, is_auto;
2382 gboolean is_diode, is_beep, is_farad;
2383 gboolean is_ohm, is_ampere, is_volt, is_hz;
2384 gboolean is_duty_cycle, is_percent;
2385};
2386
2387extern SR_PRIV const char *ms2115b_channel_formats[];
2388SR_PRIV gboolean sr_ms2115b_packet_valid(const uint8_t *buf);
2389SR_PRIV int sr_ms2115b_parse(const uint8_t *buf, float *floatval,
2390 struct sr_datafeed_analog *analog, void *info);
6c701476 2391
fcfa36fd 2392/*--- dmm/ms8250d.c ---------------------------------------------------------*/
67070942
M
2393
2394#define MS8250D_PACKET_SIZE 18
2395
2396struct ms8250d_info {
2397 gboolean is_ac, is_dc, is_auto, is_rs232, is_micro, is_nano, is_kilo;
2398 gboolean is_diode, is_milli, is_percent, is_mega, is_beep, is_farad;
2399 gboolean is_ohm, is_rel, is_hold, is_ampere, is_volt, is_hz, is_bat;
2400 gboolean is_ncv, is_min, is_max, is_sign, is_autotimer;
2401};
2402
2403SR_PRIV gboolean sr_ms8250d_packet_valid(const uint8_t *buf);
2404SR_PRIV int sr_ms8250d_parse(const uint8_t *buf, float *floatval,
2405 struct sr_datafeed_analog *analog, void *info);
2406
fcfa36fd 2407/*--- dmm/dtm0660.c ---------------------------------------------------------*/
eed3dec8
MG
2408
2409#define DTM0660_PACKET_SIZE 15
2410
2411struct dtm0660_info {
2412 gboolean is_ac, is_dc, is_auto, is_rs232, is_micro, is_nano, is_kilo;
2413 gboolean is_diode, is_milli, is_percent, is_mega, is_beep, is_farad;
2414 gboolean is_ohm, is_rel, is_hold, is_ampere, is_volt, is_hz, is_bat;
2415 gboolean is_degf, is_degc, is_c2c1_01, is_c2c1_00, is_apo, is_min;
2416 gboolean is_minmax, is_max, is_sign;
2417};
2418
2419SR_PRIV gboolean sr_dtm0660_packet_valid(const uint8_t *buf);
2420SR_PRIV int sr_dtm0660_parse(const uint8_t *buf, float *floatval,
8c677240 2421 struct sr_datafeed_analog *analog, void *info);
eed3dec8 2422
fcfa36fd 2423/*--- dmm/m2110.c -----------------------------------------------------------*/
825da8b2
MH
2424
2425#define BBCGM_M2110_PACKET_SIZE 9
2426
9d12555f
UH
2427/* Dummy info struct. The parser does not use it. */
2428struct m2110_info { int dummy; };
2429
825da8b2
MH
2430SR_PRIV gboolean sr_m2110_packet_valid(const uint8_t *buf);
2431SR_PRIV int sr_m2110_parse(const uint8_t *buf, float *floatval,
8c677240 2432 struct sr_datafeed_analog *analog, void *info);
825da8b2 2433
fcfa36fd 2434/*--- dmm/metex14.c ---------------------------------------------------------*/
ac913e5c
UH
2435
2436#define METEX14_PACKET_SIZE 14
2437
2438struct metex14_info {
556a926d 2439 size_t ch_idx;
ac913e5c
UH
2440 gboolean is_ac, is_dc, is_resistance, is_capacity, is_temperature;
2441 gboolean is_diode, is_frequency, is_ampere, is_volt, is_farad;
7fb4ff02
FS
2442 gboolean is_hertz, is_ohm, is_celsius, is_fahrenheit, is_watt;
2443 gboolean is_pico, is_nano, is_micro, is_milli, is_kilo, is_mega;
fd8dc1db 2444 gboolean is_gain, is_decibel, is_power, is_decibel_mw, is_power_factor;
7fb4ff02 2445 gboolean is_hfe, is_unitless, is_logic, is_min, is_max, is_avg;
ac913e5c
UH
2446};
2447
1df81f4b 2448#ifdef HAVE_SERIAL_COMM
ce3777ad 2449SR_PRIV int sr_metex14_packet_request(struct sr_serial_dev_inst *serial);
c4f2dfd0 2450#endif
ac913e5c
UH
2451SR_PRIV gboolean sr_metex14_packet_valid(const uint8_t *buf);
2452SR_PRIV int sr_metex14_parse(const uint8_t *buf, float *floatval,
8c677240 2453 struct sr_datafeed_analog *analog, void *info);
556a926d
GS
2454SR_PRIV gboolean sr_metex14_4packets_valid(const uint8_t *buf);
2455SR_PRIV int sr_metex14_4packets_parse(const uint8_t *buf, float *floatval,
2456 struct sr_datafeed_analog *analog, void *info);
ac913e5c 2457
fcfa36fd 2458/*--- dmm/rs9lcd.c ----------------------------------------------------------*/
05f134ab 2459
21829e67 2460#define RS9LCD_PACKET_SIZE 9
05f134ab 2461
e7ed87a4 2462/* Dummy info struct. The parser does not use it. */
bf6f8399 2463struct rs9lcd_info { int dummy; };
e7ed87a4 2464
05f134ab
AG
2465SR_PRIV gboolean sr_rs9lcd_packet_valid(const uint8_t *buf);
2466SR_PRIV int sr_rs9lcd_parse(const uint8_t *buf, float *floatval,
8c677240 2467 struct sr_datafeed_analog *analog, void *info);
05f134ab 2468
fcfa36fd 2469/*--- dmm/bm25x.c -----------------------------------------------------------*/
a24c3f4a
JH
2470
2471#define BRYMEN_BM25X_PACKET_SIZE 15
2472
2473/* Dummy info struct. The parser does not use it. */
2474struct bm25x_info { int dummy; };
2475
2476SR_PRIV gboolean sr_brymen_bm25x_packet_valid(const uint8_t *buf);
2477SR_PRIV int sr_brymen_bm25x_parse(const uint8_t *buf, float *floatval,
8c677240 2478 struct sr_datafeed_analog *analog, void *info);
a24c3f4a 2479
400bc4ff
GS
2480/*--- dmm/bm52x.c -----------------------------------------------------------*/
2481
2482#define BRYMEN_BM52X_PACKET_SIZE 24
2483#define BRYMEN_BM52X_DISPLAY_COUNT 2
2484
2485struct brymen_bm52x_info { size_t ch_idx; };
2486
2487#ifdef HAVE_SERIAL_COMM
2488SR_PRIV int sr_brymen_bm52x_packet_request(struct sr_serial_dev_inst *serial);
6bee394d 2489SR_PRIV int sr_brymen_bm82x_packet_request(struct sr_serial_dev_inst *serial);
400bc4ff
GS
2490#endif
2491SR_PRIV gboolean sr_brymen_bm52x_packet_valid(const uint8_t *buf);
6bee394d
GS
2492SR_PRIV gboolean sr_brymen_bm82x_packet_valid(const uint8_t *buf);
2493/* BM520s and BM820s protocols are similar, the parse routine is shared. */
400bc4ff
GS
2494SR_PRIV int sr_brymen_bm52x_parse(const uint8_t *buf, float *floatval,
2495 struct sr_datafeed_analog *analog, void *info);
2496
0931639a
GS
2497struct brymen_bm52x_state;
2498
2499SR_PRIV void *brymen_bm52x_state_init(void);
2500SR_PRIV void brymen_bm52x_state_free(void *state);
2501SR_PRIV int brymen_bm52x_config_get(void *state, uint32_t key, GVariant **data,
2502 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2503SR_PRIV int brymen_bm52x_config_set(void *state, uint32_t key, GVariant *data,
2504 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2505SR_PRIV int brymen_bm52x_config_list(void *state, uint32_t key, GVariant **data,
2506 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2507SR_PRIV int brymen_bm52x_acquire_start(void *state,
2508 const struct sr_dev_inst *sdi,
2509 sr_receive_data_callback *cb, void **cb_data);
2510
27186eda
GS
2511/*--- dmm/bm85x.c -----------------------------------------------------------*/
2512
2513#define BRYMEN_BM85x_PACKET_SIZE_MIN 4
2514
2515struct brymen_bm85x_info { int dummy; };
2516
2517#ifdef HAVE_SERIAL_COMM
2518SR_PRIV int brymen_bm85x_after_open(struct sr_serial_dev_inst *serial);
2519SR_PRIV int brymen_bm85x_packet_request(struct sr_serial_dev_inst *serial);
2520#endif
2521SR_PRIV gboolean brymen_bm85x_packet_valid(void *state,
2522 const uint8_t *buf, size_t len, size_t *pkt_len);
2523SR_PRIV int brymen_bm85x_parse(void *state, const uint8_t *buf, size_t len,
2524 double *floatval, struct sr_datafeed_analog *analog, void *info);
2525
0759e2f5
GS
2526/*--- dmm/bm86x.c -----------------------------------------------------------*/
2527
2528#define BRYMEN_BM86X_PACKET_SIZE 24
2529#define BRYMEN_BM86X_DISPLAY_COUNT 2
2530
2531struct brymen_bm86x_info { size_t ch_idx; };
2532
2533#ifdef HAVE_SERIAL_COMM
2534SR_PRIV int sr_brymen_bm86x_packet_request(struct sr_serial_dev_inst *serial);
2535#endif
2536SR_PRIV gboolean sr_brymen_bm86x_packet_valid(const uint8_t *buf);
2537SR_PRIV int sr_brymen_bm86x_parse(const uint8_t *buf, float *floatval,
2538 struct sr_datafeed_analog *analog, void *info);
2539
fcfa36fd 2540/*--- dmm/ut71x.c -----------------------------------------------------------*/
626027df
UH
2541
2542#define UT71X_PACKET_SIZE 11
2543
2544struct ut71x_info {
2545 gboolean is_voltage, is_resistance, is_capacitance, is_temperature;
2546 gboolean is_celsius, is_fahrenheit, is_current, is_continuity;
2547 gboolean is_diode, is_frequency, is_duty_cycle, is_dc, is_ac;
2548 gboolean is_auto, is_manual, is_sign, is_power, is_loop_current;
2549};
2550
2551SR_PRIV gboolean sr_ut71x_packet_valid(const uint8_t *buf);
2552SR_PRIV int sr_ut71x_parse(const uint8_t *buf, float *floatval,
8c677240 2553 struct sr_datafeed_analog *analog, void *info);
626027df 2554
fcfa36fd 2555/*--- dmm/vc870.c -----------------------------------------------------------*/
c36f78f7
UH
2556
2557#define VC870_PACKET_SIZE 23
2558
2559struct vc870_info {
2560 gboolean is_voltage, is_dc, is_ac, is_temperature, is_resistance;
2561 gboolean is_continuity, is_capacitance, is_diode, is_loop_current;
2562 gboolean is_current, is_micro, is_milli, is_power;
ee2e9be2 2563 gboolean is_power_factor_freq, is_power_apparent_power, is_v_a_rms_value;
c36f78f7
UH
2564 gboolean is_sign2, is_sign1, is_batt, is_ol1, is_max, is_min;
2565 gboolean is_maxmin, is_rel, is_ol2, is_open, is_manu, is_hold;
2566 gboolean is_light, is_usb, is_warning, is_auto_power, is_misplug_warn;
2567 gboolean is_lo, is_hi, is_open2;
2568
3591481e 2569 gboolean is_frequency, is_dual_display, is_auto;
c36f78f7
UH
2570};
2571
2572SR_PRIV gboolean sr_vc870_packet_valid(const uint8_t *buf);
2573SR_PRIV int sr_vc870_parse(const uint8_t *buf, float *floatval,
8c677240 2574 struct sr_datafeed_analog *analog, void *info);
c36f78f7 2575
fcfa36fd 2576/*--- dmm/vc96.c ------------------------------------------------------------*/
9456d636
MS
2577
2578#define VC96_PACKET_SIZE 13
2579
2580struct vc96_info {
2581 size_t ch_idx;
2582 gboolean is_ac, is_dc, is_resistance, is_diode, is_ampere, is_volt;
2583 gboolean is_ohm, is_micro, is_milli, is_kilo, is_mega, is_hfe;
2584 gboolean is_unitless;
2585};
2586
2587SR_PRIV gboolean sr_vc96_packet_valid(const uint8_t *buf);
2588SR_PRIV int sr_vc96_parse(const uint8_t *buf, float *floatval,
2589 struct sr_datafeed_analog *analog, void *info);
2590
fcfa36fd 2591/*--- lcr/es51919.c ---------------------------------------------------------*/
6bcb3ee8 2592
bf5c4d46
GS
2593/* Acquisition details which apply to all supported serial-lcr devices. */
2594struct lcr_parse_info {
2595 size_t ch_idx;
2596 uint64_t output_freq;
2597 const char *circuit_model;
2598};
2599
2600#define ES51919_PACKET_SIZE 17
2601#define ES51919_CHANNEL_COUNT 2
2602#define ES51919_COMM_PARAM "9600/8n1/rts=1/dtr=1"
2603
2604SR_PRIV int es51919_config_get(uint32_t key, GVariant **data,
2605 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2606SR_PRIV int es51919_config_set(uint32_t key, GVariant *data,
2607 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2608SR_PRIV int es51919_config_list(uint32_t key, GVariant **data,
2609 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2610SR_PRIV gboolean es51919_packet_valid(const uint8_t *pkt);
2611SR_PRIV int es51919_packet_parse(const uint8_t *pkt, float *floatval,
b50970a5
GS
2612 struct sr_datafeed_analog *analog, void *info);
2613
2614/*--- lcr/vc4080.c ----------------------------------------------------------*/
2615
2616/* Note: Also uses 'struct lcr_parse_info' from es51919 above. */
2617
2618#define VC4080_PACKET_SIZE 39
2619#define VC4080_COMM_PARAM "1200/8n1"
2620#define VC4080_WITH_DQ_CHANS 0 /* Enable separate D/Q channels? */
2621
2622enum vc4080_display {
2623 VC4080_DISPLAY_PRIMARY,
2624 VC4080_DISPLAY_SECONDARY,
2625#if VC4080_WITH_DQ_CHANS
2626 VC4080_DISPLAY_D_VALUE,
2627 VC4080_DISPLAY_Q_VALUE,
2628#endif
2629 VC4080_CHANNEL_COUNT,
2630};
2631
2632extern SR_PRIV const char *vc4080_channel_formats[VC4080_CHANNEL_COUNT];
2633
2634SR_PRIV int vc4080_config_list(uint32_t key, GVariant **data,
2635 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2636SR_PRIV int vc4080_packet_request(struct sr_serial_dev_inst *serial);
2637SR_PRIV gboolean vc4080_packet_valid(const uint8_t *pkt);
2638SR_PRIV int vc4080_packet_parse(const uint8_t *pkt, float *floatval,
bf5c4d46 2639 struct sr_datafeed_analog *analog, void *info);
6bcb3ee8 2640
fcfa36fd 2641/*--- dmm/ut372.c -----------------------------------------------------------*/
f3cde309
ML
2642
2643#define UT372_PACKET_SIZE 27
2644
2645struct ut372_info {
2646 int dummy;
2647};
2648
2649SR_PRIV gboolean sr_ut372_packet_valid(const uint8_t *buf);
2650SR_PRIV int sr_ut372_parse(const uint8_t *buf, float *floatval,
8c677240 2651 struct sr_datafeed_analog *analog, void *info);
f3cde309 2652
fcfa36fd 2653/*--- dmm/asycii.c ----------------------------------------------------------*/
4ba4d52a
GS
2654
2655#define ASYCII_PACKET_SIZE 16
2656
2657struct asycii_info {
2658 gboolean is_ac, is_dc, is_ac_and_dc;
2659 gboolean is_resistance, is_capacitance, is_diode, is_gain;
2660 gboolean is_frequency, is_duty_cycle, is_duty_pos, is_duty_neg;
2661 gboolean is_pulse_width, is_period_pos, is_period_neg;
2662 gboolean is_pulse_count, is_count_pos, is_count_neg;
2663 gboolean is_ampere, is_volt, is_volt_ampere, is_farad, is_ohm;
2664 gboolean is_hertz, is_percent, is_seconds, is_decibel;
2665 gboolean is_pico, is_nano, is_micro, is_milli, is_kilo, is_mega;
2666 gboolean is_unitless;
2667 gboolean is_peak_min, is_peak_max;
2668 gboolean is_invalid;
2669};
2670
1df81f4b 2671#ifdef HAVE_SERIAL_COMM
4ba4d52a
GS
2672SR_PRIV int sr_asycii_packet_request(struct sr_serial_dev_inst *serial);
2673#endif
2674SR_PRIV gboolean sr_asycii_packet_valid(const uint8_t *buf);
2675SR_PRIV int sr_asycii_parse(const uint8_t *buf, float *floatval,
2676 struct sr_datafeed_analog *analog, void *info);
2677
fcfa36fd 2678/*--- dmm/eev121gw.c --------------------------------------------------------*/
1c3098aa
GS
2679
2680#define EEV121GW_PACKET_SIZE 19
2681
2682enum eev121gw_display {
2683 EEV121GW_DISPLAY_MAIN,
2684 EEV121GW_DISPLAY_SUB,
2685 EEV121GW_DISPLAY_BAR,
2686 EEV121GW_DISPLAY_COUNT,
2687};
2688
2689struct eev121gw_info {
2690 /* Selected channel. */
2691 size_t ch_idx;
2692 /*
2693 * Measured value, number and sign/overflow flags, scale factor
2694 * and significant digits.
2695 */
2696 uint32_t uint_value;
2697 gboolean is_ofl, is_neg;
2698 int factor, digits;
2699 /* Currently active mode (meter's function). */
2700 gboolean is_ac, is_dc, is_voltage, is_current, is_power, is_gain;
2701 gboolean is_resistance, is_capacitance, is_diode, is_temperature;
2702 gboolean is_continuity, is_frequency, is_period, is_duty_cycle;
2703 /* Quantities associated with mode/function. */
2704 gboolean is_ampere, is_volt, is_volt_ampere, is_dbm;
2705 gboolean is_ohm, is_farad, is_celsius, is_fahrenheit;
2706 gboolean is_hertz, is_seconds, is_percent, is_loop_current;
2707 gboolean is_unitless, is_logic;
2708 /* Other indicators. */
2709 gboolean is_min, is_max, is_avg, is_1ms_peak, is_rel, is_hold;
2710 gboolean is_low_pass, is_mem, is_bt, is_auto_range, is_test;
2711 gboolean is_auto_poweroff, is_low_batt;
2712};
2713
015df4ae 2714extern SR_PRIV const char *eev121gw_channel_formats[];
1c3098aa 2715SR_PRIV gboolean sr_eev121gw_packet_valid(const uint8_t *buf);
1c3098aa 2716SR_PRIV int sr_eev121gw_3displays_parse(const uint8_t *buf, float *floatval,
8556703a 2717 struct sr_datafeed_analog *analog, void *info);
1c3098aa 2718
fcfa36fd 2719/*--- scale/kern.c ----------------------------------------------------------*/
e5d953b5
UH
2720
2721struct kern_info {
2722 gboolean is_gram, is_carat, is_ounce, is_pound, is_troy_ounce;
2723 gboolean is_pennyweight, is_grain, is_tael, is_momme, is_tola;
2724 gboolean is_percentage, is_piece, is_unstable, is_stable, is_error;
2725 int buflen;
2726};
2727
2728SR_PRIV gboolean sr_kern_packet_valid(const uint8_t *buf);
2729SR_PRIV int sr_kern_parse(const uint8_t *buf, float *floatval,
563ba4a5 2730 struct sr_datafeed_analog *analog, void *info);
e5d953b5 2731
aea4e458
LPC
2732/*--- sw_limits.c -----------------------------------------------------------*/
2733
2734struct sr_sw_limits {
2735 uint64_t limit_samples;
67785f25 2736 uint64_t limit_frames;
aea4e458
LPC
2737 uint64_t limit_msec;
2738 uint64_t samples_read;
67785f25 2739 uint64_t frames_read;
aea4e458
LPC
2740 uint64_t start_time;
2741};
2742
d579755a 2743SR_PRIV int sr_sw_limits_config_get(const struct sr_sw_limits *limits, uint32_t key,
aea4e458
LPC
2744 GVariant **data);
2745SR_PRIV int sr_sw_limits_config_set(struct sr_sw_limits *limits, uint32_t key,
2746 GVariant *data);
2747SR_PRIV void sr_sw_limits_acquisition_start(struct sr_sw_limits *limits);
2748SR_PRIV gboolean sr_sw_limits_check(struct sr_sw_limits *limits);
5aba93c3
GS
2749SR_PRIV int sr_sw_limits_get_remain(const struct sr_sw_limits *limits,
2750 uint64_t *samples, uint64_t *frames, uint64_t *msecs,
2751 gboolean *exceeded);
aea4e458
LPC
2752SR_PRIV void sr_sw_limits_update_samples_read(struct sr_sw_limits *limits,
2753 uint64_t samples_read);
67785f25
GS
2754SR_PRIV void sr_sw_limits_update_frames_read(struct sr_sw_limits *limits,
2755 uint64_t frames_read);
aea4e458
LPC
2756SR_PRIV void sr_sw_limits_init(struct sr_sw_limits *limits);
2757
47a102f9
GS
2758/*--- feed_queue.h ----------------------------------------------------------*/
2759
2760struct feed_queue_logic;
2761struct feed_queue_analog;
2762
2763SR_API struct feed_queue_logic *feed_queue_logic_alloc(
57140e5a 2764 const struct sr_dev_inst *sdi,
47a102f9
GS
2765 size_t sample_count, size_t unit_size);
2766SR_API int feed_queue_logic_submit(struct feed_queue_logic *q,
2767 const uint8_t *data, size_t count);
2768SR_API int feed_queue_logic_flush(struct feed_queue_logic *q);
f478c3e6 2769SR_API int feed_queue_logic_send_trigger(struct feed_queue_logic *q);
47a102f9
GS
2770SR_API void feed_queue_logic_free(struct feed_queue_logic *q);
2771
2772SR_API struct feed_queue_analog *feed_queue_analog_alloc(
57140e5a 2773 const struct sr_dev_inst *sdi,
47a102f9
GS
2774 size_t sample_count, int digits, struct sr_channel *ch);
2775SR_API int feed_queue_analog_submit(struct feed_queue_analog *q,
2776 float data, size_t count);
2777SR_API int feed_queue_analog_flush(struct feed_queue_analog *q);
2778SR_API void feed_queue_analog_free(struct feed_queue_analog *q);
2779
1483577e 2780#endif