Gerhard Sittig [Fri, 13 Jan 2017 18:44:26 +0000 (19:44 +0100)]
ols: also reflect successful identify response in diagnostics
The ols driver's scan() routine used to present the identification
response to users when the scan failed, but would not when the scan
succeeded.
Since multiple response literals are supported, it's considered useful
to see these, too, in case of successful device detection. Emit debug
messages for developers' awareness.
Gerhard Sittig [Sun, 21 Aug 2022 11:36:29 +0000 (13:36 +0200)]
resource: add support for SIGROK_FIRMWARE_PATH env variable
The optional SIGROK_FIRMWARE_DIR environment variable accepts a single
directory specification. The SIGROK_FIRMWARE_PATH variable accepts a
list of directories to search firmware images. The list separator is
platform dependent (colon or semicolon). Empty items are explicitly
ignored. Both variables get evaluated. Behaviour remains backwards
compatible, just gets extended for increased usability.
Gerhard Sittig [Tue, 18 Jun 2019 16:36:29 +0000 (18:36 +0200)]
usb: move connection string parsing out of USB enumeration/search
The sr_usb_find() routine inspects an input specification in textual
format, as well as scans for USB devices that match the caller specified
address. Factor out the text parsing including range checks for address
numbers. This part of the source code also does not depend on the libusb
library's availability.
Adjust the sr_usb_find() routine's data types for result variables. This
commit changes user visible diagnostics messages, since text parsing and
USB device lookup happen in distinct locations and don't share knowledge.
Gerhard Sittig [Sun, 28 Oct 2018 09:45:42 +0000 (10:45 +0100)]
input/wav: undo "create channels once" workaround
Undo the essence of commit 9e850040db5c which added a workaround to
create sigrok channels only once, and keep reusing them across every
file import (without checking details). Which was obsoleted by the
recent channel list check on file re-load, including proper response
when essential file properties have changed.
Indentation changes. See a whitespace ignoring diff for the essence.
Gerhard Sittig [Sun, 28 Oct 2018 09:45:42 +0000 (10:45 +0100)]
input/wav: add channel list checks for file re-read
Do for the WAV input module what commit 08f8421a9e82 did for VCD. Check
the channel list for consistency across re-imports of the same file.
This addresses the WAV part of bug #1241.
This commit also changes the WAV module's reset() method's behaviour.
The previous implementation only created channels once, and re-used that
channel list when the file got re-read. Which could cause issues when
the file's properties changed between re-runs. This implementation
always creates the channel list upon every file import, and ensures a
consistent channel list across re-imports. This follows the approach
that was taken in all other input modules before.
Gerhard Sittig [Tue, 17 Dec 2019 11:57:52 +0000 (12:57 +0100)]
drivers: update comment on "driver list" linker section
Update and slightly extend the comment on the "__sr_driver_list"
linker section which holds a list of all drivers which were built
into the libsigrok library.
Gerhard Sittig [Mon, 17 May 2021 20:14:50 +0000 (22:14 +0200)]
dmm/bm86x: check more bytes in DMM packet (undocumented by vendor)
User johnch reported via IRC that bm86x meters can lose sync to the
packet stream which goes unnoticed and tries to process invalid data.
Tighten the packet validity check, compare four bytes of the third chunk
in the DMM packet. This improves reliability, but isn't backed by vendor
documentation. It's yet to get determined whether other existing devices
don't provide the four-byte magic pattern.
Gerhard Sittig [Thu, 20 May 2021 21:46:17 +0000 (23:46 +0200)]
scpi-dmm: add "switch to local" support for Agilent protocol
Send "SYST:LOC" to Agilent protocol speaking scpi-dmm devices at the end
of the probe (--scan) as well as in close (--show, --samples, etc). This
ends "remote" and re-enters "local" mode after programmatic use. Should
increase usability, eliminates the need for manual intervention before
subsequent DMM use. Was tested with a Keysight DMM. Does not affect the
HP protocol speaking devices.
Gerhard Sittig [Thu, 19 Jul 2018 19:17:16 +0000 (21:17 +0200)]
strutil: avoid glib/platform conversion calls for empty input
It appears that either glib or some underlying platform library code for
text to number conversion yields unexpected values for return codes,
errno, and "end pointer" when _none_ of the input could get converted.
This was reported for MacOS, did not reproduce on Linux. The reported
issue was addressed in commit 51bf39a1633c, this implementation is just
much more conservative and hopefully easier to verify since it's more
explicit.
Rephrase the rational text to number conversion to avoid the problematic
input cases. Address style nits while we are here in the hope to improve
readability: Move initial assignment and subsequent updates of variables
closer together for easier verification.
Accept optional leading whitespace. Accept numbers like "123." in
addition to the previously supported ".123" formats. But insist that one
of the integral or fractional parts must be present. Try harder to setup
non-zero errno values for other failed conversion attempts beyond failed
library calls (the strtol(3) manpage suggests so in the ERRORS section).
This implementation passes on Linux, but has not been tested with MacOS
which appears to have a pickier library implementation.
Gerhard Sittig [Tue, 16 Aug 2022 20:17:45 +0000 (22:17 +0200)]
device: don't accept empty names for sigrok channels
It's unexpected when sigrok channels "have no name". Previous versions
would not strictly enforce non-empty names and could let empty names
slip in, but application code was reported to be confused when it
happened. The benefit of having channels "with no names" is questioned.
Adjust the public API routines. Accept missing name specs in the
sr_channel_new() routine for maximum backwards compatibility. Reject
missing names in sr_dev_channel_name_set() so that empty or non-empty
names can only be replaced by non-empty names. Check the return code of
sr_channel_new() in sr_dev_inst_channel_add() so that failed channel
creation gets propagated to callers. The current implementation will
never fail sr_channel_new(), but future versions might.
None of libsigrok code (device drivers, input modules) assign empty
names to channels. Applications still need to get checked. A future
commit might make names in sr_channel_new() mandatory.
Gerhard Sittig [Tue, 9 Aug 2022 16:05:49 +0000 (18:05 +0200)]
dmm/bm52x: silence compiler warning related to printf() buffer size
Increase another text buffer's size to cover the maximum length that an
integer could occupy in theory. Which amends commit 46a36bf0bb2e.
The previous implementation did not suffer from any issue, we know the
number of recordings in the BM52x DMM to remain small. This change only
silences a compiler warning, doesn't change the parser's behaviour.
Gerhard Sittig [Sat, 11 Jun 2022 14:21:40 +0000 (16:21 +0200)]
README.devices: explicitly discuss serial-over-HID in the UNI-T section
This amends commit f736691d1323. Explictly mention that USB cables for
UNI-T devices and rebrands transparently work with libsigrok's serial
communication over HID cables. Mention that uni-t-dmm is redundant.
Gerhard Sittig [Sun, 3 Apr 2022 18:09:18 +0000 (20:09 +0200)]
README.devices: add an UT-D04 on Windows section (libwdi and hidapi)
A user reported that the Windows driver which is assigned to the CH9325
based UT-D04 cable neither provides a genuine serial port nor shows up
in the sigrok enumeration which additionally uses HIDAPI. Mention that
assigning a different Windows driver can help in that case.
Gerhard Sittig [Wed, 30 Mar 2022 06:06:22 +0000 (08:06 +0200)]
README.devices: add Windows and Zadig discussion near the udev section
Add a section on Windows and device driver assignments by means of Zadig
after the section on Linux udev rules and permissions. Reference the
wiki page for the Windows platform.
Gerhard Sittig [Mon, 14 Feb 2022 20:30:14 +0000 (21:30 +0100)]
configure.ac: consider libusb_os_handle absence non-fatal on Windows
Keep checking for the libusb_os_handle data type's presence, but don't
consider its absence on Windows fatal. Recent mainline libusb provides
something similar to the event abstraction branch under the common API.
Assume that it's the integrators' or packagers' responsibility to either
use a recent library or a patched older library for sigrok builds.
All other non-Windows platforms remain unaffected, the presence check
never was fatal there. The data type check itself needs to remain in
place because the usb.c source code adjusts to its presence.
Gerhard Sittig [Tue, 21 Dec 2021 15:25:26 +0000 (16:25 +0100)]
hp-3478a: use symbolic name for status register bit field
The hp_3478a_receive_data() routine uses SPOLL to only communicate
measurement data when they have become available. Use a symbolic name
for the tested bitfield for consistency with other driver locations
and for improved readability.
Gerhard Sittig [Mon, 21 Feb 2022 20:45:18 +0000 (21:45 +0100)]
kingst-la2016: cope with 800MHz base clock for 500MHz models
The LA5016 uses an 800MHz base clock to derive the samplerate from. And
communicates divider 1 to configure the 500MHz rate. And does support
the 200MHz rate (divider 4). Which also makes the 10kHz lower boundary
unavailable on some models. Update the capture configuration logic, the
config API routines, and associated comments. Discuss how streaming may
make finer grained rates tables desirable (but stick with 1/2/5 for now).
Gerhard Sittig [Mon, 21 Feb 2022 20:43:16 +0000 (21:43 +0100)]
kingst-la2016: zero pad FPGA bitstream to 4KiB boundaries
The 2KiB padding worked for LA2016 but kept looking susipcious. Pad the
FPGA bitstream to 4KiB boundaries, which unbreaks LA5016 and still works
with LA2016.
Gerhard Sittig [Mon, 7 Feb 2022 18:42:19 +0000 (19:42 +0100)]
kingst-la2016: introduce base clock independent from max samplerate
The LA1010 devices are said to use an 800MHz base clock to derive the
samplerate of up to 100MHz from. Add this information to the list of
known devices, and adjust the samplerate dividier code path.
Keep value 0 in that column for all devices where the base clock and the
maximum samplerate are identical. For awareness during maintenance. Make
the untypical devices stand out.
Gerhard Sittig [Mon, 7 Feb 2022 17:52:20 +0000 (18:52 +0100)]
kingst-la2016: add more device types and their EEPROM magic numbers
Extend the EEPROM content check which identifies device types. Inspect
the full set of four bytes before falling back to weaker checks of two
bytes per copy. Prefer the longest run of consistent data that is found
first. Some devices are said to require inspection of byte[2] in
addition to byte[0], to tell different models apart which share the
same byte[0] value.
This was exclusively tested on LA2016 hardware. The details were derived
from the https://github.com/AlexUg/sigrok implementation (which claims
support for LA1010, the LA50xx details may be untested there as well).
The model database also includes items which are not supported by this
driver implementation, to provide the maximum amount of information to
users which became available during scan.
Gerhard Sittig [Sat, 12 Feb 2022 14:00:44 +0000 (15:00 +0100)]
tests: address printf format issues, spotted by clang on macos
The sr_rational data type has int64_t and uint64_t members, but analog.c
and strutil.c source code used "%ld" and "%lu" formats. Use PRIu64 et al
instead.
.../libsigrok/tests/strutil.c:125:14: warning: format specifies type 'long' but the argument has type 'int64_t' (aka 'long long') [-Wformat]
input, rational.p, rational.q);
^~~~~~~~~~
/usr/local/Cellar/check/0.15.2/include/check.h:472:77: note: expanded from macro 'fail_unless'
_ck_assert_failed(__FILE__, __LINE__, "Assertion '"#expr"' failed" , ## __VA_ARGS__, NULL)
^~~~~~~~~~~
Also make test stimulus static. It's a constant vector of literals and
is exclusively used in the test routine, need not occupy stack space.
Gerhard Sittig [Sun, 20 Feb 2022 07:10:33 +0000 (08:10 +0100)]
kingst-la2016: comment on FPGA register at offset 0x0004 (unused)
The vendor firmware optionally keeps reading u32 values from the FPGA
register at offset 0x0004 outside of acquisition periods. To present
the input pin's current level and changes "in real time" in the GUI.
The sigrok driver does not use this information, but it's useful to
have the comment in the source code.
Gerhard Sittig [Sun, 20 Feb 2022 10:36:43 +0000 (11:36 +0100)]
kingst-la2016: stop acquisition when USB device was lost
Check for the condition when the USB device has gone away in the middle
of getting communicated to. Terminate acquisition in that case, instead
of trying to continue.
Gerhard Sittig [Sun, 20 Feb 2022 09:06:09 +0000 (10:06 +0100)]
kingst-la2016: add support for streaming mode, works for 16 channels
Implement support for streaming mode and announce the SR_CONF_CONTINUOUS
config key. Automatically enable streaming mode for devices which don't
have local memory. Device identification, firmware download, and capture
setup are identical to "normal mode" as the vendor calls it. But the
sequence of submitting USB transfers by the host and starting capture
data transmission on the device differs. The phase of supervising the
hardware driven acquisition does not apply. Capture data is immediately
streamed to the host after initiating the acquisition.
The capture data memory layout dramatically differs. Samples are not
compressed, and samples taken at several points in time are kept in the
same memory cell. Processing is a little more expensive, bits need more
shuffling. Lack of compression makes the acquisition in stream mode
heavily depend on the reliability of USB bulk communication. The vendor
software assumes a 300Mbps boundary, and also enforces it by disabling
channels depending on the samplerate. The sigrok driver accepts any user
specified configuration, and merely warns for high amounts of traffic.
Local tests successfully communicated 320Mbps. Slow samplerates result
in slow arrival of more sample data, which periodically gets flushed to
improve usability. Thresholds when to start pushing may need tuning.
This implementation was tested with LA2016 and up to 16 channels. Other
devices are untested, especially LA1010 which lacks local memory and
thus exclusively supports streaming, and devices with 32 channels where
capture data memory layout may differ from devices with 16 channels (yet
to get verified).
Gerhard Sittig [Sun, 20 Feb 2022 08:32:14 +0000 (09:32 +0100)]
kingst-la2016: experiment with USB bulk size and pool count
The previous implementation used a pool of 32 USB bulk transfers of up
to 256KiB size each. Using a pool did speedup capture data downloads,
using more transfers or larger buffers would not make a difference.
Slightly reduce the total memory consumption again, change the setup to
8 transfers of up to 512KiB each, which results in a total of 4MiB for
pending USB communication. These numbers are as arbitrary as any other.
No attempt was made to automatically derive the values from acquisition
parameters like samplerate and samples count.
Gerhard Sittig [Sun, 20 Feb 2022 08:22:21 +0000 (09:22 +0100)]
kingst-la2016: use a pool of USB bulk transfers, speedup download
Use a pool of 32 USB bulk transfers of up to 256KiB size each. Which
doubles throughput and reduces the time to download the capture data
after acquisition has completed.
Gerhard Sittig [Sun, 20 Feb 2022 07:48:08 +0000 (08:48 +0100)]
kingst-la2016: move USB bulk transfer handling to helper routines
Concentrate all support code which handles USB bulk transfers for the
capture data download in a set of helper routines: memory allocation
and release, submission and cancellation including re-submission after
a previous completion.
Submit host side transfers earlier, between the configuration and the
start of USB bulk transfers in the device. Allocate transfers and their
buffers at the first acquisition start. Keep allocated buffers across
several acquisition periods. Relase transfers and their buffers when the
device closes. Allocate buffers of fixed size (always 256KiB, no longer
depends on the remainder of the currently downloaded capture data).
Acquisition stop cancels all currently submitted transfers, and does
postprocess their (cancelled) completion without re-submitting. This
avoids "spilling" pending transfers into the next acquisition cycle.
Name the helper routines in preparation of using multiple transfers.
Stick with a single transfer in this commit to simplify review. Use a
longer USB receive timeout (500ms for capture data, in contrast to
200ms for control transfers).
Gerhard Sittig [Sun, 20 Feb 2022 07:15:21 +0000 (08:15 +0100)]
kingst-la2016: move capture download details out of USB xfer handling
Ideally the USB transfer handling logic and the interpretation of the
downloaded capture data would not be as intertwined. The current
implementation assumes a rather specific capture model ("normal mode"
as it's called in the vendor software), and would not work in streaming
mode.
Move as many details out of the receive_transfer() routine and into the
send_chunk() data processing routine as we can. Which only leaves error
code paths and USB transfer re-submission, which get addressed in a
subsequent commit.
Gerhard Sittig [Sat, 5 Feb 2022 13:40:59 +0000 (14:40 +0100)]
kingst-la2016: add my copyright for recent improvements
The usability improvements, firmware speedups, portability and robustness
improvements, and style cleanup were non-trivial. Add my copyright to the
Kingst LA2016 driver source code.
Gerhard Sittig [Sat, 5 Feb 2022 13:30:47 +0000 (14:30 +0100)]
kingst-la2016: spew pretty FPGA register dump for development support
Implement a pretty registers dump, and call it when the FPGA bitstream
content gets checked and when hardware controlled acquisition completes.
Generate this FPGA registers dump at spew log level, accept a caller
provided address range to further reduce verbosity as needed.
This is mostly motivated by developer's curiousity. To suport research
when previously unknown models are seen. Or to see which other details
are available as an acquisition executes. Or to check whether some of
the previously written configuration could be read back.
Always call the MCU firmware download routine that is implemented in the
protocol.c source file when the api.c scan routine executes. But only
conditionally load the MCU firmware to the probed device when strictly
necessary. This makes filename information available to users since
these details are essential for the operation of a device, yet keeps
intimate firmware implementation details in the appropriate location
in the implementation.
Gerhard Sittig [Mon, 31 Jan 2022 22:25:15 +0000 (23:25 +0100)]
kingst-la2016: weaken run state check in hardware initialization
Weaken the check for plausible run states in the early read and test
immediately after the initial hardware configuration. The strict pattern
used to not match when an earlier session successfully triggered (digits
0x9 vs 0xd in the register's LSB positions). The test was never fatal,
it's just for information.
Gerhard Sittig [Mon, 31 Jan 2022 22:15:16 +0000 (23:15 +0100)]
kingst-la2016: balance frame begin and frame end emission
Track when frame begin was sent to the session, to conditionally send
frame end only when begin was sent. This is useful because frame markers
get deferred for quite some time when triggers are involved. Acquisition
stop may occur before the start of a capture was seen or processed.
Gerhard Sittig [Mon, 31 Jan 2022 22:09:53 +0000 (23:09 +0100)]
kingst-la2016: symbolic names for capture mode, trigger config comments
Use symbolic names for the capture mode (sample to RAM before download
to the host). Comment on potentially misleading field names in the
trigger configuration (enabled vs triggering channels masks). Don't
rename the fields yet until the assumption is verified.
Gerhard Sittig [Mon, 31 Jan 2022 22:01:41 +0000 (23:01 +0100)]
kingst-la2016: determine packets per chunk at runtime per model
The layout of capture data in memory most probably depends on devices'
channel counts. Chunks of 16 bytes each could either carry 5 samples of
16bit data with an 8bit repeat count, or 3 samples with 32bit data each.
Derive the number of packets per chunk at runtime from the connected
device type. Which could unbreak the LA5032 device but is yet untested.
It's an educated guess.
Gerhard Sittig [Mon, 31 Jan 2022 21:38:01 +0000 (22:38 +0100)]
kingst-la2016: extend model support (100/500 MHz, 32 channels)
Extend the code paths which handle supported samplerates and channel
counts. Explicitly test for 100/200/500 MHz rate, and 16/32 channels.
Raise errors for unexpected configurations. Keep all internal data in
32bit wide entities. Pick a suitable unitsize for logic data at runtime
depending on the detected model.
The capture data memory layout for 32 channel devices is yet to get
verified. The implementation is based on an educated guess only.
Gerhard Sittig [Mon, 31 Jan 2022 21:08:41 +0000 (22:08 +0100)]
kingst-la2016: rephrase USB bulk transfer size padding constraint
Always round up capture data USB bulk transfer sizes to full EP 6 packet
sizes. The previous implementation suggested that it's only required for
smaller transfers, but it's just a coincidence that the upper limit of
256KiB happened to also be a multiple of the 512B packet size.
It's assumed that capping at the absolute size limit and always padding
is more readable and as reliable as the previous if-else logic was.
Rephrase the round up by means of integer multiplication instead of
bit twiddling. Compilers should get what is intended, humans may prefer
to read the former.
Gerhard Sittig [Mon, 31 Jan 2022 20:49:42 +0000 (21:49 +0100)]
kingst-la2016: developer comment on capture data layout for 32ch models
The implementation assumes that capture data comes in 16byte chunks
which carry 5 packets of one 16bit sample and an 8bit repeat count each.
Which may not apply to models with 32 channels, the current compile time
literal may need to become a runtime depending value. Add a comment.
Gerhard Sittig [Mon, 31 Jan 2022 20:39:30 +0000 (21:39 +0100)]
kingst-la2016: keep FPGA active after device close
When the sigrok driver closes as the application shuts down, acquisition
of logic input channels will have completed. Generation of PWM signals
on output channels can be desirable to keep up. Do not de-initialize the
FPGA hardware in the close code path. Which allows to configure PWM by
means of sigrok-cli and use the signals between program invocations that
reconfigure the generator. Users can always disable channels before the
application shuts down if they prefer to. Similar use was seen with PSUs.
Make this approach a compile time option.
Gerhard Sittig [Mon, 31 Jan 2022 19:50:33 +0000 (20:50 +0100)]
kingst-la2016: reword buffer size in FPGA register access
Phrase communication buffer sizes in terms of FPGA register width,
instead of totalling the sizes of different bitfield width. Comment
where buffers are shared among different accesses, for awareness
during maintenance.
Introduce an "unknown register at offset 0x30" such that REG_TRIGGER
access can follow the pattern of determining the FPGA register's width.
Gerhard Sittig [Mon, 31 Jan 2022 19:45:51 +0000 (20:45 +0100)]
kingst-la2016: rename samplerate member in device context
The "current samplerate" attribute of the device context became obsolete
when the maximum samplerate became a property of the model which a device
context references.
Gerhard Sittig [Mon, 31 Jan 2022 19:38:49 +0000 (20:38 +0100)]
kingst-la2016: remove complex logic threshold voltage support
Remove the complex implementation of the three config key support to
specify the logic input threshold voltage, as well as the compile time
switch to pick from alternative implementations. This approach is easy
to come back to later when desired, its removal is in a separate VCS
commit. Getting the full -4.0..+4.0V range and continuous adjustment
would be nice to have. But it's essential for users today to see the
currently effective voltage in UIs.
Gerhard Sittig [Mon, 31 Jan 2022 18:05:02 +0000 (19:05 +0100)]
kingst-la2016: reduce a little if-deffery in logic threshold support
Move a logic threshold related switch case to the location where its
sibling config keys reside. Which eliminates a separate distant chunk
under an ifdef which should not have been there in the first place.
Make the presence of a device context member depend on the choice of
simple or complex threshold support. The simple approach exclusively
requires one index into the discrete set of a few voltages.
Gerhard Sittig [Mon, 31 Jan 2022 17:41:55 +0000 (18:41 +0100)]
kingst-la2016: implement alternative simpler threshold voltage config
The complex setup with three config keys that heavily interact with each
other did not work from the user's perspective. It's unfortunate how the
configuration of one item changed another item's value. The GUI would
not provide labels which reflect the currently configured voltage value,
the list of presets was never presented in the GUI.
Implement something that is both simpler and works with sigrok-cli as
well as pulseview. Reduce the set of choices and only provide a discrete
list of voltages. Yet try to cover most logic families and typical use
cases. This alternative approach exists in addition to the previously
implemented approach, and is selected by compile time switches. Ideally
the logic input threshold voltage would be a property of the "Logic"
channel group, but the GUI then won't display the option. That's why it
currently remains a global device option.
Pass the user specified voltage as a value from api.c to protocol.c
which eliminates intimate knowledge of the config API's internal details
(especially with the compile time options in api.c).
Gerhard Sittig [Sun, 30 Jan 2022 10:32:32 +0000 (11:32 +0100)]
kingst-la2016: adjust config param checks, threshold range check
After scan() completed the conn= can no longer be unknown. The firmware
was loaded and became effective (and communication was tested) before we
get to the config getter. Check PWM period and duty cycle value ranges
in the config setter.
Use symbolic names in the threshold voltage range check when protocol.c
forwards the configured value to the device.
Gerhard Sittig [Sun, 30 Jan 2022 10:18:12 +0000 (11:18 +0100)]
kingst-la2016: sort protocol.h priv routines in order of use
Sort the SR_PRIV la2016_*() routines in protocol.h in order of typical
use, improving navigation during maintenance. Keep protocolc. as is to
reduce the diff size.
Gerhard Sittig [Sat, 5 Feb 2022 13:54:25 +0000 (14:54 +0100)]
kingst-la2016: add PWM channel groups, announce as signal generator
Create the "Logic" and the "PWMx" channel goups, implement support to
get and set frequency, duty cycle, and enabled state. Announce the
device as a signal generator, too.
Handling of "Logic" config keys is prepared but empty in this commit.
Gerhard Sittig [Sun, 30 Jan 2022 10:03:27 +0000 (11:03 +0100)]
kingst-la2016: reduce scope of a few more declarations
Reduce the number of "top level declarations" in the protocol.h header.
Move hardware register related structs and capture data layout literals
to protocol.c where they are exclusively used. Move the capture info (a
set of values which describe the most recently completed acquisition)
into the device context itself.
Gerhard Sittig [Sun, 30 Jan 2022 09:25:41 +0000 (10:25 +0100)]
kingst-la2016: rework the device side of PWM configuration
Assign an initial PWM configuration during scan (arbitrary frequencies
at 50% duty cycle as before, but off by default). Ideally the initial
assignment gets updated by user specs at runtime, and hardware gets
configured as needed from internal data which was kept at defaults or
updated from user specs.
Combine the previous enable_pwm() and configure_pwm() routines into
set_pwm_config() which configures one channel in the device's hardware
(and transparently controls the enable flag). This eliminates the
unfortunate "channel unrolling" in the helper's API. Which eliminates
la2016_init_params() which redundantly configured the logic threshold
(done upon acquisition start again) and kept reassigning PWM parameters
across multiple open calls.
Providing the config API to adjust PWM settings remains to be done.
Gerhard Sittig [Sun, 30 Jan 2022 08:55:56 +0000 (09:55 +0100)]
kingst-la2016: complete hardware setup in probe, set features in open
Complete all of the MCU firmware load, device type identification, FPGA
bitstream load, and FPGA initialization by the end of scan(). This gives
an easily usable device of known capabilities for the remaining driver
lifetime, which just needs to get opened by connection ID (which was
retrieved during scan).
I still don't like how the driver's open() configures PWM without user
provided specs. And enforcing the logic threshold is redundant before
acquisition start. This needs more attention later.
Gerhard Sittig [Sun, 30 Jan 2022 08:37:20 +0000 (09:37 +0100)]
kingst-la2016: improve diagnostics in device type detection
Adjust the pieces of information that are shown at different verbosity
levels in the EEPROM read code path which identifies Kingst LA models.
Present something even more readable to regular users, yet keep details
available for developers when previously unknown devices are seen. Show
raw byte dumps at highest verbosity levels, to simplify the addition of
more supported devices.
Gerhard Sittig [Sun, 30 Jan 2022 07:42:21 +0000 (08:42 +0100)]
kingst-la2016: rework acquisition limits, improve CLI use
Remove the rather arbitrary previous limits of 5MSa at 100MSa/s and 5%
capture ratio. Start with the highest available samplerate (per model)
and without any samples count limit. Use 50% capture ratio which is as
arbitrary a choice as the previous value but matches what scopes do.
Drop the lower samples count limit. (An arbitrary check encoded in the
library refuses to set a value of 0, so starting with 0 is the only way
of starting unlimited and being able to optionally specify a limit.)
This results in improved CLI use out of the box. Either of --samples or
--time works as expected, and both can be used in combination. The GUI
starts from a samples count limit by default that is consistent with
other devices. Users should be happy.
Accept any samplerate spec which is covered by hardware constraints.
Keep user provided specs unmodified for later reference, map these to
hardware register values which get forwarded to the device in a best
effort manner.
Make too high sample count limits non-fatal, just cap at 10GSa length.
The device's hardware compression which is affected by input signal
patterns already kept resulting in potentially shorter captures than
configured. There is no surprise here for users either. Use the model
dependent sample memory capacity to derive maximum pre-trigger memory
sizes, which eliminates another arbitrary magic number in the driver.
Gerhard Sittig [Sun, 30 Jan 2022 07:06:28 +0000 (08:06 +0100)]
kingst-la2016: identify device type in scan() already
The vendor's design choice won't let us detect the device type from USB
enumeration data alone. EEPROM content must be read, which involves MCU
firmware communication, which only becomes available after the recently
uploaded firmware image becomes available. This extends the execution
time of the Kingst LA driver's scan() routine, but only if devices are
connected, and only for their first occurance after plugin. Subsequent
scans are quick.
Knowing the device type in the scan routine simplifies the open routine,
and allows model specific default parameters. The vendor's design choice
again won't let us read back previously configured values, each program
startup must assume a default configuration.
This implementation uses lots of small helpers to avoid open coding USB
communication details in several places. In theory up to 32 channels are
prepared, but all currently supported models have 16 channels. Different
memory sizes and channel counts are not yet effective in the acquisition
setup or session feed. The previous implementation of device open still
did too many things (configure PWM before user specs were received). A
future implementation needs to better pick which activities to run at
which points in time.
Gerhard Sittig [Fri, 28 Jan 2022 16:51:57 +0000 (17:51 +0100)]
kingst-la2016: rephrase samplerate list code path, prepare 500MHz
Rephrase the config_list() SR_CONF_SAMPLERATE branch for improved
readability. A list of supported rates gets derived from the current
device's maximum rate. Naming the tables after device models instead
of maximum rates is unexpected.
Drop the "odd" looking 4/8MHz items. Which results in consistent 1/2/5
steps in all decades. With hardware compression there is no gain to be
expected from using 4/8MHz instead of 5/10MHz. (Vendor software does
not provide that choice either.)
Add a list of samplerates for 500MHz models. These won't provide the
200MHz value, because it cannot result from the device's base clock
and an integer divider. Needs to be 250MHz instead. This is untested,
needs to get verified when a 500MHz model will be supported.
Gerhard Sittig [Wed, 26 Jan 2022 21:08:02 +0000 (22:08 +0100)]
device: introduce common helpers for channel group allocation
Provide common logic in device.c which allocates and releases an
sr_channel_group struct. The logicport import module had a local
implementation with a slightly different API. Accept an optional sdi
reference to automatically extend the sdi->channel_groups member.
Gerhard Sittig [Mon, 24 Jan 2022 21:36:53 +0000 (22:36 +0100)]
kingst-la2016: use common support for sw limits and session feed
Use common sw_limits and feed_queue helpers. Which makes --time specs
for acquisition duration available, and dramatically reduces complexity
in the send_chunk() routine. Which improves usability and reliability
and maintainability at the same time.
Assign default rate/depth/ratio in scan() already when the devc gets
created. Make an msecs timeout stop the acquisition if the hardware has
not seen the desired number of samples or exhausted its memory before.
Immediately start recording in the absence of trigger specs, drop the
pre-trigger phase in that case. Shuffle the order of activities in the
periodic receive callback. Send headers before enabling communication,
end communication before sending end markers to the session feed. Cope
when USB data is received after the configured acquisition got processed
(the hardware always overshoots due to compression and chunking). Extend
comments and diag messages.
USB receive timeouts are not fatal any longer. They even were seen
during regular operation at higher log levels. Which resulted in one
capture getting split across several "frames" unexpectedly.
Acquisition limits are not enforced most precisely in this commit, as
this would be more expensive. A little overshoot of up to 1.5kSa seems
acceptable (up to five packets with an 8bit repeat count each).
Gerhard Sittig [Mon, 24 Jan 2022 20:30:11 +0000 (21:30 +0100)]
kingst-la2016: more checks on configured rate/depth/channels
Extend the list of supported samplerates, start from 10kHz (used to
start at 20kHz before). Comment on hardware constraints which limit
the available rates, for awareness during maintenance.
Move the check for enabled channels from api.c to protocol.c, it was
only used for the trigger configuration. Rename the routine since it
never configured any channels, only got the list of currently enabled
channels to pass on to the device. Extend the range checks for the
rate and depth on acquisition start, also check the lower limits.
Moving codes which references declarations required that definitions
also moved to public location of greater scope. This is acceptable since
all of them remain local to the kingst-la2016 driver. Stick with names
as they are used right now to reduce the diff and help reviewers, these
can get unified in a later commit.
Gerhard Sittig [Mon, 24 Jan 2022 20:11:35 +0000 (21:11 +0100)]
kingst-la2016: rename logic channels to match product's labels
Rename the logic channels to "CH0" to "CH15". To match the labels on the
cover of the device which users will be expecting to see in applications.
Which also happens to match the vendor's software and user manual.
Gerhard Sittig [Sun, 23 Jan 2022 20:19:38 +0000 (21:19 +0100)]
kingst-la2016: style nits in FPGA code path and threshold selection
Check sigrok routine return codes for SR_OK not zero. The snprintf(3)
routine does include the NUL termination in the length spec. Use size_t
for the threshold selection which in essence is an enumeration.
Gerhard Sittig [Sun, 23 Jan 2022 20:00:53 +0000 (21:00 +0100)]
kingst-la2016: address style issues in api.c scan and open
Improve readability and fixup coding style of the scan(), dev_open(),
and la2016_dev_open() routines. Factor out common subexpressions, trim
text line length, adjust data types, eliminate sizeof() type redundancy.
Propagate returned error codes, check the USB enumeration result before
iteration. Drop the devc member which used to hold the sigrok context.
Release the sample data conversion buffer when acquisition start fails.
Gerhard Sittig [Sun, 23 Jan 2022 19:46:54 +0000 (20:46 +0100)]
kingst-la2016: separate complex calls from caller's control flow
Don't mix complex invocations with their evaluation of the return value
and change of flow in the source code. This is even more important for
indented multi-line argument lists and indented conditional branches
which follow. As a byproduct this reduces text line length and further
increases readability. Break other long lines. This commit picks low
hanging fruit, leaves more complex cases for another commit.
Gerhard Sittig [Sun, 23 Jan 2022 19:29:43 +0000 (20:29 +0100)]
kingst-la2016: rephrase sample data to session feed logic
Comment on the layout of the incoming captured data for awareness during
maintenance. Rephrase the send_chunk() routine for improved readability.
Eliminate too short i, j, k variables. Comment on the non-obvious flush
condition for the conversion buffer. Prefer "sample" in variable names
to not confuse captures with the device's run state. Eliminate another
literal 2 which slipped through in an earlier commit. Adjust data types.
Gerhard Sittig [Sun, 23 Jan 2022 17:24:40 +0000 (18:24 +0100)]
kingst-la2016: style nits in enable/configure PWM
Prefer booleans in the enable code path. Rename set_pwm() to better tell
apart enable and configure activities. Check more constraints on input
parameters. Adress minor style issues. Ideally enable_pwm() would not
open code the number of PWM channels in its routine signature.
Gerhard Sittig [Sun, 23 Jan 2022 18:11:41 +0000 (19:11 +0100)]
kingst-la2016: renames to better reflect sequence of activities
The previous implementation started on a single model with lots of
experiments, and could benefit from a cleanup after more knowledge was
gathered. Rename variables and routines to better reflect what actually
is happening, use more suitable data types. Drop unused devc members.
Fixup typos in diagnostics, protect against MSB issues in bitmasks.
The USB scan just yields one of the supported devices, its model is
unknown at this time. The list of enabled channels is determined upon
acquisition start when the trigger configuration gets created. The
device executes captures in hardware to internal RAM, while the driver
waits for the acquisition to complete, before downloading sample data
to the PC. Feeding sample data to the session ends when the data is
exhausted (a good condition is yet to get found). An optional trigger
marker is put into the stream of samples but only if a trigger was
configured.
Gerhard Sittig [Sun, 23 Jan 2022 17:08:45 +0000 (18:08 +0100)]
kingst-la2016: use symbolic names for device run state
Rephrase the run_state() routine in terms of symbolic identifiers,
eliminate magic numbers in the code. Extend comments on run state even
more to help reviewers. Reduce indentation in the optional logging when
the value changes.
It's assumed that the "current state and mask equals a typical pattern?"
phrase better reflects the purpose of a check, and is easier to verify
than hex numbers in a context where bit field meanings matter and not
all adjacent bits are involved).
This implementation no longer assumes that "sample to DRAM" is set. In
theory capture to internal RAM versus streaming via USB should not matter
when the acquisition state is queried.
Gerhard Sittig [Sat, 22 Jan 2022 12:47:17 +0000 (13:47 +0100)]
std: remove open coded array items count, make floats stand out
Replace the open coded literal 2 in std.c routines, prefer ARRAY_SIZE()
instead in the GVariant construction. To not confuse that item count with
other literals 2 which are related to avoiding floating point issues by
using an epsilon around an imprecise value. See a larger context for an
illustration of the commit's motivation.
Use literal 2.0 instead of 2 where floating point numbers are involved.
To raise awareness during maintenance.
Gerhard Sittig [Sun, 23 Jan 2022 16:49:33 +0000 (17:49 +0100)]
std: epsilon for std_gvar_min_max_step_thresholds() upper limit
Adjust the std_gvar_min_max_step_thresholds() routine which iterates
over a range of threshold voltages that are specified by their lower and
upper bounds and a step (stride). Allow for an epsilon in the loop's end
condition to span the full driver's announced set of values and not stop
prematurely.
The issue was observed with Kingst LA2016 which announces a range from
0.4V to 4.0V in steps of 0.1V, while the config list ends at the 3.9V
value and would have omitted the 4.0V upper bound.
Gerhard Sittig [Sun, 23 Jan 2022 16:03:11 +0000 (17:03 +0100)]
kingst-la2016: adjust register layout in acquisition configuration
The FPGA register space to configure acquisition parameters is unusual
in the sense that some 34bit values are kept in 40bit registers, while
other 32bit values are kept in 24bit registers (stores MSB only). This
answers the question how to communicate a limit of 10 billion samples
in a 32bit register (a doubt about the previous implementation). :)
Reported-By: Kevin Grant <redacted> in github PR 169
Gerhard Sittig [Sat, 22 Jan 2022 12:41:21 +0000 (13:41 +0100)]
tests: cover u24le and u40le in endianess conversion tests
Add a tiny test case which covers the principal operation of the u24le
and u40le endianess writers. Expect to see the correct number of bytes
and the significant bits. This test does not explicitly check for the
absence of adjacent garbage which a naive writer implementation might
leave behind outside of the significant bounds.
Gerhard Sittig [Sat, 22 Jan 2022 12:37:23 +0000 (13:37 +0100)]
libsigrok-internal.h: add 24bit and 40bit endianess aware byte stream writers
Implement primitives to write u24le and u40le integers, including auto
increments for the write position. These are motivated by Kingst LA2016
maintenance.
Gerhard Sittig [Sat, 22 Jan 2022 12:29:12 +0000 (13:29 +0100)]
kingst-la2016: rephrase creation of the acquisition configuration
Touch up the set_sample_config() routine's implementation. Separate the
calculation of parameter values from the construction of FPGA register
access instructions. Comment on seemingly redundant pre-trigger settings
which relate to each other in non-obvious ways. Consider unsupported
samplerates fatal: With a clock input of 100MHz to 500MHz and a lowest
user settable samplerate of 20kHz the 16bit divider shall never overrun.
If it does then a driver author was not aware during maintenance. Tweak
diagnostics for improved usability. Drop an unused devc member.
Gerhard Sittig [Sat, 22 Jan 2022 11:12:17 +0000 (12:12 +0100)]
kingst-la2016: rephrase manufacture date and device type support
The "purchase date" reader asssumed a little endian host when reading
16bit data from the device. Use endianess aware readers instead. Which
also unobfuscates the YY and MM positions in the byte array (comments
were plenty, but the code would not reflect what happened). Rephrase
the consistency check in the date and magic code paths (the inverted
bits), better reflect the XOR approach.
Prefer the "manufacture date" term since that's what the vendor is aware
of, while the customer's date of purchase or the dealer's shelf time are
unknown to vendors.
Split complex invocation from caller's flow control to improve
readability of the code path. Which also trims text line length.
Gerhard Sittig [Sat, 22 Jan 2022 11:01:45 +0000 (12:01 +0100)]
kingst-la2016: endianess and redundancy in run state gatherer
The run_state() routine assumed a little endian host. Get the device's
16bits run state by means of an endianess aware reader instead. Reduce
redundancy in the run state change diagnostics. Individually determine
the run state name, but use common code to print that information. Use
short hex literals to better reflect that only the lowest nibble gets
inspected, all other bits' meaning are unknown to us.
It remains uncertain why the state progress logic keeps checking the
"sample to DRAM" bit field. In theory these states should also work for
streaming. May just not have come up yet in the absence of support.
Gerhard Sittig [Sat, 22 Jan 2022 10:47:56 +0000 (11:47 +0100)]
kingst-la2016: address endianess issue in data feed submission
Capture data was taken from the device in an endianess aware manner, but
submission to the session feed assumed a little endian host (and casted
an u8 pointer to u16 items, which is bad). Use an endianess aware writer
before sending accumulated sample data to the sigrok session. Address
remaining open coded byte counts in several send_chunk() places.
The conversion from LE (the device) to the host and to LE (the session)
may appear redundant, but is worth keeping in place when other models
with 32 channels should get added in a future implementation.
Gerhard Sittig [Sat, 22 Jan 2022 10:28:13 +0000 (11:28 +0100)]
kingst-la2016: shuffle code order to follow application perspective
Sort "set threshold voltage" code blocks into numerical order of voltage
levels for improved readability. It's surprising to find ">= 2.9V" then
"<= -0.4V" and then "between those" at the end.
Move the la2016_has_triggered() routine next to run_state() since both
of them inspect the device's current run state. Closer inspection even
suggests that one is named inappropriately (not renamed in this commit,
to help reviewers).
The purpose of the set_run_mode() routine's argument most probably is
"mode", and not the surprising "fast blinking". Indicators may just be
a byproduct of setting mode to run or halt.
Make the set_defaults() invocation in la2016_init_device() stand out
more perceivably. Don't hide it in a return statement.
Use a symbolic name for the "user specified input threshold" item's
position in the set of choices. Stick with array size for the complete
list of items instead of hiding the size behind an unrelated name. This
improves readability of the config get/set/list routines. Trim a text
line length while we are here.
The single variable for several purposes (user specified value, and
fixed value derived from currently selected choice out of a premade
set) still looks suspicious, and is not addressed in this commit.
Gerhard Sittig [Sat, 22 Jan 2022 10:06:32 +0000 (11:06 +0100)]
kingst-la2016: concentrate magic numbers in central location
Eliminate open coded magic values which are spilled across the driver's
implementation. Concentrate tunables or derived values in a central spot
at the top of the source files near other declarations. Rephrase some
values to better reflect their purpose or magnitude.
Few values remain dubious. Add TODO comments for awareness.
Gerhard Sittig [Sat, 22 Jan 2022 09:04:14 +0000 (10:04 +0100)]
kingst-la2016: rephrase FPGA bitstream content zero padding
The upload_fpga_bitstream() routine open codes a magic length for the
padded file content, which is hard to relate to a firmware file size,
and impossible to spot during maintenance. Declare an assumed chunk size
instead and let the resource file handling code path determine the needed
length of zero padding. Drop an unneeded device context member variable.
Gerhard Sittig [Sat, 22 Jan 2022 08:31:54 +0000 (09:31 +0100)]
kingst-la2016: make FPGA bitstream upload optional
Separate the FPGA bitstream upload logic into the strict file content
upload, and the register access to initialize and enable a currently
loaded bitstream. Check before upload whether a working bitstream is
available in the device.
This eliminates a 600ms delay in every device open code path after the
initial upload. Which speeds up the start of an acquisition. Works in
Pulseview as well as sigrok-cli, even across process invocations.
Unfortunately test conditions are rather weak, they are constrained by
an arbitrary vendor's choice. Stricter checks can get added later if
the need arises (when incompatible device firmware versions are seen,
and more reliable test criteria become available). The implementation
lends itself to transparent robustness improvements.
Gerhard Sittig [Sat, 22 Jan 2022 07:38:53 +0000 (08:38 +0100)]
kingst-la2016: rephrase USB renum code path after firmware upload
The dev_open() routine postprocesses USB renumeration after a previous
FX2 MCU firmware upload. Concentrate all tunables in the driver's header
file, and discuss their meaning in relation to each other. Rephrase the
logic to start checking earlier, and keep checking for longer, adjust
diagnostics in the process. Void the "firmware uploaded" flag when the
upload took effect. Consistently use u64 for timestamps. Rename a few
variables to improve readabilty.
Gerhard Sittig [Thu, 20 Jan 2022 21:14:29 +0000 (22:14 +0100)]
kingst-la2016: rephrase comments for style, readability, and text length
Rephrase comments in the Kingst LA2016 driver to better match the sigrok
project's style. Consistently start with capitals and end in punctuation.
Use all upper case for acronyms to improve readability.
Keep text lines to an acceptable length. Use consistent open and close
phrases for multi-line comments. Drop C++ style comments. Add braces
where comments and one-line code results in multi-line branches of flow
control statements.
This commit also consistently uses lower case for hex literals, and
unobfuscates a few other literals: Use 0xff everywhere for unknown USB
addresses, prefer 1800 * 1000 over 18e5 for a 1.8 seconds interval.
Gerhard Sittig [Wed, 19 Jan 2022 20:25:54 +0000 (21:25 +0100)]
kingst-la2016: rephrase diagnostics to improve user perception
Rephrase diagnostics messages so that users easier can digest them. Keep
implementation details out of messages which are seen by default, stick
those into developer centric messages that correspond to higher verbosity
levels. Consistently start with capital letters and end in punctuation.
Drop exclamation marks. Use all caps for acronyms. Don't break format
strings so that developers can search for messages reported by users.
Break a few long source code text lines (but not all of them).