00001
00002
00003
00004
00005
00006
00007
00008 #include <stdio.h>
00009 #include "usb_ejtag_command.h"
00010
00011 #include "aaa.c"
00012 #include <myconfig.h>
00013
00014 static char *config_usb_ejtag_put_speed = 0;
00015
00016 myconfig_init("usb_ejtag.put_speed",config_usb_ejtag_put_speed,CONFIG_I,"usb ejtag put speed");
00017
00018 #if 0
00019 #define USB_FOUND 1
00020 #define USB_NO_FOUND 0
00021 #define USB_NOT_BULK_WR_FLAG 0
00022 #define USB_CAN_BULK_WR_FLAG 1
00023 #define LS232_USB_EJTAG_VENDOR_ID 0x0547
00024 #define LS232_USB_EJTAG_PRODUCT_ID 0x1002
00025
00026 int usb_can_bulk_wr_flag = USB_NOT_BULK_WR_FLAG;
00027 unsigned short usb_wr_dr_data[3] ={0};
00028 unsigned short dma32_write1_data[DMA32_WR1_MAX+1]={0};
00029 unsigned short dma32_write2_data[DMA32_WR2_MAX+3]={0};
00030 unsigned short signal_echo_data[3] ={0};
00031 unsigned short burst_echo_data[BUSRT_ECHO_MAX+3] ={0};
00032
00033 struct usb_device *current_device;
00034 usb_dev_handle *current_handle;
00035 char *bus_name="001";
00036 char *device_name="001";
00037 #endif
00038 unsigned int usb_ejtag_ID_IP_CODE(void);
00039 struct usb_device *find_device(char *busname, char *devicename)
00040 {
00041 struct usb_bus *p;
00042 struct usb_device *q;
00043 p=usb_busses;
00044 while(p!=NULL)
00045 {
00046 q=p->devices;
00047 if(strcmp(p->dirname, busname))
00048 {
00049 p=p->next;
00050 continue;
00051 }
00052 while(q!=NULL)
00053 {
00054 if(!strcmp(q->filename, devicename))
00055 return q;
00056 q=q->next;
00057 }
00058 p=p->next;
00059 }
00060
00061 return NULL;
00062 }
00063
00064
00065 int dump_busses(void)
00066 {
00067 struct usb_bus *p;
00068 struct usb_device *q;
00069 int found_usb = USB_NO_FOUND ;
00070 p = usb_busses;
00071
00072 while(p!=NULL)
00073 {
00074 q = p->devices;
00075 while(q != NULL)
00076 {
00077 fprintf(stderr," bus %s device %s vendor id=0x%04x product id=0x%04x ",
00078 p->dirname, q->filename, q->descriptor.idVendor, q->descriptor.idProduct);
00079 if((q->descriptor.idVendor == LS232_USB_EJTAG_VENDOR_ID) && (q->descriptor.idProduct == LS232_USB_EJTAG_PRODUCT_ID))
00080 {
00081 bus_name = p->dirname ;
00082 device_name = q->filename ;
00083 found_usb = USB_FOUND;
00084 fprintf(stderr," : (LS232 FX2 USB-Ejtag-Simulator is found)\n");
00085 return found_usb;
00086 }
00087 q = q->next;
00088 fprintf(stderr,"\n");
00089 }
00090 p = p->next;
00091 }
00092 return found_usb;
00093 }
00094
00095 int usb_tap_init(void)
00096 {
00097 int found_usb = USB_NO_FOUND;
00098 usb_init();
00099 usb_find_busses();
00100 usb_find_devices();
00101 found_usb = dump_busses();
00102 if(!found_usb)
00103 return USB_NO_FOUND;
00104
00105 current_device=find_device(bus_name,device_name);
00106
00107 if(current_device == NULL)
00108 {
00109 fprintf(stderr,"Cannot find device %s on bus %s\n", device_name, bus_name);
00110 found_usb = USB_NO_FOUND;
00111 }
00112
00113 return found_usb;
00114 }
00115
00116 int usb_fx2_reset(void)
00117 {
00118 current_handle = usb_open(current_device);
00119
00120 #if 1
00121 usb_clear_halt(current_handle,2);
00122
00123 usb_clear_halt(current_handle,0x86);
00124
00125 #endif
00126 if(usb_detach_kernel_driver_np(current_handle, 0)<0)
00127 {
00128 fprintf(stderr," %s\n", usb_strerror());
00129 return;
00130 }
00131 if(usb_set_configuration(current_handle,1))
00132 {
00133 fprintf(stderr," %s\n", usb_strerror());
00134 return;
00135 }
00136
00137 while(usb_claim_interface(current_handle,0)<0)
00138 {
00139 fprintf(stderr,"usb_claim_interface() failed,need to usb_detach_kernel_driver_np!\n");
00140 if(usb_detach_kernel_driver_np(current_handle, 0)<0)
00141 {
00142 usb_can_bulk_wr_flag = USB_NOT_BULK_WR_FLAG ;
00143 fprintf(stderr," %s\n", usb_strerror());
00144 exit(-1);
00145 }
00146 }
00147 fprintf(stderr,"usb_claim_interface() Successful !\n");
00148
00149 usb_ejtag_ID_IP_CODE();
00150
00151 usb_can_bulk_wr_flag = USB_CAN_BULK_WR_FLAG ;
00152
00153 return usb_can_bulk_wr_flag ;
00154 }
00155
00156
00157 void usb_stop(void)
00158 {
00159 if(usb_can_bulk_wr_flag == USB_CAN_BULK_WR_FLAG)
00160 {
00161 usb_release_interface(current_handle,0);
00162 usb_close(current_handle);
00163 }
00164 else
00165 usb_close(current_handle);
00166 fprintf(stderr,"Close the USB\n");
00167 }
00168
00169 unsigned short tap_reset(void)
00170 {
00171 unsigned short tap_reset_data=0;
00172
00173 tap_reset_data = OP_TAP_RST << OP_EJTAG_SHIFT ;
00174
00175 return tap_reset_data;
00176
00177 }
00178
00179 unsigned short target_reset(void)
00180 {
00181
00182 unsigned short target_reset_data=0;
00183
00184 target_reset_data = OP_TARGET_RST << OP_EJTAG_SHIFT ;
00185
00186 return target_reset_data;
00187
00188 }
00189
00190
00191
00192 unsigned short fpga_info_ejtag(unsigned short led_on_flag )
00193 {
00194 unsigned short fpga_info_ejtag_data=0;
00195
00196 fpga_info_ejtag_data = OP_FPGA_INFO << OP_EJTAG_SHIFT | led_on_flag ;
00197
00198 return fpga_info_ejtag_data;
00199
00200 }
00201
00202 unsigned int usb_wr_ir(unsigned short wb,unsigned short i_data ,unsigned char new_ir_data)
00203 {
00204
00205 int a=0,count = 2 ;
00206 unsigned short usb_wr_ir_data=0;
00207 unsigned char buf[2]={0,0};
00208 unsigned char buf_read[2]={0,0};
00209 unsigned int usb_wr_ir_result=0;
00210
00211 usb_wr_ir_data = OP_WR_IR << OP_EJTAG_SHIFT | wb << OP_EJTAG_W_SHIFT |i_data << OP_EJTAG_I_SHIFT | new_ir_data;
00212
00213 memset(buf, 0, 2);
00214 memset(buf_read, 0, 2);
00215
00216 buf[0] = usb_wr_ir_data & 0xFF;
00217 buf[1] = (usb_wr_ir_data & 0xFF00) >>8;
00218
00219 #ifdef DEBUG_USB_EJTAG
00220 for(i=0 ; i<count ; i++)
00221 {
00222 if((i%16 == 0) && i>0 )
00223 fprintf(stderr,"\n");
00224 fprintf(stderr,"0x%2x ",buf[i]);
00225 }
00226 fprintf(stderr,"\n====================================================================================\n");
00227 #endif
00228
00229 endpoint = 2 ;
00230 a = usb_bulk_write(current_handle, endpoint, buf, count, 1000);
00231
00232 #ifdef DEBUG_USB_EJTAG
00233 printf("usb_bulk_write end\n");
00234 #endif
00235 if(a<0)
00236 {
00237 fprintf(stderr,"Request for bulk write failed: %s\n", usb_strerror());
00238 usb_release_interface(current_handle, 0);
00239 return;
00240 }
00241
00242 if(wb == 1)
00243 {
00244 endpoint = 6 ;
00245 a = usb_bulk_read(current_handle, endpoint, buf_read, count, 1000);
00246
00247 if(a<0)
00248 {
00249 fprintf(stderr,"Request for Burst bulk read failed: %s\n", usb_strerror());
00250
00251
00252 }
00253
00254
00255
00256
00257 #ifdef DEBUG_USB_EJTAG
00258 for(i=0;i<count;i++)
00259 {
00260 if((i%16 == 0) && i>0 )
00261 printf("\n");
00262 printf("0x%x",buf_read[i]);
00263 }
00264 printf("\n");
00265 #endif
00266 usb_wr_ir_result = buf_read[1] << 8 |buf_read[0] ;
00267 }
00268
00269 return usb_wr_ir_result;
00270
00271 }
00272
00273 #if 1
00274
00275 unsigned int usb_wr_upload(unsigned char *buf_read,unsigned int len)
00276 {
00277 int i,a,count = 6 ;
00278 unsigned char buf[6];
00279
00280 unsigned int usb_wr_dr_result=0;
00281
00282 usb_wr_dr_data[0] = OP_WR_UPLOAD <<OP_EJTAG_SHIFT | 0x0 ;
00283 usb_wr_dr_data[1] = (len/4) & 0xFFFF;
00284 usb_wr_dr_data[2] = ((len/4) & 0xFFFF0000) >> 16;
00285
00286
00287 printf("len : 0x%x\n",len);
00288 if(count > 6)
00289 {
00290 fprintf(stderr, "Cannot transfer more than 6 bytes at a time.\n");
00291 exit(-1);
00292 }
00293
00294 memset(buf, 0, 6);
00295 memset(buf_read, 0, len);
00296
00297 for(i=0;i<count;i=i+2)
00298 {
00299 buf[i] = usb_wr_dr_data[i/2] & 0xFF;
00300 buf[i+1] = (usb_wr_dr_data[i/2] & 0xFF00) >>8;
00301 }
00302
00303
00304 #if 1
00305 for(i=0 ; i<count ; i++)
00306 {
00307 if((i%16 == 0) && i>0 )
00308 printf("\n");
00309 printf("0x%2x ",buf[i]);
00310 }
00311 printf("\n========================================================================================\n");
00312 #endif
00313 #if 1
00314 endpoint = 2 ;
00315 a = usb_bulk_write(current_handle, endpoint, buf, count, 1000);
00316
00317
00318 #if 1
00319 printf("usb_bulk_write end\n");
00320 #endif
00321 if(a<0)
00322 {
00323 fprintf(stderr,"Request for bulk write failed: %s\n", usb_strerror());
00324 usb_release_interface(current_handle, 0);
00325 return;
00326 }
00327
00328 endpoint = 6 ;
00329 count=len ;
00330 printf("haha-1\n");
00331 a = usb_bulk_read(current_handle, endpoint, buf_read, len, 15000);
00332 printf("haha-2\n");
00333
00334 if(a<0)
00335 {
00336 fprintf(stderr,"Request for Burst bulk read failed: %s\n", usb_strerror());
00337
00338
00339 }
00340 #endif
00341
00342
00343
00344
00345 #if 0
00346 for(i=0;i<count;i++)
00347 {
00348 if((i%8 == 0) && i>0 )
00349 {
00350 printf("\n");
00351 printf(" 0x%x ==",i);
00352 }
00353 printf("0x%x ",buf_read[i]);
00354 }
00355 printf("\n");
00356 #endif
00357
00358 usb_wr_dr_result = buf_read[3] << 24 |buf_read[2] << 16 |buf_read[1] << 8 |buf_read[0] ;
00359 return usb_wr_dr_result;
00360
00361 }
00362 #endif
00363
00364 unsigned int usb_wr_dr(unsigned short wb, unsigned short i_data ,unsigned int new_dr_data)
00365 {
00366 int i,a,count = 6 ;
00367 unsigned char buf[6];
00368 unsigned char buf_read[6];
00369
00370 unsigned int usb_wr_dr_result=0;
00371
00372 usb_wr_dr_data[0] = OP_WR_DR << OP_EJTAG_SHIFT | wb << OP_EJTAG_W_SHIFT | i_data << OP_EJTAG_I_SHIFT ;
00373 usb_wr_dr_data[1] = new_dr_data & 0xFFFF;
00374 usb_wr_dr_data[2] = (new_dr_data & 0xFFFF0000) >> 16;
00375
00376 if(count > 6)
00377 {
00378 fprintf(stderr, "Cannot transfer more than 6 bytes at a time.\n");
00379 exit(-1);
00380 }
00381
00382 memset(buf, 0, 6);
00383 memset(buf_read, 0, 6);
00384
00385 for(i=0;i<count;i=i+2)
00386 {
00387 buf[i] = usb_wr_dr_data[i/2] & 0xFF;
00388 buf[i+1] = (usb_wr_dr_data[i/2] & 0xFF00) >>8;
00389 }
00390
00391 #ifdef DEBUG_USB_EJTAG
00392 for(i=0 ; i<count ; i++)
00393 {
00394 if((i%16 == 0) && i>0 )
00395 printf("\n");
00396 printf("0x%2x ",buf[i]);
00397 }
00398 printf("\n========================================================================================\n");
00399 #endif
00400 #if 1
00401 endpoint = 2 ;
00402 a = usb_bulk_write(current_handle, endpoint, buf, count, 1000);
00403
00404 #ifdef DEBUG_USB_EJTAG
00405 printf("usb_bulk_write end\n");
00406 #endif
00407 if(a<0)
00408 {
00409 fprintf(stderr,"Request for bulk write failed: %s\n", usb_strerror());
00410 usb_release_interface(current_handle, 0);
00411 return;
00412 }
00413
00414 endpoint = 6 ;
00415 count=4;
00416 a = usb_bulk_read(current_handle, endpoint, buf_read, count, 1000);
00417
00418 if(a<0)
00419 {
00420 fprintf(stderr,"Request for Burst bulk read failed: %s\n", usb_strerror());
00421
00422
00423 }
00424 #endif
00425
00426
00427
00428 #ifdef DEBUG_USB_EJTAG
00429 for(i=0;i<count;i++)
00430 {
00431 if((i%16 == 0) && i>0 )
00432 printf("\n");
00433 printf("0x%x",buf_read[i]);
00434 }
00435 printf("\n");
00436 #endif
00437 usb_wr_dr_result = buf_read[3] << 24 |buf_read[2] << 16 |buf_read[1] << 8 |buf_read[0] ;
00438 return usb_wr_dr_result;
00439
00440 }
00441
00442
00443 unsigned int usb_ejtag_ID_IP_CODE(void)
00444 {
00445 unsigned int input_e=0,output_e=0;
00446 usb_wr_ir(1,1,0x01);
00447 input_e=0xffffffff;
00448 output_e=usb_wr_dr(1,1,0x01);
00449 fprintf(stderr,"ID-CODE : 0x%x\n",output_e);
00450
00451 usb_wr_ir(1,1,0x03);
00452 input_e=0xffffffff;
00453 output_e=usb_wr_dr(1,1,0x01);
00454 fprintf(stderr,"IP-CODE : 0x%x\n",output_e);
00455
00456 return output_e;
00457 }
00458
00459 unsigned short * dma32_write1(unsigned short count)
00460 {
00461
00462 unsigned short i=0;
00463
00464 if(count > DMA32_WR1_MAX)
00465 {
00466 printf("dma32_write1 write size MAX 1K is overflow!\n");
00467 return -1;
00468 }
00469 dma32_write1_data[0] = OP_DMA32_WRITE1 << OP_EJTAG_SHIFT | count ;
00470 for(i=1;i<count;i++)
00471 dma32_write1_data[i]=(count - i);
00472 return dma32_write1_data;
00473
00474 }
00475
00476 unsigned short * dma32_write2(unsigned int dma32_count,unsigned int * dma32_write2_data)
00477 {
00478
00479 unsigned int i=0;
00480
00481
00482 dma32_write2_data[0] = OP_DMA32_WRITE2 << OP_EJTAG_SHIFT ;
00483 dma32_write2_data[1] = dma32_count & 0xFFFF;
00484 dma32_write2_data[2] = (dma32_count & 0xFFFF0000) >> 16;
00485
00486 if(dma32_count > DMA32_WR2_MAX)
00487 {
00488 printf("burst_count is overflow , MAX size is 0x%x \n",DMA32_WR2_MAX);
00489 dma32_count = DMA32_WR2_MAX;
00490
00491 }
00492
00493 for(i=3;i<dma32_count;i++)
00494 dma32_write2_data[i] = ((i%256)<<8 | ((i%256)+0x30));
00495 #if 0
00496 for(i=0;i<burst_count;i++)
00497 {
00498 if(i%16 == 0)
00499 printf("\n");
00500 printf("0x%4x ",dma32_write2_data[i]);
00501 }
00502 #endif
00503 return dma32_write2_data;
00504
00505 }
00506
00507 #if 1
00508 unsigned short * fast_write_3(unsigned int fast_count,unsigned int * fast_write2_data_input)
00509 {
00510 int i=0;
00511
00512 int fast_count_size = fast_count/4;
00513 if(fast_count_size%4)
00514 fast_count_size++;
00515
00516 for( ;i<fast_count_size; i++)
00517 {
00518 lw_feed_data(fast_write2_data_input[i]);
00519 }
00520 #if 0
00521 j++;
00522 if(j>82)
00523 {
00524 printf("j = %d \n",j);
00525 getchar();
00526 getchar();
00527 }
00528 #endif
00529
00530 usb_wr_cache(NULL,0,0);
00531
00532
00533 }
00534 #endif
00535
00536 #if 1
00537
00538 unsigned short * fast_write2(unsigned int fast_count,unsigned int * fast_write2_data_input)
00539 {
00540
00541 unsigned int i=0;
00542 unsigned int j=0;
00543 unsigned int count=0;
00544 int a=0;
00545 unsigned int download_size_fast=fast_count/4;
00546 unsigned char *buf ;
00547
00548
00549
00550 if(fast_count%4)
00551 download_size_fast++;
00552 printf("fast_count : 0x%x , download_size_fast : 0x%x\n",fast_count,download_size_fast);
00553 fast_write2_data[0] = OP_FAST_WRITE2 << OP_EJTAG_SHIFT ;
00554 fast_write2_data[1] = config_usb_ejtag_put_speed;
00555 fast_write2_data[2] = (download_size_fast& 0xFFFF);
00556 fast_write2_data[3] =(download_size_fast & 0xFFFF0000) >> 16 ;
00557
00558 if(fast_count > FAST_WR2_MAX)
00559 {
00560 printf("fast_count is overflow , MAX size is 0x%x \n",FAST_WR2_MAX);
00561 fast_count = FAST_WR2_MAX;
00562
00563 }
00564
00565 buf=malloc(FAST_WR2_MAX);
00566
00567 for(i=4;j<download_size_fast;j++)
00568 {
00569 fast_write2_data[i++] = (fast_write2_data_input[j]& 0xFFFF);
00570 fast_write2_data[i++] = (fast_write2_data_input[j]& 0xFFFF0000) >> 16;
00571 }
00572
00573
00574 memset(buf,0,FAST_WR2_MAX);
00575
00576 count = fast_count + 8 ;
00577 for(i=0;i<count;i=i+2)
00578 {
00579 buf[i] = fast_write2_data[i/2] & 0xFF;
00580 buf[i+1] = (fast_write2_data[i/2] & 0xFF00) >>8;
00581 }
00582
00583
00584 #if 1
00585
00586 for(i=0 ; i<16 ; i++)
00587 {
00588 if((i%16 == 0) && i>0 )
00589 printf("\n");
00590 printf("0x%2x ",buf[i]);
00591 }
00592 printf("\n========================================================================================\n");
00593 #endif
00594
00595 endpoint = 2 ;
00596
00597 a = usb_bulk_write(current_handle, endpoint, buf, count, 15000000);
00598
00599 #ifdef DEBUG_USB_EJTAG
00600 printf("usb_bulk_write end\n");
00601 #endif
00602 printf("USB write size is : 0x%x , a is %d \n",a, a);
00603 if(a != count )
00604 {
00605 fprintf(stderr,"Request for bulk write failed: %s\n", usb_strerror());
00606 usb_release_interface(current_handle, 0);
00607 return;
00608 }
00609 #if 0
00610 for(i=0;i<burst_count;i++)
00611 {
00612 if(i%16 == 0)
00613 printf("\n");
00614 printf("0x%4x ",dma32_write2_data[i]);
00615 }
00616 #endif
00617
00618 free(buf);
00619 return fast_write2_data;
00620
00621 }
00622 #endif
00623
00624
00625
00626 unsigned short * signal_echo(unsigned short wb, unsigned short i_data , unsigned int echo_data)
00627 {
00628
00629
00630 signal_echo_data[0] = OP_SIGNAL_ECHO << OP_EJTAG_SHIFT | wb << OP_EJTAG_W_SHIFT | i_data << OP_EJTAG_I_SHIFT ;
00631 signal_echo_data[1] = echo_data & 0xFFFF;
00632 signal_echo_data[2] = (echo_data & 0xFFFF0000) >> 16;
00633
00634 return signal_echo_data;
00635
00636 }
00637
00638
00639
00640 unsigned short * burst_echo(unsigned int burst_count,unsigned int * echo_data)
00641 {
00642
00643 unsigned int i=0;
00644
00645
00646 burst_echo_data[0] = OP_BURST_ECHO << OP_EJTAG_SHIFT ;
00647 burst_echo_data[1] = burst_count & 0xFFFF;
00648 burst_echo_data[2] = (burst_count & 0xFFFF0000) >> 16;
00649
00650 if(burst_count > BUSRT_ECHO_MAX)
00651 {
00652 printf("burst_count is overflow , MAX size is 0x%x \n",BUSRT_ECHO_MAX);
00653 burst_count = BUSRT_ECHO_MAX;
00654
00655 }
00656
00657 for(i=3;i<burst_count;i++)
00658 burst_echo_data[i] = ((i%256)<<8 | ((i%256)+0x30));
00659 #if 0
00660 for(i=0;i<burst_count;i++)
00661 {
00662 if(i%16 == 0)
00663 printf("\n");
00664 printf("0x%4x ",burst_echo_data[i]);
00665 }
00666 #endif
00667 return burst_echo_data;
00668
00669 }
00670
00671 #if 0
00672 int main()
00673 {
00674 printf("USB Ejtag test\n");
00675 return 0;
00676 }
00677 #endif
00678
00679 #if 1
00680
00681
00682 unsigned short * fast_read(unsigned int fast_count )
00683 {
00684
00685 unsigned int i=0;
00686 unsigned int j=0;
00687 unsigned int count=0;
00688 int a=0;
00689 unsigned int download_size_fast = fast_count/4;
00690 unsigned char *buf ;
00691 unsigned char *buf_read ;
00692
00693
00694
00695 if(fast_count%4)
00696 download_size_fast++;
00697 printf("fast_count : 0x%x , download_size_fast : 0x%x\n",fast_count,download_size_fast);
00698
00699 fast_read_data[0] = OP_FAST_READ << OP_EJTAG_SHIFT ;
00700 fast_read_data[1] = config_usb_ejtag_put_speed;
00701 fast_read_data[2] = (download_size_fast& 0xFFFF);
00702 fast_read_data[3] =(download_size_fast & 0xFFFF0000) >> 16 ;
00703
00704 #if 0
00705 if(fast_count > FAST_WR2_MAX)
00706 {
00707 printf("fast_count is overflow , MAX size is 0x%x \n",FAST_WR2_MAX);
00708 fast_count = FAST_WR2_MAX;
00709
00710 }
00711 #endif
00712 buf=malloc(8);
00713
00714 buf_read = malloc(FAST_WR2_MAX);
00715
00716 #if 0
00717 for(i=4;j<download_size_fast;j++)
00718 {
00719 fast_read_data[i++] = (fast_read_data_input[j]& 0xFFFF);
00720 fast_read_data[i++] = (fast_read_data_input[j]& 0xFFFF0000) >> 16;
00721 }
00722 #endif
00723
00724
00725 memset(buf,0,8);
00726 memset(buf_read,0,FAST_WR2_MAX);
00727
00728
00729
00730 count = 8 ;
00731 for(i=0;i<count;i=i+2)
00732 {
00733 buf[i] = fast_read_data[i/2] & 0xFF;
00734 buf[i+1] = (fast_read_data[i/2] & 0xFF00) >>8;
00735 }
00736
00737
00738 #if 1
00739
00740 for(i=0 ; i< 8 ; i++)
00741 {
00742 if((i%16 == 0) && i>0 )
00743 printf("\n");
00744 printf("0x%2x ",buf[i]);
00745 }
00746 printf("\n========================================================================================\n");
00747 #endif
00748
00749 endpoint = 2 ;
00750
00751 a = usb_bulk_write(current_handle, endpoint, buf, count, 5000);
00752
00753 #ifdef DEBUG_USB_EJTAG
00754 printf("usb_bulk_write end\n");
00755 #endif
00756 printf("USB write size is : 0x%x , a is %d \n",a, a);
00757 if(a != count )
00758 {
00759 fprintf(stderr,"Request for bulk write failed: %s\n", usb_strerror());
00760 usb_release_interface(current_handle, 0);
00761 return;
00762 }
00763
00764
00765 #if 1
00766 endpoint = 6 ;
00767
00768 a = usb_bulk_read(current_handle, endpoint, buf_read, fast_count, 1500000);
00769
00770 if(a != fast_count)
00771 {
00772 fprintf(stderr,"Request for Burst bulk read failed: %s\n", usb_strerror());
00773
00774
00775 }
00776 #endif
00777
00778
00779
00780
00781 #if 1
00782 for(i=0;i < fast_count ;i++)
00783 {
00784 if((i%16 == 0) && i>0 )
00785 printf("\n");
00786 printf("0x%x ",buf_read[i]);
00787 }
00788 printf("\n");
00789 #endif
00790
00791 #if 0
00792 for(i=0;i<burst_count;i++)
00793 {
00794 if(i%16 == 0)
00795 printf("\n");
00796 printf("0x%4x ",dma32_write2_data[i]);
00797 }
00798 #endif
00799
00800 free(buf);
00801 free(buf_read);
00802 return fast_read_data;
00803
00804 }
00805 #endif
00806
00807 #if 0
00808
00809 unsigned int usb_fast_upload2(unsigned int fast_count)
00810 {
00811 int i,a,count = 6 ;
00812 unsigned char *buf;
00813 unsigned char *buf_read;
00814
00815 unsigned int usb_wr_dr_result=0;
00816 unsigned int download_size_fast = fast_count/4;
00817
00818 if(fast_count%4)
00819 download_size_fast++;
00820 printf("fast_count : 0x%x , download_size_fast : 0x%x\n",fast_count,download_size_fast);
00821
00822 if(fast_count > FAST_WR2_MAX)
00823 {
00824 printf("fast_count is overflow , MAX size is 0x%x \n",FAST_WR2_MAX);
00825 fast_count = FAST_WR2_MAX;
00826
00827 }
00828
00829
00830 usb_fast_read_data[0] = OP_FAST_READ <<OP_EJTAG_SHIFT | 0x0 ;
00831 usb_fast_read_data[1] = fast_count & 0xFFFF;
00832 usb_fast_read_data[2] = (fast_count & 0xFFFF0000) >> 16;
00833
00834 buf=malloc(FAST_WR2_MAX);
00835 buf_read=malloc(FAST_WR2_MAX);
00836
00837 if(count > FAST_WR2_MAX)
00838 {
00839 fprintf(stderr, "Cannot transfer more than 6 bytes at a time.\n");
00840 exit(-1);
00841 }
00842
00843 memset(buf, 0, FAST_WR2_MAX);
00844 memset(buf_read, 0, 600);
00845
00846 for(i=0;i<count;i=i+2)
00847 {
00848 buf[i] = usb_wr_dr_data[i/2] & 0xFF;
00849 buf[i+1] = (usb_wr_dr_data[i/2] & 0xFF00) >>8;
00850 }
00851
00852
00853 #if 1
00854 for(i=0 ; i<count ; i++)
00855 {
00856 if((i%16 == 0) && i>0 )
00857 printf("\n");
00858 printf("0x%2x ",buf[i]);
00859 }
00860 printf("\n========================================================================================\n");
00861 #endif
00862 #if 1
00863 endpoint = 2 ;
00864 a = usb_bulk_write(current_handle, endpoint, buf, count, 1000);
00865
00866
00867 #if 1
00868 printf("usb_bulk_write end\n");
00869 #endif
00870 if(a<0)
00871 {
00872 fprintf(stderr,"Request for bulk write failed: %s\n", usb_strerror());
00873 usb_release_interface(current_handle, 0);
00874 return;
00875 }
00876
00877 endpoint = 6 ;
00878 count=600;
00879 a = usb_bulk_read(current_handle, endpoint, buf_read, 60, 15000);
00880
00881 if(a<0)
00882 {
00883 fprintf(stderr,"Request for Burst bulk read failed: %s\n", usb_strerror());
00884
00885
00886 }
00887 #endif
00888
00889
00890
00891
00892 #if 1
00893 for(i=0;i<count;i++)
00894 {
00895 if((i%16 == 0) && i>0 )
00896 printf("\n");
00897 printf("0x%x ",buf_read[i]);
00898 }
00899 printf("\n");
00900 #endif
00901
00902 usb_wr_dr_result = buf_read[3] << 24 |buf_read[2] << 16 |buf_read[1] << 8 |buf_read[0] ;
00903
00904 return usb_wr_dr_result;
00905
00906 }
00907 #endif