move interrupt functions to xpcu.c
This commit is contained in:
parent
f92c0fbce9
commit
501f1c2134
84
usb-driver.c
84
usb-driver.c
@ -35,7 +35,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <usb.h>
|
#include <usb.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <pthread.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
@ -55,8 +54,6 @@ static FILE *modulesfp = NULL;
|
|||||||
static FILE *baseaddrfp = NULL;
|
static FILE *baseaddrfp = NULL;
|
||||||
static int baseaddrnum = 0;
|
static int baseaddrnum = 0;
|
||||||
static int modules_read = 0;
|
static int modules_read = 0;
|
||||||
static int ints_enabled = 0;
|
|
||||||
static pthread_mutex_t int_wait = PTHREAD_MUTEX_INITIALIZER;
|
|
||||||
|
|
||||||
#define NO_WINDRVR 1
|
#define NO_WINDRVR 1
|
||||||
|
|
||||||
@ -100,13 +97,13 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
{
|
{
|
||||||
struct card_register* cr = (struct card_register*)(wdheader->data);
|
struct card_register* cr = (struct card_register*)(wdheader->data);
|
||||||
|
|
||||||
DPRINTF("Items: %lu, Addr: 0x%lx, bytes: %lu, bar: %lu\n",
|
DPRINTF("-> Items: %lu, Addr: 0x%lx, bytes: %lu, bar: %lu\n",
|
||||||
cr->Card.dwItems,
|
cr->Card.dwItems,
|
||||||
(unsigned long)cr->Card.Item[0].I.IO.dwAddr,
|
(unsigned long)cr->Card.Item[0].I.IO.dwAddr,
|
||||||
cr->Card.Item[0].I.IO.dwBytes,
|
cr->Card.Item[0].I.IO.dwBytes,
|
||||||
cr->Card.Item[0].I.IO.dwBar);
|
cr->Card.Item[0].I.IO.dwBar);
|
||||||
|
|
||||||
DPRINTF("Items: %lu, Addr: 0x%lx, bytes: %lu, bar: %lu\n",
|
DPRINTF("-> Items: %lu, Addr: 0x%lx, bytes: %lu, bar: %lu\n",
|
||||||
cr->Card.dwItems,
|
cr->Card.dwItems,
|
||||||
(unsigned long)cr->Card.Item[1].I.IO.dwAddr,
|
(unsigned long)cr->Card.Item[1].I.IO.dwAddr,
|
||||||
cr->Card.Item[1].I.IO.dwBytes,
|
cr->Card.Item[1].I.IO.dwBytes,
|
||||||
@ -132,21 +129,21 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
cr->hCard = 0;
|
cr->hCard = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
DPRINTF("hCard: %lu\n", cr->hCard);
|
DPRINTF("<-hCard: %lu\n", cr->hCard);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_TRANSFER:
|
case USB_TRANSFER:
|
||||||
DPRINTF("in USB_TRANSFER");
|
DPRINTF("USB_TRANSFER\n");
|
||||||
{
|
{
|
||||||
struct usb_transfer *ut = (struct usb_transfer*)(wdheader->data);
|
struct usb_transfer *ut = (struct usb_transfer*)(wdheader->data);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
DPRINTF(" unique: 0x%lx, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n",
|
DPRINTF("-> unique: 0x%lx, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n",
|
||||||
ut->dwUniqueID, ut->dwPipeNum, ut->fRead,
|
ut->dwUniqueID, ut->dwPipeNum, ut->fRead,
|
||||||
ut->dwOptions, ut->dwBufferSize, ut->dwTimeout);
|
ut->dwOptions, ut->dwBufferSize, ut->dwTimeout);
|
||||||
if (ut->dwPipeNum == 0) {
|
if (ut->dwPipeNum == 0) {
|
||||||
DPRINTF("setup packet: ");
|
DPRINTF("-> setup packet: ");
|
||||||
hexdump(ut->SetupPacket, 8);
|
hexdump(ut->SetupPacket, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +163,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
DPRINTF("Transferred: %lu (%s)\n",ut->dwBytesTransferred, (ut->fRead?"read":"write"));
|
DPRINTF("Transferred: %lu (%s)\n",ut->dwBytesTransferred, (ut->fRead?"read":"write"));
|
||||||
if (ut->fRead && ut->dwBytesTransferred)
|
if (ut->fRead && ut->dwBytesTransferred)
|
||||||
{
|
{
|
||||||
DPRINTF("Read: ");
|
DPRINTF("<- Read: ");
|
||||||
hexdump(ut->pBuffer, ut->dwBytesTransferred);
|
hexdump(ut->pBuffer, ut->dwBytesTransferred);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -179,15 +176,21 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
{
|
{
|
||||||
struct interrupt *it = (struct interrupt*)(wdheader->data);
|
struct interrupt *it = (struct interrupt*)(wdheader->data);
|
||||||
|
|
||||||
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,
|
||||||
it->dwCmds, it->fEnableOk, it->dwCounter,
|
it->dwCmds, it->fEnableOk, it->dwCounter,
|
||||||
it->dwLost, it->fStopped);
|
it->dwLost, it->fStopped);
|
||||||
|
|
||||||
it->fEnableOk = 1;
|
#ifndef NO_WINDRVR
|
||||||
it->fStopped = 0;
|
ret = (*ioctl_func) (fd, request, wdioctl);
|
||||||
ints_enabled = 1;
|
#else
|
||||||
pthread_mutex_trylock(&int_wait);
|
xpcu_int_state(xpcu, it, ENABLE_INTERRUPT);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
DPRINTF("<- Handle: 0x%lx, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
|
||||||
|
it->hInterrupt, it->dwOptions,
|
||||||
|
it->dwCmds, it->fEnableOk, it->dwCounter,
|
||||||
|
it->dwLost, it->fStopped);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -197,20 +200,16 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
{
|
{
|
||||||
struct interrupt *it = (struct interrupt*)(wdheader->data);
|
struct interrupt *it = (struct interrupt*)(wdheader->data);
|
||||||
|
|
||||||
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,
|
||||||
it->dwCmds, it->fEnableOk, it->dwCounter,
|
it->dwCmds, it->fEnableOk, it->dwCounter,
|
||||||
it->dwLost, it->fStopped);
|
it->dwLost, it->fStopped);
|
||||||
#ifndef NO_WINDRVR
|
#ifndef NO_WINDRVR
|
||||||
ret = (*ioctl_func) (fd, request, wdioctl);
|
ret = (*ioctl_func) (fd, request, wdioctl);
|
||||||
#else
|
#else
|
||||||
it->dwCounter = 0;
|
xpcu_int_state(xpcu, it, DISABLE_INTERRUPT);
|
||||||
it->fStopped = 1;
|
|
||||||
ints_enabled = 0;
|
|
||||||
if (pthread_mutex_trylock(&int_wait) == EBUSY)
|
|
||||||
pthread_mutex_unlock(&int_wait);
|
|
||||||
#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,
|
||||||
it->dwCmds, it->fEnableOk, it->dwCounter,
|
it->dwCmds, it->fEnableOk, it->dwCounter,
|
||||||
it->dwLost, it->fStopped);
|
it->dwLost, it->fStopped);
|
||||||
@ -222,7 +221,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
{
|
{
|
||||||
struct usb_set_interface *usi = (struct usb_set_interface*)(wdheader->data);
|
struct usb_set_interface *usi = (struct usb_set_interface*)(wdheader->data);
|
||||||
|
|
||||||
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,
|
||||||
usi->dwAlternateSetting, usi->dwOptions);
|
usi->dwAlternateSetting, usi->dwOptions);
|
||||||
#ifndef NO_WINDRVR
|
#ifndef NO_WINDRVR
|
||||||
@ -230,7 +229,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
#else
|
#else
|
||||||
xpcu_set_interface(xpcu, usi);
|
xpcu_set_interface(xpcu, 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,
|
||||||
usi->dwAlternateSetting, usi->dwOptions);
|
usi->dwAlternateSetting, usi->dwOptions);
|
||||||
}
|
}
|
||||||
@ -242,7 +241,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
{
|
{
|
||||||
struct usb_get_device_data *ugdd = (struct usb_get_device_data*)(wdheader->data);
|
struct usb_get_device_data *ugdd = (struct usb_get_device_data*)(wdheader->data);
|
||||||
|
|
||||||
DPRINTF("unique: 0x%lx, bytes: %lu, options: %lx\n",
|
DPRINTF("-> unique: 0x%lx, bytes: %lu, options: %lx\n",
|
||||||
ugdd->dwUniqueID, ugdd->dwBytes,
|
ugdd->dwUniqueID, ugdd->dwBytes,
|
||||||
ugdd->dwOptions);
|
ugdd->dwOptions);
|
||||||
|
|
||||||
@ -260,7 +259,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
int i;
|
int i;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DPRINTF("handle: 0x%lx, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: 0x%lx, ver: %lu, nummatch: %lu\n",
|
DPRINTF("-> handle: 0x%lx, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: 0x%lx, ver: %lu, nummatch: %lu\n",
|
||||||
e->handle, e->dwAction,
|
e->handle, e->dwAction,
|
||||||
e->dwStatus, e->dwEventId, e->dwCardType,
|
e->dwStatus, e->dwEventId, e->dwCardType,
|
||||||
e->hKernelPlugIn, e->dwOptions,
|
e->hKernelPlugIn, e->dwOptions,
|
||||||
@ -269,15 +268,14 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
e->u.Usb.dwUniqueID, e->dwEventVer,
|
e->u.Usb.dwUniqueID, e->dwEventVer,
|
||||||
e->dwNumMatchTables);
|
e->dwNumMatchTables);
|
||||||
|
|
||||||
xpcu = xpcu_find(e);
|
|
||||||
#ifndef NO_WINDRVR
|
#ifndef NO_WINDRVR
|
||||||
ret = (*ioctl_func) (fd, request, wdioctl);
|
ret = (*ioctl_func) (fd, request, wdioctl);
|
||||||
#else
|
#else
|
||||||
e->handle = (unsigned long)xpcu;
|
xpcu = xpcu_find(e);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
DPRINTF("handle: 0x%lx, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: 0x%lx, ver: %lu, nummatch: %lu\n",
|
DPRINTF("<- handle: 0x%lx, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: 0x%lx, ver: %lu, nummatch: %lu\n",
|
||||||
e->handle, e->dwAction,
|
e->handle, e->dwAction,
|
||||||
e->dwStatus, e->dwEventId, e->dwCardType,
|
e->dwStatus, e->dwEventId, e->dwCardType,
|
||||||
e->hKernelPlugIn, e->dwOptions,
|
e->hKernelPlugIn, e->dwOptions,
|
||||||
@ -345,7 +343,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
{
|
{
|
||||||
struct interrupt *it = (struct interrupt*)(wdheader->data);
|
struct interrupt *it = (struct interrupt*)(wdheader->data);
|
||||||
|
|
||||||
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,
|
||||||
it->dwCmds, it->fEnableOk, it->dwCounter,
|
it->dwCmds, it->fEnableOk, it->dwCounter,
|
||||||
it->dwLost, it->fStopped);
|
it->dwLost, it->fStopped);
|
||||||
@ -353,20 +351,10 @@ 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
|
||||||
if (xpcu) {
|
xpcu_int_wait(xpcu, it);
|
||||||
if (it->dwCounter == 0) {
|
|
||||||
it->dwCounter = 1;
|
|
||||||
} else {
|
|
||||||
pthread_mutex_lock(&int_wait);
|
|
||||||
pthread_mutex_unlock(&int_wait);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pthread_mutex_lock(&int_wait);
|
|
||||||
pthread_mutex_unlock(&int_wait);
|
|
||||||
}
|
|
||||||
#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",
|
||||||
it->hInterrupt, it->dwOptions, it->dwCmds,
|
it->hInterrupt, it->dwOptions, it->dwCmds,
|
||||||
it->fEnableOk, it->dwCounter, it->dwLost,
|
it->fEnableOk, it->dwCounter, it->dwLost,
|
||||||
it->fStopped);
|
it->fStopped);
|
||||||
@ -378,12 +366,12 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
{
|
{
|
||||||
struct card_register* cr = (struct card_register*)(wdheader->data);
|
struct card_register* cr = (struct card_register*)(wdheader->data);
|
||||||
|
|
||||||
DPRINTF("Addr: 0x%lx, bytes: %lu, bar: %lu\n",
|
DPRINTF("-> Addr: 0x%lx, bytes: %lu, bar: %lu\n",
|
||||||
(unsigned long)cr->Card.Item[0].I.IO.dwAddr,
|
(unsigned long)cr->Card.Item[0].I.IO.dwAddr,
|
||||||
cr->Card.Item[0].I.IO.dwBytes,
|
cr->Card.Item[0].I.IO.dwBytes,
|
||||||
cr->Card.Item[0].I.IO.dwBar);
|
cr->Card.Item[0].I.IO.dwBar);
|
||||||
|
|
||||||
DPRINTF("hCard: %lu\n", cr->hCard);
|
DPRINTF("-> hCard: %lu\n", cr->hCard);
|
||||||
|
|
||||||
#ifndef NO_WINDRVR
|
#ifndef NO_WINDRVR
|
||||||
ret = (*ioctl_func) (fd, request, wdioctl);
|
ret = (*ioctl_func) (fd, request, wdioctl);
|
||||||
@ -403,7 +391,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
DPRINTF("handle: 0x%lx, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, kplug: %lu, options: %lu, dev: %lx:%lx, unique: 0x%lx, ver: %lu, nummatch: %lu\n",
|
DPRINTF("-> handle: 0x%lx, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, kplug: %lu, options: %lu, dev: %lx:%lx, unique: 0x%lx, ver: %lu, nummatch: %lu\n",
|
||||||
e->handle, e->dwAction, e->dwStatus,
|
e->handle, e->dwAction, e->dwStatus,
|
||||||
e->dwEventId, e->dwCardType, e->hKernelPlugIn,
|
e->dwEventId, e->dwCardType, e->hKernelPlugIn,
|
||||||
e->dwOptions, e->u.Usb.deviceId.dwVendorId,
|
e->dwOptions, e->u.Usb.deviceId.dwVendorId,
|
||||||
@ -412,7 +400,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
e->dwNumMatchTables);
|
e->dwNumMatchTables);
|
||||||
|
|
||||||
for (i = 0; i < e->dwNumMatchTables; i++)
|
for (i = 0; i < e->dwNumMatchTables; i++)
|
||||||
DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
|
DPRINTF("-> match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
|
||||||
e->matchTables[i].VendorId,
|
e->matchTables[i].VendorId,
|
||||||
e->matchTables[i].ProductId,
|
e->matchTables[i].ProductId,
|
||||||
e->matchTables[i].bDeviceClass,
|
e->matchTables[i].bDeviceClass,
|
||||||
@ -429,7 +417,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
DPRINTF("handle: 0x%lx, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, kplug: %lu, options: %lu, dev: %lx:%lx, unique: 0x%lx, ver: %lu, nummatch: %lu\n",
|
DPRINTF("<- handle: 0x%lx, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, kplug: %lu, options: %lu, dev: %lx:%lx, unique: 0x%lx, ver: %lu, nummatch: %lu\n",
|
||||||
e->handle, e->dwAction, e->dwStatus,
|
e->handle, e->dwAction, e->dwStatus,
|
||||||
e->dwEventId, e->dwCardType, e->hKernelPlugIn,
|
e->dwEventId, e->dwCardType, e->hKernelPlugIn,
|
||||||
e->dwOptions, e->u.Usb.deviceId.dwVendorId,
|
e->dwOptions, e->u.Usb.deviceId.dwVendorId,
|
||||||
@ -438,7 +426,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
e->dwNumMatchTables);
|
e->dwNumMatchTables);
|
||||||
|
|
||||||
for (i = 0; i < e->dwNumMatchTables; i++)
|
for (i = 0; i < e->dwNumMatchTables; i++)
|
||||||
DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
|
DPRINTF("<- match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
|
||||||
e->matchTables[i].VendorId,
|
e->matchTables[i].VendorId,
|
||||||
e->matchTables[i].ProductId,
|
e->matchTables[i].ProductId,
|
||||||
e->matchTables[i].bDeviceClass,
|
e->matchTables[i].bDeviceClass,
|
||||||
|
54
xpcu.c
54
xpcu.c
@ -5,10 +5,12 @@
|
|||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <usb.h>
|
#include <usb.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <pthread.h>
|
||||||
#include "usb-driver.h"
|
#include "usb-driver.h"
|
||||||
#include "xpcu.h"
|
#include "xpcu.h"
|
||||||
|
|
||||||
static struct usb_bus *busses = NULL;
|
static struct usb_bus *busses = NULL;
|
||||||
|
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 xpcu_s *xpcu, struct usb_get_device_data *ugdd) {
|
||||||
int i,j,k,l;
|
int i,j,k,l;
|
||||||
@ -225,7 +227,7 @@ int xpcu_transfer(struct xpcu_s *xpcu, struct usb_transfer *ut) {
|
|||||||
value = ut->SetupPacket[2] | (ut->SetupPacket[3] << 8);
|
value = ut->SetupPacket[2] | (ut->SetupPacket[3] << 8);
|
||||||
index = ut->SetupPacket[4] | (ut->SetupPacket[5] << 8);
|
index = ut->SetupPacket[4] | (ut->SetupPacket[5] << 8);
|
||||||
size = ut->SetupPacket[6] | (ut->SetupPacket[7] << 8);
|
size = ut->SetupPacket[6] | (ut->SetupPacket[7] << 8);
|
||||||
DPRINTF("requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype, request, value, index, size);
|
DPRINTF("-> requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype, request, value, index, size);
|
||||||
ret = usb_control_msg(xpcu->handle, requesttype, request, value, index, ut->pBuffer, size, ut->dwTimeout);
|
ret = usb_control_msg(xpcu->handle, requesttype, request, value, index, ut->pBuffer, size, ut->dwTimeout);
|
||||||
} else {
|
} else {
|
||||||
if (ut->fRead) {
|
if (ut->fRead) {
|
||||||
@ -286,9 +288,6 @@ struct xpcu_s *xpcu_find(struct event *e) {
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
bzero(&xpcu, sizeof(xpcu));
|
bzero(&xpcu, sizeof(xpcu));
|
||||||
xpcu.interface = -1;
|
|
||||||
xpcu.alternate = -1;
|
|
||||||
|
|
||||||
xpcu_init();
|
xpcu_init();
|
||||||
|
|
||||||
devpos = getenv("XILINX_USB_DEV");
|
devpos = getenv("XILINX_USB_DEV");
|
||||||
@ -363,8 +362,13 @@ struct xpcu_s *xpcu_find(struct event *e) {
|
|||||||
(interface->altsetting[ai].bInterfaceProtocol == e->matchTables[i].bInterfaceProtocol)){
|
(interface->altsetting[ai].bInterfaceProtocol == e->matchTables[i].bInterfaceProtocol)){
|
||||||
/* TODO: check interfaceClass! */
|
/* TODO: check interfaceClass! */
|
||||||
DPRINTF("found device with libusb\n");
|
DPRINTF("found device with libusb\n");
|
||||||
|
|
||||||
|
xpcu.interface = -1;
|
||||||
|
xpcu.alternate = -1;
|
||||||
xpcu.dev = dev;
|
xpcu.dev = dev;
|
||||||
xpcu.card_type = e->dwCardType;
|
xpcu.card_type = e->dwCardType;
|
||||||
|
pthread_mutex_init(&xpcu.interrupt, NULL);
|
||||||
|
e->handle = (unsigned long)&xpcu;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -373,8 +377,10 @@ struct xpcu_s *xpcu_find(struct event *e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!xpcu.dev)
|
if (!xpcu.dev) {
|
||||||
|
e->handle = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return &xpcu;
|
return &xpcu;
|
||||||
}
|
}
|
||||||
@ -413,3 +419,41 @@ void xpcu_close(struct xpcu_s *xpcu, struct event *e) {
|
|||||||
busses = NULL;
|
busses = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void xpcu_int_state(struct xpcu_s *xpcu, struct interrupt *it, int enable) {
|
||||||
|
static pthread_mutex_t *interrupt = &dummy_interrupt;
|
||||||
|
|
||||||
|
if (it->hInterrupt != (unsigned long)xpcu)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (xpcu)
|
||||||
|
interrupt = &xpcu->interrupt;
|
||||||
|
|
||||||
|
if (enable == ENABLE_INTERRUPT) {
|
||||||
|
it->fEnableOk = 1;
|
||||||
|
it->fStopped = 0;
|
||||||
|
pthread_mutex_trylock(interrupt);
|
||||||
|
} else {
|
||||||
|
it->dwCounter = 0;
|
||||||
|
it->fStopped = 1;
|
||||||
|
if (pthread_mutex_trylock(interrupt) == EBUSY)
|
||||||
|
pthread_mutex_unlock(interrupt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void xpcu_int_wait(struct xpcu_s *xpcu, struct interrupt *it) {
|
||||||
|
if (it->hInterrupt != (unsigned long)xpcu)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (xpcu) {
|
||||||
|
if (it->dwCounter == 0) {
|
||||||
|
it->dwCounter = 1;
|
||||||
|
} else {
|
||||||
|
pthread_mutex_lock(&xpcu->interrupt);
|
||||||
|
pthread_mutex_unlock(&xpcu->interrupt);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pthread_mutex_lock(&dummy_interrupt);
|
||||||
|
pthread_mutex_unlock(&dummy_interrupt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
6
xpcu.h
6
xpcu.h
@ -1,12 +1,16 @@
|
|||||||
#define XPCU_CLAIM 1
|
#define XPCU_CLAIM 1
|
||||||
#define XPCU_RELEASE 0
|
#define XPCU_RELEASE 0
|
||||||
|
|
||||||
|
#define ENABLE_INTERRUPT 1
|
||||||
|
#define DISABLE_INTERRUPT 0
|
||||||
|
|
||||||
struct xpcu_s {
|
struct xpcu_s {
|
||||||
struct usb_device *dev;
|
struct usb_device *dev;
|
||||||
usb_dev_handle *handle;
|
usb_dev_handle *handle;
|
||||||
int interface;
|
int interface;
|
||||||
int alternate;
|
int alternate;
|
||||||
unsigned long card_type;
|
unsigned long card_type;
|
||||||
|
pthread_mutex_t interrupt;
|
||||||
};
|
};
|
||||||
|
|
||||||
int __attribute__ ((visibility ("hidden"))) xpcu_deviceinfo(struct xpcu_s *xpcu, struct usb_get_device_data *ugdd);
|
int __attribute__ ((visibility ("hidden"))) xpcu_deviceinfo(struct xpcu_s *xpcu, struct usb_get_device_data *ugdd);
|
||||||
@ -15,3 +19,5 @@ void __attribute__ ((visibility ("hidden"))) xpcu_set_interface(struct xpcu_s *x
|
|||||||
struct xpcu_s __attribute__ ((visibility ("hidden"))) *xpcu_find(struct event *e);
|
struct xpcu_s __attribute__ ((visibility ("hidden"))) *xpcu_find(struct event *e);
|
||||||
void __attribute__ ((visibility ("hidden"))) xpcu_found(struct xpcu_s *xpcu, struct event *e);
|
void __attribute__ ((visibility ("hidden"))) xpcu_found(struct xpcu_s *xpcu, struct event *e);
|
||||||
void __attribute__ ((visibility ("hidden"))) xpcu_close(struct xpcu_s *xpcu, struct event *e);
|
void __attribute__ ((visibility ("hidden"))) xpcu_close(struct xpcu_s *xpcu, struct event *e);
|
||||||
|
void __attribute__ ((visibility ("hidden"))) xpcu_int_state(struct xpcu_s *xpcu, struct interrupt *it, int enable);
|
||||||
|
void __attribute__ ((visibility ("hidden"))) xpcu_int_wait(struct xpcu_s *xpcu, struct interrupt *it);
|
||||||
|
Reference in New Issue
Block a user