usb_jtag.c

Go to the documentation of this file.
00001 //
00002 // USB_JTAG.C
00003 //
00004 // Low level JTAG access code.  Handles all clocking of data in and
00005 // out of target hardware.
00006 //
00007 // Copyright (c) 2002, Jason Riffel - TotalEmbedded LLC.
00008 // All rights reserved.
00009 //
00010 // Redistribution and use in source and binary forms, with or without 
00011 // modification, are permitted provided that the following conditions 
00012 // are met:
00013 //
00014 // Redistributions of source code must retain the above copyright 
00015 // notice, this list of conditions and the following disclaimer. 
00016 //
00017 // Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in 
00019 // the documentation and/or other materials provided with the
00020 // distribution. 
00021 //
00022 // Neither the name of TotalEmbedded nor the names of its 
00023 // contributors may be used to endorse or promote products derived 
00024 // from this software without specific prior written permission.
00025 // 
00026 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00027 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00028 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
00029 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
00030 // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
00031 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
00032 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
00033 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00034 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00035 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
00036 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00037 // POSSIBILITY OF SUCH DAMAGE.
00038 //
00039 // Modifed by ZGJ on the 20090609
00040 //
00041 // INCLUDES
00042 //
00043 #include <errno.h>
00044 #include <stdio.h>
00045 #include <unistd.h>
00046 #include <sys/time.h>
00047 #include <sys/types.h>
00048 #include "usb_jtag.h"
00049 //#include "usb_ejtag_command.h"
00050 
00051 //
00052 // DEFINES
00053 //
00054 
00055 
00056 
00057 //
00058 // PROTOTYPES
00059 //
00060 
00061 //
00062 // fJTAG_Init
00063 //
00064 // Initializes the state of the JTAG hardware
00065 //
00066 extern int usb_can_bulk_wr_flag;
00067 void fJTAG_Init(void)
00068 {
00069         int found_usb = USB_NO_FOUND;
00070         found_usb = usb_tap_init();
00071         if(found_usb == USB_FOUND)
00072         {
00073                 usb_fx2_reset();
00074         }
00075         else
00076         {
00077                 fprintf(stderr,"usb device not found!\n");
00078                 exit(-1);
00079         }
00080         
00081         if(usb_can_bulk_wr_flag == USB_CAN_BULK_WR_FLAG)
00082                 tap_reset();
00083         else
00084         {
00085                 fprintf(stderr,"usb ejtag simulator not BULK read/write!\n");
00086                 exit(-1);
00087         }
00088 }
00089 
00090 
00091 //
00092 // fJTAG_Data
00093 //
00094 // Write/Read from/to the JTAG data register
00095 //
00096 unsigned int fJTAG_Data (unsigned int ui_data_out)
00097 {
00098         unsigned int  ui_data_in;
00099 
00100         ui_data_in = usb_wr_dr(1,1,ui_data_out);
00101         
00102         return(ui_data_in);
00103 }
00104 
00105 //
00106 // fJTAG_Instruction
00107 //
00108 // Read/Write from/to the instruction register
00109 //
00110 unsigned char fJTAG_Instruction(unsigned char uc_data_out)
00111 {
00112         unsigned char uc_data_in=0;
00113 #if 0
00114         uc_data_in = usb_wr_ir(1,1,uc_data_out);
00115 #else
00116         uc_data_in = usb_wr_ir(0,0,uc_data_out);
00117 #endif
00118         return(uc_data_in);
00119 }
00120 
00121 //
00122 // Write/Read from/to the JTAG Fastdata register
00123 //
00124 unsigned int fJTAG_FastData (unsigned int ui_data_out)
00125 {
00126         unsigned int  ui_data_in;
00127 
00128         ui_data_in = usb_wr_dr(1,1,ui_data_out);
00129         
00130         return(ui_data_in);
00131 }
00132 
00133 //
00134 // Write/Read from/to the JTAG DBTX register
00135 //
00136 unsigned int fJTAG_DBTX_test(unsigned int ui_data_out)
00137 {
00138         unsigned int  ui_data_in=0;
00139 
00140         ui_data_in = usb_wr_dr(1,1,ui_data_out);
00141         //fast_write2(fast_count,fast_write2_data_input);
00142         
00143         return(ui_data_in);
00144 }
00145 //
00146 // Write/Read from/to the JTAG DBTX register
00147 //
00148 unsigned int fJTAG_DBTX(unsigned int fast_count,unsigned int * fast_write2_data_input)
00149 {
00150         unsigned int  ui_data_in=0;
00151 
00152         // ui_data_in = usb_wr_dr(1,1,ui_data_out);
00153         //20090628-zgj fast_write2(fast_count,fast_write2_data_input);
00154         fast_write2(fast_count,fast_write2_data_input);
00155         //20090628-normal-lw-240KB/S  fast_write_3(fast_count,fast_write2_data_input);
00156         
00157         return(ui_data_in);
00158 }
00159 
00160 //
00161 // Read from the JTAG DBDX register
00162 //
00163 unsigned int fJTAG_DBDX(unsigned int ui_data_out)
00164 {
00165         unsigned int  ui_data_in;
00166 
00167         ui_data_in = usb_wr_dr(1,1,ui_data_out);
00168         
00169         return(ui_data_in);
00170 }
00171 
00172 //
00173 // Read from the JTAG DBDX register
00174 //
00175 unsigned int fJTAG_DBDX_TEST(unsigned int ui_data_out)
00176 {
00177         unsigned int  ui_data_in;
00178 
00179         ui_data_in = usb_wr_dr(1,1,ui_data_out);
00180         
00181         return(ui_data_in);
00182 }
00183 
00184 
00185 //
00186 // Write/Read from/to the JTAG DBTX register
00187 //
00188 unsigned int fJTAG_UPLOAD(unsigned char *buf,unsigned int upload_count)
00189 {
00190         unsigned int  ui_data_in=0;
00191 #if 1
00192         unsigned int download_ram_size=0;
00193         unsigned int init_do=0;
00194         time_t time_start;
00195         time_t time_end;
00196         time_t  time_deta=0;
00197         int i=0;
00198 
00199         if(!init_do)
00200         {
00201                 time_start = (time(&time_start))&0xffffffff;
00202                 printf("time_start : %x \n",time_start);
00203                 init_do = 1;
00204                 download_ram_size=0;
00205         }
00206 #endif
00207         // ui_data_in = usb_wr_dr(1,1,ui_data_out);
00208         //20090628-zgj fast_write2(fast_count,fast_write2_data_input);
00209 //      for(i=0 ; i< 0x10000; i++ )
00210         {
00211         //      getchar();
00212         //      getchar();
00213                 printf("======================= %d\n",i);
00214                 usb_wr_upload(buf,upload_count);
00215         }
00216         //20090628-normal-lw-240KB/S  fast_write_3(fast_count,fast_write2_data_input);
00217 
00218 #if 1
00219          download_ram_size = upload_count;
00220                 time_end = (time(&time_end))&0xffffffff;
00221                 printf("=<<<==time_end : %x \n",time_end);
00222                 time_deta= time_end - time_start;
00223                 if(time_deta == 0)
00224                         time_deta++ ;
00225                 printf("=<<<==time : %d, download_size : %x, download rate=%d B/S\n",time_deta,download_ram_size,((download_ram_size/time_deta)));
00226 #endif
00227         return(ui_data_in);
00228 }
00229 
00230 //
00231 // Write/Read from/to the JTAG DBTX register
00232 //
00233 unsigned int fJTAG_FAST_UPLOAD(unsigned int upload_count)
00234 {
00235         unsigned int  ui_data_in=0;
00236 
00237         // ui_data_in = usb_wr_dr(1,1,ui_data_out);
00238         //20090628-zgj fast_write2(fast_count,fast_write2_data_input);
00239         // usb_wr_upload(upload_count);
00240         fast_read(upload_count);
00241         //20090628-normal-lw-240KB/S  fast_write_3(fast_count,fast_write2_data_input);
00242         
00243         return(ui_data_in);
00244 }
00245 
00246 void fJTAG_unInit(void)
00247 {
00248         usb_stop();
00249 }

Generated on Fri Nov 5 07:24:46 2010 for ejtag debug tools for loongson 232 cpu by  doxygen 1.5.6