Browse Source

make it possible to share the USB and parallel cable between applications

master
Michael Gernoth 17 years ago
parent
commit
cf55ed64bb
  1. 12
      parport.c
  2. 69
      usb-driver.c

12
parport.c

@ -20,6 +20,12 @@ int parport_transfer(WD_TRANSFER *tr, int fd, unsigned int request, int ppbase,
unsigned char val; unsigned char val;
static unsigned char last_pp_write = 0; static unsigned char last_pp_write = 0;
if (parportfd < 0)
return ret;
if (ioctl(parportfd, PPCLAIM) == -1)
return -1;
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
DPRINTF("dwPort: 0x%lx, cmdTrans: %lu, dwbytes: %ld, fautoinc: %ld, dwoptions: %ld\n", DPRINTF("dwPort: 0x%lx, cmdTrans: %lu, dwbytes: %ld, fautoinc: %ld, dwoptions: %ld\n",
(unsigned long)tr[i].dwPort, tr[i].cmdTrans, tr[i].dwBytes, (unsigned long)tr[i].dwPort, tr[i].cmdTrans, tr[i].dwBytes,
@ -33,9 +39,6 @@ int parport_transfer(WD_TRANSFER *tr, int fd, unsigned int request, int ppbase,
DPRINTF("write byte: %d\n", val); DPRINTF("write byte: %d\n", val);
#endif #endif
if (parportfd < 0)
return ret;
if (port == ppbase + PP_DATA) { if (port == ppbase + PP_DATA) {
DPRINTF("data port\n"); DPRINTF("data port\n");
switch(tr[i].cmdTrans) { switch(tr[i].cmdTrans) {
@ -114,6 +117,8 @@ int parport_transfer(WD_TRANSFER *tr, int fd, unsigned int request, int ppbase,
#endif #endif
} }
ioctl(parportfd, PPRELEASE);
return ret; return ret;
} }
@ -139,6 +144,7 @@ int parport_open(int num) {
if (ioctl(parportfd, PPNEGOT, &pmode) == -1) if (ioctl(parportfd, PPNEGOT, &pmode) == -1)
return -1; return -1;
ioctl(parportfd, PPRELEASE);
#if 0 #if 0
if (cr->Card.dwItems > 1 && cr->Card.Item[1].I.IO.dwAddr) { if (cr->Card.dwItems > 1 && cr->Card.Item[1].I.IO.dwAddr) {
DPRINTF("ECP mode requested\n"); DPRINTF("ECP mode requested\n");

69
usb-driver.c

@ -57,6 +57,7 @@ static struct usb_bus *busses = NULL;
static struct usb_device *usbdevice; static struct usb_device *usbdevice;
static usb_dev_handle *usb_devhandle = NULL; static usb_dev_handle *usb_devhandle = NULL;
static int usbinterface = -1; static int usbinterface = -1;
static int usbalternate = -1;
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; static pthread_mutex_t int_wait = PTHREAD_MUTEX_INITIALIZER;
@ -234,6 +235,39 @@ static int usb_deviceinfo(unsigned char *buf) {
return len; return len;
} }
static int usb_claim(int claim) {
int ret = 0;
static int claimed = 0;
if (usbinterface < 0)
return -1;
if (claim) {
if (claimed)
return 0;
ret = usb_claim_interface(usb_devhandle, usbinterface);
if (!ret) {
claimed = 1;
ret = usb_set_altinterface(usb_devhandle, usbalternate);
if (ret)
fprintf(stderr, "usb_set_altinterface: %d\n", ret);
} else {
fprintf(stderr, "usb_claim_interface: %d -> %d (%s)\n",
usbinterface, ret, usb_strerror());
}
} else {
if (!claimed)
return 0;
ret = usb_release_interface(usb_devhandle, usbinterface);
if (!ret)
claimed = 0;
}
return ret;
}
static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
struct header_struct* wdheader = (struct header_struct*)wdioctl; struct header_struct* wdheader = (struct header_struct*)wdioctl;
struct version_struct *version; struct version_struct *version;
@ -307,8 +341,10 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
DPRINTF(" unique: %lu, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n", DPRINTF(" unique: %lu, 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);
DPRINTF("setup packet: "); if (ut->dwPipeNum == 0) {
hexdump(ut->SetupPacket, 8); DPRINTF("setup packet: ");
hexdump(ut->SetupPacket, 8);
}
if (!ut->fRead && ut->dwBufferSize) if (!ut->fRead && ut->dwBufferSize)
{ {
@ -319,6 +355,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
usb_claim(1);
/* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */ /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */
if (ut->dwPipeNum == 0) { /* control pipe */ if (ut->dwPipeNum == 0) { /* control pipe */
int requesttype, request, value, index, size; int requesttype, request, value, index, size;
@ -332,10 +369,10 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
} else { } else {
if (ut->fRead) { if (ut->fRead) {
ret = usb_bulk_read(usb_devhandle, ut->dwPipeNum, ut->pBuffer, ut->dwBufferSize, ut->dwTimeout); ret = usb_bulk_read(usb_devhandle, ut->dwPipeNum, ut->pBuffer, ut->dwBufferSize, ut->dwTimeout);
} else { } else {
ret = usb_bulk_write(usb_devhandle, ut->dwPipeNum, ut->pBuffer, ut->dwBufferSize, ut->dwTimeout); ret = usb_bulk_write(usb_devhandle, ut->dwPipeNum, ut->pBuffer, ut->dwBufferSize, ut->dwTimeout);
} }
usb_claim(0);
} }
if (ret < 0) { if (ret < 0) {
@ -416,22 +453,8 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
if (!usb_devhandle) if (!usb_devhandle)
usb_devhandle = usb_open(usbdevice); usb_devhandle = usb_open(usbdevice);
/* FIXME: Select right interface! */ usbinterface = 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); usbalternate = usi->dwAlternateSetting;
if (!ret) {
if(!ret) {
usbinterface = usbdevice->config[0].interface[usi->dwInterfaceNum].altsetting[usi->dwAlternateSetting].bInterfaceNumber;
ret = usb_set_altinterface(usb_devhandle, usi->dwAlternateSetting);
if (ret)
fprintf(stderr, "usb_set_altinterface: %d\n", ret);
} else {
fprintf(stderr, "usb_set_configuration: %d (%s)\n", ret, usb_strerror());
}
} else {
fprintf(stderr, "usb_claim_interface: %d -> %d (%s)\n",
usbdevice->config[0].interface[usi->dwInterfaceNum].altsetting[usi->dwAlternateSetting].bInterfaceNumber,
ret, usb_strerror());
}
} }
#endif #endif
DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
@ -827,15 +850,9 @@ int close(int fd) {
if (fd == windrvrfd && windrvrfd >= 0) { if (fd == windrvrfd && windrvrfd >= 0) {
DPRINTF("close windrvrfd\n"); DPRINTF("close windrvrfd\n");
if (usbinterface >= 0)
usb_release_interface(usb_devhandle, usbinterface);
if (usb_devhandle) { if (usb_devhandle)
#ifndef NO_USB_RESET
usb_reset(usb_devhandle);
#endif
usb_close(usb_devhandle); usb_close(usb_devhandle);
}
usb_devhandle = NULL; usb_devhandle = NULL;
usbinterface = -1; usbinterface = -1;

Loading…
Cancel
Save