00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <errno.h>
00044 #include <signal.h>
00045 #include <stdio.h>
00046 #include <unistd.h>
00047 #include <sys/time.h>
00048 #include <sys/types.h>
00049 #include <sys/socket.h>
00050 #include <sys/wait.h>
00051 #include <netinet/in.h>
00052 #include <netdb.h>
00053 #include "jtag.h"
00054 #include "parport.h"
00055
00056
00057
00058
00059
00060 #define dPARPORT_TAP_RESET_BIT 0x03
00061 #define dPARPORT_TAP_DI_BIT 0x06
00062 #define dPARPORT_TAP_MS_BIT 0x01
00063 #define dPARPORT_TAP_CLK_BIT 0x00
00064 #define dPARPORT_TARGET_RESET_BIT 0x04
00065
00066
00067 #define dPARPORT_TAP_DO_BIT 0x80
00068
00069
00070 #define mPARPORT_TRS_BIT(x) (x << dPARPORT_TAP_RESET_BIT )
00071 #define mPARPORT_TMS_BIT(x) (x << dPARPORT_TAP_MS_BIT )
00072 #define mPARPORT_TDI_BIT(x) (x << dPARPORT_TAP_DI_BIT )
00073 #define mPARPORT_TCK_BIT(x) (x << dPARPORT_TAP_CLK_BIT )
00074 #define mPARPORT_RST_BIT(x) (x << dPARPORT_TARGET_RESET_BIT)
00075
00076
00077
00078
00079 static unsigned char fJTAG_Wiggle(unsigned char uc_tms, unsigned char uc_tdo);
00080
00081
00082
00083
00084
00085
00086 void fJTAG_Init(void)
00087 {
00088
00089 fPARPORT_Init();
00090
00091
00092
00093
00094
00095
00096
00097 fJTAG_Wiggle(1,0);
00098 fJTAG_Wiggle(1,0);
00099 fJTAG_Wiggle(1,0);
00100 fJTAG_Wiggle(1,0);
00101 fJTAG_Wiggle(1,0);
00102 fJTAG_Wiggle(1,0);
00103
00104
00105 fJTAG_Wiggle(0,0);
00106
00107
00108 fJTAG_Instruction(1);
00109 printf("IDCODE=0x%08x\n",fJTAG_Data(1));
00110 fJTAG_Instruction(3);
00111 printf("IMPCODE=0x%08x\n",fJTAG_Data(3));
00112
00113 return;
00114 }
00115
00116
00117
00118
00119
00120
00121
00122 static unsigned char fJTAG_Wiggle(unsigned char uc_tms, unsigned char uc_tdo)
00123 {
00124 unsigned char uc_dout;
00125 unsigned char uc_din;
00126
00127 uc_dout = (unsigned char)(mPARPORT_TRS_BIT(1)|mPARPORT_TMS_BIT(uc_tms)|
00128 mPARPORT_TDI_BIT(uc_tdo)|mPARPORT_TCK_BIT(0)|
00129 mPARPORT_RST_BIT(1));
00130 fPARPORT_Write(uc_dout);
00131
00132 uc_dout = (unsigned char)(mPARPORT_TRS_BIT(1)|mPARPORT_TMS_BIT(uc_tms)|
00133 mPARPORT_TDI_BIT(uc_tdo)|mPARPORT_TCK_BIT(1)|
00134 mPARPORT_RST_BIT(1));
00135 fPARPORT_Write(uc_dout);
00136
00137
00138 uc_din = fPARPORT_Read() & dPARPORT_TAP_DO_BIT ? 0 : 1;
00139
00140 return uc_din;
00141 }
00142
00143
00144
00145
00146
00147
00148 unsigned int fJTAG_Data (unsigned int ui_data_out)
00149 {
00150 unsigned int ui_data_in;
00151 unsigned char uc_index;
00152 unsigned char uc_result;
00153
00154 fJTAG_Wiggle(1, 0);
00155 fJTAG_Wiggle(0, 0);
00156 fJTAG_Wiggle(0, 0);
00157
00158 ui_data_in = 0x00;
00159
00160
00161 for (uc_index=0; uc_index<31; uc_index++)
00162 {
00163 uc_result = fJTAG_Wiggle(0, (ui_data_out & 0x01));
00164 ui_data_out = ui_data_out >> 1;
00165 ui_data_in = ui_data_in | (uc_result << uc_index);
00166 }
00167
00168 uc_result = fJTAG_Wiggle(1, (ui_data_out & 0x01));
00169 ui_data_in = ui_data_in | (uc_result << uc_index);
00170
00171 fJTAG_Wiggle(1, 0);
00172 fJTAG_Wiggle(0, 0);
00173
00174 return(ui_data_in);
00175 }
00176
00177
00178
00179
00180 unsigned int fJTAG_FastData (unsigned int ui_data_out)
00181 {
00182 unsigned int ui_data_in;
00183 unsigned char uc_index;
00184 unsigned char uc_result;
00185
00186 fJTAG_Wiggle(1, 0);
00187 fJTAG_Wiggle(0, 0);
00188 fJTAG_Wiggle(0, 0);
00189
00190 ui_data_in = 0x00;
00191
00192 fJTAG_Wiggle(0, 0);
00193
00194 for (uc_index=0; uc_index<31; uc_index++)
00195 {
00196 uc_result = fJTAG_Wiggle(0, (ui_data_out & 0x01));
00197 ui_data_out = ui_data_out >> 1;
00198 ui_data_in = ui_data_in | (uc_result << uc_index);
00199 }
00200
00201 uc_result = fJTAG_Wiggle(1, (ui_data_out & 0x01));
00202 ui_data_in = ui_data_in | (uc_result << uc_index);
00203
00204 fJTAG_Wiggle(1, 0);
00205 fJTAG_Wiggle(0, 0);
00206
00207 return(ui_data_in);
00208 }
00209
00210
00211
00212
00213 unsigned int fJTAG_DBTX(unsigned int ui_data_out)
00214 {
00215 unsigned int ui_data_in;
00216 unsigned char uc_index;
00217 unsigned char uc_result;
00218
00219 fJTAG_Wiggle(1, 0);
00220 fJTAG_Wiggle(0, 0);
00221 fJTAG_Wiggle(0, 0);
00222
00223 ui_data_in = 0x00;
00224
00225 fJTAG_Wiggle(0, 0);
00226
00227 for (uc_index=0; uc_index<31; uc_index++)
00228 {
00229 uc_result = fJTAG_Wiggle(0, (ui_data_out & 0x01));
00230 ui_data_out = ui_data_out >> 1;
00231 ui_data_in = ui_data_in | (uc_result << uc_index);
00232 }
00233
00234 uc_result = fJTAG_Wiggle(1, (ui_data_out & 0x01));
00235 ui_data_in = ui_data_in | (uc_result << uc_index);
00236
00237 fJTAG_Wiggle(1, 0);
00238 fJTAG_Wiggle(0, 0);
00239
00240 return(ui_data_in);
00241 }
00242
00243 #if 0
00244
00245
00246
00247 unsigned int fJTAG_DBDX_TEST(unsigned int ui_data_out)
00248 {
00249 unsigned int ui_data_in;
00250 unsigned char uc_index;
00251 unsigned int uc_result=0x00;
00252 unsigned int uc_result1=0x00;
00253
00254 fJTAG_Wiggle(1, 0);
00255 fJTAG_Wiggle(0, 0);
00256 fJTAG_Wiggle(0, 0);
00257
00258 ui_data_in = 0x00;
00259
00260 uc_result1=fJTAG_Wiggle(0, 1);
00261
00262 for (uc_index=0; uc_index<31; uc_index++)
00263 {
00264 uc_result = fJTAG_Wiggle(0, (ui_data_out & 0x01));
00265 ui_data_out = ui_data_out >> 1;
00266 ui_data_in = ui_data_in | (uc_result << uc_index);
00267 }
00268
00269 uc_result = fJTAG_Wiggle(1, (ui_data_out & 0x01));
00270 ui_data_in = ui_data_in | (uc_result << uc_index);
00271
00272 fJTAG_Wiggle(1, 0);
00273 fJTAG_Wiggle(0, 0);
00274
00275
00276 return(uc_result1);
00277 }
00278 #endif
00279
00280 #if 1
00281
00282
00283
00284 unsigned int fJTAG_DBDX_TEST(unsigned int ui_data_out)
00285 {
00286 unsigned int ui_data_in;
00287
00288 unsigned int uc_result=0x00;
00289
00290 fJTAG_Wiggle(1, 0);
00291 fJTAG_Wiggle(0, 0);
00292 fJTAG_Wiggle(0, 0);
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 uc_result = fJTAG_Wiggle(1, (ui_data_out & 0x01));
00306
00307
00308 fJTAG_Wiggle(1, 0);
00309 fJTAG_Wiggle(0, 0);
00310 if(uc_result)
00311 printf("fJTAG_DBDX_TEST : 0x%x\n",uc_result);
00312 return(uc_result);
00313 }
00314 #endif
00315
00316
00317
00318
00319 unsigned int fJTAG_DBDX(unsigned int ui_data_out)
00320 {
00321 unsigned int ui_data_in;
00322 unsigned char uc_index;
00323 unsigned char uc_result;
00324
00325 fJTAG_Wiggle(1, 0);
00326 fJTAG_Wiggle(0, 0);
00327 fJTAG_Wiggle(0, 0);
00328
00329 ui_data_in = 0x00;
00330
00331 fJTAG_Wiggle(0, 0);
00332
00333 for (uc_index=0; uc_index<31; uc_index++)
00334 {
00335 uc_result = fJTAG_Wiggle(0, (ui_data_out & 0x01));
00336 ui_data_out = ui_data_out >> 1;
00337 ui_data_in = ui_data_in | (uc_result << uc_index);
00338 }
00339
00340 uc_result = fJTAG_Wiggle(1, (ui_data_out & 0x01));
00341 ui_data_in = ui_data_in | (uc_result << uc_index);
00342
00343 fJTAG_Wiggle(1, 0);
00344 fJTAG_Wiggle(0, 0);
00345
00346 return(ui_data_in);
00347 }
00348
00349
00350
00351
00352
00353
00354 unsigned char fJTAG_Instruction(unsigned char uc_data_out)
00355 {
00356 unsigned char uc_data_in;
00357 unsigned char uc_result;
00358 unsigned char uc_index;
00359
00360 fJTAG_Wiggle(1, 0);
00361 fJTAG_Wiggle(1, 0);
00362 fJTAG_Wiggle(0, 0);
00363 fJTAG_Wiggle(0, 0);
00364
00365 uc_data_in=0;
00366
00367
00368 for (uc_index=0; uc_index<4; uc_index++)
00369 {
00370 uc_result = fJTAG_Wiggle(0, (uc_data_out & 0x01));
00371 uc_data_out = uc_data_out >> 1;
00372 uc_data_in = uc_data_in | (uc_result << uc_index);
00373 }
00374
00375 uc_result = fJTAG_Wiggle(1, (uc_data_out & 0x01));
00376 uc_data_in = uc_data_in | (uc_result << uc_index);
00377
00378 fJTAG_Wiggle(1, 0);
00379 fJTAG_Wiggle(0, 0);
00380
00381 return(uc_data_in);
00382 }
00383
00384 unsigned int fJTAG_FAST_UPLOAD(unsigned int upload_count)
00385 {
00386 printf("error no this method fJTAG_FAST_UPLOAD\n");
00387 exit(-1);
00388 return -1;
00389 }
00390
00391 void fJTAG_unInit(void)
00392 {
00393 }
00394
00395
00396 unsigned int fJTAG_UPLOAD(unsigned char *buf,unsigned int upload_count)
00397 {
00398 printf("error no this method fJTAG_UPLOAD\n");
00399 exit(-1);
00400 return -1;
00401 }
00402