2 * This file is part of the libsigrok project.
4 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
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.
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.
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/>.
20 #ifndef LIBSIGROK_SIGROK_INTERNAL_H
21 #define LIBSIGROK_SIGROK_INTERNAL_H
25 #include "config.h" /* Needed for HAVE_LIBUSB_1_0 and others. */
26 #ifdef HAVE_LIBUSB_1_0
33 * libsigrok private header file, only to be used internally.
36 /*--- Macros ----------------------------------------------------------------*/
39 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
42 #ifndef ARRAY_AND_SIZE
43 #define ARRAY_AND_SIZE(a) (a), ARRAY_SIZE(a)
47 #ifdef HAVE_LIBUSB_1_0
48 libusb_context *libusb_ctx;
52 #ifdef HAVE_LIBUSB_1_0
53 struct sr_usb_dev_inst {
56 struct libusb_device_handle *devhdl;
60 #define SERIAL_PARITY_NONE 0
61 #define SERIAL_PARITY_EVEN 1
62 #define SERIAL_PARITY_ODD 2
63 struct sr_serial_dev_inst {
69 /* Private driver context. */
71 struct sr_context *sr_ctx;
75 /*--- log.c -----------------------------------------------------------------*/
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, ...);
84 /*--- device.c --------------------------------------------------------------*/
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);
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);
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);
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);
109 /*--- hwdriver.c ------------------------------------------------------------*/
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);
118 /*--- session.c -------------------------------------------------------------*/
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);
124 /*--- std.c -----------------------------------------------------------------*/
126 typedef int (*dev_close_t)(struct sr_dev_inst *sdi);
127 typedef void (*std_dev_clear_t)(void *priv);
129 SR_PRIV int std_hw_init(struct sr_context *sr_ctx, struct sr_dev_driver *di,
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,
136 SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver,
137 std_dev_clear_t clear_private);
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);
147 /*--- hardware/common/serial.c ----------------------------------------------*/
155 typedef gboolean (*packet_valid_t)(const uint8_t *buf);
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,
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);
175 /*--- hardware/common/ezusb.c -----------------------------------------------*/
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);
185 /*--- hardware/common/usb.c -------------------------------------------------*/
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);