jtag.c File Reference

#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <netdb.h>
#include "jtag.h"
#include "parport.h"

Include dependency graph for jtag.c:

Go to the source code of this file.

Defines

#define dPARPORT_TAP_CLK_BIT   0x00
#define dPARPORT_TAP_DI_BIT   0x06
#define dPARPORT_TAP_DO_BIT   0x80
#define dPARPORT_TAP_MS_BIT   0x01
#define dPARPORT_TAP_RESET_BIT   0x03
#define dPARPORT_TARGET_RESET_BIT   0x04
#define mPARPORT_RST_BIT(x)   (x << dPARPORT_TARGET_RESET_BIT)
#define mPARPORT_TCK_BIT(x)   (x << dPARPORT_TAP_CLK_BIT )
#define mPARPORT_TDI_BIT(x)   (x << dPARPORT_TAP_DI_BIT )
#define mPARPORT_TMS_BIT(x)   (x << dPARPORT_TAP_MS_BIT )
#define mPARPORT_TRS_BIT(x)   (x << dPARPORT_TAP_RESET_BIT )

Functions

unsigned int fJTAG_Data (unsigned int ui_data_out)
unsigned int fJTAG_DBDX (unsigned int ui_data_out)
unsigned int fJTAG_DBDX_TEST (unsigned int ui_data_out)
unsigned int fJTAG_DBTX (unsigned int ui_data_out)
unsigned int fJTAG_FAST_UPLOAD (unsigned int upload_count)
unsigned int fJTAG_FastData (unsigned int ui_data_out)
void fJTAG_Init (void)
unsigned char fJTAG_Instruction (unsigned char uc_data_out)
void fJTAG_unInit (void)
unsigned int fJTAG_UPLOAD (unsigned char *buf, unsigned int upload_count)
static unsigned char fJTAG_Wiggle (unsigned char uc_tms, unsigned char uc_tdo)


Define Documentation

#define dPARPORT_TAP_CLK_BIT   0x00

Definition at line 63 of file jtag.c.

#define dPARPORT_TAP_DI_BIT   0x06

Definition at line 61 of file jtag.c.

#define dPARPORT_TAP_DO_BIT   0x80

Definition at line 67 of file jtag.c.

Referenced by fJTAG_Wiggle().

#define dPARPORT_TAP_MS_BIT   0x01

Definition at line 62 of file jtag.c.

#define dPARPORT_TAP_RESET_BIT   0x03

Definition at line 60 of file jtag.c.

#define dPARPORT_TARGET_RESET_BIT   0x04

Definition at line 64 of file jtag.c.

#define mPARPORT_RST_BIT ( x   )     (x << dPARPORT_TARGET_RESET_BIT)

Definition at line 74 of file jtag.c.

Referenced by fJTAG_Wiggle().

#define mPARPORT_TCK_BIT ( x   )     (x << dPARPORT_TAP_CLK_BIT )

Definition at line 73 of file jtag.c.

Referenced by fJTAG_Wiggle().

#define mPARPORT_TDI_BIT ( x   )     (x << dPARPORT_TAP_DI_BIT )

Definition at line 72 of file jtag.c.

Referenced by fJTAG_Wiggle().

#define mPARPORT_TMS_BIT ( x   )     (x << dPARPORT_TAP_MS_BIT )

Definition at line 71 of file jtag.c.

Referenced by fJTAG_Wiggle().

#define mPARPORT_TRS_BIT ( x   )     (x << dPARPORT_TAP_RESET_BIT )

Definition at line 70 of file jtag.c.

Referenced by fJTAG_Wiggle().


Function Documentation

unsigned int fJTAG_Data ( unsigned int  ui_data_out  ) 

Definition at line 148 of file jtag.c.

References fJTAG_Wiggle().

00149 {
00150   unsigned int  ui_data_in;
00151   unsigned char uc_index;
00152   unsigned char uc_result;
00153   
00154   fJTAG_Wiggle(1, 0);  // enter select-dr-scan
00155   fJTAG_Wiggle(0, 0);  // enter capture-dr
00156   fJTAG_Wiggle(0, 0);  // enter shift-dr
00157 
00158   ui_data_in = 0x00;
00159 
00160   // Clock all but last bit out
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   // On last bit set the TAP_MS
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);  // enter update-dr
00172   fJTAG_Wiggle(0, 0);  // enter runtest-idle
00173 
00174   return(ui_data_in);
00175 }

