libusb 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.travis.yml +1 -0
- data/History.md +8 -0
- data/README.md +5 -15
- data/Rakefile +8 -1
- data/ext/extconf.rb +49 -12
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/AUTHORS +12 -1
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/COPYING +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/ChangeLog +18 -2
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/INSTALL +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/Makefile.am +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/Makefile.in +31 -18
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/NEWS +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/PORTING +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/README +5 -3
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/TODO +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/common.xcconfig +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/config.h +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/debug.xcconfig +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/libusb.xcconfig +0 -0
- data/ext/libusb-1.0.20/Xcode/libusb.xcodeproj/project.pbxproj +865 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/libusb_debug.xcconfig +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/libusb_release.xcconfig +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/release.xcconfig +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/aclocal.m4 +35 -32
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/README +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/config.h +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/jni/Android.mk +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/jni/Application.mk +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/jni/examples.mk +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/jni/libusb.mk +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/jni/tests.mk +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/compile +1 -1
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/config.guess +13 -160
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/config.h.in +6 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/config.sub +26 -12
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/configure +244 -20
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/configure.ac +27 -4
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/depcomp +1 -1
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/doc/Makefile.am +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/doc/Makefile.in +19 -6
- data/ext/libusb-1.0.20/doc/doxygen.cfg.in +2334 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/Makefile.am +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/Makefile.in +19 -6
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/dpfp.c +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/dpfp_threaded.c +15 -10
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/ezusb.c +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/ezusb.h +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/fxload.c +28 -7
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/getopt/getopt.c +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/getopt/getopt.h +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/getopt/getopt1.c +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/hotplugtest.c +21 -3
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/listdevs.c +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/sam3u_benchmark.c +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/xusb.c +2 -1
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/install-sh +170 -196
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb-1.0.pc.in +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/Makefile.am +15 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/Makefile.in +192 -53
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/core.c +218 -100
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/descriptor.c +3 -1
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/hotplug.c +26 -9
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/hotplug.h +8 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/io.c +432 -290
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/libusb-1.0.def +2 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/libusb-1.0.rc +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/libusb.h +11 -10
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/libusbi.h +106 -29
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/darwin_usb.c +27 -67
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/darwin_usb.h +3 -7
- data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.am +5 -0
- data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.in +810 -0
- data/ext/libusb-1.0.20/libusb/os/haiku/aclocal.m4 +1193 -0
- data/ext/libusb-1.0.20/libusb/os/haiku/compile +347 -0
- data/ext/libusb-1.0.20/libusb/os/haiku/config.guess +1421 -0
- data/ext/libusb-1.0.20/libusb/os/haiku/config.sub +1807 -0
- data/ext/libusb-1.0.20/libusb/os/haiku/configure +17579 -0
- data/ext/libusb-1.0.20/libusb/os/haiku/configure.ac +8 -0
- data/ext/libusb-1.0.20/libusb/os/haiku/depcomp +791 -0
- data/ext/libusb-1.0.20/libusb/os/haiku/haiku_pollfs.cpp +378 -0
- data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb.h +112 -0
- data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_backend.cpp +550 -0
- data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.cpp +255 -0
- data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.h +180 -0
- data/ext/libusb-1.0.20/libusb/os/haiku/install-sh +501 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/ltmain.sh +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/m4/libtool.m4 +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/m4/ltoptions.m4 +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/m4/ltsugar.m4 +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/m4/ltversion.m4 +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/m4/lt~obsolete.m4 +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/missing +1 -1
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/linux_netlink.c +4 -4
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/linux_udev.c +1 -2
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/linux_usbfs.c +46 -49
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/linux_usbfs.h +1 -1
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/netbsd_usb.c +9 -73
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/openbsd_usb.c +9 -73
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/poll_posix.c +2 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/poll_posix.h +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/poll_windows.c +3 -1
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/poll_windows.h +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/threads_posix.c +3 -3
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/threads_posix.h +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/threads_windows.c +3 -1
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/threads_windows.h +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/wince_usb.c +87 -250
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/wince_usb.h +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/windows_common.h +1 -1
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/windows_usb.c +267 -181
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/windows_usb.h +22 -7
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/strerror.c +5 -2
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/sync.c +2 -1
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/version.h +1 -1
- data/ext/libusb-1.0.20/libusb/version_nano.h +1 -0
- data/ext/libusb-1.0.20/ltmain.sh +9655 -0
- data/ext/libusb-1.0.20/m4/libtool.m4 +7992 -0
- data/ext/libusb-1.0.20/m4/ltoptions.m4 +384 -0
- data/ext/libusb-1.0.20/m4/ltsugar.m4 +123 -0
- data/ext/libusb-1.0.20/m4/ltversion.m4 +23 -0
- data/ext/libusb-1.0.20/m4/lt~obsolete.m4 +98 -0
- data/ext/libusb-1.0.20/missing +215 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/tests/Makefile.am +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/tests/Makefile.in +19 -6
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/tests/libusb_testlib.h +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/tests/stress.c +0 -0
- data/ext/{libusb-1.0.19 → libusb-1.0.20}/tests/testlib.c +0 -0
- data/lib/libusb.rb +1 -0
- data/lib/libusb/call.rb +1 -0
- data/lib/libusb/context.rb +5 -2
- data/lib/libusb/stdio.rb +25 -0
- data/lib/libusb/version_gem.rb +1 -1
- data/libusb.gemspec +2 -1
- metadata +152 -115
- metadata.gz.sig +0 -0
- data/ext/libusb-1.0.19/Xcode/libusb.xcodeproj/project.pbxproj +0 -1
- data/ext/libusb-1.0.19/doc/doxygen.cfg.in +0 -1288
- data/ext/libusb-1.0.19/libusb/version_nano.h +0 -1
File without changes
|
@@ -40,6 +40,8 @@
|
|
40
40
|
* with a fake pipe. The read/write functions are only meant to be used in that
|
41
41
|
* context.
|
42
42
|
*/
|
43
|
+
#include <config.h>
|
44
|
+
|
43
45
|
#include <errno.h>
|
44
46
|
#include <stdio.h>
|
45
47
|
#include <stdlib.h>
|
@@ -331,7 +333,7 @@ struct winfd usbi_create_fd(HANDLE handle, int access_mode, struct usbi_transfer
|
|
331
333
|
wfd.cancel_fn = cancel_fn;
|
332
334
|
|
333
335
|
if ((access_mode != RW_READ) && (access_mode != RW_WRITE)) {
|
334
|
-
usbi_warn(NULL, "only one of RW_READ or RW_WRITE are supported
|
336
|
+
usbi_warn(NULL, "only one of RW_READ or RW_WRITE are supported. "
|
335
337
|
"If you want to poll for R/W simultaneously, create multiple fds from the same handle.");
|
336
338
|
return INVALID_WINFD;
|
337
339
|
}
|
File without changes
|
@@ -19,10 +19,10 @@
|
|
19
19
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
20
20
|
*/
|
21
21
|
|
22
|
+
#include <config.h>
|
23
|
+
|
22
24
|
#if defined(__linux__) || defined(__OpenBSD__)
|
23
|
-
# if defined(
|
24
|
-
# define _GNU_SOURCE
|
25
|
-
# else
|
25
|
+
# if defined(__OpenBSD__)
|
26
26
|
# define _BSD_SOURCE
|
27
27
|
# endif
|
28
28
|
# include <unistd.h>
|
File without changes
|
@@ -19,6 +19,7 @@
|
|
19
19
|
*/
|
20
20
|
|
21
21
|
#include <config.h>
|
22
|
+
|
22
23
|
#include <objbase.h>
|
23
24
|
#include <errno.h>
|
24
25
|
#include <stdarg.h>
|
@@ -185,7 +186,8 @@ int usbi_cond_timedwait(usbi_cond_t *cond,
|
|
185
186
|
// GetSystemTimeAsFileTime() is not available on CE
|
186
187
|
SYSTEMTIME st;
|
187
188
|
GetSystemTime(&st);
|
188
|
-
SystemTimeToFileTime(&st, &filetime)
|
189
|
+
if (!SystemTimeToFileTime(&st, &filetime))
|
190
|
+
return 0;
|
189
191
|
rtime.LowPart = filetime.dwLowDateTime;
|
190
192
|
rtime.HighPart = filetime.dwHighDateTime;
|
191
193
|
rtime.QuadPart -= epoch_time;
|
File without changes
|
@@ -22,32 +22,19 @@
|
|
22
22
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
23
23
|
*/
|
24
24
|
|
25
|
-
#include <
|
25
|
+
#include <config.h>
|
26
26
|
|
27
27
|
#include <stdint.h>
|
28
|
-
#include <errno.h>
|
29
28
|
#include <inttypes.h>
|
30
29
|
|
30
|
+
#include "libusbi.h"
|
31
31
|
#include "wince_usb.h"
|
32
32
|
|
33
|
-
// Forward declares
|
34
|
-
static int wince_clock_gettime(int clk_id, struct timespec *tp);
|
35
|
-
unsigned __stdcall wince_clock_gettime_threaded(void* param);
|
36
|
-
|
37
33
|
// Global variables
|
38
34
|
uint64_t hires_frequency, hires_ticks_to_ps;
|
39
|
-
|
40
|
-
const uint64_t epoch_time = UINT64_C(116444736000000000); // 1970.01.01 00:00:000 in MS Filetime
|
35
|
+
const uint64_t epoch_time = UINT64_C(116444736000000000); // 1970.01.01 00:00:000 in MS Filetime
|
41
36
|
int windows_version = WINDOWS_CE;
|
42
37
|
static int concurrent_usage = -1;
|
43
|
-
// Timer thread
|
44
|
-
// NB: index 0 is for monotonic and 1 is for the thread exit event
|
45
|
-
HANDLE timer_thread = NULL;
|
46
|
-
HANDLE timer_mutex = NULL;
|
47
|
-
struct timespec timer_tp;
|
48
|
-
volatile LONG request_count[2] = {0, 1}; // last one must be > 0
|
49
|
-
HANDLE timer_request[2] = { NULL, NULL };
|
50
|
-
HANDLE timer_response = NULL;
|
51
38
|
HANDLE driver_handle = INVALID_HANDLE_VALUE;
|
52
39
|
|
53
40
|
/*
|
@@ -65,9 +52,9 @@ static char* windows_error_str(uint32_t retval)
|
|
65
52
|
uint32_t error_code, format_error;
|
66
53
|
|
67
54
|
error_code = retval?retval:GetLastError();
|
68
|
-
|
55
|
+
|
69
56
|
safe_stprintf(wErr_string, ERR_BUFFER_SIZE, _T("[%d] "), error_code);
|
70
|
-
|
57
|
+
|
71
58
|
size = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error_code,
|
72
59
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &wErr_string[safe_tcslen(wErr_string)],
|
73
60
|
ERR_BUFFER_SIZE - (DWORD)safe_tcslen(wErr_string), NULL);
|
@@ -94,11 +81,11 @@ static char* windows_error_str(uint32_t retval)
|
|
94
81
|
|
95
82
|
static struct wince_device_priv *_device_priv(struct libusb_device *dev)
|
96
83
|
{
|
97
|
-
|
84
|
+
return (struct wince_device_priv *) dev->os_priv;
|
98
85
|
}
|
99
86
|
|
100
87
|
// ceusbkwrapper to libusb error code mapping
|
101
|
-
static int translate_driver_error(int error)
|
88
|
+
static int translate_driver_error(int error)
|
102
89
|
{
|
103
90
|
switch (error) {
|
104
91
|
case ERROR_INVALID_PARAMETER:
|
@@ -113,7 +100,7 @@ static int translate_driver_error(int error)
|
|
113
100
|
case ERROR_BUSY:
|
114
101
|
return LIBUSB_ERROR_BUSY;
|
115
102
|
|
116
|
-
// Error codes that are either unexpected, or have
|
103
|
+
// Error codes that are either unexpected, or have
|
117
104
|
// no suitable LIBUSB_ERROR equivilant.
|
118
105
|
case ERROR_CANCELLED:
|
119
106
|
case ERROR_INTERNAL_ERROR:
|
@@ -149,8 +136,9 @@ static int init_dllimports()
|
|
149
136
|
return LIBUSB_SUCCESS;
|
150
137
|
}
|
151
138
|
|
152
|
-
static int init_device(
|
153
|
-
|
139
|
+
static int init_device(
|
140
|
+
struct libusb_device *dev, UKW_DEVICE drv_dev,
|
141
|
+
unsigned char bus_addr, unsigned char dev_addr)
|
154
142
|
{
|
155
143
|
struct wince_device_priv *priv = _device_priv(dev);
|
156
144
|
int r = LIBUSB_SUCCESS;
|
@@ -168,8 +156,9 @@ static int init_device(struct libusb_device *dev, UKW_DEVICE drv_dev,
|
|
168
156
|
// Internal API functions
|
169
157
|
static int wince_init(struct libusb_context *ctx)
|
170
158
|
{
|
171
|
-
int
|
159
|
+
int r = LIBUSB_ERROR_OTHER;
|
172
160
|
HANDLE semaphore;
|
161
|
+
LARGE_INTEGER li_frequency;
|
173
162
|
TCHAR sem_name[11+1+8]; // strlen(libusb_init)+'\0'+(32-bit hex PID)
|
174
163
|
|
175
164
|
_stprintf(sem_name, _T("libusb_init%08X"), (unsigned int)GetCurrentProcessId()&0xFFFFFFFF);
|
@@ -208,37 +197,17 @@ static int wince_init(struct libusb_context *ctx)
|
|
208
197
|
goto init_exit;
|
209
198
|
}
|
210
199
|
|
211
|
-
//
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
timer_response = CreateSemaphore(NULL, 0, MAX_TIMER_SEMAPHORES, NULL);
|
223
|
-
if (timer_response == NULL) {
|
224
|
-
usbi_err(ctx, "could not create timer response semaphore - aborting");
|
225
|
-
goto init_exit;
|
226
|
-
}
|
227
|
-
timer_mutex = CreateMutex(NULL, FALSE, NULL);
|
228
|
-
if (timer_mutex == NULL) {
|
229
|
-
usbi_err(ctx, "could not create timer mutex - aborting");
|
230
|
-
goto init_exit;
|
231
|
-
}
|
232
|
-
timer_thread = CreateThread(NULL, 0, wince_clock_gettime_threaded, NULL, 0, NULL);
|
233
|
-
if (timer_thread == NULL) {
|
234
|
-
usbi_err(ctx, "Unable to create timer thread - aborting");
|
235
|
-
goto init_exit;
|
236
|
-
}
|
237
|
-
|
238
|
-
// Wait for timer thread to init before continuing.
|
239
|
-
if (WaitForSingleObject(timer_response, INFINITE) != WAIT_OBJECT_0) {
|
240
|
-
usbi_err(ctx, "Failed to wait for timer thread to become ready - aborting");
|
241
|
-
goto init_exit;
|
200
|
+
// find out if we have access to a monotonic (hires) timer
|
201
|
+
if (QueryPerformanceFrequency(&li_frequency)) {
|
202
|
+
hires_frequency = li_frequency.QuadPart;
|
203
|
+
// The hires frequency can go as high as 4 GHz, so we'll use a conversion
|
204
|
+
// to picoseconds to compute the tv_nsecs part in clock_gettime
|
205
|
+
hires_ticks_to_ps = UINT64_C(1000000000000) / hires_frequency;
|
206
|
+
usbi_dbg("hires timer available (Frequency: %"PRIu64" Hz)", hires_frequency);
|
207
|
+
} else {
|
208
|
+
usbi_dbg("no hires timer available on this platform");
|
209
|
+
hires_frequency = 0;
|
210
|
+
hires_ticks_to_ps = UINT64_C(0);
|
242
211
|
}
|
243
212
|
}
|
244
213
|
// At this stage, either we went through full init successfully, or didn't need to
|
@@ -250,30 +219,6 @@ init_exit: // Holds semaphore here.
|
|
250
219
|
UkwCloseDriver(driver_handle);
|
251
220
|
driver_handle = INVALID_HANDLE_VALUE;
|
252
221
|
}
|
253
|
-
if (timer_thread) {
|
254
|
-
SetEvent(timer_request[1]); // actually the signal to quit the thread.
|
255
|
-
if (WAIT_OBJECT_0 != WaitForSingleObject(timer_thread, INFINITE)) {
|
256
|
-
usbi_warn(ctx, "could not wait for timer thread to quit");
|
257
|
-
TerminateThread(timer_thread, 1); // shouldn't happen, but we're destroying
|
258
|
-
// all objects it might have held anyway.
|
259
|
-
}
|
260
|
-
CloseHandle(timer_thread);
|
261
|
-
timer_thread = NULL;
|
262
|
-
}
|
263
|
-
for (i = 0; i < 2; i++) {
|
264
|
-
if (timer_request[i]) {
|
265
|
-
CloseHandle(timer_request[i]);
|
266
|
-
timer_request[i] = NULL;
|
267
|
-
}
|
268
|
-
}
|
269
|
-
if (timer_response) {
|
270
|
-
CloseHandle(timer_response);
|
271
|
-
timer_response = NULL;
|
272
|
-
}
|
273
|
-
if (timer_mutex) {
|
274
|
-
CloseHandle(timer_mutex);
|
275
|
-
timer_mutex = NULL;
|
276
|
-
}
|
277
222
|
}
|
278
223
|
|
279
224
|
if (r != LIBUSB_SUCCESS)
|
@@ -286,7 +231,6 @@ init_exit: // Holds semaphore here.
|
|
286
231
|
|
287
232
|
static void wince_exit(void)
|
288
233
|
{
|
289
|
-
int i;
|
290
234
|
HANDLE semaphore;
|
291
235
|
TCHAR sem_name[11+1+8]; // strlen(libusb_init)+'\0'+(32-bit hex PID)
|
292
236
|
|
@@ -307,29 +251,6 @@ static void wince_exit(void)
|
|
307
251
|
if (--concurrent_usage < 0) { // Last exit
|
308
252
|
exit_polling();
|
309
253
|
|
310
|
-
if (timer_thread) {
|
311
|
-
SetEvent(timer_request[1]); // actually the signal to quit the thread.
|
312
|
-
if (WAIT_OBJECT_0 != WaitForSingleObject(timer_thread, INFINITE)) {
|
313
|
-
usbi_dbg("could not wait for timer thread to quit");
|
314
|
-
TerminateThread(timer_thread, 1);
|
315
|
-
}
|
316
|
-
CloseHandle(timer_thread);
|
317
|
-
timer_thread = NULL;
|
318
|
-
}
|
319
|
-
for (i = 0; i < 2; i++) {
|
320
|
-
if (timer_request[i]) {
|
321
|
-
CloseHandle(timer_request[i]);
|
322
|
-
timer_request[i] = NULL;
|
323
|
-
}
|
324
|
-
}
|
325
|
-
if (timer_response) {
|
326
|
-
CloseHandle(timer_response);
|
327
|
-
timer_response = NULL;
|
328
|
-
}
|
329
|
-
if (timer_mutex) {
|
330
|
-
CloseHandle(timer_mutex);
|
331
|
-
timer_mutex = NULL;
|
332
|
-
}
|
333
254
|
if (driver_handle != INVALID_HANDLE_VALUE) {
|
334
255
|
UkwCloseDriver(driver_handle);
|
335
256
|
driver_handle = INVALID_HANDLE_VALUE;
|
@@ -372,7 +293,7 @@ static int wince_get_device_list(
|
|
372
293
|
if (dev) {
|
373
294
|
usbi_dbg("using existing device for %d/%d (session %ld)",
|
374
295
|
bus_addr, dev_addr, session_id);
|
375
|
-
// Release just this element in the device list (as we already hold a
|
296
|
+
// Release just this element in the device list (as we already hold a
|
376
297
|
// reference to it).
|
377
298
|
UkwReleaseDeviceList(driver_handle, &devices[i], 1);
|
378
299
|
release_list_offset++;
|
@@ -404,7 +325,7 @@ err_out:
|
|
404
325
|
*discdevs = new_devices;
|
405
326
|
safe_unref_device(dev);
|
406
327
|
// Release the remainder of the unprocessed device list.
|
407
|
-
// The devices added to new_devices already will still be passed up to libusb,
|
328
|
+
// The devices added to new_devices already will still be passed up to libusb,
|
408
329
|
// which can dispose of them at its leisure.
|
409
330
|
UkwReleaseDeviceList(driver_handle, &devices[release_list_offset], count - release_list_offset);
|
410
331
|
return r;
|
@@ -423,8 +344,8 @@ static void wince_close(struct libusb_device_handle *handle)
|
|
423
344
|
}
|
424
345
|
|
425
346
|
static int wince_get_device_descriptor(
|
426
|
-
|
427
|
-
|
347
|
+
struct libusb_device *device,
|
348
|
+
unsigned char *buffer, int *host_endian)
|
428
349
|
{
|
429
350
|
struct wince_device_priv *priv = _device_priv(device);
|
430
351
|
|
@@ -461,8 +382,8 @@ static int wince_get_config_descriptor(
|
|
461
382
|
}
|
462
383
|
|
463
384
|
static int wince_get_configuration(
|
464
|
-
|
465
|
-
|
385
|
+
struct libusb_device_handle *handle,
|
386
|
+
int *config)
|
466
387
|
{
|
467
388
|
struct wince_device_priv *priv = _device_priv(handle->dev);
|
468
389
|
UCHAR cv = 0;
|
@@ -578,19 +499,17 @@ static int wince_attach_kernel_driver(
|
|
578
499
|
struct wince_device_priv *priv = _device_priv(handle->dev);
|
579
500
|
if (!UkwAttachKernelDriver(priv->dev, interface_number)) {
|
580
501
|
return translate_driver_error(GetLastError());
|
581
|
-
}
|
502
|
+
}
|
582
503
|
return LIBUSB_SUCCESS;
|
583
504
|
}
|
584
505
|
|
585
|
-
static void wince_destroy_device(
|
586
|
-
struct libusb_device *dev)
|
506
|
+
static void wince_destroy_device(struct libusb_device *dev)
|
587
507
|
{
|
588
508
|
struct wince_device_priv *priv = _device_priv(dev);
|
589
509
|
UkwReleaseDeviceList(driver_handle, &priv->dev, 1);
|
590
510
|
}
|
591
511
|
|
592
|
-
static void wince_clear_transfer_priv(
|
593
|
-
struct usbi_transfer *itransfer)
|
512
|
+
static void wince_clear_transfer_priv(struct usbi_transfer *itransfer)
|
594
513
|
{
|
595
514
|
struct wince_transfer_priv *transfer_priv = (struct wince_transfer_priv*)usbi_transfer_get_os_priv(itransfer);
|
596
515
|
struct winfd wfd = fd_to_winfd(transfer_priv->pollable_fd.fd);
|
@@ -600,13 +519,12 @@ static void wince_clear_transfer_priv(
|
|
600
519
|
usbi_free_fd(&transfer_priv->pollable_fd);
|
601
520
|
}
|
602
521
|
|
603
|
-
static int wince_cancel_transfer(
|
604
|
-
struct usbi_transfer *itransfer)
|
522
|
+
static int wince_cancel_transfer(struct usbi_transfer *itransfer)
|
605
523
|
{
|
606
524
|
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
|
607
525
|
struct wince_device_priv *priv = _device_priv(transfer->dev_handle->dev);
|
608
526
|
struct wince_transfer_priv *transfer_priv = (struct wince_transfer_priv*)usbi_transfer_get_os_priv(itransfer);
|
609
|
-
|
527
|
+
|
610
528
|
if (!UkwCancelTransfer(priv->dev, transfer_priv->pollable_fd.overlapped, UKW_TF_NO_WAIT)) {
|
611
529
|
return translate_driver_error(GetLastError());
|
612
530
|
}
|
@@ -656,7 +574,7 @@ static int wince_submit_control_or_bulk_transfer(struct usbi_transfer *itransfer
|
|
656
574
|
|
657
575
|
ret = UkwIssueControlTransfer(priv->dev, flags, setup, buf, bufLen, &transfer->actual_length, wfd.overlapped);
|
658
576
|
} else {
|
659
|
-
ret = UkwIssueBulkTransfer(priv->dev, flags, transfer->endpoint, transfer->buffer,
|
577
|
+
ret = UkwIssueBulkTransfer(priv->dev, flags, transfer->endpoint, transfer->buffer,
|
660
578
|
transfer->length, &transfer->actual_length, wfd.overlapped);
|
661
579
|
}
|
662
580
|
if (!ret) {
|
@@ -667,7 +585,6 @@ static int wince_submit_control_or_bulk_transfer(struct usbi_transfer *itransfer
|
|
667
585
|
return libusbErr;
|
668
586
|
}
|
669
587
|
usbi_add_pollfd(ctx, transfer_priv->pollable_fd.fd, direction_in ? POLLIN : POLLOUT);
|
670
|
-
itransfer->flags |= USBI_TRANSFER_UPDATED_FDS;
|
671
588
|
|
672
589
|
return LIBUSB_SUCCESS;
|
673
590
|
}
|
@@ -677,8 +594,7 @@ static int wince_submit_iso_transfer(struct usbi_transfer *itransfer)
|
|
677
594
|
return LIBUSB_ERROR_NOT_SUPPORTED;
|
678
595
|
}
|
679
596
|
|
680
|
-
static int wince_submit_transfer(
|
681
|
-
struct usbi_transfer *itransfer)
|
597
|
+
static int wince_submit_transfer(struct usbi_transfer *itransfer)
|
682
598
|
{
|
683
599
|
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
|
684
600
|
|
@@ -697,7 +613,9 @@ static int wince_submit_transfer(
|
|
697
613
|
}
|
698
614
|
}
|
699
615
|
|
700
|
-
static void wince_transfer_callback(
|
616
|
+
static void wince_transfer_callback(
|
617
|
+
struct usbi_transfer *itransfer,
|
618
|
+
uint32_t io_result, uint32_t io_size)
|
701
619
|
{
|
702
620
|
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
|
703
621
|
struct wince_transfer_priv *transfer_priv = (struct wince_transfer_priv*)usbi_transfer_get_os_priv(itransfer);
|
@@ -706,10 +624,10 @@ static void wince_transfer_callback(struct usbi_transfer *itransfer, uint32_t io
|
|
706
624
|
|
707
625
|
usbi_dbg("handling I/O completion with errcode %d", io_result);
|
708
626
|
|
709
|
-
if (io_result == ERROR_NOT_SUPPORTED &&
|
627
|
+
if (io_result == ERROR_NOT_SUPPORTED &&
|
710
628
|
transfer->type != LIBUSB_TRANSFER_TYPE_CONTROL) {
|
711
|
-
/* For functional stalls, the WinCE USB layer (and therefore the USB Kernel Wrapper
|
712
|
-
* Driver) will report USB_ERROR_STALL/ERROR_NOT_SUPPORTED in situations where the
|
629
|
+
/* For functional stalls, the WinCE USB layer (and therefore the USB Kernel Wrapper
|
630
|
+
* Driver) will report USB_ERROR_STALL/ERROR_NOT_SUPPORTED in situations where the
|
713
631
|
* endpoint isn't actually stalled.
|
714
632
|
*
|
715
633
|
* One example of this is that some devices will occasionally fail to reply to an IN
|
@@ -723,7 +641,7 @@ static void wince_transfer_callback(struct usbi_transfer *itransfer, uint32_t io
|
|
723
641
|
usbi_dbg("checking I/O completion with errcode ERROR_NOT_SUPPORTED is really a stall");
|
724
642
|
if (UkwIsPipeHalted(priv->dev, transfer->endpoint, &halted)) {
|
725
643
|
/* Pipe status retrieved, so now request endpoint status by sending a GET_STATUS
|
726
|
-
* control request to the device. This is done synchronously, which is a bit
|
644
|
+
* control request to the device. This is done synchronously, which is a bit
|
727
645
|
* naughty, but this is a special corner case.
|
728
646
|
*/
|
729
647
|
WORD wStatus = 0;
|
@@ -792,7 +710,9 @@ static void wince_transfer_callback(struct usbi_transfer *itransfer, uint32_t io
|
|
792
710
|
}
|
793
711
|
}
|
794
712
|
|
795
|
-
static void wince_handle_callback
|
713
|
+
static void wince_handle_callback(
|
714
|
+
struct usbi_transfer *itransfer,
|
715
|
+
uint32_t io_result, uint32_t io_size)
|
796
716
|
{
|
797
717
|
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
|
798
718
|
|
@@ -804,7 +724,7 @@ static void wince_handle_callback (struct usbi_transfer *itransfer, uint32_t io_
|
|
804
724
|
wince_transfer_callback (itransfer, io_result, io_size);
|
805
725
|
break;
|
806
726
|
case LIBUSB_TRANSFER_TYPE_BULK_STREAM:
|
807
|
-
|
727
|
+
break;
|
808
728
|
default:
|
809
729
|
usbi_err(ITRANSFER_CTX(itransfer), "unknown endpoint type %d", transfer->type);
|
810
730
|
}
|
@@ -853,9 +773,11 @@ static int wince_handle_events(
|
|
853
773
|
wince_handle_callback(transfer, io_result, io_size);
|
854
774
|
} else if (found) {
|
855
775
|
usbi_err(ctx, "matching transfer for fd %x has not completed", fds[i]);
|
776
|
+
usbi_mutex_unlock(&ctx->open_devs_lock);
|
856
777
|
return LIBUSB_ERROR_OTHER;
|
857
778
|
} else {
|
858
779
|
usbi_err(ctx, "could not find a matching transfer for fd %x", fds[i]);
|
780
|
+
usbi_mutex_unlock(&ctx->open_devs_lock);
|
859
781
|
return LIBUSB_ERROR_NOT_FOUND;
|
860
782
|
}
|
861
783
|
}
|
@@ -867,105 +789,20 @@ static int wince_handle_events(
|
|
867
789
|
/*
|
868
790
|
* Monotonic and real time functions
|
869
791
|
*/
|
870
|
-
unsigned __stdcall wince_clock_gettime_threaded(void* param)
|
871
|
-
{
|
872
|
-
LARGE_INTEGER hires_counter, li_frequency;
|
873
|
-
LONG nb_responses;
|
874
|
-
int timer_index;
|
875
|
-
|
876
|
-
// Init - find out if we have access to a monotonic (hires) timer
|
877
|
-
if (!QueryPerformanceFrequency(&li_frequency)) {
|
878
|
-
usbi_dbg("no hires timer available on this platform");
|
879
|
-
hires_frequency = 0;
|
880
|
-
hires_ticks_to_ps = UINT64_C(0);
|
881
|
-
} else {
|
882
|
-
hires_frequency = li_frequency.QuadPart;
|
883
|
-
// The hires frequency can go as high as 4 GHz, so we'll use a conversion
|
884
|
-
// to picoseconds to compute the tv_nsecs part in clock_gettime
|
885
|
-
hires_ticks_to_ps = UINT64_C(1000000000000) / hires_frequency;
|
886
|
-
usbi_dbg("hires timer available (Frequency: %"PRIu64" Hz)", hires_frequency);
|
887
|
-
}
|
888
|
-
|
889
|
-
// Signal wince_init() that we're ready to service requests
|
890
|
-
if (ReleaseSemaphore(timer_response, 1, NULL) == 0) {
|
891
|
-
usbi_dbg("unable to release timer semaphore: %s", windows_error_str(0));
|
892
|
-
}
|
893
|
-
|
894
|
-
// Main loop - wait for requests
|
895
|
-
while (1) {
|
896
|
-
timer_index = WaitForMultipleObjects(2, timer_request, FALSE, INFINITE) - WAIT_OBJECT_0;
|
897
|
-
if ( (timer_index != 0) && (timer_index != 1) ) {
|
898
|
-
usbi_dbg("failure to wait on requests: %s", windows_error_str(0));
|
899
|
-
continue;
|
900
|
-
}
|
901
|
-
if (request_count[timer_index] == 0) {
|
902
|
-
// Request already handled
|
903
|
-
ResetEvent(timer_request[timer_index]);
|
904
|
-
// There's still a possiblity that a thread sends a request between the
|
905
|
-
// time we test request_count[] == 0 and we reset the event, in which case
|
906
|
-
// the request would be ignored. The simple solution to that is to test
|
907
|
-
// request_count again and process requests if non zero.
|
908
|
-
if (request_count[timer_index] == 0)
|
909
|
-
continue;
|
910
|
-
}
|
911
|
-
switch (timer_index) {
|
912
|
-
case 0:
|
913
|
-
WaitForSingleObject(timer_mutex, INFINITE);
|
914
|
-
// Requests to this thread are for hires always
|
915
|
-
if (QueryPerformanceCounter(&hires_counter) != 0) {
|
916
|
-
timer_tp.tv_sec = (long)(hires_counter.QuadPart / hires_frequency);
|
917
|
-
timer_tp.tv_nsec = (long)(((hires_counter.QuadPart % hires_frequency)/1000) * hires_ticks_to_ps);
|
918
|
-
} else {
|
919
|
-
// Fallback to real-time if we can't get monotonic value
|
920
|
-
// Note that real-time clock does not wait on the mutex or this thread.
|
921
|
-
wince_clock_gettime(USBI_CLOCK_REALTIME, &timer_tp);
|
922
|
-
}
|
923
|
-
ReleaseMutex(timer_mutex);
|
924
|
-
|
925
|
-
nb_responses = InterlockedExchange((LONG*)&request_count[0], 0);
|
926
|
-
if ( (nb_responses)
|
927
|
-
&& (ReleaseSemaphore(timer_response, nb_responses, NULL) == 0) ) {
|
928
|
-
usbi_dbg("unable to release timer semaphore: %s", windows_error_str(0));
|
929
|
-
}
|
930
|
-
continue;
|
931
|
-
case 1: // time to quit
|
932
|
-
usbi_dbg("timer thread quitting");
|
933
|
-
return 0;
|
934
|
-
}
|
935
|
-
}
|
936
|
-
usbi_dbg("ERROR: broken timer thread");
|
937
|
-
return 1;
|
938
|
-
}
|
939
|
-
|
940
792
|
static int wince_clock_gettime(int clk_id, struct timespec *tp)
|
941
793
|
{
|
942
|
-
|
794
|
+
LARGE_INTEGER hires_counter;
|
943
795
|
ULARGE_INTEGER rtime;
|
944
|
-
|
796
|
+
FILETIME filetime;
|
945
797
|
SYSTEMTIME st;
|
946
798
|
switch(clk_id) {
|
947
799
|
case USBI_CLOCK_MONOTONIC:
|
948
|
-
if (hires_frequency != 0) {
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
r = WaitForSingleObject(timer_response, TIMER_REQUEST_RETRY_MS);
|
953
|
-
switch(r) {
|
954
|
-
case WAIT_OBJECT_0:
|
955
|
-
WaitForSingleObject(timer_mutex, INFINITE);
|
956
|
-
*tp = timer_tp;
|
957
|
-
ReleaseMutex(timer_mutex);
|
958
|
-
return LIBUSB_SUCCESS;
|
959
|
-
case WAIT_TIMEOUT:
|
960
|
-
usbi_dbg("could not obtain a timer value within reasonable timeframe - too much load?");
|
961
|
-
break; // Retry until successful
|
962
|
-
default:
|
963
|
-
usbi_dbg("WaitForSingleObject failed: %s", windows_error_str(0));
|
964
|
-
return LIBUSB_ERROR_OTHER;
|
965
|
-
}
|
966
|
-
}
|
800
|
+
if (hires_frequency != 0 && QueryPerformanceCounter(&hires_counter)) {
|
801
|
+
tp->tv_sec = (long)(hires_counter.QuadPart / hires_frequency);
|
802
|
+
tp->tv_nsec = (long)(((hires_counter.QuadPart % hires_frequency) / 1000) * hires_ticks_to_ps);
|
803
|
+
return LIBUSB_SUCCESS;
|
967
804
|
}
|
968
|
-
// Fall through and return real-time if monotonic was not detected @
|
805
|
+
// Fall through and return real-time if monotonic read failed or was not detected @ init
|
969
806
|
case USBI_CLOCK_REALTIME:
|
970
807
|
// We follow http://msdn.microsoft.com/en-us/library/ms724928%28VS.85%29.aspx
|
971
808
|
// with a predef epoch_time to have an epoch that starts at 1970.01.01 00:00
|
@@ -985,48 +822,48 @@ static int wince_clock_gettime(int clk_id, struct timespec *tp)
|
|
985
822
|
}
|
986
823
|
|
987
824
|
const struct usbi_os_backend wince_backend = {
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
825
|
+
"Windows CE",
|
826
|
+
0,
|
827
|
+
wince_init,
|
828
|
+
wince_exit,
|
992
829
|
|
993
|
-
|
830
|
+
wince_get_device_list,
|
994
831
|
NULL, /* hotplug_poll */
|
995
|
-
|
996
|
-
|
832
|
+
wince_open,
|
833
|
+
wince_close,
|
997
834
|
|
998
|
-
|
999
|
-
|
1000
|
-
|
835
|
+
wince_get_device_descriptor,
|
836
|
+
wince_get_active_config_descriptor,
|
837
|
+
wince_get_config_descriptor,
|
1001
838
|
NULL, /* get_config_descriptor_by_value() */
|
1002
839
|
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
840
|
+
wince_get_configuration,
|
841
|
+
wince_set_configuration,
|
842
|
+
wince_claim_interface,
|
843
|
+
wince_release_interface,
|
1007
844
|
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
845
|
+
wince_set_interface_altsetting,
|
846
|
+
wince_clear_halt,
|
847
|
+
wince_reset_device,
|
1011
848
|
|
1012
849
|
NULL, /* alloc_streams */
|
1013
850
|
NULL, /* free_streams */
|
1014
851
|
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
852
|
+
wince_kernel_driver_active,
|
853
|
+
wince_detach_kernel_driver,
|
854
|
+
wince_attach_kernel_driver,
|
1018
855
|
|
1019
|
-
|
856
|
+
wince_destroy_device,
|
1020
857
|
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
858
|
+
wince_submit_transfer,
|
859
|
+
wince_cancel_transfer,
|
860
|
+
wince_clear_transfer_priv,
|
1024
861
|
|
1025
|
-
|
862
|
+
wince_handle_events,
|
863
|
+
NULL, /* handle_transfer_completion() */
|
1026
864
|
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
0,
|
865
|
+
wince_clock_gettime,
|
866
|
+
sizeof(struct wince_device_priv),
|
867
|
+
sizeof(struct wince_device_handle_priv),
|
868
|
+
sizeof(struct wince_transfer_priv),
|
1032
869
|
};
|