Commit Graph

2529 Commits

Author SHA1 Message Date
Gerhard Sittig 5208214739 input/saleae: improve L2D undersampling, do provide sample data
The Saleae Logic exported files (Logic2 digital format) don't contain a
samplerate, so users need to specify the value. For values smaller than
the samplerate that was used during the capture undersampling will take
place. An implementation detail of the input module could result in
incorrect timing of sample values in the session feed. In extreme cases
none of the periods between signal edges qualified for submission. In
that case no sample data was sent to the sigrok session at all.

  $ sigrok-cli -i digital_1.bin -I saleae:samplerate=1000

Keep the very timestamp at hand when the last sample data was submitted.
Only advance that timestamp when more sample data was sent. This avoids
the accumulation of timing errors for undersampling scenarios, and does
forward undersampled input data when the user provided sample period has
passed.

This fixes bug #1600.
2020-09-02 19:52:44 +02:00
Gerhard Sittig 565c8c3545 korad-kaxxxxp: remove obsolete code (clear before read, timeout literal)
The korad response read routine clears the receive buffers, so callers
don't have to. This amends commit d2cc60bd45.

The acquisition timeout is handled by common sw_limits support. Remove
the no longer referenced literal. This amends commit 3f9b48ae5f.
2020-09-01 17:15:54 +02:00
Gerhard Sittig d2cc60bd45 korad-kaxxxxp: speed up scan process, rephrase response read routine
The Korad protocol relies on unterminated request and response strings,
which works well enough for fixed length acquisition and status queries.
But the variable length replies to identification requests suffered from
an implementation detail in the receive routine. A large timeout must be
used because supported devices reportedly are slow to respond. There is
no simple yet robust condition to detect the response's completion. The
scan code must prepare for the maximum response length across the set of
supported devices. Unfortunately the maximum amount of time was spent
waiting for the response to occupy the provided response buffer, before
a long total timeout expired.

Rework the korad driver's helper routine which gets a variable length
non-terminated text string. Keep the long initial timeout, and keep
iterating in that initial phase to quickly detect when response data
became available. But terminate the read sequence after a shorter period
without receive data after some initial receive data was seen. Assume
that identification responses get transferred at wire speed and without
additional delays beyond bitrate expectations. Acquisition and status
responses shall not be affected by this change.

This speeds up the scan for devices from roughly 5s to some 0.1s on
newer devices (KA3005P v5.5) and 0.5s on older devices (KA3005P V2.0).

This commit also addresses an issue in the response text termination,
where partial responses contained undefined data. The previous version's
return value was unspecific: Negative for fatal errors, but either zero
or non-zero for successful reads, with no way for callers to learn about
the received amount of data. The rephrased version always returns the
amount of received data, and adds internal documentation which discusses
the implementation's constraints and the motivation for the approach.

This is a modified version of the initial implementation which was
Submitted-By: Karl Palsson <karlp@tweak.net.au>
2020-09-01 17:11:36 +02:00
Gerhard Sittig fcacf532f5 korad-kaxxxxp: style cleanup in device scan, keep serno at hand
Cleanup style in the korad driver's scan() routine. Keep declarations
out of code blocks. Reduce redundancy and improve robustness in the
response buffer length calculation. Reduce clutter and group related
instructions together. Unobfuscate result checks, and keep the result
at hand (for diagnostics, or error propagation). Unobfuscate string
comparisons in the model ID lookups, terminate the search upon match.
Use a not so terse name for data that gets referenced at rather distant
locations.

Keep the optionally available serial number at hand, to present it to
users when desired. This aspect was
Reported-By: Karl Palsson <karlp@tweak.net.au>
2020-08-28 16:28:47 +02:00
Gerhard Sittig 003ad0ab8c input/saleae: keep previous channels across cleanup() call
The previous implementation of the cleanup() routine in the saleae input
module kept user specified options, but lost the previously created list
of sigrok channels. Keep it.

Also make sure that reset() voids the previous copy after grabbing its
value. To not unexpectedly release resources which still get referenced.

This shall unbreak file-reload.
2020-08-26 17:06:15 +02:00
Gerhard Sittig f403cb9de9 scpi-pps: use remote and local modes for HMP4000
Stop using the unusal "mixed" mode (local interface available during
remote operation) for HMP4000, applications may not be prepared for this
use case. Use traditional "remote" and "local" modes instead. This change
also ends remote mode after the application is done using the device.
2020-08-25 21:06:01 +02:00
Gerhard Sittig 22f76e188b scpi-pps: Add more HMP4000 series devices
List both vendor names "HAMEG" and "ROHDE&SCHWARZ" in the scpi-pps
driver, either responses were seen for HMP4000 devices. Unfortunately
vendor names don't support regex matches, so they require individual
profile items. The items also "violate" the alpha sort order in the list
of profiles, but keeping the series' models together is more important.

Add a declaration for the HMP4030 device which re-uses the HMP4040 data
but open codes the smaller channel count. Ideally the .probe_channels()
routine would receive the scpi_pps item as a parameter, and could yield
model specific result data from common information for the series. The
implementation in this commit is the least intrusive approach until
something better becomes available.

This shall cover the whole HMP4000 series:
  https://www.rohde-schwarz.com/product/hmp4000
2020-08-25 20:59:31 +02:00
Florian Schmidt bd5f0a143e scpi-pps: add support for Hameg / Rohde & Schwarz HMP4040
This commit introduces initial support for the HMP4040 power supply by
Rohde & Schwarz. It allows to configure the device and "statically" read
back current state. Automatic status updates with per-channel details
are not available yet (common support is missing).

[ gsi: drop status update remainder, address minor style nits ]
2020-08-25 20:58:54 +02:00
Gerhard Sittig f91c6940ab scpi_serial: add "GWInstek VCP" (PID 0x0030) as seen in GDM-834x 2020-08-25 19:38:23 +02:00
Gerhard Sittig 395c1850b7 scpi-dmm: factor out some OL detection limits
Prepare the "plus/minus infinity" checks for OL conditions to use
model dependent limits. This commit does not change behaviour.
2020-08-25 19:38:23 +02:00
Gerhard Sittig 7d95afb9be scpi-dmm: add SR_CONF_CONN getter
Add config_get() support for conn= specs. This is a best-effort approach.
Failure to get the SCPI connection text is non-fatal during probe.
2020-08-25 19:38:23 +02:00
v1ne 6f9234e6f3 ols: Detect Demon Core, use its canonic command names
Document Demon Core commands and associated metadata magic numbers.
See http://web.archive.org/web/20190317154112/
http://mygizmos.org/ols/Logic-Sniffer-FPGA-Spec.pdf for documentation.

Detect the Demon Core presence, use more symbolic names in related
code paths to eliminate magic numbers, switch to their canonic names.

Reviewed-By: Wolfram Sang <wsa@kernel.org>
2020-08-24 07:57:13 +02:00
v1ne 2755ab36f3 ols: Refactor, deduplicate logic packet code
Reviewed-By: Wolfram Sang <wsa@kernel.org>
2020-08-24 07:57:06 +02:00
v1ne dcdc2848b7 ols: Use symbolic name for "success" error code.
Reviewed-By: Wolfram Sang <wsa@kernel.org>
2020-08-24 07:43:03 +02:00
v1ne 58a75642e9 ols: Make constant names more precise, clarify comment
Reviewed-By: Wolfram Sang <wsa@kernel.org>
2020-08-24 07:33:13 +02:00
v1ne a80bed7656 ols: Rename "flags" to "capture flags".
In the current implementation the "flags" are exclusively used for
captures. Prepare the introduction of device flags by renaming the
capture related flags which are specific to an operation.

Reviewed-By: Wolfram Sang <wsa@kernel.org>
2020-08-24 07:29:03 +02:00
v1ne a2b1a53bb4 ols: Symbolic name for magic value, reflect units in variable names
Reviewed-By: Wolfram Sang <wsa@kernel.org>
2020-08-24 07:26:43 +02:00
v1ne f1a37f3924 ols: Remove stray command
It's nowhere documented and nowhere used.

Reviewed-By: Wolfram Sang <wsa@kernel.org>
2020-08-24 07:26:01 +02:00
v1ne 0ccc6f7cdf ols: Make use of zero-initialization.
No need to assign zero after gmalloc0(). Move comments to declaration.