Here is the call graph for this function:

unsigned int fJTAG_DBDX ( unsigned int  ui_data_out  ) 

Definition at line 319 of file jtag.c.

References fJTAG_Wiggle().

00320 {
00321   unsigned int  ui_data_in;
00322   unsigned char uc_index;
00323   unsigned char uc_result;
00324   
00325   fJTAG_Wiggle(1, 0);  // enter select-dr-scan
00326   fJTAG_Wiggle(0, 0);  // enter capture-dr
00327   fJTAG_Wiggle(0, 0);  // enter shift-dr
00328 
00329   ui_data_in = 0x00;
00330 
00331       fJTAG_Wiggle(0, 0);  // write a 0 to the JTAG DBDX register
00332   // Clock all but last bit out
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   // On last bit set the TAP_MS
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);  // enter update-dr
00344   fJTAG_Wiggle(0, 0);  // enter runtest-idle
00345 //zgj printf("fJTAG_DBDX===data : 0x%x\n",ui_data_in);
00346   return(ui_data_in);
00347 }

Here is the call graph for this function:

unsigned int fJTAG_DBDX_TEST ( unsigned int  ui_data_out  ) 

Definition at line 284 of file jtag.c.

References fJTAG_Wiggle().

00285 {
00286   unsigned int  ui_data_in;
00287 //  unsigned char uc_index;
00288   unsigned int uc_result=0x00;
00289   
00290   fJTAG_Wiggle(1, 0);  // enter select-dr-scan
00291   fJTAG_Wiggle(0, 0);  // enter capture-dr
00292   fJTAG_Wiggle(0, 0);  // enter shift-dr
00293 
00294 //  ui_data_in = 0x00;
00295 
00296 //      fJTAG_Wiggle(0, 0);  // write a 0 to the JTAG DBDX register
00297   // Clock all but last bit out
00298 //  for (uc_index=0; uc_index<31; uc_index++)
00299 //    {
00300 //      uc_result   = fJTAG_Wiggle(0, (ui_data_out & 0x01));
00301 //      ui_data_out = ui_data_out >> 1;
00302 //      ui_data_in  = ui_data_in | (uc_result << uc_index);
00303 //    }
00304   // On last bit set the TAP_MS
00305   uc_result   = fJTAG_Wiggle(1, (ui_data_out & 0x01));
00306 //  ui_data_in  = ui_data_in | (uc_result << uc_index);
00307 
00308   fJTAG_Wiggle(1, 0);  // enter update-dr
00309   fJTAG_Wiggle(0, 0);  // enter runtest-idle
00310   if(uc_result)
00311         printf("fJTAG_DBDX_TEST : 0x%x\n",uc_result);
00312   return(uc_result);
00313 }

Here is the call graph for this function:

unsigned int fJTAG_DBTX ( unsigned int  ui_data_out  ) 

Definition at line 213 of file jtag.c.

References fJTAG_Wiggle().

Referenced by fMIPS32_USB_DownloadModule().

00214 {
00215   unsigned int  ui_data_in;
00216   unsigned char uc_index;
00217   unsigned char uc_result;
00218   
00219   fJTAG_Wiggle(1, 0);  // enter select-dr-scan
00220   fJTAG_Wiggle(0, 0);  // enter capture-dr
00221   fJTAG_Wiggle(0, 0);  // enter shift-dr
00222 
00223   ui_data_in = 0x00;
00224 
00225       fJTAG_Wiggle(0, 0);  // write a 0 to the Fastdata register
00226   // Clock all but last bit out
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   // On last bit set the TAP_MS
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);  // enter update-dr
00238   fJTAG_Wiggle(0, 0);  // enter runtest-idle
00239 
00240   return(ui_data_in);
00241 }

Here is the call graph for this function:

unsigned int fJTAG_FAST_UPLOAD ( unsigned int  upload_count  ) 

Definition at line 384 of file jtag.c.

Referenced by USB_UPLOAD_FAST().

00385 {
00386  printf("error no this method fJTAG_FAST_UPLOAD\n");
00387  exit(-1);
00388  return -1;
00389 }

