2 * This file is part of the sigrok project.
4 * Copyright (C) 2010 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 SIGROK_SIGROK_H
21 #define SIGROK_SIGROK_H
30 /* Returned status/error codes */
31 #define SIGROK_STATUS_DISABLED 0
34 #define SIGROK_ERR_BADVALUE 20
36 /* Handy little macros */
37 #define KHZ(n) (n * 1000)
38 #define MHZ(n) (n * 1000000)
39 #define GHZ(n) (n * 1000000000)
41 /* Data types, used by hardware plugins for set_configuration() */
51 /* (Unused) protocol decoder stack entry */
62 /* datafeed_packet.type values */
75 struct datafeed_packet {
81 struct datafeed_header {
83 struct timeval starttime;
93 struct output_format *format;
94 struct device *device;
99 struct output_format {
102 void (*init) (struct output *o);
103 int (*data) (struct output *o, char *data_in, uint64_t length_in,
104 char **data_out, uint64_t *length_out);
105 int (*event) (struct output *o, int event_type, char **data_out,
106 uint64_t *length_out);
109 struct output_format **output_list(void);
110 int filter_probes(int in_unitsize, int out_unitsize, int *probelist,
111 char *data_in, uint64_t length_in, char **data_out,
112 uint64_t *length_out);
114 /*--- analyzer.c ------------------------------------------------------------*/
120 * TODO: Parameters? If so, configured plugins need another struct.
121 * TODO: Input and output format?
125 /*--- backend.c -------------------------------------------------------------*/
127 int sigrok_init(void);
128 void sigrok_cleanup(void);
130 /*--- datastore.c -----------------------------------------------------------*/
132 /* Size of a chunk in units */
133 #define DATASTORE_CHUNKSIZE 512000
136 /* Size in bytes of the number of units stored in this datastore */
138 unsigned int num_units;
142 struct datastore *datastore_new(int unitsize);
143 void datastore_destroy(struct datastore *ds);
144 void datastore_put(struct datastore *ds, void *data, unsigned int length,
145 int in_unitsize, int *probelist);
147 /*--- debug.c ---------------------------------------------------------------*/
149 void hexdump(unsigned char *address, int length);
151 /*--- device.c --------------------------------------------------------------*/
154 * This represents a generic device connected to the system.
155 * For device-specific information, ask the plugin. The plugin_index refers
156 * to the device index within that plugin; it may be handling more than one
157 * device. All relevant plugin calls take a device_index parameter for this.
160 /* Which plugin handles this device */
161 struct device_plugin *plugin;
162 /* A plugin may handle multiple devices of the same type */
164 /* List of struct probe* */
166 /* Data acquired by this device, if any */
167 struct datastore *datastore;
177 extern GSList *devices;
179 void device_scan(void);
180 void device_close_all(void);
181 GSList *device_list(void);
182 struct device *device_new(struct device_plugin *plugin, int plugin_index);
183 void device_clear(struct device *device);
184 void device_destroy(struct device *dev);
186 void device_probe_clear(struct device *device, int probenum);
187 void device_probe_add(struct device *device, char *name);
188 struct probe *probe_find(struct device *device, int probenum);
189 void device_probe_name(struct device *device, int probenum, char *name);
191 void device_trigger_clear(struct device *device);
192 void device_trigger_set(struct device *device, int probenum, char *trigger);
194 /*--- hwplugin.c ------------------------------------------------------------*/
196 /* Hardware plugin capabilities */
198 HWCAP_DUMMY, // used to terminate lists
199 HWCAP_LOGIC_ANALYZER,
200 HWCAP_SAMPLERATE, // change samplerate
201 HWCAP_PROBECONFIG, // configure probe mask
202 HWCAP_CAPTURE_RATIO, // set pre-trigger / post-trigger ratio
203 HWCAP_LIMIT_MSEC, // set a time limit for sample acquisition
204 HWCAP_LIMIT_SAMPLES, // set a limit on number of samples
207 struct hwcap_option {
214 struct sigrok_device_instance {
222 struct usb_device_instance *usb;
223 struct serial_device_instance *serial;
227 /* sigrok_device_instance types */
233 struct usb_device_instance {
236 struct libusb_device_handle *devhdl;
239 struct serial_device_instance {
244 /* Device instance status */
247 /* Found, but still booting */
249 /* Live, but not in use */
251 /* Actively in use in a session */
256 * TODO: This sucks, you just kinda have to "know" the returned type.
257 * TODO: Need a DI to return the number of trigger stages supported.
260 /* Device info IDs */
262 /* struct sigrok_device_instance for this specific device */
264 /* The number of probes connected to this device */
266 /* Samplerates supported by this device, (struct samplerates) */
268 /* Types of trigger supported, out of "01crf" (char *) */
270 /* The currently set samplerate in Hz (uint64_t) */
274 /* a device supports either a range of samplerates with steps of a given
275 * granularity, or is limited to a set of defined samplerates. use either
276 * step or list, but not both.
285 struct device_plugin {
286 /* plugin-specific */
289 int (*init) (char *deviceinfo);
290 void (*cleanup) (void);
292 /* device-specific */
293 int (*open) (int device_index);
294 void (*close) (int device_index);
295 void *(*get_device_info) (int device_index, int device_info_id);
296 int (*get_status) (int device_index);
297 int *(*get_capabilities) (void);
298 int (*set_configuration) (int device_index, int capability, void *value);
299 int (*start_acquisition) (int device_index, gpointer session_device_id);
300 void (*stop_acquisition) (int device_index, gpointer session_device_id);
306 /* Not really using this */
307 GSource *timeout_source;
310 typedef int (*receive_data_callback) (int fd, int revents, void *user_data);
312 int load_hwplugins(void);
313 GSList *list_hwplugins(void);
315 /* Generic device instances */
316 struct sigrok_device_instance *sigrok_device_instance_new(int index,
317 int status, char *vendor, char *model, char *version);
318 struct sigrok_device_instance *get_sigrok_device_instance(GSList *device_instances, int device_index);
319 void sigrok_device_instance_free(struct sigrok_device_instance *sdi);
321 /* USB-specific instances */
322 struct usb_device_instance *usb_device_instance_new(uint8_t bus,
323 uint8_t address, struct libusb_device_handle *hdl);
324 void usb_device_instance_free(struct usb_device_instance *usb);
326 /* Serial-specific instances */
327 struct serial_device_instance *serial_device_instance_new(char *port, int fd);
328 void serial_device_instance_free(struct serial_device_instance *serial);
330 int find_hwcap(int *capabilities, int hwcap);
331 struct hwcap_option *find_hwcap_option(int hwcap);
332 void source_remove(int fd);
333 void source_add(int fd, int events, int timeout, receive_data_callback rcv_cb, void *user_data);
335 /*--- session.c -------------------------------------------------------------*/
337 typedef void (*source_callback_remove) (int fd);
338 typedef void (*source_callback_add) (int fd, int events, int timeout,
339 receive_data_callback callback, void *user_data);
340 typedef void (*datafeed_callback) (struct device *device,
341 struct datafeed_packet *packet);
344 /* List of struct device* */
346 /* List of struct analyzer* */
348 /* datafeed callbacks */
349 GSList *datafeed_callbacks;
354 struct session *session_load(char *filename);
355 struct session *session_new(void);
356 void session_destroy(void);
357 void session_device_clear(void);
358 int session_device_add(struct device *device);
360 /* Protocol analyzers setup */
361 void session_pa_clear(void);
362 void session_pa_add(struct analyzer *pa);
365 void session_datafeed_callback_clear(void);
366 void session_datafeed_callback_add(datafeed_callback callback);
368 /* Session control */
369 int session_start(void);
370 void session_stop(void);
371 void session_bus(struct device *device, struct datafeed_packet *packet);
372 void make_metadata(char *filename);
373 int session_save(char *filename);
375 /*--- hwcommon.c ------------------------------------------------------------*/
377 int ezusb_reset(struct libusb_device_handle *hdl, int set_clear);
378 int ezusb_install_firmware(libusb_device_handle *hdl, char *filename);
380 GSList *list_serial_ports(void);