X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/usb-driver/blobdiff_plain/9bfaca620d7dca45f8c5b71c2dcc4e1329db7ffd..refs/heads/master:/xpcu.c diff --git a/xpcu.c b/xpcu.c index 6ee54d8..56e584c 100644 --- a/xpcu.c +++ b/xpcu.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "usb-driver.h" #include "xpcu.h" @@ -25,7 +26,6 @@ struct xpcu_event_s { }; static struct usb_bus *busses = NULL; -static pthread_mutex_t dummy_interrupt = PTHREAD_MUTEX_INITIALIZER; int xpcu_deviceinfo(struct usb_get_device_data *ugdd) { struct xpcu_s *xpcu = (struct xpcu_s*)ugdd->dwUniqueID; @@ -222,9 +222,11 @@ static int xpcu_claim(struct xpcu_s *xpcu, int claim) { if (!claimed) return 0; +#if 0 ret = usb_release_interface(xpcu->handle, xpcu->interface); if (!ret) claimed = 0; +#endif } return ret; @@ -300,15 +302,13 @@ static void xpcu_init(void) { usb_find_devices(); busses = usb_get_busses(); - - pthread_mutex_init(&dummy_interrupt, NULL); } int xpcu_find(struct event *e) { struct xpcu_event_s *xpcu_event = NULL; struct xpcu_s *xpcu = NULL; - char* devpos; + char* usbdev; struct usb_bus *bus; int busnum = -1, devnum = -1; int i; @@ -317,20 +317,15 @@ int xpcu_find(struct event *e) { xpcu_init(); - xpcu_event = malloc(sizeof(struct xpcu_event_s)); - if (!xpcu_event) - return -ENOMEM; - - bzero(xpcu_event, sizeof(struct xpcu_event_s)); - xpcu_event->xpcu = NULL; - xpcu_event->count = 0; - xpcu_event->interrupt_count = 0; - pthread_mutex_init(&xpcu_event->interrupt, NULL); - - devpos = getenv("XILINX_USB_DEV"); - if (devpos != NULL) { + usbdev = getenv("XILINX_USB_DEV"); + if (usbdev != NULL) { int j; char *devstr = NULL, *remainder; + char *devpos; + + devpos = strdup(usbdev); + if (!devpos) + return -ENOMEM; DPRINTF("XILINX_USB_DEV=%s\n", devpos); @@ -356,8 +351,19 @@ int xpcu_find(struct event *e) { } } } + free(devpos); } + xpcu_event = malloc(sizeof(struct xpcu_event_s)); + if (!xpcu_event) + return -ENOMEM; + + bzero(xpcu_event, sizeof(struct xpcu_event_s)); + xpcu_event->xpcu = NULL; + xpcu_event->count = 0; + xpcu_event->interrupt_count = 0; + pthread_mutex_init(&xpcu_event->interrupt, NULL); + for (i = 0; i < e->dwNumMatchTables; i++) { DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", @@ -484,21 +490,20 @@ int xpcu_close(struct event *e) { int xpcu_int_state(struct interrupt *it, int enable) { struct xpcu_event_s *xpcu_event = (struct xpcu_event_s*)it->hInterrupt; - pthread_mutex_t *interrupt = &dummy_interrupt; - if (xpcu_event) - interrupt = &xpcu_event->interrupt; + if (!xpcu_event) + return -ENODEV; if (enable == ENABLE_INTERRUPT) { it->fEnableOk = 1; it->fStopped = 0; it->dwCounter = 0; - pthread_mutex_trylock(interrupt); + pthread_mutex_trylock(&xpcu_event->interrupt); } else { it->dwCounter = 0; it->fStopped = 1; - if (pthread_mutex_trylock(interrupt) == EBUSY) - pthread_mutex_unlock(interrupt); + if (pthread_mutex_trylock(&xpcu_event->interrupt) == EBUSY) + pthread_mutex_unlock(&xpcu_event->interrupt); } return 0; @@ -507,18 +512,16 @@ int xpcu_int_state(struct interrupt *it, int enable) { int xpcu_int_wait(struct interrupt *it) { struct xpcu_event_s *xpcu_event = (struct xpcu_event_s*)it->hInterrupt; - if (xpcu_event) { - if (it->dwCounter < xpcu_event->count) { - it->dwCounter++; - } else { - pthread_mutex_lock(&xpcu_event->interrupt); - pthread_mutex_unlock(&xpcu_event->interrupt); - } - xpcu_event->interrupt_count++; + if (!xpcu_event) + return -ENODEV; + + if (it->dwCounter < xpcu_event->count) { + it->dwCounter++; } else { - pthread_mutex_lock(&dummy_interrupt); - pthread_mutex_unlock(&dummy_interrupt); + pthread_mutex_lock(&xpcu_event->interrupt); + pthread_mutex_unlock(&xpcu_event->interrupt); } + xpcu_event->interrupt_count++; return 0; }