unsigned int fJTAG_FastData ( unsigned int  ui_data_out  ) 

Definition at line 180 of file jtag.c.

References fJTAG_Wiggle().

Referenced by fMIPS32_ExecuteDebugModule(), and fMIPS32_Transfer().

00181 {
00182   unsigned int  ui_data_in;
00183   unsigned char uc_index;
00184   unsigned char uc_result;
00185   
00186   fJTAG_Wiggle(1, 0);  // enter select-dr-scan
00187   fJTAG_Wiggle(0, 0);  // enter capture-dr
00188   fJTAG_Wiggle(0, 0);  // enter shift-dr
00189 
00190   ui_data_in = 0x00;
00191 
00192       fJTAG_Wiggle(0, 0);  // write a 0 to the Fastdata register
00193   // Clock all but last bit out
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   // On last bit set the TAP_MS
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);  // enter update-dr
00205   fJTAG_Wiggle(0, 0);  // enter runtest-idle
00206 
00207   return(ui_data_in);
00208 }

Here is the call graph for this function:

void fJTAG_Init ( void   ) 

Definition at line 86 of file jtag.c.

References fJTAG_Data(), fJTAG_Instruction(), fJTAG_Wiggle(), and fPARPORT_Init().

00087 {
00088   // First we need to init the parallel port
00089   fPARPORT_Init();
00090   
00091   // Wiggle the TAP_RESET bit - Be mindful of the target reset bit
00092 //  fPARPORT_Write((unsigned char)mPARPORT_RST_BIT(1)|mPARPORT_TRS_BIT(0));
00093 //  fPARPORT_Write((unsigned char)mPARPORT_RST_BIT(1)|mPARPORT_TRS_BIT(1));
00094 
00095   // Run through a handful of clock cycles with TMS high to make sure
00096   // we are in the TEST-LOGIC-RESET state.
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   // Enter the RUN-TEST-IDLE state
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 }

Here is the call graph for this function:

unsigned char fJTAG_Instruction ( unsigned char  uc_data_out  ) 

Definition at line 354 of file jtag.c.

References fJTAG_Wiggle().

00355 {
00356   unsigned char uc_data_in;
00357   unsigned char uc_result;
00358   unsigned char uc_index;
00359 
00360   fJTAG_Wiggle(1, 0);  // enter select-dr-scan
00361   fJTAG_Wiggle(1, 0);  // enter select-ir-scan
00362   fJTAG_Wiggle(0, 0);  // enter capture-ir
00363   fJTAG_Wiggle(0, 0);  // enter shift-ir (dummy)
00364 
00365   uc_data_in=0;
00366   
00367   // Clock all but last bit out
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   // On last bit set the TAP_MS
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);  // enter update-ir
00379   fJTAG_Wiggle(0, 0);  // enter runtest-idle
00380 
00381   return(uc_data_in);
00382 }

Here is the call graph for this function:

void fJTAG_unInit ( void   ) 

Definition at line 391 of file jtag.c.

00392 {
00393 }

unsigned int fJTAG_UPLOAD ( unsigned char *  buf,
unsigned int  upload_count 
)

Definition at line 396 of file jtag.c.

Referenced by cmd_get().

00397 {
00398  printf("error no this method fJTAG_UPLOAD\n");
00399  exit(-1);
00400  return -1;
00401 }

static unsigned char fJTAG_Wiggle ( unsigned char  uc_tms,
unsigned char  uc_tdo 
) [static]

Definition at line 122 of file jtag.c.

References dPARPORT_TAP_DO_BIT, fPARPORT_Read(), fPARPORT_Write(), mPARPORT_RST_BIT, mPARPORT_TCK_BIT, mPARPORT_TDI_BIT, mPARPORT_TMS_BIT, and mPARPORT_TRS_BIT.

Referenced by fJTAG_Data(), fJTAG_DBDX(), fJTAG_DBDX_TEST(), fJTAG_DBTX(), fJTAG_FastData(), fJTAG_Init(), and fJTAG_Instruction().

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   // Read in the status bit (inverted in hardware)
00138   uc_din = fPARPORT_Read() & dPARPORT_TAP_DO_BIT ? 0 : 1;
00139 
00140   return uc_din;
00141 }

Here is the call graph for this function:


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