use a pthread mutex for interrupts
This commit is contained in:
parent
dbda1264f8
commit
533f4b68ba
2
Makefile
2
Makefile
@ -1,7 +1,7 @@
|
|||||||
CFLAGS=-Wall
|
CFLAGS=-Wall
|
||||||
|
|
||||||
xilinx.so: xilinx.c xilinx.h
|
xilinx.so: xilinx.c xilinx.h
|
||||||
gcc $(CFLAGS) $< -o $@ -ldl -lusb -shared
|
gcc $(CFLAGS) $< -o $@ -ldl -lusb -lpthread -shared
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f xilinx.so
|
rm -f xilinx.so
|
||||||
|
17
usb-driver.c
17
usb-driver.c
@ -20,6 +20,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <usb.h>
|
#include <usb.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <pthread.h>
|
||||||
#include "xilinx.h"
|
#include "xilinx.h"
|
||||||
|
|
||||||
static int (*ioctl_func) (int, int, void *) = NULL;
|
static int (*ioctl_func) (int, int, void *) = NULL;
|
||||||
@ -31,6 +32,7 @@ static struct usb_device *usbdevice;
|
|||||||
static usb_dev_handle *usb_devhandle = NULL;
|
static usb_dev_handle *usb_devhandle = NULL;
|
||||||
static unsigned long card_type;
|
static unsigned long card_type;
|
||||||
static int ints_enabled = 0;
|
static int ints_enabled = 0;
|
||||||
|
static pthread_mutex_t int_wait = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
#define NO_WINDRVR 1
|
#define NO_WINDRVR 1
|
||||||
#undef DEBUG
|
#undef DEBUG
|
||||||
@ -232,10 +234,12 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CARD_REGISTER:
|
case CARD_REGISTER:
|
||||||
|
/* TODO: Implement for LPT-support */
|
||||||
|
#if 0
|
||||||
{
|
{
|
||||||
//struct card_register* cr = (struct card_register*)(wdheader->data);
|
struct card_register* cr = (struct card_register*)(wdheader->data);
|
||||||
/* Todo: LPT-Port already in use */
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr,"faking CARD_REGISTER\n");
|
fprintf(stderr,"faking CARD_REGISTER\n");
|
||||||
#endif
|
#endif
|
||||||
@ -318,7 +322,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
|
|
||||||
it->fEnableOk = 1;
|
it->fEnableOk = 1;
|
||||||
ints_enabled = 1;
|
ints_enabled = 1;
|
||||||
//ret = (*ioctl_func) (fd, request, wdioctl);
|
pthread_mutex_trylock(&int_wait);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -339,6 +343,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
it->dwCounter = 0;
|
it->dwCounter = 0;
|
||||||
it->fStopped = 1;
|
it->fStopped = 1;
|
||||||
ints_enabled = 0;
|
ints_enabled = 0;
|
||||||
|
pthread_mutex_unlock(&int_wait);
|
||||||
#endif
|
#endif
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr,"Handle: %lu, 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);
|
fprintf(stderr,"Handle: %lu, 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);
|
||||||
@ -366,7 +371,6 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
/* FIXME: Select right interface! */
|
/* FIXME: Select right interface! */
|
||||||
ret = usb_claim_interface(usb_devhandle, usbdevice->config[0].interface[usi->dwInterfaceNum].altsetting[usi->dwAlternateSetting].bInterfaceNumber);
|
ret = usb_claim_interface(usb_devhandle, usbdevice->config[0].interface[usi->dwInterfaceNum].altsetting[usi->dwAlternateSetting].bInterfaceNumber);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
//ret = usb_set_configuration(usb_devhandle, usbdevice->config[0].bConfigurationValue);
|
|
||||||
if(!ret) {
|
if(!ret) {
|
||||||
ret = usb_set_altinterface(usb_devhandle, usi->dwAlternateSetting);
|
ret = usb_set_altinterface(usb_devhandle, usi->dwAlternateSetting);
|
||||||
if (ret)
|
if (ret)
|
||||||
@ -397,7 +401,6 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
fprintf(stderr, "unique: %lu, bytes: %lu, options: %lx\n", ugdd->dwUniqueID, ugdd->dwBytes, ugdd->dwOptions);
|
fprintf(stderr, "unique: %lu, bytes: %lu, options: %lx\n", ugdd->dwUniqueID, ugdd->dwBytes, ugdd->dwOptions);
|
||||||
#endif
|
#endif
|
||||||
pSize = ugdd->dwBytes;
|
pSize = ugdd->dwBytes;
|
||||||
//ret = (*ioctl_func) (fd, request, wdioctl);
|
|
||||||
if (!ugdd->dwBytes) {
|
if (!ugdd->dwBytes) {
|
||||||
if (usbdevice) {
|
if (usbdevice) {
|
||||||
ugdd->dwBytes = usb_deviceinfo(NULL);
|
ugdd->dwBytes = usb_deviceinfo(NULL);
|
||||||
@ -508,10 +511,10 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
if (it->dwCounter == 0) {
|
if (it->dwCounter == 0) {
|
||||||
it->dwCounter = 1;
|
it->dwCounter = 1;
|
||||||
} else {
|
} else {
|
||||||
while(ints_enabled) {sleep(1);}
|
pthread_mutex_lock(&int_wait);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while(ints_enabled) {sleep(1);}
|
pthread_mutex_lock(&int_wait);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user