Reviewed-By: Wolfram Sang <wsa@kernel.org>
2020-08-24 07:24:27 +02:00
Frank Stettner fe8c5aef1f libsigrok.h: Add Joule, Coulomb, and Ah units.
Also extend a comment on energy in comparison to power.
2020-08-22 21:53:56 +02:00
Frank Stettner 82ff704449 libsigrok.h: Add MQ for electric charge. 2020-08-22 21:53:56 +02:00
Frank Stettner f5247d953f teleinfo: Fix measured quantity (energy, not power). 2020-08-22 21:53:39 +02:00
Gerhard Sittig 98b7b08956 output/csv: always generate text for analog/logic data packets
Unconditionally generate output text when a session packet is received
which carries analog or logic sample data. Even if the data gets queued
and is not shown immediately, in that case the output text remains empty
but needs to be present. Otherwise applications may assume that the CSV
output module had not handled the data at all, which would result in
unexpected "screen output" with fallback data being interleaved with the
CSV output.

This resolves bug #1026 in its strictest sense (the unexpected presence
of fallback data). But leaves all other issues mentioned in comment 1.
2020-08-22 19:04:31 +02:00
Gerhard Sittig ce384e074f output/csv: check unsupported/untested input signal conditions
The current implementation of the CSV output module makes assumptions
which don't hold. Which results in incorrect or incomplete output for
some combinations of logic and analog signals.

Check for some of the known problematic conditions, and warn the user
about potentially unexpected results. This is a workaround until the
issues properly get addressed in the implementation.

This is motivated by but does not resolve bug #1026.
2020-08-22 19:00:05 +02:00
Timo Kokkonen a3ec8a9aa1 serial-dmm: Add GW Instek GDM-397 meter support.
This meter appears to be rebranded UNI-T UT61B, but with
improved input protection.
2020-08-22 09:10:42 +02:00
Gerhard Sittig e37e301e26 korad-kaxxxxp: add support for forced "detection" of a given model
Korad PSU models are rather popular. But the successful operation of
currently unsupported model names or firmware versions is hard to verify
by users, because building the library from locally modified sources is
involved.

Introduce support for the "force_detect=" scan option. Warning messages
contain how the device identifies itself. Optional user specs can force
the assignment of the driver to the unsupported model. Which results in
reports that include the identification details as well as the successful
use of the device.

  $ sigrok-cli -d korad-kaxxxxp:conn=...:force_detect=KORADKA3005PV2.0 --show
2020-08-22 09:10:29 +02:00
Gerhard Sittig d643e6bc39 hwdriver: introduce SR_CONF_FORCE_DETECT config key (scan option)
Often previously unsupported models might be covered by existing code,
but would not match against a builtin list of known devices.

Introduce a config key which provides a scan option for users to force
the use of a driver with an unsupported device. This increases the
probability of requests for support of an additional model which are
associated with a successful use of that very device, and eliminates
the necessity to build from source for the trivial cases.

It's up to individual drivers whether they support forced detection,
and how they interpret the value of the scan option.
2020-08-22 09:10:29 +02:00
Gerhard Sittig 048250d0e0 korad-kaxxxxp: add config_get() support for SR_CONF_CONN
Let applications query the device instance's conn= key. This lets users
recognize individual devices if multiple of them are connected.

  $ sigrok-cli -d korad-kaxxxxp:conn=/dev/ttyACM0 --show
  ...
  korad-kaxxxxp:conn=/dev/ttyACM0 - Korad KA3005P with 2 channels: V I
  ...
2020-08-22 09:10:29 +02:00
Timo Kokkonen 860ee00ab1 scpi-dmm: Remove SYST:LOC hack for GWInstek meters.
No need for this hack anymymore as there is now DMM_CMD_SETUP_LOCAL
command that can be used to return unit back to "local" mode properly.
2020-08-20 12:48:13 -07:00
Timo Kokkonen 4c80a27284 scpi-dmm: Add new command DMM_CMD_SETUP_LOCAL.
Add new command DMM_CMD_SETUP_LOCAL for setting device back
to "local" mode. If device implmements this command, it is
sent when driver is closed and after device "scan".

Define DMM_CMD_SETUP_LOCAL for GWInstek meters, so they get
returned to local mode automatically after use.
2020-08-20 12:48:00 -07:00
Gerhard Sittig 25879a34e9 scpi-dmm: alpha-sort the list of supported devices (vendor/model list)
Any order is as arbitrary as any other. The alphabetical order of vendor
and model names might be the most robust during maintenance: easiest to
remember, easiest to use when checking for presence, and easiest to add
to or resolve conflicts during merges. Vendor renames (HP to Agilent to
Keysight, et al) are ugly but can't be helped easily.
2020-08-17 20:32:08 +02:00
Gerhard Sittig 33aa8117e3 scpi-dmm: minor style adjustment (gdm906x, analog init, comments, diag)
Address minor style issues: Need not assign NULL after g_malloc0(), need
not check for NULL before g_free(). Rephrase diagnostics messages which
are user visible by default, remove internal development details. Reword
a few comments, and adjust their grammar for consistency across the code
base. The sr_analog_init() routine executed immediately before getting
measurements, need not (re-)assign endianess or floating point details,
except those which do change after initialization (double vs float).
Rephrase model dependent checks for easier adjustment during maintenance.
Unobfuscate string comparisons.
2020-08-17 20:01:02 +02:00
Gerhard Sittig 72cd558d4a scpi: Raise severity when IDN response lacks the serial number field.
Raise the diagnostics message's severity from debug to warn when the
'*IDN?' response lacks the serial number field. Although it has only
been seen for some GWInstek DMMs, it violates the SCPI spec, and more
or other activity is required in a future implementation. This change
amends commit 47e7a6395e.
2020-08-17 19:07:37 +02:00
Gerhard Sittig 6dc0007c71 scpi_serial: Rephrase NL and NL+CR line termination check.
Rearrange the check for line termination in SCPI receive data, and add a
comment in that spot. Keep related conditions together, avoid line breaks
for complex terms. This shall simplify review, and raise awareness during
maintenance. This change amends commit a0ade2f933.
2020-08-17 18:48:50 +02:00
Timo Kokkonen 4e5ff004d8 scpi_serial: Add GW-Instek GPD-9061 (USBCDC mode) VID/PID. 2020-08-17 18:35:17 +02:00
Timo Kokkonen 868fc65ec3 scpi-dmm: Add support for GW-Instek 906X series bench multimeters.
- Add support for GDM-9060 and GDM-9061 DMMs.
2020-08-17 18:35:17 +02:00
Timo Kokkonen d0b602f00f scpi-dmm: Add support for GW-Instek 8200A series bench multimeters.
- Add support for GDM-8251A and GDM-8255A DMMs.
2020-08-17 18:35:17 +02:00
Timo Kokkonen 47e7a6395e scpi: Support devices that omit serial number in *IDN? command responses. 2020-08-17 18:35:17 +02:00
Timo Kokkonen a0ade2f933 scpi_serial: Add support for (broken) devices sending NL+CR terminator.
This allows SCPI code to work with devices that terminate their responses
with NL+CR (instead of usual NL) like some GW-Instek DMMs.
2020-08-17 18:35:17 +02:00
Gerhard Sittig d7df9dc738 serial_hid: add iokit= prefix for the Mac IOKit special case
Rephrase the logic which turns HIDAPI paths returned from enumerations
into something that can be used with conn= device options. Rearrange
code paths and rename variables to hopefully increase readability, and
to prepare support for more conditions in future implementations.

Replace the "IOService:" prefix on recent Mac versions with the "iokit="
literal, to eliminate the previously unhandled colon in path names. This
resolves bug #1586.

Move the allocation of a writable buffer from the callers to the callee,
to simplify multiple call sites, and most of all because the caller need
not be aware of the buffer's required size (input and output size can
differ in either direction).

Update the conn=hid/ section in README.devices, add the iokit= prefix.
2020-08-09 16:09:04 +02:00
Gerhard Sittig 4feb6ec9a2 output/csv: complete and improve timestamp construction support
Unbreak the timestamp calculation when session data is received in
multiple packets. Avoid a division by zero when the samplerate is not
known yet the time column is requested. Only calculate timestamps when
the time column is requested. Use floating point during the scaling,
only convert to integer immediately before printing. Change line breaks
to not split a complex sub-expression across several lines.
2020-08-05 21:03:11 +02:00
Earle F. Philhower, III 01ac3eedfa output/csv: Avoid accumulated timestamp error for odd samplerates
The conversion of sample rates to sample periods and the repeated
addition of truncated values (integer variables) resulted in the
accumulation of errors in the timestamp column for odd samplerate
values. How to reproduce:

  $ sigrok-cli -d demo:analog_channels=0 \
      -c samplerate=6000000 --samples 1200001 \
      -O csv:time=true | tail

