|
From: mohammed a. <abu...@gm...> - 2007-02-28 14:18:33
|
Hello,
I have the following code that takes more than a min to finisg:
-------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include <usb.h>
// Search token for the cypress chip.
#define CYP_VENDOR_ID 0x04b4
#define CYP_PRODUCT_ID 0x8613
struct usb_device* cypress_init();
void sighandler(int );
// Global vars
struct usb_device* cypress_dev;
struct usb_dev_handle* cypress_dev_handle;
char* bytes;
struct usb_interface_descriptor interface ;
int verbose = 0;
int c,i,a,ret;
int main(int argc, char* argv[]){
// First, init the cypress chip..
cypress_dev = cypress_init();
// Second, open it ...
if (cypress_dev) cypress_dev_handle = usb_open(cypress_dev);
else {
printf("Fatel Error: No Cypress CY7C68xx devices connected. Exiting
\n");
return -9;
}
if (cypress_dev_handle){
// Now, detatch the usbtest kernel driver assigned to the cypress chip upon
//hotpluging it into the system
usb_detach_kernel_driver_np(cypress_dev_handle ,0);
usb_set_configuration(cypress_dev_handle,
cypress_dev->config->bConfigurationValue);
interface = cypress_dev->config[0].interface[0].altsetting[1];
usb_claim_interface(cypress_dev_handle,interface.bInterfaceNumber);
usb_set_altinterface(cypress_dev_handle,interface.bAlternateSetting);
//assign the endpoint addresses....
int epo = interface.endpoint[0].bEndpointAddress;
int epi = interface.endpoint[1].bEndpointAddress;
usb_clear_halt(cypress_dev_handle, epi );
//printf ("ep_out is %0x while ep_in is %0x\n",epo,epi);
bytes = (char*) malloc(512);
memset(bytes,0,sizeof(bytes));
/*write 40 Mbytes worth of data to the bulk endpoint*/
/*i am calculating this by: 512 (packet size) * 2 = 1 KB, * 1000 = 1MB, * 40
= 40 MB*/
for (i = 0; i < 2 * 1000 * 40 ; i++){
ret = usb_bulk_write(cypress_dev_handle, epi,bytes, 512, 0 /*the timrout is
ignored for bulk transfer*/);
//printf ("i is:%d\t ret is %d\t bytes is %s\n",i, ret,bytes);
}
}
else {
printf("Could not open the Cypress chip. Quiting \n");
return -1;
}
usb_release_interface(cypress_dev_handle,0);
usb_close(cypress_dev_handle);
return 0;
}
struct usb_device* cypress_init(){
struct usb_bus *bus =NULL;
struct usb_device *dev =NULL;
usb_init();
usb_find_busses();
usb_find_devices();
usb_set_debug(9);
for (bus = usb_busses; bus; bus = bus->next)
for (dev = bus->devices; dev; dev = dev->next)
if ((dev->descriptor.idVendor == CYP_VENDOR_ID) &&
(dev->descriptor.idProduct == CYP_PRODUCT_ID)) return
dev;
return NULL;
}
void sighandler(int sig){
//usb_release_interface(cypress_dev_handle,0);
usb_close(cypress_dev_handle);
}
-------------------------------------------------------
As root, I ran "time ./a.out" and got
# time ./a.out
real 1m9.793s
user 0m0.118s
sys 0m0.490s
# time ./a.out
real 1m15.078s
user 0m0.095s
sys 0m0.438s
root@elive[/home/me/cypress]#
The lsusb -vv output of the cypress FX2 device is at:
http://abuhijle.googlepages.com/libusb-vvoutput
I am trying to achieve that max possible speed to write to the device. There
are no other processes I am running along with a.out. My goal is to reduce
this > 1 minute to less than one second!! It is a USB 2, I know I should not
expect the standard's 60 MBytes transfer rate because of overhead and all
other issues so I am shooting for 40.
Any errors in my code, please..? Any tipe on making this faster....
here are some more info:
# libusb-config --version
0.1.12
# uname -a
Linux elive 2.6.15.7 #2 Tue Dec 5 06:48:06 CET 2006 i686 GNU/Linux
gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --with-tune=i686
--enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
-M
|