more parts of the config infrastructure
This commit is contained in:
parent
3cc5a0bc5a
commit
25ba7a4909
28
config.c
28
config.c
@ -1,5 +1,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include "usb-driver.h"
|
||||||
|
#include "parport.h"
|
||||||
|
#ifdef JTAGKEY
|
||||||
|
#include "jtagkey.h"
|
||||||
|
#endif
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
static struct parport_config pp_config[4];
|
static struct parport_config pp_config[4];
|
||||||
@ -17,15 +23,37 @@ static void read_config() {
|
|||||||
pp_config[i].num = i;
|
pp_config[i].num = i;
|
||||||
pp_config[i].ppbase = i*0x10;
|
pp_config[i].ppbase = i*0x10;
|
||||||
pp_config[i].real = 1;
|
pp_config[i].real = 1;
|
||||||
|
pp_config[i].open = parport_open;
|
||||||
|
pp_config[i].close = parport_close;
|
||||||
|
pp_config[i].transfer = parport_transfer;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef JTAGKEY
|
#ifdef JTAGKEY
|
||||||
pp_config[3].real = 0;
|
pp_config[3].real = 0;
|
||||||
pp_config[3].usb_vid = 0x0403;
|
pp_config[3].usb_vid = 0x0403;
|
||||||
pp_config[3].usb_pid = 0xcff8;
|
pp_config[3].usb_pid = 0xcff8;
|
||||||
|
pp_config[3].open = jtagkey_open;
|
||||||
|
pp_config[3].close = jtagkey_close;
|
||||||
|
pp_config[3].transfer = jtagkey_transfer;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct parport_config *config_get(int num) {
|
||||||
|
struct parport_config *ret = NULL;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
read_config();
|
||||||
|
|
||||||
|
for (i=0; i<sizeof(pp_config)/sizeof(struct parport_config); i++) {
|
||||||
|
if (pp_config[i].num == num) {
|
||||||
|
ret = &(pp_config[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned char config_is_real_pport(int num) {
|
unsigned char config_is_real_pport(int num) {
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
int i;
|
int i;
|
||||||
|
5
config.h
5
config.h
@ -4,9 +4,12 @@ struct parport_config {
|
|||||||
unsigned char real;
|
unsigned char real;
|
||||||
unsigned short usb_vid;
|
unsigned short usb_vid;
|
||||||
unsigned short usb_pid;
|
unsigned short usb_pid;
|
||||||
/* TODO: function pointer */
|
int (*open) (int num);
|
||||||
|
void (*close) (int handle);
|
||||||
|
int (*transfer) (WD_TRANSFER *tr, int fd, unsigned int request, int ppbase, int ecpbase, int num);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct parport_config *config_get(int num);
|
||||||
unsigned char config_is_real_pport(int num);
|
unsigned char config_is_real_pport(int num);
|
||||||
unsigned short config_usb_vid(int num);
|
unsigned short config_usb_vid(int num);
|
||||||
unsigned short config_usb_pid(int num);
|
unsigned short config_usb_pid(int num);
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
static int parportfd = -1;
|
static int parportfd = -1;
|
||||||
|
|
||||||
int pp_transfer(WD_TRANSFER *tr, int fd, unsigned int request, int ppbase, int ecpbase, int num) {
|
int parport_transfer(WD_TRANSFER *tr, int fd, unsigned int request, int ppbase, int ecpbase, int num) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int i;
|
int i;
|
||||||
unsigned long port;
|
unsigned long port;
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
int pp_transfer(WD_TRANSFER *tr, int fd, unsigned int request, int ppbase, int ecpbase, int num);
|
int parport_transfer(WD_TRANSFER *tr, int fd, unsigned int request, int ppbase, int ecpbase, int num);
|
||||||
int parport_open(int num);
|
int parport_open(int num);
|
||||||
void parport_close(int handle);
|
void parport_close(int handle);
|
||||||
|
39
usb-driver.c
39
usb-driver.c
@ -41,15 +41,12 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include "usb-driver.h"
|
#include "usb-driver.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "parport.h"
|
|
||||||
#ifdef JTAGKEY
|
|
||||||
#include "jtagkey.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int (*ioctl_func) (int, int, void *) = NULL;
|
static int (*ioctl_func) (int, int, void *) = NULL;
|
||||||
static int windrvrfd = -1;
|
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;
|
||||||
FILE *modulesfp = NULL;
|
FILE *modulesfp = NULL;
|
||||||
FILE *baseaddrfp = NULL;
|
FILE *baseaddrfp = NULL;
|
||||||
int baseaddrnum = 0;
|
int baseaddrnum = 0;
|
||||||
@ -248,7 +245,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
switch(request & ~(0xc0000000)) {
|
switch(request & ~(0xc0000000)) {
|
||||||
case VERSION:
|
case VERSION:
|
||||||
version = (struct version_struct*)(wdheader->data);
|
version = (struct version_struct*)(wdheader->data);
|
||||||
strcpy(version->version, "libusb-driver.so $Revision: 1.67 $");
|
strcpy(version->version, "libusb-driver.so $Revision: 1.68 $");
|
||||||
version->versionul = 802;
|
version->versionul = 802;
|
||||||
DPRINTF("VERSION\n");
|
DPRINTF("VERSION\n");
|
||||||
break;
|
break;
|
||||||
@ -278,12 +275,8 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
ret = (*ioctl_func) (fd, request, wdioctl);
|
ret = (*ioctl_func) (fd, request, wdioctl);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#ifdef JTAGKEY
|
pport = config_get((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
|
||||||
if (!config_is_real_pport((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10))
|
ret = pport->open((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
|
||||||
ret = jtagkey_open((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
ret = parport_open((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
|
|
||||||
|
|
||||||
ppbase = (unsigned long)cr->Card.Item[0].I.IO.dwAddr;
|
ppbase = (unsigned long)cr->Card.Item[0].I.IO.dwAddr;
|
||||||
|
|
||||||
@ -566,14 +559,7 @@ 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 = pport->transfer(tr, fd, request, ppbase, ecpbase, 1);
|
||||||
#ifdef JTAGKEY
|
|
||||||
if (!config_is_real_pport(ppbase / 0x10)) {
|
|
||||||
ret = jtagkey_transfer(tr, fd, request, ppbase, ecpbase, 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif /* JTAGKEY */
|
|
||||||
ret = pp_transfer(tr, fd, request, ppbase, ecpbase, 1);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -587,13 +573,7 @@ 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 = pport->transfer(tr, fd, request, ppbase, ecpbase, num);
|
||||||
#ifdef JTAGKEY
|
|
||||||
if (!config_is_real_pport(ppbase / 0x10)) {
|
|
||||||
ret = jtagkey_transfer(tr, fd, request, ppbase, ecpbase, num);
|
|
||||||
} else
|
|
||||||
#endif /* JTAGKEY */
|
|
||||||
ret = pp_transfer(tr, fd, request, ppbase, ecpbase, num);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -653,12 +633,7 @@ 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
|
||||||
#ifdef JTAGKEY
|
pport->close(cr->hCard);
|
||||||
if (cr->hCard == 0xff)
|
|
||||||
jtagkey_close(cr->hCard);
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
parport_close(cr->hCard);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user