#include <usb.h>
#include <errno.h>
#include <pthread.h>
+#include <stdint.h>
#include "usb-driver.h"
#include "xpcu.h"
};
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;
if (!claimed)
return 0;
+#if 0
ret = usb_release_interface(xpcu->handle, xpcu->interface);
if (!ret)
claimed = 0;
+#endif
}
return ret;
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;
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);
}
}
}
+ 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",
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;
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;
}