Commit Graph

100 Commits

Author SHA1 Message Date
Bert Vermeulen 6f4b1868e8 sr/drivers: use sr_dev_inst instead of device index for dev_config_set()
All driver API calls using device index as a parameter will instead use a
const struct sr_dev_inst.
2012-08-03 10:27:39 +02:00
Bert Vermeulen cbd798f400 fx2lafw: don't use deprecated hwcap_get_all() driver API call 2012-08-03 10:27:39 +02:00
Bert Vermeulen a27999e657 fx2lafw: don't use deprecated hwcap_get_all() driver API call 2012-08-03 10:27:37 +02:00
Bert Vermeulen c5e82ca5e3 fx2lafw: device scan fixes 2012-08-03 10:27:37 +02:00
Bert Vermeulen f69b47f0f8 fx2lafw: a device scan always invalidates any previous scans 2012-08-03 10:27:37 +02:00
Bert Vermeulen 6e9339aae2 fx2lafw: use new driver info_get() API call 2012-08-03 10:27:37 +02:00
Bert Vermeulen a8cc8e44b9 fx2lafw: use driver struct-based device instance list 2012-08-03 10:27:37 +02:00
Bert Vermeulen 06717a8a60 fx2lafw: use new instance-based probe list 2012-08-03 10:27:37 +02:00
Bert Vermeulen 3a7a22cb07 fx2lafw: use new init/scan API 2012-08-03 10:27:37 +02:00
Bert Vermeulen 61136ea603 sr: add new driver API call: scan()
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.
2012-08-03 10:27:36 +02:00
Bert Vermeulen 40dda2c3a5 sr: remove unused argument from hardware driver function init()
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.
2012-08-03 10:27:36 +02:00
Ivan Fedorov 0e8d0e24d0 sr: fx2lafw: Add 16bit support for USBee DX and clones
gnuplot script support only 8 channels
2012-08-03 00:25:37 +02:00
Ivan Fedorov c9166745f2 sr: fx2lafw: Add basic support for USBee DX and clones 2012-08-01 00:12:00 +04:00
Lars-Peter Clausen e7d087bf0e sr: fx2lafw: Free transfers in reverse order
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>
2012-07-08 21:39:30 +02:00
Bert Vermeulen 45c59c8bdd sr: moved sigrok.h so libsigrok/libsigrok.h
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.
2012-07-05 01:17:28 +02:00
Lars-Peter Clausen 25f5d66a77 sr: fx2lafw: Fix potential leaks in acquisition_start error paths
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>
2012-07-04 01:11:50 +02:00
Lars-Peter Clausen c03f045004 sr: fx2lafw: Do not start a new acquisition if the old is still running
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>
2012-07-04 01:11:50 +02:00
Lars-Peter Clausen 0caa1ef0cb sr: fx2lafw: Abort pending transfers when sampling is stopped
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>
2012-07-04 01:11:50 +02:00
Lars-Peter Clausen 2769eed991 sr: fx2lafw: Move empty_transfer_count to device ctx
If one device is failing it should not affect the transfers of other devices.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2012-06-28 00:40:52 +02:00
Lars-Peter Clausen 5af666a94e sr: fx2lafw: Calculate buffer size and timeout based on sample rate
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>
2012-06-28 00:40:52 +02:00
Lars-Peter Clausen 7ce737a77c sr: fx2lafw: Handle the transfer's status
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>
2012-06-28 00:40:52 +02:00
Lars-Peter Clausen 17dff8a1e6 sr: fx2lafw: Avoid unnecessary alloc/free combo
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>
2012-06-28 00:40:51 +02:00
Lars-Peter Clausen f855de7575 sr: fx2lafw: Properly free transfer
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>
2012-06-28 00:40:51 +02:00
Lars-Peter Clausen bd47acabe3 sr: fx2lafw: Allocate header and packet struct on the stack
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>
2012-06-28 00:40:51 +02:00
Joel Holdsworth 0c156e06c5 fx2lafw: Made libusb_claim_interface error messages more informative 2012-06-28 00:40:48 +02:00
Bert Vermeulen 3b6c19303d fx2lafw: fix broken firmware upload timeout
Also corner case error init.
2012-06-27 01:02:39 +02:00
Lars-Peter Clausen fa114e4ab1 sr: fx2lafw: Set correct unitsize for trigger buffer
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>
2012-06-25 19:48:21 +02:00
Lars-Peter Clausen f3ab43a8fb sr: fx2lafw: Fix multistage trigger
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>
2012-06-24 14:35:26 +02:00
Lars-Peter Clausen eabf24035b sr: fx2lafw: Fix memory leaks in receive_transfer
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>
2012-06-22 09:23:30 +02:00
Uwe Hermann 0a88ec3d9c sr: fx2lafw: Use gboolean, cosmetics, fix gcc warning. 2012-05-31 22:48:40 +02:00
Joel Holdsworth d1ddc7a9a8 fx2lafw: Added device caps and added support for wide sampling 2012-05-31 19:52:32 +01:00
Joel Holdsworth a533743dd1 sr: Made sample rate lists const 2012-05-31 19:51:11 +01:00
Joel Holdsworth 1b79df2f57 sr: Made the dev_config_set parameter a const pointer 2012-05-31 19:51:11 +01:00
Joel Holdsworth b7f578bef5 sr: Made the dev_info_get return value const 2012-05-31 19:51:10 +01:00
Joel Holdsworth 915f7cc87a sr: Made hwcap const 2012-05-31 19:51:09 +01:00
Bert Vermeulen f366e86c68 sr: change all drivers to use SR_DF_META_LOGIC 2012-05-30 23:55:36 +02:00
Uwe Hermann 0a8c0c324e sr: fx2lafw: Only check for correct major FW version.
Changes in the minor version number are OK, as those should never
contain any incompatible/API changes.
2012-05-30 23:23:14 +02:00
Uwe Hermann 921634ec10 sr: Fix typos. 2012-05-30 22:42:47 +02:00
Uwe Hermann cf94c8167b sr: fx2lafw: Add (C) line from old saleae driver it's based on. 2012-05-30 22:42:45 +02:00
Uwe Hermann f60fdf6ebe sr: fx2lafw: s/MAX_RENUM_DELAY/MAX_RENUM_DELAY_MS/. 2012-05-30 09:30:50 +02:00
Uwe Hermann e8bd58ffd2 sr: fx2lafw: Fix a firmware upload bug on 32bit systems.
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.
2012-05-30 09:30:18 +02:00
Uwe Hermann 9f05304e4e sr: ARMFLY AX-Pro is supported by fx2lafw (LA only). 2012-05-29 20:25:08 +02:00
Joel Holdsworth 79dc64985f fx2lafw: Added support for 20kHz and 25kHz sampling 2012-05-10 13:10:59 +01:00
Joel Holdsworth 897c1a2ee5 fx2lafw: Added support for 100kHz and 50kHz sampling 2012-05-10 13:08:09 +01:00
Uwe Hermann 1e94408ae5 sr: fx2lafw: Get/display FX2 REVID. 2012-05-06 19:54:46 +02:00
Uwe Hermann 1663e4706c sr: fx2lafw: Braintechnology USB-LPS support. 2012-05-06 17:24:40 +02:00
Bert Vermeulen 6b73d9a598 fx2lafw: use iManufacturer/iProduct fields to identify our firmware
It's more deterministic than the endpoint profile check we did before. Which
was also broken.
2012-04-27 01:28:47 +02:00
Uwe Hermann 934cde02b8 fx2lafw: supported_samplerates[] should be 0-terminated. 2012-04-19 00:55:29 +02:00
Joel Holdsworth f488762a17 fx2lafw: Added support for default Cypess FX2 without EEPROM 2012-04-19 00:12:22 +02:00
Joel Holdsworth 9304d57650 fx2lafw: Added slower sample rates 2012-04-18 19:07:39 +01:00