aaa.c

Go to the documentation of this file.
00001 #include "usb_jtag.h"
00002 #include"mips32.h"
00003 #define EP_IN 0x6
00004 #define EP_OUT 0x2
00005 static unsigned char last_ir ;
00006 static unsigned char updated ;
00007 unsigned int usb_wr_ir_nwb(unsigned char new_ir_data);
00008 unsigned int usb_wr_dr_nwb(unsigned int new_dr_data);
00009 
00010 
00011 void usb_hardware_send(unsigned char*ptr,unsigned int len)
00012 {
00013     int a ;
00014     a=usb_bulk_write(current_handle,EP_OUT,ptr,len,5000);
00015     if(a!=len)
00016     {
00017         printf("Request for bulk write failed: %s\n");
00018         return ;
00019     }
00020 }
00021 
00022 //make sure the length is sufficent
00023 void usb_hardware_rcv(unsigned char*ptr,unsigned int len)
00024 {
00025     int a=usb_bulk_read(current_handle,EP_IN,ptr,len,5000);
00026     if(a!=len)
00027     {
00028         printf("Request for bulk write failed: %s\n");
00029         return ;
00030     }
00031 }
00032 
00033 #define PACK_BUFF_SIZE 1024*1024*10
00034 int pack_buff_cntr=0 ;
00035 unsigned char pack_buffer[PACK_BUFF_SIZE];
00036 
00037 // static unsigned char *pack_buffer;
00038 int init_my_1=0;
00039 #define MY_DEBUG 
00040 //printf("%s :%d \n",__FUNCTION__,__LINE__);
00041 unsigned char *usb_wr_cache(unsigned char*ptr,unsigned int len,int rd_len)
00042 {
00043     int i,j,k,a ;
00044 
00045      // if(ptr != NULL)
00046      //         usb_hardware_send(ptr,len);
00047 #if 1
00048     int do_send_now=a=0; //  (0==rd_len)?0:1 ;
00049 /*
00050     if(!init_my_1)
00051     { 
00052         init_my_1 = 1;
00053         pack_buffer = malloc(PACK_BUFF_SIZE);
00054     }
00055 */
00056     if(ptr==NULL)
00057         do_send_now=1 ;
00058     if(len==0)
00059         do_send_now=1 ;
00060     
00061     if(PACK_BUFF_SIZE<(pack_buff_cntr+len+64))
00062     {   
00063         do_send_now=1 ;
00064         a=1;
00065     }
00066     else 
00067         for(i=0;i<len;++i)
00068         //      pack_buff_cntr++;
00069                 pack_buffer[pack_buff_cntr++]=ptr[i];
00070     MY_DEBUG
00071     // if(do_send_now&&(pack_buff_cntr!=0))
00072     if(do_send_now)
00073     {
00074     MY_DEBUG
00075         //printf("sending a packdge ,which size is %d\n",pack_buff_cntr);
00076         usb_hardware_send(pack_buffer,pack_buff_cntr);
00077         pack_buff_cntr=0 ;
00078         if(a)
00079         {
00080                 for(i=0;i<len;++i)
00081         //      pack_buff_cntr++;
00082                  pack_buffer[pack_buff_cntr++]=ptr[i];
00083         }
00084     }
00085     MY_DEBUG
00086 #endif
00087 
00088 #if 0
00089     if(rd_len!=0)
00090     {
00091     MY_DEBUG
00092         usb_hardware_rcv(ptr,rd_len);
00093     MY_DEBUG
00094     }
00095     MY_DEBUG
00096 #endif
00097     return ptr ;
00098 }
00099 
00100 
00101 unsigned int lw_feed_data(unsigned int data)
00102 {
00103     unsigned int ui_result ;
00104     // printf("Info : feed 0x%08x with 0x%08x\n",lw_get_ejtag_addr(),data);
00105     usb_wr_ir_nwb(dJTAG_REGISTER_DATA);
00106     usb_wr_dr_nwb(data);
00107     
00108     ui_result=dMIPS32_ECR_CPU_RESET_OCCURED|dMIPS32_ECR_PROBE_ENABLE|
00109     dMIPS32_ECR_PROBE_VECTOR ;
00110     usb_wr_ir_nwb(dJTAG_REGISTER_CONTROL);
00111     usb_wr_dr_nwb(ui_result);
00112     //  usb_wr_cache(NULL,0,0);
00113 }
00114 
00115 unsigned int usb_wr_ir_nwb(unsigned char new_ir_data)
00116 {
00117     int a ;
00118     unsigned short usb_wr_ir_data ;
00119     //=0xff&(new_ir_data <<8 )+0x10;
00120     new_ir_data&=0x1f ;
00121     usb_wr_ir_data=new_ir_data+1<<4 ;
00122     if(last_ir==new_ir_data)return ;
00123     last_ir=new_ir_data ;
00124     updated=1 ;
00125 }
00126 
00127 unsigned int usb_wr_dr_nwb(unsigned int new_dr_data)
00128 {
00129     unsigned short usb_wr_dr_data[20];
00130     static unsigned char buf[32];
00131     static unsigned char tmp[4];
00132     int i,a,count=6 ;
00133     unsigned int usb_wr_dr_result=0 ;
00134 //    int i_data=(wb==0)?0:1 ;
00135 //    wb=i_data ;
00136     if(updated)
00137     {
00138         tmp[0]=last_ir ;
00139         //usb_wr_ir_data&0xff;
00140         tmp[1]=0x10 ;
00141         //no need to write back.
00142         usb_wr_cache(tmp,2,0);
00143         updated=0 ;
00144     }
00145     usb_wr_dr_data[0]=OP_WR_DR<<OP_EJTAG_SHIFT ;
00146     // if (wb)  usb_wr_dr_data[0]|= 1 << OP_EJTAG_W_SHIFT ;
00147     //  if (wb) usb_wr_dr_data[0]|= 1 << OP_EJTAG_I_SHIFT ;
00148     usb_wr_dr_data[1]=new_dr_data&0xFFFF ;
00149     usb_wr_dr_data[2]=(new_dr_data&0xFFFF0000)>>16 ;
00150     for(i=0;i<count;i=i+2)
00151     {
00152         buf[i]=usb_wr_dr_data[i/2]&0xFF ;
00153         buf[i+1]=(usb_wr_dr_data[i/2]&0xFF00)>>8 ;
00154     }
00155     
00156     usb_wr_cache(buf,6,0);
00157     
00158     return 0 ;
00159 }
00160 

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