2010-04-02 18:18:27 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the sigrok project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Bert Vermeulen <bert@biot.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SIGROK_SIGROK_H
|
|
|
|
#define SIGROK_SIGROK_H
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <libusb.h>
|
|
|
|
|
2011-01-20 22:00:59 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2010-04-05 14:41:54 +00:00
|
|
|
/*
|
|
|
|
* Status/error codes returned by libsigrok functions.
|
|
|
|
*
|
|
|
|
* All possible return codes of libsigrok functions must be listed here.
|
|
|
|
* Functions should never return hardcoded numbers as status, but rather
|
|
|
|
* use these #defines instead. All error codes are negative numbers.
|
|
|
|
*
|
|
|
|
* The error codes are globally unique in libsigrok, i.e. if one of the
|
2010-04-05 23:29:32 +00:00
|
|
|
* libsigrok functions returns a "malloc error" it must be exactly the same
|
|
|
|
* return value as used by all other functions to indicate "malloc error".
|
2010-04-05 14:41:54 +00:00
|
|
|
* There must be no functions which indicate two different errors via the
|
|
|
|
* same return code.
|
|
|
|
*
|
|
|
|
* Also, for compatibility reasons, no defined return codes are ever removed
|
|
|
|
* or reused for different #defines later. You can only add new #defines and
|
|
|
|
* return codes, but never remove or redefine existing ones.
|
|
|
|
*/
|
2011-01-10 12:47:24 +00:00
|
|
|
#define SIGROK_OK 0 /* No error */
|
|
|
|
#define SIGROK_ERR -1 /* Generic/unspecified error */
|
|
|
|
#define SIGROK_ERR_MALLOC -2 /* Malloc/calloc/realloc error */
|
|
|
|
#define SIGROK_ERR_SAMPLERATE -3 /* Incorrect samplerate */
|
2010-04-02 18:18:27 +00:00
|
|
|
|
2011-01-05 23:51:29 +00:00
|
|
|
/* limited by uint64_t */
|
|
|
|
#define MAX_NUM_PROBES 64
|
|
|
|
#define MAX_PROBENAME_LEN 32
|
|
|
|
|
2010-04-02 18:18:27 +00:00
|
|
|
/* Handy little macros */
|
2010-04-15 17:49:14 +00:00
|
|
|
#define KHZ(n) ((n) * 1000)
|
|
|
|
#define MHZ(n) ((n) * 1000000)
|
|
|
|
#define GHZ(n) ((n) * 1000000000)
|
2010-04-02 18:18:27 +00:00
|
|
|
|
2011-01-10 17:14:26 +00:00
|
|
|
#define HZ_TO_NS(n) (1000000000 / (n))
|
|
|
|
|
2010-04-12 22:34:20 +00:00
|
|
|
#ifndef ARRAY_SIZE
|
|
|
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
|
|
|
#endif
|
|
|
|
|
2011-01-09 05:48:39 +00:00
|
|
|
#ifndef ARRAY_AND_SIZE
|
|
|
|
#define ARRAY_AND_SIZE(a) (a), ARRAY_SIZE(a)
|
|
|
|
#endif
|
|
|
|
|
2011-01-10 12:47:24 +00:00
|
|
|
typedef int (*receive_data_callback) (int fd, int revents, void *user_data);
|
|
|
|
|
|
|
|
/* Data types used by hardware plugins for set_configuration() */
|
2010-04-02 18:18:27 +00:00
|
|
|
enum {
|
|
|
|
T_UINT64,
|
|
|
|
T_CHAR,
|
2011-01-23 03:58:32 +00:00
|
|
|
T_NULL,
|
2010-04-02 18:18:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROTO_RAW,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (Unused) protocol decoder stack entry */
|
|
|
|
struct protocol {
|
|
|
|
char *name;
|
|
|
|
int id;
|
|
|
|
int stackindex;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* datafeed_packet.type values */
|
|
|
|
enum {
|
|
|
|
DF_HEADER,
|
|
|
|
DF_END,
|
|
|
|
DF_TRIGGER,
|
2011-01-09 05:32:38 +00:00
|
|
|
DF_LOGIC,
|
2011-01-10 04:13:46 +00:00
|
|
|
DF_ANALOG,
|
2011-01-09 05:32:38 +00:00
|
|
|
DF_PD,
|
2010-04-02 18:18:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct datafeed_packet {
|
|
|
|
uint16_t type;
|
2010-08-12 03:49:00 +00:00
|
|
|
uint64_t length;
|
2011-01-09 05:32:38 +00:00
|
|
|
uint16_t unitsize;
|
2010-04-02 18:18:27 +00:00
|
|
|
void *payload;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct datafeed_header {
|
|
|
|
int feed_version;
|
|
|
|
struct timeval starttime;
|
2010-04-05 13:31:39 +00:00
|
|
|
uint64_t samplerate;
|
2010-04-02 18:18:27 +00:00
|
|
|
int protocol_id;
|
2011-01-10 17:08:43 +00:00
|
|
|
int num_analog_probes;
|
|
|
|
int num_logic_probes;
|
2010-04-02 18:18:27 +00:00
|
|
|
};
|
|
|
|
|
2011-01-21 03:14:53 +00:00
|
|
|
struct analog_probe {
|
|
|
|
uint8_t att;
|
2011-01-21 13:25:50 +00:00
|
|
|
uint8_t res; /* Needs to be a power of 2, FIXME */
|
|
|
|
uint16_t val; /* Max hardware ADC width is 16bits */
|
2011-01-21 03:14:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct analog_sample {
|
2011-01-21 13:25:50 +00:00
|
|
|
uint8_t num_probes; /* Max hardware probes is 256 */
|
2011-01-21 03:14:53 +00:00
|
|
|
struct analog_probe probes[];
|
|
|
|
};
|
|
|
|
|
2010-04-30 22:54:39 +00:00
|
|
|
struct input {
|
|
|
|
struct input_format *format;
|
2011-01-11 22:58:41 +00:00
|
|
|
char *param;
|
|
|
|
struct device *vdevice;
|
2010-04-30 22:54:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct input_format {
|
|
|
|
char *extension;
|
|
|
|
char *description;
|
2011-01-07 18:55:25 +00:00
|
|
|
int (*format_match) (const char *filename);
|
2011-01-11 22:58:41 +00:00
|
|
|
int (*init) (struct input *in);
|
|
|
|
int (*loadfile) (struct input *in, const char *filename);
|
2010-04-30 22:54:39 +00:00
|
|
|
};
|
|
|
|
|
2010-04-02 18:18:27 +00:00
|
|
|
struct output {
|
|
|
|
struct output_format *format;
|
|
|
|
struct device *device;
|
|
|
|
char *param;
|
|
|
|
void *internal;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct output_format {
|
|
|
|
char *extension;
|
|
|
|
char *description;
|
2011-01-09 22:22:48 +00:00
|
|
|
int df_type;
|
2010-04-05 14:20:09 +00:00
|
|
|
int (*init) (struct output *o);
|
2010-04-02 18:18:27 +00:00
|
|
|
int (*data) (struct output *o, char *data_in, uint64_t length_in,
|
|
|
|
char **data_out, uint64_t *length_out);
|
|
|
|
int (*event) (struct output *o, int event_type, char **data_out,
|
|
|
|
uint64_t *length_out);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct analyzer {
|
|
|
|
char *name;
|
|
|
|
char *filename;
|
|
|
|
/*
|
|
|
|
* TODO: Parameters? If so, configured plugins need another struct.
|
|
|
|
* TODO: Input and output format?
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Size of a chunk in units */
|
|
|
|
#define DATASTORE_CHUNKSIZE 512000
|
|
|
|
|
|
|
|
struct datastore {
|
|
|
|
/* Size in bytes of the number of units stored in this datastore */
|
|
|
|
int ds_unitsize;
|
2010-05-09 11:25:03 +00:00
|
|
|
unsigned int num_units; /* TODO: uint64_t */
|
2010-04-02 18:18:27 +00:00
|
|
|
GSList *chunklist;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This represents a generic device connected to the system.
|
|
|
|
* For device-specific information, ask the plugin. The plugin_index refers
|
|
|
|
* to the device index within that plugin; it may be handling more than one
|
|
|
|
* device. All relevant plugin calls take a device_index parameter for this.
|
|
|
|
*/
|
|
|
|
struct device {
|
|
|
|
/* Which plugin handles this device */
|
|
|
|
struct device_plugin *plugin;
|
|
|
|
/* A plugin may handle multiple devices of the same type */
|
|
|
|
int plugin_index;
|
|
|
|
/* List of struct probe* */
|
|
|
|
GSList *probes;
|
|
|
|
/* Data acquired by this device, if any */
|
|
|
|
struct datastore *datastore;
|
|
|
|
};
|
|
|
|
|
2011-01-10 17:08:43 +00:00
|
|
|
enum {
|
|
|
|
PROBE_TYPE_LOGIC,
|
|
|
|
PROBE_TYPE_ANALOG,
|
|
|
|
};
|
|
|
|
|
2010-04-02 18:18:27 +00:00
|
|
|
struct probe {
|
|
|
|
int index;
|
2011-01-22 13:18:31 +00:00
|
|
|
int type;
|
2010-04-02 18:18:27 +00:00
|
|
|
gboolean enabled;
|
|
|
|
char *name;
|
|
|
|
char *trigger;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern GSList *devices;
|
|
|
|
|
|
|
|
/* Hardware plugin capabilities */
|
|
|
|
enum {
|
2011-01-10 21:17:52 +00:00
|
|
|
HWCAP_DUMMY, /* Used to terminate lists */
|
2011-01-15 04:11:40 +00:00
|
|
|
/* device classes */
|
2010-04-02 18:18:27 +00:00
|
|
|
HWCAP_LOGIC_ANALYZER,
|
2011-01-15 04:11:40 +00:00
|
|
|
|
|
|
|
/* device options */
|
2011-01-10 21:17:52 +00:00
|
|
|
HWCAP_SAMPLERATE, /* Change samplerate */
|
|
|
|
HWCAP_PROBECONFIG, /* Configure probe mask */
|
|
|
|
HWCAP_CAPTURE_RATIO, /* Set pre/post-trigger capture ratio */
|
2011-01-15 04:11:40 +00:00
|
|
|
HWCAP_PATTERN_MODE, /* Pattern generator mode */
|
|
|
|
|
|
|
|
/* acquisition modes */
|
2011-01-10 21:17:52 +00:00
|
|
|
HWCAP_LIMIT_MSEC, /* Set a time limit for sample acquisition */
|
|
|
|
HWCAP_LIMIT_SAMPLES, /* Set a limit on number of samples */
|
|
|
|
HWCAP_CONTINUOUS,
|
2010-04-02 18:18:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct hwcap_option {
|
|
|
|
int capability;
|
|
|
|
int type;
|
|
|
|
char *description;
|
|
|
|
char *shortname;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sigrok_device_instance {
|
|
|
|
int index;
|
|
|
|
int status;
|
|
|
|
int instance_type;
|
|
|
|
char *vendor;
|
|
|
|
char *model;
|
|
|
|
char *version;
|
2011-01-09 05:50:45 +00:00
|
|
|
void *priv;
|
2010-04-02 18:18:27 +00:00
|
|
|
union {
|
|
|
|
struct usb_device_instance *usb;
|
|
|
|
struct serial_device_instance *serial;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/* sigrok_device_instance types */
|
|
|
|
enum {
|
|
|
|
USB_INSTANCE,
|
|
|
|
SERIAL_INSTANCE,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct usb_device_instance {
|
|
|
|
uint8_t bus;
|
|
|
|
uint8_t address;
|
|
|
|
struct libusb_device_handle *devhdl;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct serial_device_instance {
|
|
|
|
char *port;
|
|
|
|
int fd;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Device instance status */
|
|
|
|
enum {
|
|
|
|
ST_NOT_FOUND,
|
|
|
|
/* Found, but still booting */
|
|
|
|
ST_INITIALIZING,
|
|
|
|
/* Live, but not in use */
|
|
|
|
ST_INACTIVE,
|
|
|
|
/* Actively in use in a session */
|
|
|
|
ST_ACTIVE,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: This sucks, you just kinda have to "know" the returned type.
|
|
|
|
* TODO: Need a DI to return the number of trigger stages supported.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Device info IDs */
|
|
|
|
enum {
|
|
|
|
/* struct sigrok_device_instance for this specific device */
|
|
|
|
DI_INSTANCE,
|
|
|
|
/* The number of probes connected to this device */
|
|
|
|
DI_NUM_PROBES,
|
2010-04-05 13:31:39 +00:00
|
|
|
/* Samplerates supported by this device, (struct samplerates) */
|
2010-04-02 18:18:27 +00:00
|
|
|
DI_SAMPLERATES,
|
|
|
|
/* Types of trigger supported, out of "01crf" (char *) */
|
|
|
|
DI_TRIGGER_TYPES,
|
2010-04-05 13:31:39 +00:00
|
|
|
/* The currently set samplerate in Hz (uint64_t) */
|
|
|
|
DI_CUR_SAMPLERATE,
|
2011-01-15 04:11:40 +00:00
|
|
|
/* Supported pattern generator modes */
|
|
|
|
DI_PATTERNMODES,
|
2010-04-02 18:18:27 +00:00
|
|
|
};
|
|
|
|
|
2010-04-15 18:07:16 +00:00
|
|
|
/*
|
|
|
|
* A device supports either a range of samplerates with steps of a given
|
|
|
|
* granularity, or is limited to a set of defined samplerates. Use either
|
2010-04-02 18:18:27 +00:00
|
|
|
* step or list, but not both.
|
|
|
|
*/
|
|
|
|
struct samplerates {
|
|
|
|
uint64_t low;
|
|
|
|
uint64_t high;
|
|
|
|
uint64_t step;
|
|
|
|
uint64_t *list;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct device_plugin {
|
2010-04-15 18:07:16 +00:00
|
|
|
/* Plugin-specific */
|
2010-04-02 18:18:27 +00:00
|
|
|
char *name;
|
|
|
|
int api_version;
|
|
|
|
int (*init) (char *deviceinfo);
|
|
|
|
void (*cleanup) (void);
|
|
|
|
|
2010-04-15 18:07:16 +00:00
|
|
|
/* Device-specific */
|
2010-04-02 18:18:27 +00:00
|
|
|
int (*open) (int device_index);
|
|
|
|
void (*close) (int device_index);
|
|
|
|
void *(*get_device_info) (int device_index, int device_info_id);
|
|
|
|
int (*get_status) (int device_index);
|
|
|
|
int *(*get_capabilities) (void);
|
|
|
|
int (*set_configuration) (int device_index, int capability, void *value);
|
|
|
|
int (*start_acquisition) (int device_index, gpointer session_device_id);
|
|
|
|
void (*stop_acquisition) (int device_index, gpointer session_device_id);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gsource_fd {
|
|
|
|
GSource source;
|
|
|
|
GPollFD gpfd;
|
|
|
|
/* Not really using this */
|
|
|
|
GSource *timeout_source;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct session {
|
|
|
|
/* List of struct device* */
|
|
|
|
GSList *devices;
|
|
|
|
/* List of struct analyzer* */
|
|
|
|
GSList *analyzers;
|
2010-04-15 18:07:16 +00:00
|
|
|
/* Datafeed callbacks */
|
2010-04-02 18:18:27 +00:00
|
|
|
GSList *datafeed_callbacks;
|
|
|
|
GTimeVal starttime;
|
|
|
|
};
|
|
|
|
|
2011-01-10 12:47:24 +00:00
|
|
|
#include "sigrok-proto.h"
|
2011-01-15 13:41:57 +00:00
|
|
|
|
2011-01-20 22:00:59 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-02 18:18:27 +00:00
|
|
|
#endif
|