From: hackbard Date: Tue, 10 Apr 2007 09:37:13 +0000 (+0000) Subject: usb init fixed X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3e1d629125a9b6e9c3e47c600593562dcad0a21;p=my-code%2Ffpga.git usb init fixed --- diff --git a/fx2/cypress_fx2_xilprg.patch b/fx2/cypress_fx2_xilprg.patch index 96d9eab..6b9f513 100644 --- a/fx2/cypress_fx2_xilprg.patch +++ b/fx2/cypress_fx2_xilprg.patch @@ -1,6 +1,218 @@ +diff -Nur xilprg-0.5/cypress_fx2_xilprg.patch xilprg-new/cypress_fx2_xilprg.patch +--- xilprg-0.5/cypress_fx2_xilprg.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xilprg-new/cypress_fx2_xilprg.patch 2007-04-10 10:33:17.000000000 +0200 +@@ -0,0 +1,208 @@ ++diff -Nur xilprg-0.5/makefile xilprg-new/makefile ++--- xilprg-0.5/makefile 2006-08-23 07:41:20.000000000 +0200 +++++ xilprg-new/makefile 2007-04-07 17:09:16.000000000 +0200 ++@@ -40,6 +40,7 @@ ++ $(SRC_DIR)/prgfile.cpp \ ++ $(SRC_DIR)/chip.cpp \ ++ $(SRC_DIR)/parport.cpp \ +++ $(SRC_DIR)/onbusb.cpp \ ++ $(SRC_DIR)/cable.cpp \ ++ $(SRC_DIR)/digilent.cpp \ ++ $(SRC_DIR)/xilinx.cpp ++diff -Nur xilprg-0.5/src/cable.cpp xilprg-new/src/cable.cpp ++--- xilprg-0.5/src/cable.cpp 2006-08-23 07:38:34.000000000 +0200 +++++ xilprg-new/src/cable.cpp 2007-04-07 17:20:55.000000000 +0200 ++@@ -49,6 +49,7 @@ ++ #include "chip.h" ++ #include "cmdline.h" ++ #include "digilent.h" +++#include "onbusb.h" ++ #include "parport.h" ++ ++ cable::cable() ++@@ -587,6 +588,9 @@ ++ if (stricmp(argv[0], "dusb") == 0) ++ cbl = new digilent; ++ else +++ if (stricmp(argv[0], "ousb") ==0) +++ cbl = new onbusb; +++ else ++ { ++ msgf(STR_INVALID_CABLE_DEF); ++ return NULL; ++diff -Nur xilprg-0.5/src/onbusb.cpp xilprg-new/src/onbusb.cpp ++--- xilprg-0.5/src/onbusb.cpp 1970-01-01 01:00:00.000000000 +0100 +++++ xilprg-new/src/onbusb.cpp 2007-04-07 17:15:34.000000000 +0200 ++@@ -0,0 +1,113 @@ +++/* +++ * onboard usb +++ * +++ * author: till & frank zirkelbach +++ * +++ */ +++ +++#include "xilprg.h" +++#include "utils.h" +++#include "onbusb.h" +++ +++onbusb::onbusb() +++{ +++ handle=NULL; +++} +++ +++onbusb::~onbusb() +++{ +++} +++ +++int onbusb::open() +++{ +++ +++ struct usb_bus *bus; +++ +++ usb_init(); +++ usb_find_busses(); +++ usb_find_devices(); +++ +++ bus=usb_get_busses(); +++ while(bus) { +++ dev=bus->devices; +++ while(dev) { +++ if(dev->descriptor.idVendor==USB_VENDOR_ID && +++ dev->descriptor.idProduct==USB_PRODUCT_ID) +++ /* found the device */ +++ return 0; +++ dev=dev->next; +++ } +++ bus=bus->next; +++ } +++ +++ return -1; +++ +++ handle=usb_open(dev); +++ if(handle==NULL) +++ goto cleanup; +++ +++ if(usb_set_configuration(handle,1)<0) +++ goto cleanup; +++ +++ if(usb_claim_interface(handle,0)<0) +++ goto cleanup; +++ +++ if(usb_set_altinterface(handle,1)<0) +++ goto cleanup; +++ +++ data = 0x10; +++ +++ reset_tap_state(); +++ +++ return 0; +++ +++cleanup: +++ +++ close(); +++ +++ return 1; +++ +++} +++ +++int onbusb::close() +++{ +++ +++ usb_close(handle); +++ +++ return 0; +++} +++ +++int onbusb::get_description(string& desc) +++{ +++ char s[256]; +++ sprintf(s, "onboard usb bitbanging"); +++ desc = s; +++ return 0; +++} +++ +++void onbusb::set_tdi(int bit) +++{ +++ if (bit) data |= 0x04; else data &= ~0x04; +++ data|=0xa0; +++ usb_bulk_write(handle,0x01,&data,1,0); +++} +++ +++void onbusb::set_tck(int bit) +++{ +++ if (bit) data |= 0x10; else data &= ~0x10; +++ data|=0xa0; +++ usb_bulk_write(handle,0x01,&data,1,0); +++} +++ +++void onbusb::set_tms(int bit) +++{ +++ if (bit) data |= 0x08; else data &= ~0x08; +++ data|=0xa0; +++ usb_bulk_write(handle,0x01,&data,1,0); +++} +++ +++int onbusb::get_tdo() +++{ +++ usb_bulk_read(handle,0x81,&data,1,0); +++ return data & 0x01 ? 1 : 0; +++} ++diff -Nur xilprg-0.5/src/onbusb.h xilprg-new/src/onbusb.h ++--- xilprg-0.5/src/onbusb.h 1970-01-01 01:00:00.000000000 +0100 +++++ xilprg-new/src/onbusb.h 2007-04-07 17:14:07.000000000 +0200 ++@@ -0,0 +1,43 @@ +++/* +++ * onboard usb +++ * +++ * author: till & frank zirkelbach +++ * +++ */ +++ +++#ifndef _ONBUSB_H_INCLUDED_ +++#define _ONBUSB_H_INCLUDED_ +++ +++#include "cable.h" +++ +++#include +++ +++class onbusb : public cable +++{ +++public: +++ onbusb(); +++ virtual ~onbusb(); +++ +++ enum +++ { +++ USB_VENDOR_ID = 0x04b4, +++ USB_PRODUCT_ID = 0x8613 +++ }; +++ +++ virtual int open(); +++ virtual int close(); +++ +++ virtual int get_description(string&); +++ +++ virtual void set_tdi(int); +++ virtual void set_tck(int); +++ virtual void set_tms(int); +++ virtual int get_tdo(); +++ +++protected: +++ char data; +++ struct usb_device *dev; +++ usb_dev_handle *handle; +++}; +++ +++#endif ++diff -Nur xilprg-0.5/src/strtable.cpp xilprg-new/src/strtable.cpp ++--- xilprg-0.5/src/strtable.cpp 2006-08-23 07:38:34.000000000 +0200 +++++ xilprg-new/src/strtable.cpp 2007-04-07 16:56:25.000000000 +0200 ++@@ -137,7 +137,7 @@ ++ //STR_CMD_CABLE ++ "cable\0" ++ "Sets programmer cable\0" ++- "cable {xil3 [ioaddr]|dusb}\0", +++ "cable {xil3 [ioaddr]|dusb|ousb}\0", ++ //STR_CMD_CHIPS ++ "chips\0" ++ "Prints supported devices\0" diff -Nur xilprg-0.5/makefile xilprg-new/makefile --- xilprg-0.5/makefile 2006-08-23 07:41:20.000000000 +0200 -+++ xilprg-new/makefile 2007-04-07 17:09:16.000000000 +0200 ++++ xilprg-new/makefile 2007-04-10 10:33:28.000000000 +0200 @@ -40,6 +40,7 @@ $(SRC_DIR)/prgfile.cpp \ $(SRC_DIR)/chip.cpp \ @@ -11,7 +223,7 @@ diff -Nur xilprg-0.5/makefile xilprg-new/makefile $(SRC_DIR)/xilinx.cpp diff -Nur xilprg-0.5/src/cable.cpp xilprg-new/src/cable.cpp --- xilprg-0.5/src/cable.cpp 2006-08-23 07:38:34.000000000 +0200 -+++ xilprg-new/src/cable.cpp 2007-04-07 17:20:55.000000000 +0200 ++++ xilprg-new/src/cable.cpp 2007-04-10 10:33:28.000000000 +0200 @@ -49,6 +49,7 @@ #include "chip.h" #include "cmdline.h" @@ -32,8 +244,8 @@ diff -Nur xilprg-0.5/src/cable.cpp xilprg-new/src/cable.cpp return NULL; diff -Nur xilprg-0.5/src/onbusb.cpp xilprg-new/src/onbusb.cpp --- xilprg-0.5/src/onbusb.cpp 1970-01-01 01:00:00.000000000 +0100 -+++ xilprg-new/src/onbusb.cpp 2007-04-07 17:15:34.000000000 +0200 -@@ -0,0 +1,113 @@ ++++ xilprg-new/src/onbusb.cpp 2007-04-10 11:32:01.000000000 +0200 +@@ -0,0 +1,126 @@ +/* + * onboard usb + * @@ -68,9 +280,39 @@ diff -Nur xilprg-0.5/src/onbusb.cpp xilprg-new/src/onbusb.cpp + dev=bus->devices; + while(dev) { + if(dev->descriptor.idVendor==USB_VENDOR_ID && -+ dev->descriptor.idProduct==USB_PRODUCT_ID) ++ dev->descriptor.idProduct==USB_PRODUCT_ID) { ++ + /* found the device */ ++ ++ printf("found matching usb device\n"); ++ ++ handle=usb_open(dev); ++ if(handle==NULL) ++ goto cleanup; ++ ++ printf("got handle\n"); ++ ++ if(usb_set_configuration(handle,1)<0) ++ goto cleanup; ++ ++ printf("set configuration\n"); ++ ++ if(usb_claim_interface(handle,0)<0) ++ goto cleanup; ++ ++ printf("claimed interface\n"); ++ ++ if(usb_set_altinterface(handle,1)<0) ++ goto cleanup; ++ ++ printf("set alt interface\n"); ++ ++ data = 0x10; ++ ++ reset_tap_state(); ++ + return 0; ++ } + dev=dev->next; + } + bus=bus->next; @@ -78,30 +320,13 @@ diff -Nur xilprg-0.5/src/onbusb.cpp xilprg-new/src/onbusb.cpp + + return -1; + -+ handle=usb_open(dev); -+ if(handle==NULL) -+ goto cleanup; -+ -+ if(usb_set_configuration(handle,1)<0) -+ goto cleanup; -+ -+ if(usb_claim_interface(handle,0)<0) -+ goto cleanup; -+ -+ if(usb_set_altinterface(handle,1)<0) -+ goto cleanup; -+ -+ data = 0x10; -+ -+ reset_tap_state(); -+ -+ return 0; -+ +cleanup: + ++ perror("device open"); ++ + close(); + -+ return 1; ++ return -1; + +} + @@ -125,7 +350,7 @@ diff -Nur xilprg-0.5/src/onbusb.cpp xilprg-new/src/onbusb.cpp +{ + if (bit) data |= 0x04; else data &= ~0x04; + data|=0xa0; -+ usb_bulk_write(handle,0x01,&data,1,0); ++ //usb_bulk_write(handle,0x01,&data,1,0); +} + +void onbusb::set_tck(int bit) @@ -139,7 +364,7 @@ diff -Nur xilprg-0.5/src/onbusb.cpp xilprg-new/src/onbusb.cpp +{ + if (bit) data |= 0x08; else data &= ~0x08; + data|=0xa0; -+ usb_bulk_write(handle,0x01,&data,1,0); ++ //usb_bulk_write(handle,0x01,&data,1,0); +} + +int onbusb::get_tdo() @@ -149,7 +374,7 @@ diff -Nur xilprg-0.5/src/onbusb.cpp xilprg-new/src/onbusb.cpp +} diff -Nur xilprg-0.5/src/onbusb.h xilprg-new/src/onbusb.h --- xilprg-0.5/src/onbusb.h 1970-01-01 01:00:00.000000000 +0100 -+++ xilprg-new/src/onbusb.h 2007-04-07 17:14:07.000000000 +0200 ++++ xilprg-new/src/onbusb.h 2007-04-10 10:33:28.000000000 +0200 @@ -0,0 +1,43 @@ +/* + * onboard usb @@ -196,7 +421,7 @@ diff -Nur xilprg-0.5/src/onbusb.h xilprg-new/src/onbusb.h +#endif diff -Nur xilprg-0.5/src/strtable.cpp xilprg-new/src/strtable.cpp --- xilprg-0.5/src/strtable.cpp 2006-08-23 07:38:34.000000000 +0200 -+++ xilprg-new/src/strtable.cpp 2007-04-07 16:56:25.000000000 +0200 ++++ xilprg-new/src/strtable.cpp 2007-04-10 10:33:28.000000000 +0200 @@ -137,7 +137,7 @@ //STR_CMD_CABLE "cable\0"