diff options
| -rw-r--r-- | host/opcd_test.c | 52 | ||||
| -rw-r--r-- | host/opcd_usb.c | 26 | ||||
| -rw-r--r-- | host/opcd_usb.h | 2 | 
3 files changed, 59 insertions, 21 deletions
diff --git a/host/opcd_test.c b/host/opcd_test.c index 37f3094..00f986f 100644 --- a/host/opcd_test.c +++ b/host/opcd_test.c @@ -61,8 +61,14 @@ static void print_help(void)  		"\t-w\t--reg-write\treg value\n"  		"\t-r\t--reg-read\treg\n" +		"\t-W\t--fifo-write\thex\n" +		"\t-R\t--fifo-read\thex\n" +  		"\t-s\t--set-bits\treg\tmask\n" -		"\t-c\t--clear-bits\treg\tmask\n"); +		"\t-c\t--clear-bits\treg\tmask\n" + +		"\t-u\t--usb-perf\txfer_size\n" +		);  } @@ -79,24 +85,29 @@ static struct option opts[] = {  	{ "adc-loop", 0, 0, 'A' },  	{ "ssc-read", 0, 0, 'S' },  	{ "loop", 0, 0, 'L' }, +	{ "serial-number", 0, 0, 'n' },  	{ "help", 0, 0, 'h'},  };	  int main(int argc, char **argv)  {  	struct opcd_handle *od; -	int c; +	int c, outfd, retlen; +	char *data;  	static char buf[8192];  	int buf_len = sizeof(buf);  	print_welcome(); -	od = opcd_init(); +	if (!strcmp(argv[0], "opicc_test")) +		od = opcd_init(1); +	else +		od = opcd_init(0);  	while (1) {  		int option_index = 0; -		c = getopt_long(argc, argv, "l:r:w:R:W:s:c:h?u:aASL", opts, +		c = getopt_long(argc, argv, "l:r:w:R:W:s:c:h?u:aASLn", opts,  				&option_index);  		if (c == -1) @@ -115,7 +126,7 @@ int main(int argc, char **argv)  		case 'r':  			if (get_number(optarg, 0x00, OPENPCD_REG_MAX, &i) < 0)  				exit(2); -			printf("reading register 0x%02x: "); +			printf("reading register 0x%02x: ", i);  			opcd_send_command(od, OPENPCD_CMD_READ_REG, i, 0, 0, NULL);  			opcd_recv_reply(od, buf, buf_len);  			break; @@ -174,17 +185,42 @@ int main(int argc, char **argv)  		case 'S':  			opcd_send_command(od, OPENPCD_CMD_SSC_READ, 0, 1, 0, NULL);  			opcd_recv_reply(od, buf, buf_len); -			/* FIXME: interpret and print ADC result */ +			/* FIXME: interpret and print SSC result */  			break;  		case 'L': -			while (1)  -				opcd_recv_reply(od, buf, buf_len); +			outfd = open("/tmp/opcd_samples", +				     O_CREAT|O_WRONLY|O_APPEND, 0664); +			if (outfd < 0) +				exit(2); +			while (1) { +				data = buf + sizeof(struct openpcd_hdr); +				retlen = opcd_recv_reply(od, buf, buf_len); +				if (retlen < 0) +					break; +				printf("DATA: %s\n", opcd_hexdump(data, retlen-4)); +#if 1 +				write(outfd, data, retlen-4); +				fsync(outfd); +#endif +			} +			close(outfd);  			break;  		case 'h':  		case '?':  			print_help();  			exit(0);  			break; +		case 'n': +			opcd_send_command(od, OPENPCD_CMD_GET_SERIAL, 0, 1, 4, +					  NULL); +			retlen = opcd_recv_reply(od, buf, +						 sizeof(struct openpcd_hdr)+4); +			if (retlen > 0) { +				data = buf + sizeof(struct openpcd_hdr); +				printf("SERIAL: %s\n", opcd_hexdump(data, retlen-4)); +			} else +				printf("ERROR: %d, %s\n", retlen, usb_strerror()); +			break;  		default:  			fprintf(stderr, "unknown key `%c'\n", c);  			print_help(); diff --git a/host/opcd_usb.c b/host/opcd_usb.c index 9224516..d5f7db9 100644 --- a/host/opcd_usb.c +++ b/host/opcd_usb.c @@ -54,20 +54,21 @@ opcd_hexdump(const void *data, unsigned int len)  #define OPCD_IN_EP	0x82  #define OPCD_INT_EP	0x83 -static struct usb_device *find_opcd_handle(void) +static struct usb_device *find_opcd_handle(int picc)  {  	struct usb_bus *bus; +	u_int16_t product_id; + +	if (picc) +		product_id = OPENPICC_PRODUCT_ID; +	else +		product_id = OPENPCD_PRODUCT_ID;  	for (bus = usb_busses; bus; bus = bus->next) {  		struct usb_device *dev;  		for (dev = bus->devices; dev; dev = dev->next) { -			if (dev->descriptor.idVendor == OPENPCD_VENDOR_ID -			    && (dev->descriptor.idProduct == OPENPCD_PRODUCT_ID || -			        dev->descriptor.idProduct == OPENPCD_PRODUCT_ID) -			    && dev->descriptor.iManufacturer == 0 -			    && dev->descriptor.iProduct == 0 -			    && dev->descriptor.bNumConfigurations == 1 -			    && dev->config->iConfiguration == 0) +			if (dev->descriptor.idVendor == OPENPCD_VENDOR_ID && +			    dev->descriptor.idProduct == product_id)  				return dev;  		}  	} @@ -100,7 +101,7 @@ static void handle_interrupt(struct usbdevfs_urb *uurb, void *userdata)  		fprintf(stderr, "unable to resubmit interupt urb\n");  } -struct opcd_handle *opcd_init(void) +struct opcd_handle *opcd_init(int picc)  {  	struct opcd_handle *oh;  	struct usb_device *dev; @@ -113,7 +114,7 @@ struct opcd_handle *opcd_init(void)  	ausb_init(); -	dev = find_opcd_handle(); +	dev = find_opcd_handle(picc);  	if (!dev) {  		fprintf(stderr, "Cannot find OpenPCD device. "  			"Are you sure it is connected?\n"); @@ -163,8 +164,9 @@ int opcd_recv_reply(struct opcd_handle *od, char *buf, int len)  		return ret;  	} -	printf("RX: %s\n", opcd_hexdump(buf, ret)); -	opcd_dump_hdr((struct openpcd_hdr *)buf); +	//printf("RX: %s\n", opcd_hexdump(buf, ret)); +	//printf("RX: %s\n", opcd_hexdump(buf, 48)); +	//opcd_dump_hdr((struct openpcd_hdr *)buf);  	return ret;  } diff --git a/host/opcd_usb.h b/host/opcd_usb.h index e9698f0..7304396 100644 --- a/host/opcd_usb.h +++ b/host/opcd_usb.h @@ -12,7 +12,7 @@ struct opcd_handle {  extern const char *opcd_hexdump(const void *data, unsigned int len); -extern struct opcd_handle *opcd_init(void); +extern struct opcd_handle *opcd_init(int is_picc);  extern void opcd_fini(struct opcd_handle *od);  extern int opcd_recv_reply(struct opcd_handle *od, char *buf, int len);  | 