Accept the additional cost to reduce the error. Always get the timestamp
in a new calculation based on the sample number and the sample rate.

This addresses bug #1027.

Signed-off-by: Earle F. Philhower, III <earlephilhower@yahoo.com>
[ gsi: rephrased commit message, how to reprodue ]
2020-08-05 20:53:57 +02:00
Timo Kokkonen b81cfbc349 gwinstek-gpd: Add missing SW limits API calls. 2020-08-03 18:54:33 +02:00
Gerhard Sittig d579755a66 sw_limits: add const for limits param for config_get
The sr_sw_limits_config_get() routine exclusively reads the 'limits'
parameter, need not write to it. Add the 'const' attribute.
2020-08-03 17:53:11 +02:00
Gerhard Sittig 0dc27cd1db serial: make failed flush() in open() non-fatal, CP2110 flush() return
Commit cb828f1b3e introduced an unconditional flush() call in the
open() routine's body, and passed its return value in verbatim form to
open() callers. Some of the transports/cables for serial communication
yield the SR_ERR_NA return value. Consider this a non-fatal condition.

Unbreak the CP2110 HID chip's flush() implementation. Don't expect a
return value of 0 from HID write calls, instead expect to see the number
of written bytes for successful calls.

This was tested with ch9325 (UT-D04), cp2110 (UT-D09) and bu86x.
2020-08-01 14:55:20 +02:00
Timo Kokkonen 13726d30b2 gwinstek-gpd: Add support to old (hardware) revision units.
Manufacturer revised hardware design without changing model numbers at some point.
Old units have firmware that behaves differently. Responses are terminated with \r
instead of \n. And STATUS? command response format is different.
2020-08-01 07:19:49 +02:00
Timo Kokkonen 3b316fdca0 gwinstek-gpd: Add support for GPD-3303S. 2020-07-31 14:28:38 +02:00
Gerhard Sittig dc172c38d2 output/ascii: data type nits, rephrase sample bit access
Use size types for counters, unsigned for bit manipulation. Trigger
position needs to remain a signed int (must be possible to go negative
for "not here", and strictly remains within the output text line length,
so should be good).

Rephrase the nested loop during bit extraction from logic packets, and
how a channel's value at a given sample number gets accessed. Eliminate
redundancy in that spot, to improve readability and simplify maintenance.
2020-07-31 11:25:29 +02:00
Gerhard Sittig 31907b76de output/ascii: style nits in name alignment and trigger flush
Unobfuscate the implementation of the recent channel name alignment and
trigger position flush, address other style nits of earlier versions:

Don't need a GString for runtime constant channel names (which also
suffered from a mismatch of declaration and allocation). Don't need to
"construct space" when printf(3) can align the value. Pre-allocate text
buffers with more appropriate length when known in advance. Drop another
unused variable. Eliminate data type redundancy in malloc(3) calls. Make
sure to get zeroed memory, disabled channels can result in assignment
gaps. Use consistent brace style and separate variable declaration from
use (no RAII here).

Excess text line length remains, there has been a lot of it in the
previous implementation. It is left for another commit.

Tested with:

  $ sigrok-cli -d demo:analog_channels=0:logic_channels=4 --samples 40 -O ascii -t D3=r -w
2020-07-31 10:39:50 +02:00
v1ne cc835205cd output/ascii: Also print trigger marker for "short" data lines
The trigger position would be missing in the output text when the number of
available samples is less than the configured text line length. Do flush the
trigger marker for the last chunk of accumulated samples, too.

How to reproduce:

  $ sigrok-cli -d ... --samples 32 -O ascii:width=128

[ gsi: rephrased commit message ]
2020-07-31 10:30:22 +02:00
v1ne 3b93d3c24b output/ascii: Vertically align logic channel names
This results in vertical alignment of sample data and trigger positions.
The implementation assumes that the channel names' byte count corresponds
to the space which they occupy on screen. Channel names with umlauts still
may suffer from misalignment.

[ gsi: rephrased commit message ]
2020-07-31 10:24:43 +02:00
v1ne f64f51b404 output/ascii: Remove unused variable 2020-07-31 10:24:26 +02:00
milan hauth 588295b8b9 analog: avoid double free in '-O analog' shutdown path
Do void the 'def' and 'values' references for '-O analog' module options
in the shutdown path, to avoid double free calls.
2020-07-28 17:07:22 +02:00
Gerhard Sittig 9dde746023 output/srzip: improve robustness (analog-only acquisition)
For pure analog acquisition without logic data the ZIP creation code
path resulted in a division by zero. Skip the bytes to samples math in
that case. How to reproduce:

  $ sigrok-cli -d demo:logic_channels=0:analog_channels=1 --samples 20 -o file.sr

Avoid a dependency on malloc(0) behaviour while we are here. Add a
warning on data feed submitter implementation issues, to not silently
drop the data, which could surprise users. This ShouldNotHappen(TM) for
correct implementations where channel counts and unit size agree, but
was observed with incomplete out-of-tree implementations. Eliminate
a data type redundancy in another malloc() call.
2020-07-27 19:45:46 +02:00
Mike Walters 85cff5cfba scpi-dmm: Add Agilent 34410A. 2020-07-27 01:10:57 +01:00
Wolfram Sang cb828f1b3e serial: flush() after open() in the serial core.
Quite some drivers flush the serial port after opening it. And quite
some don't although they should. Factor this out, so serial_open() will
always flush the port. The removal in the drivers was done with this
small coccinelle script:

@@
struct sr_serial_dev_inst *serial;
@@

        serial_open(serial, ...)
        ... when != serial
-       serial_flush(serial);

and then the results and the unmatched findings of serial_flush() were
audited.

Signed-off-by: Wolfram Sang <wsa@kernel.org>
2020-07-26 16:06:42 +02:00
Gerhard Sittig 3b13990f7d bt: drop bt_put_le16() dependency (not universally available)
Eliminate the dependency on the non-portable bt_put_le16() routine. It
isn't available in all supported BlueZ versions, and won't be available
in other platform backends. Prefer write_u16le() which is available on
all sigrok supported platforms.
2020-07-26 10:47:59 +02:00
Gerhard Sittig f8a8d4bb70 input: use common support to send samplerate meta packet 2020-07-24 20:15:40 +02:00
Gerhard Sittig 9084c39608 input/saleae: reduce the format match routine's greed
Only return OK from the format match routine when either of the tested
conditions reliably matched. Return an error in all other cases. This
avoids that the Saleae module is "winning a contest" due to even the
weakest condition, and then is not able to handle the input file.
2020-07-24 18:40:38 +02:00
Gerhard Sittig d891892dc0 input/saleae: introduce input module for Saleae Logic exported files
Start the implementation of an input module which covers Saleae Logic's
export files. CSV and VCD are handled by other modules, this one accepts
binary exports for Logic1 digital data (every sample, and when changed),
Logic1 analog data, Logic2 digital data, and Logic2 analog data.

The newer file format versions contain header information and can get
auto-detected, the older formats require a user spec. Some of the file
formats lack essential information in the file content, thus require
another user spec (samplerate for digital data is an example).

The .logicdata file format is unknown, and is not supported. The .sal
format could get added later, but requires local file I/O in the input
module, which current common infrastructure does not provide.
2020-07-24 17:21:13 +02:00
Gerhard Sittig daa895cba3 libsigrok-internal: add endianess helpers for floating point types
Extend the common set of endianess conversion helpers. Cover readers and
writers for little endian single and double precision and 64bit integer
values, including support to advance the read/write position.
2020-07-24 17:02:40 +02:00
Gerhard Sittig dd8bec71c2 input/vcd: unbreak the logic which skips a user specified period
Rephrase the default value for the 'skip' option and the detection of a
user specified value. This is tricky because: Sample numbers are kept in
64bit values. Skip and downsample are fed to formulae so we want them
both to be unsigned. Yet absence of a user spec as well as possible user
values 0 and positive must be told apart. Use all-ones for the default
of "-1" which translates to "first timestamp", users need not be able to
specify that negative value.

Make sure to only downsample 'skip' values when the user specified some.
Which avoids the undesired insertion of huge idle gaps at the start of
the capture. An earlier implementation had to check for -1, this recent
version uses an unsigned number in combination with a boolean flag to
achieve this.

Reword some diagnostics messages, and print the samples count between
timestamps while we are here. Add a check for successful text to number
conversion of timestamp values.

