![]() |
libsigrok
0.3.0
sigrok hardware access and backend library
|
00001 /* 00002 * This file is part of the libsigrok project. 00003 * 00004 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com> 00005 * 00006 * This program is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #ifndef LIBSIGROK_LIBSIGROK_H 00021 #define LIBSIGROK_LIBSIGROK_H 00022 00023 #include <stdio.h> 00024 #include <sys/time.h> 00025 #include <stdint.h> 00026 #include <inttypes.h> 00027 #include <glib.h> 00028 00029 #ifdef __cplusplus 00030 extern "C" { 00031 #endif 00032 00033 /** 00034 * @file 00035 * 00036 * The public libsigrok header file to be used by frontends. 00037 * 00038 * This is the only file that libsigrok users (frontends) are supposed to 00039 * use and \#include. There are other header files which get installed with 00040 * libsigrok, but those are not meant to be used directly by frontends. 00041 * 00042 * The correct way to get/use the libsigrok API functions is: 00043 * 00044 * @code{.c} 00045 * #include <libsigrok/libsigrok.h> 00046 * @endcode 00047 */ 00048 00049 /* 00050 * All possible return codes of libsigrok functions must be listed here. 00051 * Functions should never return hardcoded numbers as status, but rather 00052 * use these enum values. All error codes are negative numbers. 00053 * 00054 * The error codes are globally unique in libsigrok, i.e. if one of the 00055 * libsigrok functions returns a "malloc error" it must be exactly the same 00056 * return value as used by all other functions to indicate "malloc error". 00057 * There must be no functions which indicate two different errors via the 00058 * same return code. 00059 * 00060 * Also, for compatibility reasons, no defined return codes are ever removed 00061 * or reused for different errors later. You can only add new entries and 00062 * return codes, but never remove or redefine existing ones. 00063 */ 00064 00065 /** Status/error codes returned by libsigrok functions. */ 00066 enum sr_error_code { 00067 SR_OK = 0, /**< No error. */ 00068 SR_ERR = -1, /**< Generic/unspecified error. */ 00069 SR_ERR_MALLOC = -2, /**< Malloc/calloc/realloc error. */ 00070 SR_ERR_ARG = -3, /**< Function argument error. */ 00071 SR_ERR_BUG = -4, /**< Errors hinting at internal bugs. */ 00072 SR_ERR_SAMPLERATE = -5, /**< Incorrect samplerate. */ 00073 SR_ERR_NA = -6, /**< Not applicable. */ 00074 SR_ERR_DEV_CLOSED = -7, /**< Device is closed, but must be open. */ 00075 SR_ERR_TIMEOUT = -8, /**< A timeout occurred. */ 00076 SR_ERR_CHANNEL_GROUP = -9, /**< A channel group must be specified. */ 00077 00078 /* 00079 * Note: When adding entries here, don't forget to also update the 00080 * sr_strerror() and sr_strerror_name() functions in error.c. 00081 */ 00082 }; 00083 00084 #define SR_MAX_CHANNELNAME_LEN 32 00085 00086 /* Handy little macros */ 00087 #define SR_HZ(n) (n) 00088 #define SR_KHZ(n) ((n) * (uint64_t)(1000ULL)) 00089 #define SR_MHZ(n) ((n) * (uint64_t)(1000000ULL)) 00090 #define SR_GHZ(n) ((n) * (uint64_t)(1000000000ULL)) 00091 00092 #define SR_HZ_TO_NS(n) ((uint64_t)(1000000000ULL) / (n)) 00093 00094 /** libsigrok loglevels. */ 00095 enum sr_loglevel { 00096 SR_LOG_NONE = 0, /**< Output no messages at all. */ 00097 SR_LOG_ERR = 1, /**< Output error messages. */ 00098 SR_LOG_WARN = 2, /**< Output warnings. */ 00099 SR_LOG_INFO = 3, /**< Output informational messages. */ 00100 SR_LOG_DBG = 4, /**< Output debug messages. */ 00101 SR_LOG_SPEW = 5, /**< Output very noisy debug messages. */ 00102 }; 00103 00104 /* 00105 * Use SR_API to mark public API symbols, and SR_PRIV for private symbols. 00106 * 00107 * Variables and functions marked 'static' are private already and don't 00108 * need SR_PRIV. However, functions which are not static (because they need 00109 * to be used in other libsigrok-internal files) but are also not meant to 00110 * be part of the public libsigrok API, must use SR_PRIV. 00111 * 00112 * This uses the 'visibility' feature of gcc (requires gcc >= 4.0). 00113 * 00114 * This feature is not available on MinGW/Windows, as it is a feature of 00115 * ELF files and MinGW/Windows uses PE files. 00116 * 00117 * Details: http://gcc.gnu.org/wiki/Visibility 00118 */ 00119 00120 /* Marks public libsigrok API symbols. */ 00121 #ifndef _WIN32 00122 #define SR_API __attribute__((visibility("default"))) 00123 #else 00124 #define SR_API 00125 #endif 00126 00127 /* Marks private, non-public libsigrok symbols (not part of the API). */ 00128 #ifndef _WIN32 00129 #define SR_PRIV __attribute__((visibility("hidden"))) 00130 #else 00131 #define SR_PRIV 00132 #endif 00133 00134 /** Type definition for callback function for data reception. */ 00135 typedef int (*sr_receive_data_callback)(int fd, int revents, void *cb_data); 00136 00137 /** Data types used by sr_config_info(). */ 00138 enum sr_datatype { 00139 SR_T_UINT64 = 10000, 00140 SR_T_STRING, 00141 SR_T_BOOL, 00142 SR_T_FLOAT, 00143 SR_T_RATIONAL_PERIOD, 00144 SR_T_RATIONAL_VOLT, 00145 SR_T_KEYVALUE, 00146 SR_T_UINT64_RANGE, 00147 SR_T_DOUBLE_RANGE, 00148 SR_T_INT32, 00149 }; 00150 00151 /** Value for sr_datafeed_packet.type. */ 00152 enum sr_packettype { 00153 /** Payload is sr_datafeed_header. */ 00154 SR_DF_HEADER = 10000, 00155 /** End of stream (no further data). */ 00156 SR_DF_END, 00157 /** Payload is struct sr_datafeed_meta */ 00158 SR_DF_META, 00159 /** The trigger matched at this point in the data feed. No payload. */ 00160 SR_DF_TRIGGER, 00161 /** Payload is struct sr_datafeed_logic. */ 00162 SR_DF_LOGIC, 00163 /** Payload is struct sr_datafeed_analog. */ 00164 SR_DF_ANALOG, 00165 /** Beginning of frame. No payload. */ 00166 SR_DF_FRAME_BEGIN, 00167 /** End of frame. No payload. */ 00168 SR_DF_FRAME_END, 00169 }; 00170 00171 /** Measured quantity, sr_datafeed_analog.mq. */ 00172 enum sr_mq { 00173 SR_MQ_VOLTAGE = 10000, 00174 SR_MQ_CURRENT, 00175 SR_MQ_RESISTANCE, 00176 SR_MQ_CAPACITANCE, 00177 SR_MQ_TEMPERATURE, 00178 SR_MQ_FREQUENCY, 00179 /** Duty cycle, e.g. on/off ratio. */ 00180 SR_MQ_DUTY_CYCLE, 00181 /** Continuity test. */ 00182 SR_MQ_CONTINUITY, 00183 SR_MQ_PULSE_WIDTH, 00184 SR_MQ_CONDUCTANCE, 00185 /** Electrical power, usually in W, or dBm. */ 00186 SR_MQ_POWER, 00187 /** Gain (a transistor's gain, or hFE, for example). */ 00188 SR_MQ_GAIN, 00189 /** Logarithmic representation of sound pressure relative to a 00190 * reference value. */ 00191 SR_MQ_SOUND_PRESSURE_LEVEL, 00192 /** Carbon monoxide level */ 00193 SR_MQ_CARBON_MONOXIDE, 00194 /** Humidity */ 00195 SR_MQ_RELATIVE_HUMIDITY, 00196 /** Time */ 00197 SR_MQ_TIME, 00198 }; 00199 00200 /** Unit of measured quantity, sr_datafeed_analog.unit. */ 00201 enum sr_unit { 00202 /** Volt */ 00203 SR_UNIT_VOLT = 10000, 00204 /** Ampere (current). */ 00205 SR_UNIT_AMPERE, 00206 /** Ohm (resistance). */ 00207 SR_UNIT_OHM, 00208 /** Farad (capacity). */ 00209 SR_UNIT_FARAD, 00210 /** Kelvin (temperature). */ 00211 SR_UNIT_KELVIN, 00212 /** Degrees Celsius (temperature). */ 00213 SR_UNIT_CELSIUS, 00214 /** Degrees Fahrenheit (temperature). */ 00215 SR_UNIT_FAHRENHEIT, 00216 /** Hertz (frequency, 1/s, [Hz]). */ 00217 SR_UNIT_HERTZ, 00218 /** Percent value. */ 00219 SR_UNIT_PERCENTAGE, 00220 /** Boolean value. */ 00221 SR_UNIT_BOOLEAN, 00222 /** Time in seconds. */ 00223 SR_UNIT_SECOND, 00224 /** Unit of conductance, the inverse of resistance. */ 00225 SR_UNIT_SIEMENS, 00226 /** 00227 * An absolute measurement of power, in decibels, referenced to 00228 * 1 milliwatt (dBu). 00229 */ 00230 SR_UNIT_DECIBEL_MW, 00231 /** Voltage in decibel, referenced to 1 volt (dBV). */ 00232 SR_UNIT_DECIBEL_VOLT, 00233 /** 00234 * Measurements that intrinsically do not have units attached, such 00235 * as ratios, gains, etc. Specifically, a transistor's gain (hFE) is 00236 * a unitless quantity, for example. 00237 */ 00238 SR_UNIT_UNITLESS, 00239 /** Sound pressure level relative so 20 micropascals. */ 00240 SR_UNIT_DECIBEL_SPL, 00241 /** 00242 * Normalized (0 to 1) concentration of a substance or compound with 0 00243 * representing a concentration of 0%, and 1 being 100%. This is 00244 * represented as the fraction of number of particles of the substance. 00245 */ 00246 SR_UNIT_CONCENTRATION, 00247 /** Revolutions per minute. */ 00248 SR_UNIT_REVOLUTIONS_PER_MINUTE, 00249 /** Apparent power [VA]. */ 00250 SR_UNIT_VOLT_AMPERE, 00251 /** Real power [W]. */ 00252 SR_UNIT_WATT, 00253 /** Consumption [Wh]. */ 00254 SR_UNIT_WATT_HOUR, 00255 }; 00256 00257 /** Values for sr_datafeed_analog.flags. */ 00258 enum sr_mqflag { 00259 /** Voltage measurement is alternating current (AC). */ 00260 SR_MQFLAG_AC = 0x01, 00261 /** Voltage measurement is direct current (DC). */ 00262 SR_MQFLAG_DC = 0x02, 00263 /** This is a true RMS measurement. */ 00264 SR_MQFLAG_RMS = 0x04, 00265 /** Value is voltage drop across a diode, or NAN. */ 00266 SR_MQFLAG_DIODE = 0x08, 00267 /** Device is in "hold" mode (repeating the last measurement). */ 00268 SR_MQFLAG_HOLD = 0x10, 00269 /** Device is in "max" mode, only updating upon a new max value. */ 00270 SR_MQFLAG_MAX = 0x20, 00271 /** Device is in "min" mode, only updating upon a new min value. */ 00272 SR_MQFLAG_MIN = 0x40, 00273 /** Device is in autoranging mode. */ 00274 SR_MQFLAG_AUTORANGE = 0x80, 00275 /** Device is in relative mode. */ 00276 SR_MQFLAG_RELATIVE = 0x100, 00277 /** Sound pressure level is A-weighted in the frequency domain, 00278 * according to IEC 61672:2003. */ 00279 SR_MQFLAG_SPL_FREQ_WEIGHT_A = 0x200, 00280 /** Sound pressure level is C-weighted in the frequency domain, 00281 * according to IEC 61672:2003. */ 00282 SR_MQFLAG_SPL_FREQ_WEIGHT_C = 0x400, 00283 /** Sound pressure level is Z-weighted (i.e. not at all) in the 00284 * frequency domain, according to IEC 61672:2003. */ 00285 SR_MQFLAG_SPL_FREQ_WEIGHT_Z = 0x800, 00286 /** Sound pressure level is not weighted in the frequency domain, 00287 * albeit without standards-defined low and high frequency limits. */ 00288 SR_MQFLAG_SPL_FREQ_WEIGHT_FLAT = 0x1000, 00289 /** Sound pressure level measurement is S-weighted (1s) in the 00290 * time domain. */ 00291 SR_MQFLAG_SPL_TIME_WEIGHT_S = 0x2000, 00292 /** Sound pressure level measurement is F-weighted (125ms) in the 00293 * time domain. */ 00294 SR_MQFLAG_SPL_TIME_WEIGHT_F = 0x4000, 00295 /** Sound pressure level is time-averaged (LAT), also known as 00296 * Equivalent Continuous A-weighted Sound Level (LEQ). */ 00297 SR_MQFLAG_SPL_LAT = 0x8000, 00298 /** Sound pressure level represented as a percentage of measurements 00299 * that were over a preset alarm level. */ 00300 SR_MQFLAG_SPL_PCT_OVER_ALARM = 0x10000, 00301 /** Time is duration (as opposed to epoch, ...). */ 00302 SR_MQFLAG_DURATION = 0x20000, 00303 /** Device is in "avg" mode, averaging upon each new value. */ 00304 SR_MQFLAG_AVG = 0x40000, 00305 }; 00306 00307 /** 00308 * @struct sr_context 00309 * Opaque structure representing a libsigrok context. 00310 * 00311 * None of the fields of this structure are meant to be accessed directly. 00312 * 00313 * @see sr_init(), sr_exit(). 00314 */ 00315 struct sr_context; 00316 00317 /** Packet in a sigrok data feed. */ 00318 struct sr_datafeed_packet { 00319 uint16_t type; 00320 const void *payload; 00321 }; 00322 00323 /** Header of a sigrok data feed. */ 00324 struct sr_datafeed_header { 00325 int feed_version; 00326 struct timeval starttime; 00327 }; 00328 00329 /** Datafeed payload for type SR_DF_META. */ 00330 struct sr_datafeed_meta { 00331 GSList *config; 00332 }; 00333 00334 /** Logic datafeed payload for type SR_DF_LOGIC. */ 00335 struct sr_datafeed_logic { 00336 uint64_t length; 00337 uint16_t unitsize; 00338 void *data; 00339 }; 00340 00341 /** Analog datafeed payload for type SR_DF_ANALOG. */ 00342 struct sr_datafeed_analog { 00343 /** The channels for which data is included in this packet. */ 00344 GSList *channels; 00345 /** Number of samples in data */ 00346 int num_samples; 00347 /** Measured quantity (voltage, current, temperature, and so on). 00348 * Use SR_MQ_VOLTAGE, ... */ 00349 int mq; 00350 /** Unit in which the MQ is measured. Use SR_UNIT_VOLT, ... */ 00351 int unit; 00352 /** Bitmap with extra information about the MQ. Use SR_MQFLAG_AC, ... */ 00353 uint64_t mqflags; 00354 /** The analog value(s). The data is interleaved according to 00355 * the channels list. */ 00356 float *data; 00357 }; 00358 00359 /** Input (file) format struct. */ 00360 struct sr_input { 00361 /** 00362 * A pointer to this input format's 'struct sr_input_format'. 00363 * The frontend can use this to call the module's callbacks. 00364 */ 00365 struct sr_input_format *format; 00366 00367 GHashTable *param; 00368 00369 struct sr_dev_inst *sdi; 00370 00371 void *internal; 00372 }; 00373 00374 /** Input (file) format driver. */ 00375 struct sr_input_format { 00376 /** The unique ID for this input format. Must not be NULL. */ 00377 char *id; 00378 00379 /** 00380 * A short description of the input format, which can (for example) 00381 * be displayed to the user by frontends. Must not be NULL. 00382 */ 00383 char *description; 00384 00385 /** 00386 * Check if this input module can load and parse the specified file. 00387 * 00388 * @param[in] filename The name (and path) of the file to check. 00389 * 00390 * @retval TRUE This module knows the format. 00391 * @retval FALSE This module does not know the format. 00392 */ 00393 int (*format_match) (const char *filename); 00394 00395 /** 00396 * Initialize the input module. 00397 * 00398 * @param in A pointer to a valid 'struct sr_input' that the caller 00399 * has to allocate and provide to this function. It is also 00400 * the responsibility of the caller to free it later. 00401 * @param[in] filename The name (and path) of the file to use. 00402 * 00403 * @retval SR_OK Success 00404 * @retval other Negative error code. 00405 */ 00406 int (*init) (struct sr_input *in, const char *filename); 00407 00408 /** 00409 * Load a file, parsing the input according to the file's format. 00410 * 00411 * This function will send datafeed packets to the session bus, so 00412 * the calling frontend must have registered its session callbacks 00413 * beforehand. 00414 * 00415 * The packet types sent across the session bus by this function must 00416 * include at least SR_DF_HEADER, SR_DF_END, and an appropriate data 00417 * type such as SR_DF_LOGIC. It may also send a SR_DF_TRIGGER packet 00418 * if appropriate. 00419 * 00420 * @param in A pointer to a valid 'struct sr_input' that the caller 00421 * has to allocate and provide to this function. It is also 00422 * the responsibility of the caller to free it later. 00423 * @param filename The name (and path) of the file to use. 00424 * 00425 * @retval SR_OK Success 00426 * @retval other Negative error code. 00427 */ 00428 int (*loadfile) (struct sr_input *in, const char *filename); 00429 }; 00430 00431 /** Output (file) format struct. */ 00432 struct sr_output { 00433 /** A pointer to this output's format. */ 00434 struct sr_output_format *format; 00435 00436 /** 00437 * The device for which this output module is creating output. This 00438 * can be used by the module to find out channel names and numbers. 00439 */ 00440 const struct sr_dev_inst *sdi; 00441 00442 /** 00443 * An optional parameter which the frontend can pass in to the 00444 * output module. How the string is interpreted is entirely up to 00445 * the module. 00446 */ 00447 GHashTable *params; 00448 00449 /** 00450 * A generic pointer which can be used by the module to keep internal 00451 * state between calls into its callback functions. 00452 * 00453 * For example, the module might store a pointer to a chunk of output 00454 * there, and only flush it when it reaches a certain size. 00455 */ 00456 void *internal; 00457 }; 00458 00459 /** Output (file) format driver. */ 00460 struct sr_output_format { 00461 /** 00462 * A unique ID for this output format. Must not be NULL. 00463 * 00464 * It can be used by frontends to select this output format for use. 00465 * 00466 * For example, calling sigrok-cli with <code>-O hex</code> will 00467 * select the hexadecimal text output format. 00468 */ 00469 char *id; 00470 00471 /** 00472 * A short description of the output format. Must not be NULL. 00473 * 00474 * This can be displayed by frontends, e.g. when selecting the output 00475 * format for saving a file. 00476 */ 00477 char *description; 00478 00479 /** 00480 * This function is called once, at the beginning of an output stream. 00481 * 00482 * The device struct will be available in the output struct passed in, 00483 * as well as the param field -- which may be NULL or an empty string, 00484 * if no parameter was passed. 00485 * 00486 * The module can use this to initialize itself, create a struct for 00487 * keeping state and storing it in the <code>internal</code> field. 00488 * 00489 * @param o Pointer to the respective 'struct sr_output'. 00490 * 00491 * @retval SR_OK Success 00492 * @retval other Negative error code. 00493 */ 00494 int (*init) (struct sr_output *o); 00495 00496 /** 00497 * This function is passed a copy of every packed in the data feed. 00498 * Any output generated by the output module in response to the 00499 * packet should be returned in a newly allocated GString 00500 * <code>out</code>, which will be freed by the caller. 00501 * 00502 * Packets not of interest to the output module can just be ignored, 00503 * and the <code>out</code> parameter set to NULL. 00504 * 00505 * @param o Pointer to the respective 'struct sr_output'. 00506 * @param sdi The device instance that generated the packet. 00507 * @param packet The complete packet. 00508 * @param out A pointer where a GString * should be stored if 00509 * the module generates output, or NULL if not. 00510 * 00511 * @retval SR_OK Success 00512 * @retval other Negative error code. 00513 */ 00514 int (*receive) (struct sr_output *o, 00515 const struct sr_datafeed_packet *packet, GString **out); 00516 00517 /** 00518 * This function is called after the caller is finished using 00519 * the output module, and can be used to free any internal 00520 * resources the module may keep. 00521 * 00522 * @retval SR_OK Success 00523 * @retval other Negative error code. 00524 */ 00525 int (*cleanup) (struct sr_output *o); 00526 }; 00527 00528 /** Constants for channel type. */ 00529 enum sr_channeltype { 00530 /** Channel type is logic channel. */ 00531 SR_CHANNEL_LOGIC = 10000, 00532 /** Channel type is analog channel. */ 00533 SR_CHANNEL_ANALOG, 00534 }; 00535 00536 /** Information on single channel. */ 00537 struct sr_channel { 00538 /** Number of channels, starting at 0. */ 00539 int index; 00540 /** Channel type (SR_CHANNEL_LOGIC, ...) */ 00541 int type; 00542 /** Is this channel enabled? */ 00543 gboolean enabled; 00544 /** Name of channel. */ 00545 char *name; 00546 /** Trigger string, format like used by sigrok-cli */ 00547 char *trigger; 00548 }; 00549 00550 /** Structure for groups of channels that have common properties. */ 00551 struct sr_channel_group { 00552 /** Name of the channel group. */ 00553 char *name; 00554 /** List of sr_channel structs of the channels belonging to this group. */ 00555 GSList *channels; 00556 /** Private data for driver use. */ 00557 void *priv; 00558 }; 00559 00560 /** Used for setting or getting value of a config item. */ 00561 struct sr_config { 00562 /** Config key like SR_CONF_CONN, etc. */ 00563 int key; 00564 /** Key-specific data. */ 00565 GVariant *data; 00566 }; 00567 00568 /** Information about a config key. */ 00569 struct sr_config_info { 00570 /** Config key like SR_CONF_CONN, etc. */ 00571 int key; 00572 /** Data type like SR_T_STRING, etc. */ 00573 int datatype; 00574 /** Id string, e.g. "serialcomm". */ 00575 char *id; 00576 /** Name, e.g. "Serial communication". */ 00577 char *name; 00578 /** Verbose description (unused currently). */ 00579 char *description; 00580 }; 00581 00582 /** Constants for device classes */ 00583 enum sr_configkey { 00584 /*--- Device classes ------------------------------------------------*/ 00585 00586 /** The device can act as logic analyzer. */ 00587 SR_CONF_LOGIC_ANALYZER = 10000, 00588 00589 /** The device can act as an oscilloscope. */ 00590 SR_CONF_OSCILLOSCOPE, 00591 00592 /** The device can act as a multimeter. */ 00593 SR_CONF_MULTIMETER, 00594 00595 /** The device is a demo device. */ 00596 SR_CONF_DEMO_DEV, 00597 00598 /** The device can act as a sound level meter. */ 00599 SR_CONF_SOUNDLEVELMETER, 00600 00601 /** The device can measure temperature. */ 00602 SR_CONF_THERMOMETER, 00603 00604 /** The device can measure humidity. */ 00605 SR_CONF_HYGROMETER, 00606 00607 /** The device can measure energy consumption. */ 00608 SR_CONF_ENERGYMETER, 00609 00610 /** The device can demodulate signals. */ 00611 SR_CONF_DEMODULATOR, 00612 00613 /** Programmable power supply. */ 00614 SR_CONF_POWER_SUPPLY, 00615 00616 /*--- Driver scan options -------------------------------------------*/ 00617 00618 /** 00619 * Specification on how to connect to a device. 00620 * 00621 * In combination with SR_CONF_SERIALCOMM, this is a serial port in 00622 * the form which makes sense to the OS (e.g., /dev/ttyS0). 00623 * Otherwise this specifies a USB device, either in the form of 00624 * @verbatim <bus>.<address> @endverbatim (decimal, e.g. 1.65) or 00625 * @verbatim <vendorid>.<productid> @endverbatim 00626 * (hexadecimal, e.g. 1d6b.0001). 00627 */ 00628 SR_CONF_CONN = 20000, 00629 00630 /** 00631 * Serial communication specification, in the form: 00632 * 00633 * @verbatim <baudrate>/<databits><parity><stopbits> @endverbatim 00634 * 00635 * Example: 9600/8n1 00636 * 00637 * The string may also be followed by one or more special settings, 00638 * in the form "/key=value". Supported keys and their values are: 00639 * 00640 * rts 0,1 set the port's RTS pin to low or high 00641 * dtr 0,1 set the port's DTR pin to low or high 00642 * flow 0 no flow control 00643 * 1 hardware-based (RTS/CTS) flow control 00644 * 2 software-based (XON/XOFF) flow control 00645 * 00646 * This is always an optional parameter, since a driver typically 00647 * knows the speed at which the device wants to communicate. 00648 */ 00649 SR_CONF_SERIALCOMM, 00650 00651 /*--- Device configuration ------------------------------------------*/ 00652 00653 /** The device supports setting its samplerate, in Hz. */ 00654 SR_CONF_SAMPLERATE = 30000, 00655 00656 /** The device supports setting a pre/post-trigger capture ratio. */ 00657 SR_CONF_CAPTURE_RATIO, 00658 00659 /** The device supports setting a pattern (pattern generator mode). */ 00660 SR_CONF_PATTERN_MODE, 00661 00662 /** The device supports Run Length Encoding. */ 00663 SR_CONF_RLE, 00664 00665 /** The device supports setting trigger slope. */ 00666 SR_CONF_TRIGGER_SLOPE, 00667 00668 /** Trigger source. */ 00669 SR_CONF_TRIGGER_SOURCE, 00670 00671 /** Horizontal trigger position. */ 00672 SR_CONF_HORIZ_TRIGGERPOS, 00673 00674 /** Buffer size. */ 00675 SR_CONF_BUFFERSIZE, 00676 00677 /** Time base. */ 00678 SR_CONF_TIMEBASE, 00679 00680 /** Filter. */ 00681 SR_CONF_FILTER, 00682 00683 /** Volts/div. */ 00684 SR_CONF_VDIV, 00685 00686 /** Coupling. */ 00687 SR_CONF_COUPLING, 00688 00689 /** Trigger types. */ 00690 SR_CONF_TRIGGER_TYPE, 00691 00692 /** The device supports setting its sample interval, in ms. */ 00693 SR_CONF_SAMPLE_INTERVAL, 00694 00695 /** Number of timebases, as related to SR_CONF_TIMEBASE. */ 00696 SR_CONF_NUM_TIMEBASE, 00697 00698 /** Number of vertical divisions, as related to SR_CONF_VDIV. */ 00699 SR_CONF_NUM_VDIV, 00700 00701 /** Sound pressure level frequency weighting. */ 00702 SR_CONF_SPL_WEIGHT_FREQ, 00703 00704 /** Sound pressure level time weighting. */ 00705 SR_CONF_SPL_WEIGHT_TIME, 00706 00707 /** Sound pressure level measurement range. */ 00708 SR_CONF_SPL_MEASUREMENT_RANGE, 00709 00710 /** Max hold mode. */ 00711 SR_CONF_HOLD_MAX, 00712 00713 /** Min hold mode. */ 00714 SR_CONF_HOLD_MIN, 00715 00716 /** Logic low-high threshold range. */ 00717 SR_CONF_VOLTAGE_THRESHOLD, 00718 00719 /** The device supports using an external clock. */ 00720 SR_CONF_EXTERNAL_CLOCK, 00721 00722 /** 00723 * The device supports swapping channels. Typical this is between 00724 * buffered and unbuffered channels. 00725 */ 00726 SR_CONF_SWAP, 00727 00728 /** Center frequency. 00729 * The input signal is downmixed by this frequency before the ADC 00730 * anti-aliasing filter. 00731 */ 00732 SR_CONF_CENTER_FREQUENCY, 00733 00734 /** The device supports setting the number of logic channels. */ 00735 SR_CONF_NUM_LOGIC_CHANNELS, 00736 00737 /** The device supports setting the number of analog channels. */ 00738 SR_CONF_NUM_ANALOG_CHANNELS, 00739 00740 /** Output voltage. */ 00741 SR_CONF_OUTPUT_VOLTAGE, 00742 00743 /** Maximum output voltage. */ 00744 SR_CONF_OUTPUT_VOLTAGE_MAX, 00745 00746 /** Output current. */ 00747 SR_CONF_OUTPUT_CURRENT, 00748 00749 /** Maximum output current. */ 00750 SR_CONF_OUTPUT_CURRENT_MAX, 00751 00752 /** Enabling/disabling output. */ 00753 SR_CONF_OUTPUT_ENABLED, 00754 00755 /** Channel output configuration. */ 00756 SR_CONF_OUTPUT_CHANNEL, 00757 00758 /** Over-voltage protection (OVP) */ 00759 SR_CONF_OVER_VOLTAGE_PROTECTION, 00760 00761 /** Over-current protection (OCP) */ 00762 SR_CONF_OVER_CURRENT_PROTECTION, 00763 00764 /** Choice of clock edge for external clock ("r" or "f"). */ 00765 SR_CONF_CLOCK_EDGE, 00766 00767 /*--- Special stuff -------------------------------------------------*/ 00768 00769 /** Scan options supported by the driver. */ 00770 SR_CONF_SCAN_OPTIONS = 40000, 00771 00772 /** Device options for a particular device. */ 00773 SR_CONF_DEVICE_OPTIONS, 00774 00775 /** Session filename. */ 00776 SR_CONF_SESSIONFILE, 00777 00778 /** The device supports specifying a capturefile to inject. */ 00779 SR_CONF_CAPTUREFILE, 00780 00781 /** The device supports specifying the capturefile unit size. */ 00782 SR_CONF_CAPTURE_UNITSIZE, 00783 00784 /** Power off the device. */ 00785 SR_CONF_POWER_OFF, 00786 00787 /** 00788 * Data source for acquisition. If not present, acquisition from 00789 * the device is always "live", i.e. acquisition starts when the 00790 * frontend asks and the results are sent out as soon as possible. 00791 * 00792 * If present, it indicates that either the device has no live 00793 * acquisition capability (for example a pure data logger), or 00794 * there is a choice. sr_config_list() returns those choices. 00795 * 00796 * In any case if a device has live acquisition capabilities, it 00797 * is always the default. 00798 */ 00799 SR_CONF_DATA_SOURCE, 00800 00801 /*--- Acquisition modes ---------------------------------------------*/ 00802 00803 /** 00804 * The device supports setting a sample time limit (how long 00805 * the sample acquisition should run, in ms). 00806 */ 00807 SR_CONF_LIMIT_MSEC = 50000, 00808 00809 /** 00810 * The device supports setting a sample number limit (how many 00811 * samples should be acquired). 00812 */ 00813 SR_CONF_LIMIT_SAMPLES, 00814 00815 /** 00816 * The device supports setting a frame limit (how many 00817 * frames should be acquired). 00818 */ 00819 SR_CONF_LIMIT_FRAMES, 00820 00821 /** 00822 * The device supports continuous sampling. Neither a time limit 00823 * nor a sample number limit has to be supplied, it will just acquire 00824 * samples continuously, until explicitly stopped by a certain command. 00825 */ 00826 SR_CONF_CONTINUOUS, 00827 00828 /** The device has internal storage, into which data is logged. This 00829 * starts or stops the internal logging. */ 00830 SR_CONF_DATALOG, 00831 00832 /** Device mode for multi-function devices. */ 00833 SR_CONF_DEVICE_MODE, 00834 00835 /** Self test mode. */ 00836 SR_CONF_TEST_MODE, 00837 }; 00838 00839 /** Device instance data 00840 */ 00841 struct sr_dev_inst { 00842 /** Device driver. */ 00843 struct sr_dev_driver *driver; 00844 /** Index of device in driver. */ 00845 int index; 00846 /** Device instance status. SR_ST_NOT_FOUND, etc. */ 00847 int status; 00848 /** Device instance type. SR_INST_USB, etc. */ 00849 int inst_type; 00850 /** Device vendor. */ 00851 char *vendor; 00852 /** Device model. */ 00853 char *model; 00854 /** Device version. */ 00855 char *version; 00856 /** List of channels. */ 00857 GSList *channels; 00858 /** List of sr_channel_group structs */ 00859 GSList *channel_groups; 00860 /** Device instance connection data (used?) */ 00861 void *conn; 00862 /** Device instance private data (used?) */ 00863 void *priv; 00864 }; 00865 00866 /** Types of device instance, struct sr_dev_inst.type */ 00867 enum sr_dev_inst_type { 00868 /** Device instance type for USB devices. */ 00869 SR_INST_USB = 10000, 00870 /** Device instance type for serial port devices. */ 00871 SR_INST_SERIAL, 00872 /** Device instance type for SCPI devices. */ 00873 SR_INST_SCPI, 00874 }; 00875 00876 /** Device instance status, struct sr_dev_inst.status */ 00877 enum sr_dev_inst_status { 00878 /** The device instance was not found. */ 00879 SR_ST_NOT_FOUND = 10000, 00880 /** The device instance was found, but is still booting. */ 00881 SR_ST_INITIALIZING, 00882 /** The device instance is live, but not in use. */ 00883 SR_ST_INACTIVE, 00884 /** The device instance is actively in use in a session. */ 00885 SR_ST_ACTIVE, 00886 /** The device is winding down its session. */ 00887 SR_ST_STOPPING, 00888 }; 00889 00890 /** Device driver data. See also http://sigrok.org/wiki/Hardware_driver_API . */ 00891 struct sr_dev_driver { 00892 /* Driver-specific */ 00893 /** Driver name. Lowercase a-z, 0-9 and dashes (-) only. */ 00894 char *name; 00895 /** Long name. Verbose driver name shown to user. */ 00896 char *longname; 00897 /** API version (currently 1). */ 00898 int api_version; 00899 /** Called when driver is loaded, e.g. program startup. */ 00900 int (*init) (struct sr_context *sr_ctx); 00901 /** Called before driver is unloaded. 00902 * Driver must free all resouces held by it. */ 00903 int (*cleanup) (void); 00904 /** Scan for devices. Driver should do all initialisation required. 00905 * Can be called several times, e.g. with different port options. 00906 * \retval NULL Error or no devices found. 00907 * \retval other GSList of a struct sr_dev_inst for each device. 00908 * Must be freed by caller! 00909 */ 00910 GSList *(*scan) (GSList *options); 00911 /** Get list of device instances the driver knows about. 00912 * \returns NULL or GSList of a struct sr_dev_inst for each device. 00913 * Must not be freed by caller! 00914 */ 00915 GSList *(*dev_list) (void); 00916 /** Clear list of devices the driver knows about. */ 00917 int (*dev_clear) (void); 00918 /** Query value of a configuration key in driver or given device instance. 00919 * @see sr_config_get(). 00920 */ 00921 int (*config_get) (int id, GVariant **data, 00922 const struct sr_dev_inst *sdi, 00923 const struct sr_channel_group *cg); 00924 /** Set value of a configuration key in driver or a given device instance. 00925 * @see sr_config_set(). */ 00926 int (*config_set) (int id, GVariant *data, 00927 const struct sr_dev_inst *sdi, 00928 const struct sr_channel_group *cg); 00929 /** Channel status change. 00930 * @see sr_dev_channel_enable(), sr_dev_trigger_set(). */ 00931 int (*config_channel_set) (const struct sr_dev_inst *sdi, 00932 struct sr_channel *ch, unsigned int changes); 00933 /** Apply configuration settings to the device hardware. 00934 * @see sr_config_commit().*/ 00935 int (*config_commit) (const struct sr_dev_inst *sdi); 00936 /** List all possible values for a configuration key in a device instance. 00937 * @see sr_config_list(). 00938 */ 00939 int (*config_list) (int info_id, GVariant **data, 00940 const struct sr_dev_inst *sdi, 00941 const struct sr_channel_group *cg); 00942 00943 /* Device-specific */ 00944 /** Open device */ 00945 int (*dev_open) (struct sr_dev_inst *sdi); 00946 /** Close device */ 00947 int (*dev_close) (struct sr_dev_inst *sdi); 00948 /** Begin data acquisition on the specified device. */ 00949 int (*dev_acquisition_start) (const struct sr_dev_inst *sdi, 00950 void *cb_data); 00951 /** End data acquisition on the specified device. */ 00952 int (*dev_acquisition_stop) (struct sr_dev_inst *sdi, 00953 void *cb_data); 00954 00955 /* Dynamic */ 00956 /** Device driver private data. Initialized by init(). */ 00957 void *priv; 00958 }; 00959 00960 /** 00961 * @struct sr_session 00962 * 00963 * Opaque data structure representing a libsigrok session. None of the fields 00964 * of this structure are meant to be accessed directly. 00965 */ 00966 struct sr_session; 00967 00968 #include "proto.h" 00969 #include "version.h" 00970 00971 #ifdef __cplusplus 00972 } 00973 #endif 00974 00975 #endif
1.7.6.1