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
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
00038 int init_my_1=0;
00039 #define MY_DEBUG
00040
00041 unsigned char *usb_wr_cache(unsigned char*ptr,unsigned int len,int rd_len)
00042 {
00043 int i,j,k,a ;
00044
00045
00046
00047 #if 1
00048 int do_send_now=a=0;
00049
00050
00051
00052
00053
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
00069 pack_buffer[pack_buff_cntr++]=ptr[i];
00070 MY_DEBUG
00071
00072 if(do_send_now)
00073 {
00074 MY_DEBUG
00075
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
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
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
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
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
00135
00136 if(updated)
00137 {
00138 tmp[0]=last_ir ;
00139
00140 tmp[1]=0x10 ;
00141
00142 usb_wr_cache(tmp,2,0);
00143 updated=0 ;
00144 }
00145 usb_wr_dr_data[0]=OP_WR_DR<<OP_EJTAG_SHIFT ;
00146
00147
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