pass pointer to usb-driver structure through impact
This commit is contained in:
parent
8af4d9103d
commit
19acdb82e4
22
usb-driver.c
22
usb-driver.c
@ -33,7 +33,6 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <usb.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
@ -49,7 +48,6 @@ static int windrvrfd = -1;
|
|||||||
static unsigned long ppbase = 0;
|
static unsigned long ppbase = 0;
|
||||||
static unsigned long ecpbase = 0;
|
static unsigned long ecpbase = 0;
|
||||||
static struct parport_config *pport = NULL;
|
static struct parport_config *pport = NULL;
|
||||||
static struct xpcu_s *xpcu = NULL;
|
|
||||||
static FILE *modulesfp = NULL;
|
static FILE *modulesfp = NULL;
|
||||||
static FILE *baseaddrfp = NULL;
|
static FILE *baseaddrfp = NULL;
|
||||||
static int baseaddrnum = 0;
|
static int baseaddrnum = 0;
|
||||||
@ -156,7 +154,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
#ifndef NO_WINDRVR
|
#ifndef NO_WINDRVR
|
||||||
ret = (*ioctl_func) (fd, request, wdioctl);
|
ret = (*ioctl_func) (fd, request, wdioctl);
|
||||||
#else
|
#else
|
||||||
ret = xpcu_transfer(xpcu, ut);
|
ret = xpcu_transfer(ut);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -184,7 +182,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
#ifndef NO_WINDRVR
|
#ifndef NO_WINDRVR
|
||||||
ret = (*ioctl_func) (fd, request, wdioctl);
|
ret = (*ioctl_func) (fd, request, wdioctl);
|
||||||
#else
|
#else
|
||||||
ret = xpcu_int_state(xpcu, it, ENABLE_INTERRUPT);
|
ret = xpcu_int_state(it, ENABLE_INTERRUPT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DPRINTF("<- Handle: 0x%lx, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
|
DPRINTF("<- Handle: 0x%lx, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
|
||||||
@ -207,7 +205,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
#ifndef NO_WINDRVR
|
#ifndef NO_WINDRVR
|
||||||
ret = (*ioctl_func) (fd, request, wdioctl);
|
ret = (*ioctl_func) (fd, request, wdioctl);
|
||||||
#else
|
#else
|
||||||
ret = xpcu_int_state(xpcu, it, DISABLE_INTERRUPT);
|
ret = xpcu_int_state(it, DISABLE_INTERRUPT);
|
||||||
#endif
|
#endif
|
||||||
DPRINTF("<- Handle: 0x%lx, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
|
DPRINTF("<- Handle: 0x%lx, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
|
||||||
it->hInterrupt, it->dwOptions,
|
it->hInterrupt, it->dwOptions,
|
||||||
@ -227,7 +225,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
#ifndef NO_WINDRVR
|
#ifndef NO_WINDRVR
|
||||||
ret = (*ioctl_func) (fd, request, wdioctl);
|
ret = (*ioctl_func) (fd, request, wdioctl);
|
||||||
#else
|
#else
|
||||||
ret = xpcu_set_interface(xpcu, usi);
|
ret = xpcu_set_interface(usi);
|
||||||
#endif
|
#endif
|
||||||
DPRINTF("<- unique: 0x%lx, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
|
DPRINTF("<- unique: 0x%lx, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
|
||||||
usi->dwUniqueID, usi->dwInterfaceNum,
|
usi->dwUniqueID, usi->dwInterfaceNum,
|
||||||
@ -245,7 +243,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
ugdd->dwUniqueID, ugdd->dwBytes,
|
ugdd->dwUniqueID, ugdd->dwBytes,
|
||||||
ugdd->dwOptions);
|
ugdd->dwOptions);
|
||||||
|
|
||||||
ret = xpcu_deviceinfo(xpcu, ugdd);
|
ret = xpcu_deviceinfo(ugdd);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -271,7 +269,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
#ifndef NO_WINDRVR
|
#ifndef NO_WINDRVR
|
||||||
ret = (*ioctl_func) (fd, request, wdioctl);
|
ret = (*ioctl_func) (fd, request, wdioctl);
|
||||||
#else
|
#else
|
||||||
xpcu = xpcu_find(e);
|
ret = xpcu_find(e);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -333,7 +331,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
#ifndef NO_WINDRVR
|
#ifndef NO_WINDRVR
|
||||||
ret = (*ioctl_func) (fd, request, wdioctl);
|
ret = (*ioctl_func) (fd, request, wdioctl);
|
||||||
#else
|
#else
|
||||||
ret = xpcu_close(xpcu, e);
|
ret = xpcu_close(e);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -351,7 +349,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
#ifndef NO_WINDRVR
|
#ifndef NO_WINDRVR
|
||||||
ret = (*ioctl_func) (fd, request, wdioctl);
|
ret = (*ioctl_func) (fd, request, wdioctl);
|
||||||
#else
|
#else
|
||||||
ret = xpcu_int_wait(xpcu, it);
|
ret = xpcu_int_wait(it);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DPRINTF("<- INT_WAIT_RETURN: Handle: 0x%lx, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
|
DPRINTF("<- INT_WAIT_RETURN: Handle: 0x%lx, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
|
||||||
@ -413,7 +411,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
#ifndef NO_WINDRVR
|
#ifndef NO_WINDRVR
|
||||||
ret = (*ioctl_func) (fd, request, wdioctl);
|
ret = (*ioctl_func) (fd, request, wdioctl);
|
||||||
#else
|
#else
|
||||||
ret = xpcu_found(xpcu, e);
|
ret = xpcu_found(e);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -507,8 +505,6 @@ int close(int fd) {
|
|||||||
|
|
||||||
if (fd == windrvrfd && windrvrfd >= 0) {
|
if (fd == windrvrfd && windrvrfd >= 0) {
|
||||||
DPRINTF("close windrvrfd\n");
|
DPRINTF("close windrvrfd\n");
|
||||||
|
|
||||||
xpcu = NULL;
|
|
||||||
windrvrfd = -1;
|
windrvrfd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
80
xpcu.c
80
xpcu.c
@ -9,19 +9,26 @@
|
|||||||
#include "usb-driver.h"
|
#include "usb-driver.h"
|
||||||
#include "xpcu.h"
|
#include "xpcu.h"
|
||||||
|
|
||||||
|
struct xpcu_s {
|
||||||
|
struct usb_device *dev;
|
||||||
|
usb_dev_handle *handle;
|
||||||
|
int interface;
|
||||||
|
int alternate;
|
||||||
|
unsigned long card_type;
|
||||||
|
pthread_mutex_t interrupt;
|
||||||
|
};
|
||||||
|
|
||||||
static struct usb_bus *busses = NULL;
|
static struct usb_bus *busses = NULL;
|
||||||
static pthread_mutex_t dummy_interrupt = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t dummy_interrupt = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
int xpcu_deviceinfo(struct xpcu_s *xpcu, struct usb_get_device_data *ugdd) {
|
int xpcu_deviceinfo(struct usb_get_device_data *ugdd) {
|
||||||
|
struct xpcu_s *xpcu = (struct xpcu_s*)ugdd->dwUniqueID;
|
||||||
int i,j,k,l;
|
int i,j,k,l;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
unsigned char *buf = NULL;
|
unsigned char *buf = NULL;
|
||||||
WDU_CONFIGURATION **pConfigs, **pActiveConfig;
|
WDU_CONFIGURATION **pConfigs, **pActiveConfig;
|
||||||
WDU_INTERFACE **pActiveInterface;
|
WDU_INTERFACE **pActiveInterface;
|
||||||
|
|
||||||
if (ugdd->dwUniqueID != (unsigned long)xpcu)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
if (!xpcu)
|
if (!xpcu)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
@ -217,12 +224,10 @@ static int xpcu_claim(struct xpcu_s *xpcu, int claim) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xpcu_transfer(struct xpcu_s *xpcu, struct usb_transfer *ut) {
|
int xpcu_transfer(struct usb_transfer *ut) {
|
||||||
|
struct xpcu_s *xpcu = (struct xpcu_s*)ut->dwUniqueID;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (ut->dwUniqueID != (unsigned long)xpcu)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
if (!xpcu)
|
if (!xpcu)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
@ -256,9 +261,8 @@ int xpcu_transfer(struct xpcu_s *xpcu, struct usb_transfer *ut) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xpcu_set_interface(struct xpcu_s *xpcu, struct usb_set_interface *usi) {
|
int xpcu_set_interface(struct usb_set_interface *usi) {
|
||||||
if (usi->dwUniqueID != (unsigned long)xpcu)
|
struct xpcu_s *xpcu = (struct xpcu_s*)usi->dwUniqueID;
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
if (!xpcu)
|
if (!xpcu)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
@ -293,14 +297,13 @@ static void xpcu_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct xpcu_s *xpcu_find(struct event *e) {
|
int xpcu_find(struct event *e) {
|
||||||
static struct xpcu_s xpcu;
|
struct xpcu_s *xpcu = NULL;
|
||||||
char* devpos;
|
char* devpos;
|
||||||
struct usb_bus *bus;
|
struct usb_bus *bus;
|
||||||
int busnum = -1, devnum = -1;
|
int busnum = -1, devnum = -1;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
bzero(&xpcu, sizeof(xpcu));
|
|
||||||
xpcu_init();
|
xpcu_init();
|
||||||
|
|
||||||
devpos = getenv("XILINX_USB_DEV");
|
devpos = getenv("XILINX_USB_DEV");
|
||||||
@ -376,11 +379,16 @@ struct xpcu_s *xpcu_find(struct event *e) {
|
|||||||
/* TODO: check interfaceClass! */
|
/* TODO: check interfaceClass! */
|
||||||
DPRINTF("found device with libusb\n");
|
DPRINTF("found device with libusb\n");
|
||||||
|
|
||||||
xpcu.interface = -1;
|
xpcu = malloc(sizeof(struct xpcu_s));
|
||||||
xpcu.alternate = -1;
|
if (!xpcu)
|
||||||
xpcu.dev = dev;
|
return -ENOMEM;
|
||||||
xpcu.card_type = e->dwCardType;
|
|
||||||
pthread_mutex_init(&xpcu.interrupt, NULL);
|
bzero(xpcu, sizeof(struct xpcu_s));
|
||||||
|
xpcu->interface = -1;
|
||||||
|
xpcu->alternate = -1;
|
||||||
|
xpcu->dev = dev;
|
||||||
|
xpcu->card_type = e->dwCardType;
|
||||||
|
pthread_mutex_init(&xpcu->interrupt, NULL);
|
||||||
e->handle = (unsigned long)&xpcu;
|
e->handle = (unsigned long)&xpcu;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -390,16 +398,15 @@ struct xpcu_s *xpcu_find(struct event *e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!xpcu.dev) {
|
e->handle = (unsigned long)xpcu;
|
||||||
e->handle = 0;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return &xpcu;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xpcu_found(struct xpcu_s *xpcu, struct event *e) {
|
int xpcu_found(struct event *e) {
|
||||||
if (e->handle && e->handle == (unsigned long)xpcu && xpcu->dev) {
|
struct xpcu_s *xpcu = (struct xpcu_s*)e->handle;
|
||||||
|
|
||||||
|
if (xpcu && xpcu->dev) {
|
||||||
struct usb_interface *interface = xpcu->dev->config->interface;
|
struct usb_interface *interface = xpcu->dev->config->interface;
|
||||||
|
|
||||||
e->dwCardType = xpcu->card_type;
|
e->dwCardType = xpcu->card_type;
|
||||||
@ -418,9 +425,8 @@ int xpcu_found(struct xpcu_s *xpcu, struct event *e) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xpcu_close(struct xpcu_s *xpcu, struct event *e) {
|
int xpcu_close(struct event *e) {
|
||||||
if (e->handle != (unsigned long)xpcu)
|
struct xpcu_s *xpcu = (struct xpcu_s*)e->handle;
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
if (!xpcu)
|
if (!xpcu)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
@ -431,20 +437,16 @@ int xpcu_close(struct xpcu_s *xpcu, struct event *e) {
|
|||||||
usb_close(xpcu->handle);
|
usb_close(xpcu->handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
xpcu->handle = NULL;
|
|
||||||
xpcu->interface = -1;
|
|
||||||
xpcu->alternate = -1;
|
|
||||||
busses = NULL;
|
busses = NULL;
|
||||||
|
free(xpcu);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xpcu_int_state(struct xpcu_s *xpcu, struct interrupt *it, int enable) {
|
int xpcu_int_state(struct interrupt *it, int enable) {
|
||||||
static pthread_mutex_t *interrupt = &dummy_interrupt;
|
struct xpcu_s *xpcu = (struct xpcu_s*)it->hInterrupt;
|
||||||
|
pthread_mutex_t *interrupt = &dummy_interrupt;
|
||||||
if (it->hInterrupt != (unsigned long)xpcu)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
if (xpcu)
|
if (xpcu)
|
||||||
interrupt = &xpcu->interrupt;
|
interrupt = &xpcu->interrupt;
|
||||||
@ -463,7 +465,9 @@ int xpcu_int_state(struct xpcu_s *xpcu, struct interrupt *it, int enable) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xpcu_int_wait(struct xpcu_s *xpcu, struct interrupt *it) {
|
int xpcu_int_wait(struct interrupt *it) {
|
||||||
|
struct xpcu_s *xpcu = (struct xpcu_s*)it->hInterrupt;
|
||||||
|
|
||||||
if (it->hInterrupt != (unsigned long)xpcu)
|
if (it->hInterrupt != (unsigned long)xpcu)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
|
25
xpcu.h
25
xpcu.h
@ -4,20 +4,11 @@
|
|||||||
#define ENABLE_INTERRUPT 1
|
#define ENABLE_INTERRUPT 1
|
||||||
#define DISABLE_INTERRUPT 0
|
#define DISABLE_INTERRUPT 0
|
||||||
|
|
||||||
struct xpcu_s {
|
int __attribute__ ((visibility ("hidden"))) xpcu_deviceinfo(struct usb_get_device_data *ugdd);
|
||||||
struct usb_device *dev;
|
int __attribute__ ((visibility ("hidden"))) xpcu_transfer(struct usb_transfer *ut);
|
||||||
usb_dev_handle *handle;
|
int __attribute__ ((visibility ("hidden"))) xpcu_set_interface(struct usb_set_interface *usi);
|
||||||
int interface;
|
int __attribute__ ((visibility ("hidden"))) xpcu_find(struct event *e);
|
||||||
int alternate;
|
int __attribute__ ((visibility ("hidden"))) xpcu_found(struct event *e);
|
||||||
unsigned long card_type;
|
int __attribute__ ((visibility ("hidden"))) xpcu_close(struct event *e);
|
||||||
pthread_mutex_t interrupt;
|
int __attribute__ ((visibility ("hidden"))) xpcu_int_state(struct interrupt *it, int enable);
|
||||||
};
|
int __attribute__ ((visibility ("hidden"))) xpcu_int_wait(struct interrupt *it);
|
||||||
|
|
||||||
int __attribute__ ((visibility ("hidden"))) xpcu_deviceinfo(struct xpcu_s *xpcu, struct usb_get_device_data *ugdd);
|
|
||||||
int __attribute__ ((visibility ("hidden"))) xpcu_transfer(struct xpcu_s *xpcu, struct usb_transfer *ut);
|
|
||||||
int __attribute__ ((visibility ("hidden"))) xpcu_set_interface(struct xpcu_s *xpcu, struct usb_set_interface *usi);
|
|
||||||
struct xpcu_s __attribute__ ((visibility ("hidden"))) *xpcu_find(struct event *e);
|
|
||||||
int __attribute__ ((visibility ("hidden"))) xpcu_found(struct xpcu_s *xpcu, struct event *e);
|
|
||||||
int __attribute__ ((visibility ("hidden"))) xpcu_close(struct xpcu_s *xpcu, struct event *e);
|
|
||||||
int __attribute__ ((visibility ("hidden"))) xpcu_int_state(struct xpcu_s *xpcu, struct interrupt *it, int enable);
|
|
||||||
int __attribute__ ((visibility ("hidden"))) xpcu_int_wait(struct xpcu_s *xpcu, struct interrupt *it);
|
|
||||||
|
Reference in New Issue
Block a user