Commit Graph

25 Commits

Author SHA1 Message Date
Uwe Hermann 176d785d33 Drop trailing whitespace in various files. 2017-06-06 14:10:02 +02:00
Uwe Hermann 039a2fd78a src/usb.c: Only allow hex characters in CONN_USB_VIDPID.
(and also allow case-insensitive specification)

Thanks to Hannu Vuolasaho for the fix.
2015-12-29 13:21:01 +01:00
Daniel Elstner 3393f185a5 session: Remove debug spew on I/O events
This really is a bit much with some drivers that do lots of small
I/O transfers.
2015-11-26 21:44:31 +01:00
Uwe Hermann e4ce146fef sr_usb_find(): Increase the 'bus' limit to 255.
On some systems it can happen that the USB 'bus' number is a lot larger
than 64, but sr_usb_find() currently errors out if it is > 64.

Example:
Bus 250 Device 006: ID 1ab1:04ce 1ab1 DS1000Z Series[...]

Increase that limit so that the code will work everywhere. This bus number
is queried via libusb_get_bus_number() which returns an uint8_t, so we're
limiting to 255 here.

Thanks to 'ssi' on IRC for reporting the issue.
2015-11-21 20:27:25 +01:00
Uwe Hermann b98b70222f usb.c: Fix usb_get_port_path() issue on Mac OS X.
Apparently (some versions of) Mac OS X have the same problem with
usb_get_port_path() as FreeBSD does. Work around this in the same way.

Thanks to hanyazou@gmail.com for the patch!

This fixes bug #673.
2015-11-15 19:11:54 +01:00
Daniel Elstner 5eff221e8c usb: Skip add/remove of FD on destroyed source
This avoids nasty GLib-CRITICALs on Windows with some drivers.
2015-10-02 01:13:16 +02:00
Daniel Elstner 6ec6c43b47 Build: Include <config.h> first in all source files
Since Autoconf places some important feature flags only into the
configuration header, it is necessary to include it globally to
guarantee a consistent build.
2015-09-13 18:54:46 +02:00
Daniel Elstner c2bf5506ee session: Port to GLib main loop
Replace the custom session main loop with the GLib main loop.
This is phase one of the port, which leaves the session and
driver APIs unchanged while replacing the internals.
2015-09-10 22:46:20 +02:00
Daniel Elstner c1adbb1e23 Build: Add configure check for libusb event-abstraction
This is intended to make people notice when libusb is too old
for the new Windows code. However, this is not foolproof, since
the libusb version may be different at runtime.
2015-09-08 00:08:16 +02:00
Daniel Elstner 534b634ce2 USB: Handle live changes to the set of FDs to poll
Introduce new internal session API for changing the set of polled
file descriptors for an already installed event source. Use the
new API to apply changes to the USB poll FDs when requested to do
so by libusb. Doing so is necessary to make the generic USB code
work on Windows.
2015-09-08 00:08:16 +02:00
Daniel Elstner 1b0c6b6d15 USB: On Windows, assume G_IO_IN for the event mask 2015-09-08 00:08:16 +02:00
Daniel Elstner 4b9e253213 USB: Remove Windows-specific event handling code
For the generic code to work on Windows, a version of libusb
with the experimental event-abstraction changes is required.
2015-09-08 00:04:22 +02:00
Daniel Elstner 5a7d8dac90 USB: Handle the case of a callback removing its event source 2015-09-05 04:21:26 +02:00
Daniel Elstner 358c4ed5b8 USB: On Windows, block to wait for libusb events
This is another attempt at getting the mess that is libusb event
handling on Windows under control. Until libusb makes its HANDLEs
available for polling, we have no choice but to block while waiting
for libusb events. Since we do not want to force drivers to deal
with multi-threading issues, that means we have to block in the
session main loop.

Fortunately, it turns out that our drivers aren't using multiple
event sources, so it is actually possible to block the main loop
without disrupting too much. This also gets rid of the USB thread
on Windows. Thankfully, libusb does not seem to care that we are
now calling libusb_handle_events_timeout_completed() twice per
iteration: first a blocking call (with timeout) in the callback
wrapper, followed by the non-blocking call in the driver-supplied
callback.
2015-09-04 19:04:23 +02:00
Daniel Elstner 92248e7821 session: Allow multiple poll FDs per event source
Turns out that having one event source per libusb poll FD is
a bad idea. There is only a single callback for all poll FDs,
and libusb expects to be called only once per poll iteration,
no matter how many FDs triggered.

Also, they should all share the same timeout, which should get
reset on events from any polled FD. The new timeout handling made
this problem apparent, as it caused the callback to be invoked
multiple times on timeouts, once for each separate event source.

