This changes the semantics of the init() call as well. That now only
initializes the driver -- an administrative affair, no hardware gets
touched during this call. It returns a standard SR_OK or SR_ERR* code.
The scan() call does a discovery run for devices it knows, and returns
the number found. It can be called at any time.
It was actually used in one way: the session file loaded abused it for
passing in the filename -- something it definitely wasn't intended for.
This now uses the proper way to pass arguments to a driver: the new
SR_HWCAP_SESSIONFILE.
The OLS driver could also use it as an indication of the serial port to
use instead of actively probing all serial ports on the system, but there
wasn't any frontend code that passed in such a parameter, making it
entirely useless. That will soon be handled differently with the new
scan() API call, regardless.
Both pipe channels are currently configured as blocking. We read from the pipe
in receive_data. Since the channel is configured as blocking we'll block in
receive_data until all data has been received. receive_data will be called from
the mainloop, so as consequence the mainloop will be blocked until the demo
device has finished sampling. This is not so much of a problem if we are
sampling in blocking mode (using sr_session_run()) and the demo device is the
only device in the session, but it will fail badly for all other configurations
(e.g. multiple devices or async sampling).
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Free the USB transfers in the reverse order of which they were submitted. This
will avoid that while transfer 0 is cancelledd transfer 1 is started by the
host controller, and so on.
Reported-by: Peter Stuge <peter@stuge.se>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
The session and demo device code contain a hack to make the demo device work on
Windows. This was neccessary since polling on windows requires special handling
and we can not just pass in the raw fd to poll.
With the previous patches which added support for non-fd based event sources
this hack is no longer required. The patch moves the GIOChannels used by the
demo device to the demo device context and uses sr_session_source_add_channel
to register a source for the channels instead of using the raw pipe fds.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
All frontends will have to include <libsigrok/libsigrok.h> from now on.
This header includes proto.h and version.h, both installed from the
distribution into $INCLUDE/libsigrok/ as well.
The only dynamically changed header is now version.h, which has both
libsigrok and libtool compile-time versions in it.
Only one limit should be active at a time. Make sure that the sample limit is
disabled when a time limit is set and vice versa.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Call abort_acquisition if starting sampling fails in acquisition_start, this
will ensure that all already allocated resources are being freed again.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This may happen if the acquisition_start is called right after calling
acquisition_stop and not all transfers have been freed or on repeated calls to
acquisition_start. If it happens we'll enter an undefined state and all kind of
strange behavior may occur, so error out in such a case.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
The recent reworks of the fx2lafw made sure that the total buffer size is large
enough hold 500ms of data. This was done to improve performance and stability.
That the timeout value for a transfer was also increased to over 500ms, a side
effect of this is that when sampling is stopped there will be a additional delay
of 500ms. This is because the driver waits for all transfers to be freed
before it sends a SR_DF_END packet. Once sampling has stopped this will only
happen once a transfer times out. This patch cancels all pending transfers when
sampling is stopped, this will cause them to be freed almost immediately and the
additional delay will disappear.
Also make sure, that if we know, that we just have received the last transfer to
not resubmit this transfer again.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Currently timeout and buffer size are hard-coded in the fx2lafw driver which is
non-optimal if we want to get good results at both high and low sample rates.
The timeout is hard-coded to 40ms, which doesn't work well when sampling at
a low sample rate. E.g. at 20kHz filling all available buffer space alone takes
6 seconds. So naturally we'll see a lot of transfers timeout in this case.
The buffer size is hard-coded to 4096 bytes, which does not work well with high
sample rates. E.g. at 24MHz these 4096 bytes are enough space for 0.17ms of
data. The total buffer size is enough for about 5ms of data. Sooner or later the
application won't be able to resubmit a transfer within this time span and the
device will abort data acquisition. Usually this happens within the first few
seconds of sampling.
This patch adds a few new helper functions which calculate the buffer size and
timeout based on the current sample rate.
The buffer size is chosen to be large enough to hold about 10ms of data and it
also must be a multiple of 512 bytes since the firmware will send us the data
in 512 byte chunks.
The timeout is set to the time it would take to fill the whole available buffer
space plus a 25% headroom to accommodate for jitter. This is more than enough,
but there is no need to make the timeout a tight deadline, since it is only
meant as a last resort in case the device stops submitting data. And in this
case data acquisition will be aborted anyway.
The patch also limits the the number of transfers so that the total buffer
space is not much more of 500ms. This will ensure that we do not have to
wait too long when aborting data acquisition.
This patch also significantly reduces the number of context switches when
sampling at a higher sample rate. On my system for example the CPU load of
sigrok-cli when sampling at 24MHz goes down from ~25% to 3-4%.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
While errors are usually already implicitly caught by looking at the packet
length field there is one error status which is worth special handling. If the
device has been removed there is not really a chance to recover from this error
so data acquisition can be stopped immediately.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
In receive_transfer for each completed transfer a new buffer is allocated and
the old one is freed. We can avoid this by simply reusing the buffer for the
next transfer. This is possible if we only resubmit the transfer after all
processing on the data buffer has been done. A new buffer is only allocated if
the size of the old one is not 4096 bytes.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
When freeing a transfer we also have to free the transfer buffer. We also have
to keep track of the number of allocated transfers and if the freed transfer was
the last one stop acquisition. This patch introduces a helper function which
takes care of all of this.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
The header and packet struct are only used in the scope of this function and
they are freed at the end of it. Also these structs are rather small, so they
can safely be allocated on the stack. By doing so memory leaks on the error
paths are avoided.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Samples received before the trigger point are stored. From the
trigger point on, every chunk received from the device is sent
up the session bus. After the device has finished sending, the
stored samples are transmitted.
Commit 88b75eb719 ("fx2lafw: Added device caps and added support for wide
sampling") increased the size of the trigger buffer from 8 to 16 bit, but forgot
to adjust the unitsize logic packet which is used to send the contents of the
trigger buffer. This patch sets the unitsize to sizeof() of the trigger buffer.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Multistage triggers currently do no work, because there is a return statement
in the middle of the trigger detector which will be hit as soon as the first
stage in a multistage trigger matches. This patch removes the return statement
so that the trigger detector can continue to try to match the next stage. In
order for this to work we also make sure that the trigger stage is only reset
if the current sample does not match.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
There are a few memory leaks in the receive_transfer transfer function. The most
serve of them is that a sample buffer is not freed if the triggered has not
matched yet, which causes a sigrok process which is waiting for a trigger to
consume several megabytes of memory within seconds. The other leaks are on the
error paths in that function.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
We should generally use api.c for API related functions and put the other
functions (mostly hardware-specific low-level code) into other C file(s)
for better readability.
MQ is the measured quantity, e.g. voltage, current, temperature.
UNIT is the unit in which these quantities are measured, e.g. volt,
ampere, celsius, kelvin, etc. etc.
The same MQ can be specified in different UNITs by the driver, depending
on what the hardware reports. Conversion is left to the frontends.
Not yet used, but it's the key to knowing where in the frame to
start displaying; the frame is used as a circular buffer, and what
is sent is effectively a snapshot.
The ntohs() from <arpa/inet.h> is not available on MinGW/Windows. There
are ways to work around this, but as we use glib already, using g_ntohs()
is the best option anyway.
The glib GTimeVal data type (and some functions using it) will be faded
out from glib sooner or later, so it's not a good idea to use them anyway.
In this specific case GTimeVal.tv_sec was overflowing, leading a check in
libsigrok to fail, and thus to FX2 firmware upload errors, i.e.
non-working fx2lafw devices.
http://thread.gmane.org/gmane.comp.debugging.sigrok.devel/166
The root cause is that GTimeVal.tv_sec is a 'glong' (8 bytes on 64bit
systems, but only 4 on 32bit systems).
We now use an int64_t (and g_get_monotonic_time() instead of the more
problematics g_get_current_time() which uses a GTimeVal).
This has been verified to fix the issue on a 32bit system.
Other uses of GTimeVal in libsigrok will be removed in a later release.
Also, drop unneeded GTV_TO_MSEC.
There are various ZEROPLUS models with different probe numbers. For now
hardcode to 16 (for the popular LAP-C(16032)). This will need to be
fixed in a dynamic way later.
This fixes a segfault due to only 16 probe-names being defined, but the
drivers returning 32 as probecount.
Also, add some additional debug output.
Start/stop acquisition callbacks: Consistently name the 'void *' parameter
cb_data for now. The per-device-instance device pointer is called
'session_dev_id' everywhere for now, but this should be renamed to
something more clear.
Avoid plain malloc()/free() in sr/srd, especially in the API calls.
Also avoid g_malloc*() in favor of g_try_malloc*().
Use g_strdup() instead of strdup() so that we can use g_free()
consistently everywhere.
Exceptions: Stuff that is allocated via other libs (not using glib),
should also be properly free'd using the respective free-ing function
(instead of g_free()). Examples: Stuff allocated by libusb, libftdi, etc.
Also, use sr_err() instead of sr_warn() for actual errors. sr_warn() is
meant for non-fatal/uncritical warnings.
This will come back in some form or another later, but for now
don't clutter the API with non-working stuff. Removing stuff from APIs
is not possible without breaking the API, adding stuff later is simpler.
Use SR_API to mark public API symbols, and SR_PRIV for private symbols.
Variables and functions marked 'static' are private already and don't
need SR_PRIV. However, functions which are not static (because they need
to be used in other libsigrok-internal files) but are also not meant to
be part of the public libsigrok API, must use SR_PRIV.
This uses the 'visibility' feature of gcc (requires gcc >= 4.0).
Details: http://gcc.gnu.org/wiki/Visibility
The API should be generic and only provide sr_device_instance_new() and
friends, but not sr_usb_device_instance_new(), sr_serial_device_instance_new(),
or others for other device types we may have in the future. The
frontends shouldn't have to know or care about this implementation detail.
This also fixes the problem that parts of sigrok.h contained
'#ifdef HAVE_LIBUSB_1_0' and such, which is even less desirable for the API.
The usb/serial instance specifics are now private, and each driver that
needs them keeps a pointer in its driver-specific context.
Make the zeroplus driver use a "struct zp" with per-device-instance
data (such as samplerate, trigger settings, and so on), like the other
drivers do.
Also, add a few more error checks.
For now, there's no analog/scope support in sigrok yet (will be added
later), so remove any such items from the public API (sigrok.h).
Having '#if defined(HAVE_LA_ALSA)' in sigrok.h is a bug anyway, the API
must not have anything device-dependent in general, and sigrok.h
specifically must not have any #ifdefs for specific hardware.
In the lib, we should only #include "sigrok.h" or "sigrok-internal.h",
but not the (possibly installed and thus different/older versions) via
<sigrok.h> or <sigrok-internal.h>.
Frontends should of course use <sigrok.h> and <sigrok-internal.h>.
This enables support for devices that have a different VID/PID
than the Saleae Logic, and yet another after firmware upload.
After firmware upload is checked every 100ms whether it came back,
instead of always waiting for 2 seconds.
If the kernel attaches a driver to a device we know, detact it first.
This is useful to allow frontends to react upon close failures in a
way they see fit (e.g. a popup in the GUI, or error message in the CLI).
They can also still ignore the error if they want, of course.
They're not too useful as they mostly consist of a list of function names,
and that list is already available in the respective struct. The wiki
API docs and the code in the various hardware/output drivers serve as
useful examples already, no need for additional files.
The g_malloc()/g_malloc0() versions exit/segfault if not enough memory
is available, which is not a good thing in libsigrok.
Instead, we use the g_try_malloc()/g_try_malloc0() variants, which
return NULL if not enough memory is available, so that the caller can
handle the error properly.
We should use these (internal) functions in libsigrok exclusively from
now on, i.e. no more use of glib's g_debug() etc.
These functions are only for libsigrok, the frontends use whatever
logging mechanism is suitable there.
support for metadata in recent versions of the FPGA code
moved constants and structs out to separate header file
got rid of all device instance-specific globals
When no firmware file is found, return the right error code so sigrok
doesn't continue running with no firmware loaded.
Thanks Martin Stensgård <mastensg@ping.uio.no> for the patch!
Until now the build would break if the user doesn't enable at least one
of the libusb1.0-based LAs. I.e., you could not compile only OLS, or
only the demo driver.
If the device is closed without previously running hw_openedev
the driver crashes (happens in cleanup). This patch checks
if the device has been opened.
* Both Analog and Logic capture works.
* Analog values are raw ADC, still useless.
* Triggers aren't implemented.
* Pattern Generator not implemented.
* Everything is broken. :)
When initialized, the driver starts a thread that generates signal data.
This data is written to a pipe (write file descriptor).
The other end of the pipe (read file descriptor), is connected to the
main polling code, like any other driver.
Note: This patch adds a new dependency on libgthread.
At the moment, you can list the driver's device:
$ ./cli/sigrok-cli -D
The following devices were found:
ID Device
0 Sigrok project Demo Driver v1.0 with 8 probes
And use it for random signal generation:
$ /opt/sigrok/bin/sigrok-cli -d 0 --samples 50 -f bits -p 1-8
sigrok 0.1pre2
Acquisition with 8/8 probes at 0 Hz
1:10111100 11010110 00001011 00011110 00111010 11110100 10
2:11010110 00111111 01001010 11111101 11010011 00010010 11
3:11000101 01000001 10100011 10100100 10110000 11110011 00
4:00100111 11110100 10011101 01100111 00100101 01001110 10
5:00011100 00101100 10111000 11001101 01011101 01011011 01
6:10110101 10111110 10010110 10111000 11011010 10000100 11
7:11111111 01001111 11110110 11010010 10000101 01001111 00
8:01000101 01111110 01010111 00000111 00010010 00000101 11
The next step is to make demo driver customisable (per-probe signal clock,
reference sample signals : serial, I2C, CAN...).
Thanks Olivier Fauchon <olivier@aixmarseille.com> for the patch.
Use libtool "noinst" local helper libs and use one Makefile.am per
subdir, which is the usual/preferred method. These helper libraries are
purely local and will not be installed.
This also fixes out-of-tree builds of sigrok, i.e. building in a
directory other than the sigrok source directory, e.g.
$ cd /home/user
$ git clone ...sigrok
$ cd sigrok
$ ./autogen.sh
$ mkdir /tmp/foo
$ cd /tmp/foo
$ /home/user/sigrok/configure
$ make
$ make install
This will place all build results (.o files, .la files, etc) in the
local build directory (/tmp/foo) instead of the source directory
(/home/user/sigrok in this example). The installation directory is
selected via the --prefix configure option (/usr/local per default).
We have SIGROK_OK for functions calls where no errors occured. All
error code names start with SIGROK_ERR and are globally unique,
negative values.
The value SIGROK_ERR is a generic/unspecified error code, all others,
such as SIGROK_ERR_MALLOC, refer to a specific error condition.
This commit renames the old SIGROK_NOK etc.