How to reproduce:

  $ pulseview -i file.vcd
  $ pulseview -i file.vcd -I vcd:downsample=5
  $ pulseview -i file.vcd -I vcd:skip=111381600

Example file:

  $timescale 1 ns $end
  $scope module top $end
  $var wire 1 ! d1 $end
  $upscope $end
  $enddefinitions $end
  #111381815
  0!
  #111381905
  1!
  #111381990
  0!
  #111382075
2020-07-24 16:10:55 +02:00
Gerhard Sittig c03aaf342c output/srzip: queue samples before ZIP operation
Accumulate samples from multiple session feed packets before sending
them off to ZIP archive operations. This improves throughput for those
setups where acquisition devices or input modules provide only few
samples per session feed send call.

This version also splits large packets from applications into smaller
ZIP members (if the application's packet size is larger than the output
module's local buffer size). If that is not desired, the implementation
needs adjustment to immediately pass larger blocks to ZIP operations
(after potentially flushing previously queued data) instead of looping.

This fixes bug #974.
2020-07-24 09:13:43 +02:00
Gerhard Sittig 8c5bd3d9c7 output/vcd: support analog data, more channels, minor cleanup
Extend and rephrase the VCD output module, to support mixed signal data,
support higher channel counts, and address other minor issues.

Increase the number of VCD identifiers which can get generated. Bump the
limit from 94 to 18346 channels. Prefer single letter names for backwards
compatibility for the first channels. Use two or three letter identifiers
as needed for higher channel counts.

Add support for analog channels, and carefully organize a queue such
that timestamps and their data only get written after input data for
_all_ channels was received from the session feed. Provide IEEE754
double precision values for maximum compatibility with other VCD aware
software, although sigrok internally passes analog data with single
precision. This makes potential later adjustment transparent to external
software.

Factor out and rephrase code while we are here. This implementation
avoids glib calls where they'd hurt performance. A local pool reduces
malloc() pressure to increase throughput. String manipulation is tuned
for simplicity and reduced cost. Special code paths were added to tune
the use cases where mixed signals are not involved (immediate write to
the output text, bypassing the output module's local queue).

An srzip input implementation detail still makes the VCD output consume
lots of memory during merge sort of channels' data. See bug #1566.

Other nits got addressed in bypassing: Adjust data types. Separate the
gathering of detail information and the construction of the VCD header
text to simplify review and future maintenance. Skip VCD identifiers for
disabled channels. Emit a final timestamp to flush the last sample, and
communicate the total capture length.

Update comments. Update the copyright for recent non-trivial changes.
2020-07-24 09:10:27 +02:00
Gerhard Sittig 0ab36d2f54 input/vcd: rework VCD file import logic (vector, integer, real)
Extend and rework the VCD input module: accept more data types, improve
usability, fix known issues.

Add support for bit vectors (arbitrary width), multi-bit integer values
(absolute 64bit width limit, internal limitation to single precision),
and floating point numbers ('real' in VCD, single precision in sigrok).
Unfortunately sigrok neither has concepts of multi-bit logic channels
nor IEEE-1364 stdlogic values, the input module maps input data to
strict boolean and multiple logic channels. A vector's channels are
named and grouped to reflect their relation. VCD 'integer' types are
mapped to sigrok analog channels. Add support for scoped signal names,
and the re-use of one VCD signal name for multiple variables.

Rework file and text handling. Only skip pointless UTF-8 BOMs before
file content (not between sections). Handle lack of line termination at
the end of the input file. Process individual lines of input chunks,
avoid glib calls when they'd result in malloc pressure, and severely
degrade performance. Avoid expensive string operations in hot loops.

Rearrange the order of parse steps, to simplify maintenance and review:
end of section, new section, timestamp, data values, unsupported. Flush
previously queued values in the absence of a final timestamp. Unbreak
$comment sections in the data part. Apply stricter checks to input data,
and propagate errors. Avoid silent operation (weak warnings can go
unnoticed) which yields results that are unexpected to users. Unbreak
the combination of 'downsample' with 'skip' and 'compress'. Reduce noise
when users limit the number of channels while the input file contains
more data (keep a list of consciously ignored channels). Do warn or
error out for serious and unexpected conditions.

Address minor issues. Use common support for datafeed submission. Keep
user specified options across file re-load. Fixup data type nits, move
complex code blocks into separate routines. Sort the groups of routines,
put helpers first and concentrate public routines at the bottom. Extend
the builtin help text. Update comments, update the copyright for the
non-trivial changes.

Fixes bug #776 by adding support for bit vectors.
Fixes bug #1476 by flushing most recently received sample data.
2020-07-24 09:10:27 +02:00
Gerhard Sittig 47a102f9bb input: introduce helper for buffered submission of sample data
Input modules often find themselves in the situation where sample data
was received and could be sent to the session bus, but submission should
get deferred to reduce the number of send calls and provide larger data
chunks in these calls. Introduce common support code for buffered sample
data submission (both logic and analog), provide a simple alloc, submit,
flush, and free API.
2020-07-24 09:10:27 +02:00
Gerhard Sittig cb0fedd942 input/binary: align sr_session_send() chunks to unit size
The input/binary module chops raw input data into chunks and sends these
to the session feed. The total size of input chunks got aligned to the
unit size, the session feed output didn't. Make sure to align session
packets with the input data's unit size, too.

This fixes bug #1582.
2020-07-23 21:59:29 +02:00
Soeren Apel 5f8cf332a6 fx2lafw: Use 1 as default for frame limit and reset num_frames 2020-07-13 23:07:56 +02:00
Valentin Ochs bfc34b9ab0 fx2lafw: Add support for frames
When using a number of frames that is not 1, the driver will read
samples up to its limit and then wait for another trigger. This will be
repeated until the configured number of frames has been finished.
2020-07-13 23:07:56 +02:00
motte f5083435cb Korad-kaxxxxp: Add model Tenma 72-2550 2020-07-13 15:46:06 +02:00
Valentin Ochs 34ce4d8258 Fix #1576 by handling DSO1000B's CHAN#:PROB? responses 2020-07-12 23:30:20 +02:00
Valentin Ochs e434f624ba serial-lcr: Allow retrieving frame limit 2020-07-12 20:38:36 +02:00
Valentin Ochs 1b8a37c688 rigol-ds: Allow retrieving frame limit 2020-06-27 22:57:10 +02:00
Valentin Ochs 50bc52f3a6 hantek-dso: Allow retrieving frame limit 2020-06-27 22:56:57 +02:00
Valentin Ochs 98c7ef378c hameg-hmo: Allow retrieving frame limit 2020-06-27 22:56:39 +02:00
Valentin Ochs 7c48d434f0 gwinstek-gds-800: Allow retrieving frame limit 2020-06-27 22:56:10 +02:00
Andy Lutomirski 025bd56f10 scpi_usbtmc_libusb: Retry if a Bulk-IN request starts with an empty packet
This seems to make the Rigol DS1054Z work.  It's still a bit janky --
on a live capture, sample 688 (zero-based) out of the 1200-sample
frame seems to consistently contain garbage.  I'm not sure what's
going on.
2020-06-25 00:03:24 +02:00
Andy Lutomirski e2283318c1 scpi_usbtmc_libusb: Check that bulk in requests read the entire header
The Rigol DS1054Z sometimes returns zero bytes in response to a bulk in
request.  sigrok ends up reading out of bounds and failing ungracefully
when this happens.  Check that libusb returned a full USBTMC header and
fail gracefully if it did not.
2020-06-25 00:03:24 +02:00
Andy Lutomirski 6999029585 rigol-ds: Improve short block handling
When a short block is received, clean up the header state so that the
next block can be read.

Based on a patch for #1011 by Aleksander Alsekseev.
2020-06-25 00:03:24 +02:00
Valentin Ochs 16e96ca3af rigol-ds: Send some commands on 1st frame only
This can speed up reading of multiple segments by a factor 2 (9s vs 18s
when reading 5 frames with 2 channels and 7 kSa)
2020-06-24 23:58:17 +02:00
Valentin Ochs 06ed999aa4 rigol-ds: Experimental support for segmented data with PROTOCOL_V3 models 2020-06-24 23:56:01 +02:00
Valentin Ochs 19f31c8ace rigol-ds: Experimental support for V5 frame reading 2020-06-24 23:56:01 +02:00
Valentin Ochs 8cbe5339b1 rigol-ds: Add support for reading segmented data for protocol v4 2020-06-24 23:56:01 +02:00
Valentin Ochs 704910e32c rigol-ds: Fix reading data from internal memory
According to the programming manual, one should issue

    :WAV:RES
    :WAV:BEG

before reading data from internal memory. Without this, the wrong data
will be returned.
2020-06-24 23:56:01 +02:00
Valentin Ochs 1cbb3b1cfb rigol-ds: Get correct samplerate for Memory and Segmented sources
Read it at the start of acquisition. This prevents requests for
the SR from interfering with ongoing transfers.

This fixes bug #1217.
2020-06-24 23:56:01 +02:00
Valentin Ochs 418c99248c rigol-ds: Do not stop reading after the first frame 2020-06-24 23:56:01 +02:00
Wolfram Sang 9b09360654 std: avoid doube close
I want to fix this double-close issue I see with my OLS:

First close at the end of a 'scan':

sr: [00:00.045171] openbench-logic-sniffer: Got metadata key 0x00, metadata ends.
sr: [00:00.045178] openbench-logic-sniffer: Disabling demux mode.
sr: [00:00.045186] serial: Closing serial port /dev/ttyACM0.

Second one as part of hwdriver cleanup:

sr: [00:00.046088] hwdriver: Cleaning up all drivers.
sr: [00:00.046108] serial: Closing serial port /dev/ttyACM0.
sr: [00:00.046116] serial-libsp: Cannot close unopened serial port /dev/ttyACM0.

So, before closing a second time, check if the device is not idle.

I am optimistic this could fix bugs #1151 and #1275, too.

Signed-off-by: Wolfram Sang <wsa@kernel.org>
2020-06-24 23:20:41 +02:00
Walter Goossens 8b58a519e4 korad-kaxxxxp: Add KA3005P v5.5
Signed-off-by: Walter Goossens <waltergoossens@creative-embedded.com>
2020-06-20 21:54:07 +02:00
Wolfram Sang 35be304ba6 openbench-logic-sniffer: improve error messages when scanning ID
- always say 'ID' when the ID command failed
- print hexdump of a faulty ID because on a stalled device we may get
  0x00 bytes which would terminate the string early.

Signed-off-by: Wolfram Sang <wsa@kernel.org>
2020-06-13 23:55:34 +02:00
Florian Schmidt 3f48ab0282 kingst-la2016: improved bitstream upload and fix for v3.4.2
of vendor's bitstream.
is now tested to work with version 3.4.0 and 3.4.2.

[fixes #1559]
2020-06-08 23:49:29 +02:00
Uwe Hermann b2b6dd55ec kingst-la2016: Use ARRAY_SIZE. 2020-06-07 00:48:29 +02:00
Florian Schmidt f2cd2debf9 kingst-la2016: tested with idVendor=77a1, idProduct=01a2 2020-06-07 00:48:24 +02:00
Andreas Sandberg cae33a5874 rdtech-tc: Add initial support for the RDTech TC66C
This changeset adds support for the RDTech TC66C USB power meter.

Currently, the driver reports the following channels:
  * V: VBus voltage
  * I: VBus current
  * D+: D+ voltage
  * D-: D- voltage
  * E: Energy consumed in threshold-based recording mode.

The number of significant digits shown for each channel has been set
to match the number of digits shown on the device.

Usage example:

sigrok-cli -d rdtech-tc:conn=/dev/ttyACM0 --scan

Known issues:

  * BLE support is currently unimplemented. This uses a different
    command set, but the same poll data format.

Kudos to Ben V. Brown for reverse engineering some of the protocol and
documenting the encryption key used for poll data.

Signed-off-by: Andreas Sandberg <andreas@sandberg.pp.se>
2020-06-05 00:25:26 +02:00
Uwe Hermann 219c63ea1b src/crc.c: Add missing file. 2020-06-05 00:25:26 +02:00
Andreas Sandberg 4ea012bdf5 crc: Factor out CRC16 implementation from Modbus
Being able to calculate a CRC16 is useful in multiple places, factor
this into a new module with CRC implementation. This module currently
only supports ANSI/Modbus/USB flavor of CRC16.

Signed-off-by: Andreas Sandberg <andreas@sandberg.pp.se>
2020-06-05 00:25:26 +02:00
Andreas Sandberg 8b607a24e7 rdtech-um: Add initial support for the RDTech UMxx series
This changeset adds support for the RDTech UMxx series of USB power
meters. The driver has been tested with the RDTech UM24C, but should
support the UM24C, UM25C, and the UM34C.

Currently, the driver reports the following channels:
  * V: VBus voltage
  * I: VBus current
  * D+: D+ voltage
  * D-: D- voltage
  * T: Device temperature
  * E: Energy consumed in threshold-based recording mode.

The number of significant digits shown for each channel has been set
to match the number of digits shown on a UM24C.

Missing features:

  * There is currently no support for configuring threshold-based
    recording from sigrok, but this can be done on the device itself.

  * Fast charging mode currently not logged.

Usage example:

sigrok-cli -d rdtech-um:conn=bt/rfcomm/MAC --scan
sigrok-cli -d rdtech-um:conn=/dev/rfcomm0 --scan

Known issues:

  * When using sigrok's Bluetooth transport implementation, the device
    is disconnected between probing and sampling. Some devices (e.g.,
    the UM24C), dislikes this and can't be reconnected reliably for
    sampling. This is not an issue when setting up a rfcomm device
    manually and using it as a serial port.

Kudos to Sven Slootweg for documenting most of the protocol.

Signed-off-by: Andreas Sandberg <andreas@sandberg.pp.se>
2020-06-05 00:25:26 +02:00
Uwe Hermann ef2196712c binary_helpers: Drop unnecessary malloc check.
(as per HACKING)
2020-06-05 00:25:26 +02:00
Andreas Sandberg 18698b40d1 binary_helpers: Add helper for devices with binary data
Many devices receive a struct with binary values when polled. Many of
these values will correspond channels in sigrok. This
change introduces helper functions for automatically reading and
scaling such values and sending them down a sigrok analog channel.

Signed-off-by: Andreas Sandberg <andreas@sandberg.pp.se>
2020-06-05 00:07:30 +02:00
Andreas Sandberg 0cc3d090b7 libsigrok.h: Add SR_MQ_ENERGY 2020-06-04 23:13:43 +02:00
Gerhard Sittig cbfaf5e073 uni-t-ut181a: comment on how to start a recording
The meter allows remote controlled start of recordings, but requires a
few parameters where it's uncertain how to most appropriately get these
by means of SR_CONF_* keys.

Introduce SR_CONF_SET support for SR_CONF_DATALOG to raise awareness,
but leave the implementation empty for now. Leave a TODO comment which
discusses the meter's commands that one might want to use from here.
2020-06-01 18:35:05 +02:00
Gerhard Sittig ebc5110989 uni-t-ut181a: implement device driver for the UNI-T UT181A multimeter
Extend the previously introduced skeleton driver for UNI-T UT181A. Introduce
support for the full multimeter's protocol as it was documented by the ut181a
project. Which covers the retrieval of live readings, saved measurements, and
recordings, in all of the meter's modes and including relative, min/max, and
peak submodes. This implementation also parses compare mode (limits check)
responses, although it cannot express the result in terms of the session feed.

Announce the device as a multimeter as well as a thermometer, it supports
up to two probes including difference mode. When in doubt, prefer usability
over feature coverage (the driver side reflects all properties of the meter,
but not all features can get controlled by the driver). The probe routine
requires that users specify the serial port, and enable serial communication
on the meter.

Several TODO items remain. Comments in the driver code discuss limitations
of the current implementation, as well as cases where the meter's features
don't map well to sigrok's internal presentation. This implementation also
contains (optional, off by default) diagnostics for research on the serial
protocol.
2020-06-01 18:35:05 +02:00
Gerhard Sittig 3094e9d8ca uni-t-ut181a: Initial driver skeleton. 2020-06-01 18:35:05 +02:00
Gerhard Sittig 5cc292b34a asix-sigma: discuss usability of data pattern trigger specs
When data patterns for trigger specs span multiple bits, users may not
want to specify long lists of "<ch>=<lvl>" conditions for sigrok-cli's
--trigger option, and count channels by hand. Or click a dozen dialogs
to specify one data pattern, or modify a previous specification. Setups
with few traces may accept that, "data heavy" setups like parallel data
or address bus inspection may not.

Add comments which discuss the potential use of SR_CONF_TRIGGER_PATTERN.
Outline a syntax which may be flexible enough _and_ acceptable to users,
support data patterns and edge triggers alike, in several presentations
that serve different use cases.  This commit exclusively adds comments,
does not change behaviour.

Update a comment in the user spec to internal format trigger spec parser
to expand on hardware constraints and implementation limitations. Rename
an identifier which checks the number of edge conditions, not the number
of accepted trigger spec details.
2020-05-31 23:56:40 +02:00
Gerhard Sittig e092671365 asix-sigma: unconditionally re-enable trigger support code
Trigger support became operational again. Drop the compile time switch
which disabled the previously incomplete implementation.

This resolves bug #359.
2020-05-31 23:56:16 +02:00
Gerhard Sittig f14e6f7e1a asix-sigma: complete and extend capture mode supervision
Parse trigger specs early when acquisition starts, timeout calculation
needs to reflect on it. Either immediately start an acquisition timeout
for trigger-less configurations. Or prepare a timeout which spans the
post-trigger period, but only start its active period when the trigger
match was detected by the device's hardware.

Extend mode tracking during acquisition to handle other special cases.
Terminate acquisition when the user specified sample count limit exceeds
the hardware capacity, or when no limits were specified and the device's
memory is exhausted.

There is a slight inaccuracy in this approach, but the implementation
fails on the safe side. When both user specified limits and triggers are
involved, then at least the user specified time or sample count span is
provided. Usually more data is sent to the session feed, and all of the
requested period is covered. This is because of the software poll period
and the potential to start the timeout slightly late. As well as having
added some slack for hardware pipelines in the timeout calculation.
2020-05-31 23:53:42 +02:00
Gerhard Sittig debe1ff66d asix-sigma: download sample memory in multiple receive calls
The previous implementation ran the complete sample memory retrieval
in a single call to the receive callback. Which in combination with
slow USB communication and deep memory could block application logic
for rather long periods of time.

Rephrase the download_capture() routine such that it can spread its
workload across multiple invocations. Run the acquisition stop and
resource allocation for the download, the interpretation of a set of
DRAM lines, and the resource cleanup, as needed. And keep calling the
download routine until completion of the interpretation of the sample
memory region of interest. The workload size per invocation may need
more adjustment.

The previous implementation could stall UI progress for some 20-30s.
This change lets users perceive UI progress while sample memory gets
retrieved and interpreted.

This resolves bug #1005.
2020-05-31 23:52:24 +02:00
Gerhard Sittig 914f8160e7 asix-sigma: drop obsolete "trigger countdown" in sample interpretation
Recent commits added "position tracking" for interesting spots in the
sample stream and the current iteration pointer. Which obsoletes the
counters for remaining items until trigger, the "triggered here" flags,
as well as the unfortunate "rewind a little" workaround which lacked a
comment on its motivation or implementation details.
2020-05-31 23:51:23 +02:00
Gerhard Sittig 8a72362505 asix-sigma: re-enable software check for exact trigger position
The hardware provided trigger match location is inaccurate. Do check
sample values against the initial trigger condition spec for a short
range of the retrieved sample data, to refine the trigger marker's
position which is sent to the session feed.

Temporarily ignore the optional sample count limit for trigger-using
acquisitions, to reduce the diff size and simplify review. Since the
hardware transparently compresses sample data, we cannot reliably
determine where to start the download and interpretation of sample data,
and the submission to the session feed. Starting early in the sample
memory content, and sticking with the strict sample count limit, could
clip submission before the actual trigger position.

This implementation provides _at least_ the requested amount of data,
and does cover the spot of interest (the trigger position). This, and
the trigger support's having become operational again, is considered an
important improvement. The inaccuracy is considered acceptable for now.
Trigger-less acquisition does enforce the exact sample count limit.
2020-05-31 23:49:35 +02:00
Gerhard Sittig 66d1790cc0 asix-sigma: rephrase sample memory iteration position and trigger check
Rephrase how the sample memory iteration position gets tracked, increment
after every event slot already. Update the "last seen sample" status more
often (an event slot can hold several sample items). Arrange for a period
of time where software will check sample data for trigger matches. This
improves the precision of the hardware provided trigger match location.

Do send hardware provided trigger locations to the session feed even if
the software check found no match on the data content. This covers user
initiated button presses (which can unblock the acquisition when the
application provided trigger condition never matches).

Note that this implementation does manage the window of supervision, but
does not yet check the sample values against the trigger condition. This
gets added later.
2020-05-31 23:46:21 +02:00
Gerhard Sittig 16a5d5ac7d asix-sigma: rework outer sample download loop (DRAM lines iteration)
Factor USB data transfer out of the code path which interprets sample
memory content. Keep internal state of sample memory download in the
device context. This eliminates local variables, and ideally allows a
future implementation to spread chunked downloads across several read
callbacks, which would improve UI responsiveness.

Update comments while we are here. Address minor portability nits (ull
suffix vs UINT64_C macro). The inner loops (iterating clusters and their
events which contain individual samples) are not affected by this commit.
2020-05-31 23:45:29 +02:00
Gerhard Sittig 1385f791b0 asix-sigma: more trigger LUT download rephrase, think 16bit entities
Further rephrase the sigma_write_trigger_lut() routine. It's helpful to
"think" in BE16 quantities to improve readability of LUT address and
parameter downloads. Better matches the vendor's documentation. Also use
a better name for the "trigger select 2" register content.
2020-05-31 23:44:56 +02:00
Gerhard Sittig ee5cef7103 asix-sigma: concentrate more sample memory interpretation params
Start moving parameters into the device context which are related to the
interpretation of sample memory content. This can simplify error paths,
allow to release resources late. And ideally sample memory download and
interpretation could spread across several receive callbacks, improving
UI responsiveness. Also makes total and current dimensions available to
deeper nesting levels in the interpretation, which currently don't have
access to these details.
2020-05-31 23:44:29 +02:00
Gerhard Sittig de4c29fa91 asix-sigma: concentrate parameters for sample memory interpretation
Create a sub struct in the device context which keeps those parameters
which are related to sample memory interpretation. Which also obsoletes
the 'state' struct and only leaves the 'state' enum as a remainder.

Use the "samples per event" condition instead of the samplerate when
extracting a number of samples from an event's storage. Rename the
de-interleaving routines to better reflect their purpose.
2020-05-31 23:44:09 +02:00
Gerhard Sittig ea57157d0d asix-sigma: force strict boolen arith in LUT item manipulation
Mechanically adjust the add_trigger_function() routine to address nits,
attempt to improve maintainability.

Raise awareness of the fact that strict binary arithmetics is done (bit
operators are used), the strict 0..1 set of values needs to be enforced,
and mere "logical truthness" is not good enough in this spot. Explicitly
check for bit positions instead of "shifting out" the bit of interest
and have the 0/1 value result nearly by coincidence.

Extend comments. Group related instructions and separate them from other
groups. Reduce the scope of the rather generic i, j, tmp named variables
which are just too easy to get wrong.
2020-05-31 23:43:17 +02:00
Gerhard Sittig 3f5f548410 asix-sigma: use more helpers for bit mask creation
Rename macros to better reflect which of them check a bit position, and
which span a bit field of given width. Adjust more call sites to use the
macros. This takes tedium out of maintenance as well as review. Has the
minor benefit of somewhat shortening text lines, and eliminating nested
parentheses (or getting perceived as if it would).
2020-05-31 23:42:53 +02:00
Gerhard Sittig 156b6879e9 asix-sigma: rephrase limits management, use sub structure
Move the acquisition limits related variables into a sub struct within
the device context. Over time they became numerous, and might grow more
in the future.
2020-05-31 23:42:32 +02:00
Gerhard Sittig fb65ca09b7 asix-sigma: track whether triggers were specified when acquisition started
There are several separate conditions which the driver needs to tell
apart. There is a compile time switch whether trigger support shall be
built in. There is the condition whether acquisition start involved a
user provided trigger spec. And there is the hardware flag whether a
previously configured trigger condition matched and where its position
is.

Only accept user provided trigger specs when trigger support is builtin.
(The get/set/list availability and spec passing is done in applications
outside of the library, we better check just to make sure.) Only setup
the trigger related hardware parameters when a spec was provided. Only
check for trigger positions when the hardware detected a match.
2020-05-31 23:41:40 +02:00
Gerhard Sittig 8a57728d0e asix-sigma: enable trigger support code (development HACK)
Enable the compile time option which builds trigger support code into
the asix-sigma driver. This is a development hack. Trigger support in
the driver is incomplete and currently not operational.
2020-05-31 23:41:23 +02:00
Gerhard Sittig 3d9373af2e asix-sigma: data type nits, minor variable renames
Address remaining data type nits. Use more appropriate types for sizes
and counters and indices, as well as for booleans.

Prefer more verbose variable names in a few spots to avoid the rather
generic 'i' symbol, especially in complex code paths with deeply nested
flow control or with long distances between declaration and use. Re-use
an existing buffer in the acquisition start for command sequences which
setup trigger in/out as well as clock parameters.

Introduce some variables which may seem unnecessary. But these are
useful for research during maintenance.

This is a mechanical adjustment, behaviour does not change.
2020-05-31 23:41:06 +02:00
Gerhard Sittig 53c8a99c41 asix-sigma: prepare configuration re-use across sigrok sessions
Introduce the required infrastructure to store successfully applied
configuration data in hardware registers. This lets the probe phase of
the next sigrok session pick up where the previous session left. Which
improves usability, and increases performance by eliminating delays in
the acquisition start, by not repeating unnecessary firmware uploads.

The vendor documentation suggests there would be FPGA registers that are
available for application use ("plugin configuration"). Unfortunately
experiments show that registers beyond address 0x0f don't hold the data
which was written to them. As do unused registers in the first page. So
the desirable feature is not operational in this implementation. There
could be different netlist versions which I'm not aware of, or there
could be flaws in this driver implementation. This needs more attention.
2020-05-31 23:40:19 +02:00
Gerhard Sittig 8bd4dc8799 asix-sigma: nits in the hardware configuration declaration
Stop assuming that C language variables whould have a specific memory
layout that applications could rely on. Use normal data types in higher
abstraction layers, drop non-portable bit fields. Use existing macros
for the creation of bit masks of a given width.
2020-05-31 23:39:55 +02:00
Gerhard Sittig 17ed72cc44 sw_limits: start msec timeout period only after start() call
When application code used the common SW limits API, the call sequence
of init() then set() then check() already kept expiring, which is rather
unexpected. The timeout period should only start when start() is called,
check() should not signal expiration before the start() call.

The specific use case is the combination of an msecs timeout and capture
ratio when triggers are used. The post-trigger period only starts when
the trigger match was seen, even though its length is already known when
the acquisition starts. It's desirable to run the start() call for the
post-trigger timeout late, and not terminate the acquisition before the
trigger match.
2020-05-31 23:39:28 +02:00
Gerhard Sittig dbb3e2ad3d serial: accept bitrate only serialcomm= spec, default to 8n1 frames
The previous implementation considered both the UART bitrate and the
frame format mandatory, users had to specify "/8n1" as well just to
change the bitrate.

This commit makes the frame format optional, and defaults to 8n1 which
is so popular these days. When specified, the frame format still needs
to preceed the other optional flow and handshake flags, for maximum
backwards compatibility, and equal robustness in the process of parsing
serialcomm= specs.

Unfortunately device drivers cannot specify their preferred or default
UART frame format. Which means that users still need to provide these
when a device does not use 8n1. This is not a regression, the previous
implementation always needed the frame format spec.
2020-05-31 23:39:19 +02:00
Gerhard Sittig 7718f3ca8f asix-sigma: update comment on channel names (vendor doc says "1-16")
Eliminate doubt from a comment on ASIX SIGMA's channel names which was
introduced in commit d261dbbfcc. Publicly available documentation does
agree their names start at "1" and go up to "16".
2020-05-29 08:06:18 +02:00
Gerhard Sittig 2d8a508976 asix-sigma: add support for external clock
The 50MHz netlist supports the use of an external clock. Any of the 16
channels can use any of its edges to have another sample taken from all
the other pins. It's nice that the hardware does track timestamps, which
results in an exact reproduction of the input signals' timing with 20ns
resolution, although the clock is externally provided and need not have
a fixed rate.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 16791da9c9 asix-sigma: more trigger spec to register values conversion sync with doc
Rephrase more parts of sigma_build_basic_trigger() to closer match the
vendor documentation. Use the M3Q name. Be explicit about "parameters"
setup (even if that means to assign zero values, comments help there).
Using three BE16 items for the parameters improves readability.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 7dd766e0aa asix-sigma: rephrase trigger LUT creation (mechanical change)
Rephrase the sigma_build_basic_trigger() and build_lut_entry() routines
to hopefully improve readability. Avoid the use of short and generic
identifiers which are just too easy to confuse with each other and the
1 literal and negation operator in deeply nested loops and complex
expressions that span several text lines. Reduce indentation where
appropriate. Concentrate initialization and use of variables such that
reviewers need less context for verification.

This is a purely mechanical change, the function of triggers remains
untested for now. Setting "selres" in that spot is suspicious, too.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 72ea3b84bd asix-sigma: rephrase trigger LUT upload to hardware for readability
Rephrase the sigma_write_trigger_lut() routine to work on "a higher
level" of abstraction. Avoid short and most of all generic variable
names. Use identifiers that are closer to the vendor documentation.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 0f017b7da9 asix-sigma: rephrase and extend register access for readability
Reduce the probability of errors during maintenance, and also increase
readability. Replace open coded nibble extraction and bit positions by
accessor helpers and symbolic identifiers. Adjust existing math where it
did not match the vendor documentation. Always communicate 8bit register
addresses, don't assume that application use remains within a specific
"page". Provide more FPGA register access primitives so that call sites
need not re-invent FPGA command sequence construction. Remove remaining
open coded endianess conversion in DRAM access.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 419f109505 asix-sigma: rephrase firmware dependent param upload at acquisition start
The 100/200MHz supporting FPGA netlists differ in their register set
from 50MHz netlists. Adjust the parameter download at acquisition start.

Raise awareness of the "TriggerSelect" and "TriggerSelect2" difference
(the former only exists in 50MHz netlists, the latter's meaning differs
between firmware variants). "ClockSelect" semantics also differs between
netlists. Stop sending four bytes to a register that is just one byte
deep, channel selection happened to work by mere coincidence.

Eliminate a few more magic numbers, unobfuscate respective code paths.
Though some questions remain (trigger related, not a blocker for now,
needs to get addressed later).
2020-05-29 08:06:18 +02:00
Gerhard Sittig abcd477196 asix-sigma: keep remaining samplerate handling in protocol.c
Make the list of supported samplerates an internal detail of the
protocol.c source file. Have the api.c source file retrieve the list
as well as the currently configured value by means of query routines.

Ideally the current rate could get retrieved from hardware at runtime.
A future driver implementation could do that. This version sticks with
the lowest supported rate, as in the previous version.
2020-05-29 08:06:18 +02:00
Gerhard Sittig a426f74aca asix-sigma: cosmetics, sort protocol.h function groups
Sort "semi public" routines and "global data" of the asix-sigma driver
in the protocol.h header file by their use. Add comments. This improves
maintenance of the driver source.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 7fe1f91f75 asix-sigma: prepare FTDI open/close for "optional open"
Move all of the FTDI connection handling from api.c to protocol.c, and
prepare "forced" and "optional" open/close. This allows future driver
code to gracefully handle situations where FPGA registers need to get
accessed, while the caller may be inside or outside the "opened" period
of the session. This is motivated by automatic netlist type and sample
rate detection, to avoid the cost of repeated firmware uploads.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 88a5f9eabe asix-sigma: improve error propagation, increase robustness
Detect more error conditions, and unbreak those code paths where wrong
data was forwarded. It's essential to tell the USB communication layer,
sigrok API error codes, and glib mainloop receive callbacks apart. Since
the compiler won't notice, maintainers have to be extra careful.

Rephrase diagnostics messages. The debug and spew levels are intended
for developers, but the error/warn/info levels will get presented to
users, should read more fluently and speak from the application's POV.
Allow long text lines in source code, to not break string literals which
users will report and developers need to search for (this matches Linux
kernel coding style).

This commit also combines the retrieval of sample memory fill level,
trigger position, and status flags. Since these values span an adjacent
set of FPGA registers. Which reduces USB communication overhead, and
simplifies error handling. The helper routine considers the retrieval
of each of these values as optional from the caller's perspective, to
simplify other use cases (mode check during acquisition, before sample
download after acquisition has stopped).

INIT pin sensing after PROG pin pulsing was reworked, to handle the
technicalities of the FTDI chip and its USB communication and the FTDI
library which is an external dependency of this device driver. Captures
of USB traffic suggest that pin state is communicated at arbitrary times.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 5c231fc466 asix-sigma: style nits, expression complexity, information locality
Address minor style nits to improve readability and simplify review. The
sizeof() expressions need not duplicate data type details. Concentrate
the assignment to, update of, and evaluation of variables in closer
proximity to reduce potential for errors during maintenance. Separate
the gathering of input data and the check for their availability from
each other, to simplify expressions and better reflect the logic's flow.
2020-05-29 08:06:18 +02:00
Gerhard Sittig 9334ed6ccd asix-sigma: update copyright notice for recent non-trivial changes 2020-05-29 07:50:33 +02:00
Gerhard Sittig 2a62a9c44e asix-sigma: more u16 sample memory access nits (timestamps, values)
Further "flatten" the DRAM layout's declaration for sample data. Declare
timestamps and sample data as uint16_t, keep accessing them via endianess
aware conversion routines. Accessing a larger integer in smaller quantities
is perfectly fine, the inverse direction would be problematic.
2020-05-29 07:50:33 +02:00
Gerhard Sittig a53b8e4d74 asix-sigma: improve robustness of parameter upload to hardware
Keep application data in its logical presentation in C language struct
fields. Explicitly convert to raw byte streams by means of endianess
aware conversion helpers. Don't assume a specific memory layout for
C language variables any longer. This improves portability, and
reliability of hardware access across compiler versions and build
configurations.

This change also unobfuscates the "disabled channels" arithmetics in
the sample rate dependent logic. Passes read-only pointers to write
routines. Improves buffer size checks. Reduces local buffer size for
DRAM reads. Rewords comments on "decrement then subtract 64" during
trigger/stop position gathering. Unobfuscates access to sample data
after download (timestamps, and values). Covers a few more occurances
of magic numbers for memory organization.

Prefer masks over shift counts for hardware register bit fields, to
improve consistency of the declaration block and code instructions.
Improve maintenability of the LA mode initiation after FPGA netlist
configuration (better match written data and read-back expectation,
eliminate magic literals that are hidden in nibbles).
2020-05-29 07:50:33 +02:00
Gerhard Sittig 9b4d261fab asix-sigma: style nits, devc in routine signatures, long text lines
Move the 'devc' parameter to the front in routine signatures for the
remaining locations which were not adjusted yet. Reduce indentation of
continuation lines, especially in long routine signatures. Try to not
break string literals in diagnostics messages, rephrase some of the
messages. Massage complex formulae for the same reason.

Whitespace changes a lot, word positions move on text lines. See a
corresponding whitespace ignoring and/or word diff for the essence of
the change.
2020-05-29 07:50:23 +02:00
Gerhard Sittig b65649f6b9 asix-sigma: reword list of sample rates, (try to) use 1/2/5 steps
The driver got extended in a previous commit to accept any hardware
supported samplerate in the setter API, although the list call does
suggest a discrete set of rates (a subset of the hardware capabilities).
Update a comment to catch up with the implementation.

Drop the 250kHz item, it's too close to 200kHz. Add a 2MHz item to
achieve a more consistent 1/2/5 sequence in each decade. Unfortunately
50MHz and an integer divider will never result in 20MHz, that's why
25MHz is an exception to this rule (has been before, just "stands out
more perceivably" in this adjusted sequence).
2020-05-29 07:50:18 +02:00
Gerhard Sittig c749d1ca57 asix-sigma: improve robustness of firmware download, delay and retry
Running several firmware uploads in quick repetition sometimes failed.
It's essential to stop the active netlist from preventing the FPGA's
getting reconfigured (FTDI to FPGA pins are so few, and shared). Delays
in a single iteration of the initiation sequence improves reliability.
Retries of the sequence are belt and suspenders on top of that.

Before the change, failure to configure was roughly one in ten. After
the change, several thousand reconfigurations passed without failure.
2020-05-29 07:50:18 +02:00
Gerhard Sittig 80e717b3cf asix-sigma: eliminate magic numbers in firmware file references
Use symbolic identifiers to select firmware images, which eliminates
magic 0/1/2 position numbers in the list of files, improves readability
and also improves robustness. Move 'devc' to 'ctx' and before other
arguments in routine signatures while we are here.
2020-05-29 07:50:18 +02:00
Gerhard Sittig 1bb9dc8217 asix-sigma: mark FPGA config phase in "state" of dev context
FPGA configuration (netlist upload) of ASIX SIGMA devices is rather
special a phase, and deserves its own state in the device context's
"state" tracking. Not only is the logic analyzer not available during
this period, the FTDI cable is also put into bitbanging mode instead
of regular data communication in FIFO mode, and netlist configuration
takes a considerable amount of time (tenths of a second).
2020-05-29 07:50:18 +02:00
Gerhard Sittig 5e78a56481 asix-sigma: rework time/count limits support, accept more samplerates
Use common support for SW limits, and untangle the formerly convoluted
logic for sample count or time limits. Accept user provided samplerate
values when the hardware supports them, also those which are not listed.

The previous implementation mapped sample count limits to timeout specs
which depend on the samplerate. The order of applications' calls into
the config set routines is unspecified, the use of one common storage
space led to an arbitrary resulting value for the msecs limit, and loss
of user specified values for read-back.

Separate the input which was specified by applications, from limits
which were derived from this input and determine the acquisition phase's
duration, from sample count limits which apply to sample data download
and session feed submission after the acquisition finished. This allows
to configure the values in any order, to read back previously configured
values, and to run arbitrary numbers of acquisition and download cycles
without losing input specs.

This commit also concentrates all the limits related computation in a
single location at the start of the acquisition. Moves the submission
buffer's count limit container to the device context where the other
limits are kept as well. Renames the samplerate variable, and drops an
aggressive check for supported rates (now uses hardware constraints as
the only condition). Removes an unused variable in the device context.
2020-05-29 07:50:18 +02:00
Gerhard Sittig 98b43eb3cd asix-sigma: rephrase submission of logic data to session feed
Introduce a 4MiB session feed submission buffer in the device context.
This reduces the number of API calls and improves performance of srzip
archive creation.

This change also eliminates complex logic which manipulates a previously
created buffer's length and data position, to split the queued data when
a trigger position was involed. The changed implementation results in a
data flow from sample memory to the session feed which feels more natural
during review, and better lends itself to future trigger support code.

Use common SW limits support for the optional sample count limit. Move
'sdi' and 'devc' parameters to the front to match conventions. Reduce
indentation in routine signatures while we are here.

This implementation is prepared to handle trigger positions, but for now
disables the specific logic which checks for trigger condition matches
to improve the trigger marker's resolution. This will get re-enabled in
a later commit.
2020-05-29 07:50:18 +02:00
Gerhard Sittig 2c33b09255 asix-sigma: eliminate magic numbers in sample memory access
Add more symbolic identifiers, and rename some of the existing names for
access to SIGMA sample memory. This eliminates magic numbers and reduces
redundancy and potential for errors during maintenance.

This commit also concentrates DRAM layout related declarations in the
header file in a single location, which previously were scattered, and
separated registers from their respective bit fields.

Extend comments on the difference of events versus sample data.
2020-05-29 07:50:18 +02:00
Gerhard Sittig 7c41c420aa asix-sigma: move FPGA commands before register layout declaration
Move the FPGA commands (which can access registers, and sample memory)
declarations before the register layout declaration. Which then no
longer separates the registers declarations from their bit fields.
Update comments on the register set while we are here.
2020-05-29 07:50:18 +02:00
Gerhard Sittig 07411a605e asix-sigma: rephrase some of the FPGA command exchange
Eliminate a few magic numbers in FPGA commands, use symbolic identifiers
for automatic register address increments, and DRAM access bank selects.
Improve grouping of related declarations in the header file.
2020-05-29 07:49:58 +02:00
Gerhard Sittig 9fb4c6324d asix-sigma: sync FPGA register names with documentation
Rename source code identifiers for FPGA registers to closer match the
vendor's documentation.
2020-05-29 07:49:58 +02:00
Gerhard Sittig dc0906e21c asix-sigma: eliminate magic numbers in FPGA configuration
Slightly rephrase and comment on the FPGA configuration of the ASIX
SIGMA logic analyzer. Use symbolic pin names to eliminate magic numbers.
Concentrate FPGA related comments in a single spot, tell the Xilinx FPGA
from FTDI cable (uses bitbang mode for slave serial configuration).

This fixes typos in the PROG pulse and INIT check (tests D5 and comments
on D6). Also removes the most probably undesired 100s timeout in the
worst case (100M us, 10K iterations times 10ms delay). Obsoletes labels
for error paths. Drops a few empty lines to keep related instruction
blocks together. Includes other style nits.
2020-05-29 07:49:58 +02:00