In order to fix this, change the implementation to allow for an
arbitrary number of poll FDs per event source. This number is
zero for timer FDs, one for normal I/O sources, and one or more
for libusb sources (Unix only).

Also, on Windows, do not get an additional timeout from libusb
in the event loop. This is only appropriate when polling the
libusb FDs directly, which we aren't doing on Windows.
2015-09-03 19:37:09 +02:00
Daniel Elstner 62d7945f80 session: Properly accumulate event source timeouts
Keep track of when source timeouts are due and properly compare
against accumulated elapsed time between invocations. This prevents
sources with short timeouts from blocking other sources with longer
timeouts indefinitely.
2015-09-03 19:37:09 +02:00
Daniel Elstner 89efe06460 session: Fix USB timeout handling
In sr_session_iteration(), remove the inverted evaluation of the
block parameter if a USB source is present. This stops the deluge
of USB event callbacks due to the timeout always being zero.

Also, just for cleanliness, initialize the revents member of each
GPollFD instance to zero.
2015-09-03 19:37:09 +02:00
Bert Vermeulen 67e95ed37d Add sr_usb_close(). 2015-08-25 19:13:17 +02:00
Daniel Elstner c1aae90038 Build: Set local include directories in Makefile.am
Move the include flags for files in the source tree from
configure.ac to Makefile.am where they belong.  Also use
AM_CPPFLAGS instead of CFLAGS/CXXFLAGS to make sure the
files in the build/source tree are always picked up first.

Also, remove the include/libsigrok sub-directory from the
search path, thereby making the <libsigrok/> prefix mandatory
when building libsigrok itself.  This matches the convention
already imposed on users of the library.
2015-08-16 18:28:12 +02:00
Martin Ling f6c30de4b0 Initial fix attempt for a thread-related issue on Windows.
This is a partial fix for bug #343, which lead to a large amount of
handles being created, and eventually to a frontend "hang".

It's not yet a "full" fix as some issues are still observable,
but it successfully improves the situation on Windows to the extent
that frontend hangs due to large amounts of handles no longer seem
to happen.

Thanks to Boris Gjenero <boris.gjenero@gmail.com> for the debugging
efforts, testing, and updating of this patch!

Additionally, this seems to also fix a "SysClk LWLA hanging" bug
and apparently not receiving any samples during an acquisition
(tested on an LWLA1034).

This closes bug #328.
2015-03-24 20:14:04 +01:00
Uffe Jakobsen 19643b96e2 Fix FreeBSD issue with libusb_get_port_numbers()
Currently (as of date 20150122) an ioctl problem within the
FreeBSD kernel is preventing libusb_get_port_numbers() from working.
Hence calls to libusb_get_port_numbers() will always return 0.
This makes it impossible to establish a physical path the the usb device.

This problem has existed "forever" -
meaning that libusb_get_port_numbers() has never worked.

A fix is committed to FreeBSD "current" head  -
and will later be merged (MFC'ed) to maintenance branches.
See: https://svnweb.freebsd.org/base?view=revision&revision=277417

Additionally FreeBSD requires that devices prior to calling
libusb_get_port_numbers() have been opened with libusb_open().

The patch is "forwards-compatible".
Currently it acts specificly to libusb_get_port_numbers()
currently returning 0 on FreeBSD.
In these situations it constructs an artificial path to the device.
When FreeBSD kernels appears with proper working ioctl
supporting libusb_get_port_numbers() the code will construct
proper physical paths for newer kernels - while still generating
artificial physical paths for older defective kernels.
2015-01-25 23:36:29 +01:00
Vincent Palatin 2f004b4bc1 usb_get_port_path(): fix libusb error checking
When libusb cannot access a device, libusb_get_port_numbers() will return
an error. Check the return code rather than doing invalid pointer
operations (out-of-bound read).

Avoid segfaults at sigrok-cli startup on my setup where some USB devices are
not accessible and also make Valgrind happier.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
2014-11-23 17:58:21 +01:00
Aurelien Jacobs 76bc5f6376 usb: Simplify usb_get_port_path() and fix writing into a const char *. 2014-10-12 19:36:11 +02:00
Soeren Apel db156e5409 Add usb_get_port_path() helper function
There is currently no way to uniquely identify USB devices in
libsigrok. It uses the "bus.address" scheme which is only
constant as long as the device remains attached to the bus.
In order to allow USB device persistence in PulseView, devices
need to provide a unique identifier even in absence of a
serial number. This function is the first step as it provides
the ability to query the physical location of a USB device.
2014-09-24 00:40:03 +02:00
Bert Vermeulen 155b680da4 Reorganize project tree. 2014-07-22 18:19:29 +02:00
Renamed from hardware/common/usb.c (Browse further)