]> sigrok.org Git - libsigrok.git/blob - libsigrok-internal.h
Code drop from DreamSourceLabs first source release.
[libsigrok.git] / libsigrok-internal.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef LIBSIGROK_SIGROK_INTERNAL_H
21 #define LIBSIGROK_SIGROK_INTERNAL_H
22
23 #include <stdarg.h>
24 #include <glib.h>
25 #include "config.h" /* Needed for HAVE_LIBUSB_1_0 and others. */
26 #ifdef HAVE_LIBUSB_1_0
27 #include <libusb.h>
28 #endif
29
30 /**
31  * @file
32  *
33  * libsigrok private header file, only to be used internally.
34  */
35
36 /*--- Macros ----------------------------------------------------------------*/
37
38 #ifndef ARRAY_SIZE
39 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
40 #endif
41
42 #ifndef ARRAY_AND_SIZE
43 #define ARRAY_AND_SIZE(a) (a), ARRAY_SIZE(a)
44 #endif
45
46 struct sr_context {
47 #ifdef HAVE_LIBUSB_1_0
48         libusb_context *libusb_ctx;
49 #endif
50 };
51
52 #ifdef HAVE_LIBUSB_1_0
53 struct sr_usb_dev_inst {
54         uint8_t bus;
55         uint8_t address;
56         struct libusb_device_handle *devhdl;
57 };
58 #endif
59
60 #define SERIAL_PARITY_NONE 0
61 #define SERIAL_PARITY_EVEN 1
62 #define SERIAL_PARITY_ODD  2
63 struct sr_serial_dev_inst {
64         char *port;
65         char *serialcomm;
66         int fd;
67 };
68
69 /* Private driver context. */
70 struct drv_context {
71         struct sr_context *sr_ctx;
72         GSList *instances;
73 };
74
75 /*--- log.c -----------------------------------------------------------------*/
76
77 SR_PRIV int sr_log(int loglevel, const char *format, ...);
78 SR_PRIV int sr_spew(const char *format, ...);
79 SR_PRIV int sr_dbg(const char *format, ...);
80 SR_PRIV int sr_info(const char *format, ...);
81 SR_PRIV int sr_warn(const char *format, ...);
82 SR_PRIV int sr_err(const char *format, ...);
83
84 /*--- device.c --------------------------------------------------------------*/
85
86 SR_PRIV struct sr_probe *sr_probe_new(int index, int type,
87                                       gboolean enabled, const char *name);
88 SR_PRIV void sr_dev_probes_free(struct sr_dev_inst *sdi);
89
90 /* Generic device instances */
91 SR_PRIV struct sr_dev_inst *sr_dev_inst_new(int mode, int index, int status,
92                                             const char *vendor, const char *model, const char *version);
93 SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi);
94
95 #ifdef HAVE_LIBUSB_1_0
96 /* USB-specific instances */
97 SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus,
98                 uint8_t address, struct libusb_device_handle *hdl);
99 SR_PRIV GSList *sr_usb_find_usbtmc(libusb_context *usb_ctx);
100 SR_PRIV void sr_usb_dev_inst_free(struct sr_usb_dev_inst *usb);
101 #endif
102
103 /* Serial-specific instances */
104 SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(const char *port,
105                 const char *serialcomm);
106 SR_PRIV void sr_serial_dev_inst_free(struct sr_serial_dev_inst *serial);
107
108
109 /*--- hwdriver.c ------------------------------------------------------------*/
110
111 SR_PRIV void sr_hw_cleanup_all(void);
112 SR_PRIV struct sr_config *sr_config_new(int key, GVariant *data);
113 SR_PRIV void sr_config_free(struct sr_config *src);
114 SR_PRIV int sr_source_remove(int fd);
115 SR_PRIV int sr_source_add(int fd, int events, int timeout,
116         sr_receive_data_callback_t cb, void *cb_data);
117
118 /*--- session.c -------------------------------------------------------------*/
119
120 SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
121                 const struct sr_datafeed_packet *packet);
122 SR_PRIV int sr_session_stop_sync(void);
123
124 /*--- std.c -----------------------------------------------------------------*/
125
126 typedef int (*dev_close_t)(struct sr_dev_inst *sdi);
127 typedef void (*std_dev_clear_t)(void *priv);
128
129 SR_PRIV int std_hw_init(struct sr_context *sr_ctx, struct sr_dev_driver *di,
130                 const char *prefix);
131 SR_PRIV int std_hw_dev_acquisition_stop_serial(struct sr_dev_inst *sdi,
132                 void *cb_data, dev_close_t hw_dev_close_fn,
133                 struct sr_serial_dev_inst *serial, const char *prefix);
134 SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi,
135                 const char *prefix);
136 SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver,
137                 std_dev_clear_t clear_private);
138
139 /*--- trigger.c -------------------------------------------------*/
140 SR_PRIV uint64_t sr_trigger_get_mask0(uint16_t stage);
141 SR_PRIV uint64_t sr_trigger_get_mask1(uint16_t stage);
142 SR_PRIV uint64_t sr_trigger_get_value0(uint16_t stage);
143 SR_PRIV uint64_t sr_trigger_get_value1(uint16_t stage);
144 SR_PRIV uint64_t sr_trigger_get_edge0(uint16_t stage);
145 SR_PRIV uint64_t sr_trigger_get_edge1(uint16_t stage);
146
147 /*--- hardware/common/serial.c ----------------------------------------------*/
148
149 enum {
150         SERIAL_RDWR = 1,
151         SERIAL_RDONLY = 2,
152         SERIAL_NONBLOCK = 4,
153 };
154
155 typedef gboolean (*packet_valid_t)(const uint8_t *buf);
156
157 SR_PRIV int serial_open(struct sr_serial_dev_inst *serial, int flags);
158 SR_PRIV int serial_close(struct sr_serial_dev_inst *serial);
159 SR_PRIV int serial_flush(struct sr_serial_dev_inst *serial);
160 SR_PRIV int serial_write(struct sr_serial_dev_inst *serial,
161                 const void *buf, size_t count);
162 SR_PRIV int serial_read(struct sr_serial_dev_inst *serial, void *buf,
163                 size_t count);
164 SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate,
165                 int bits, int parity, int stopbits, int flowcontrol, int rts, int dtr);
166 SR_PRIV int serial_set_paramstr(struct sr_serial_dev_inst *serial,
167                 const char *paramstr);
168 SR_PRIV int serial_readline(struct sr_serial_dev_inst *serial, char **buf,
169                 int *buflen, gint64 timeout_ms);
170 SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial,
171                                  uint8_t *buf, size_t *buflen,
172                                  size_t packet_size, packet_valid_t is_valid,
173                                  uint64_t timeout_ms, int baudrate);
174
175 /*--- hardware/common/ezusb.c -----------------------------------------------*/
176
177 #ifdef HAVE_LIBUSB_1_0
178 SR_PRIV int ezusb_reset(struct libusb_device_handle *hdl, int set_clear);
179 SR_PRIV int ezusb_install_firmware(libusb_device_handle *hdl,
180                                    const char *filename);
181 SR_PRIV int ezusb_upload_firmware(libusb_device *dev, int configuration,
182                                   const char *filename);
183 #endif
184
185 /*--- hardware/common/usb.c -------------------------------------------------*/
186
187 #ifdef HAVE_LIBUSB_1_0
188 SR_PRIV GSList *sr_usb_find(libusb_context *usb_ctx, const char *conn);
189 SR_PRIV int sr_usb_open(libusb_context *usb_ctx, struct sr_usb_dev_inst *usb);
190 #endif
191
192
193
194 #endif