Subversion Repositories ngs

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. /*
  2.  *  INFO:
  3.  *     jtag.cpp (C) 2003  Dr. Yuri Klimets (www.jtag.tk, jtagtools.sf.net)  
  4.  *     E-mail: klimets@jtag.tk
  5.  *     Rev. 1.5 - 23.11.2003
  6.  *  
  7.  *  
  8.  *  DESCRIPTION:
  9.  *     Contains implementation of JTAG class methods
  10.  *
  11.  *
  12.  *  DISCLAIMER:
  13.  *     This program is free software; you can redistribute it and/or modify
  14.  *     it under the terms of the GNU General Public License as published by
  15.  *     the Free Software Foundation; either version 2 of the License, or
  16.  *     (at your option) any later version.
  17.  *
  18.  *     This program is distributed in the hope that it will be useful,
  19.  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  *     GNU General Public License for more details.
  22.  *
  23.  *     You should have received a copy of the GNU General Public License
  24.  *     along with this program; if not, write to the Free Software
  25.  *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. */  
  27.  
  28. #include "jtag.h"
  29. #include <string.h>
  30.  
  31. JTAG::JTAG(int mode, int g_size) {
  32.  status=0;
  33.  tap=new TAP(mode,g_size);
  34.  if (tap==NULL) status=TAP_FAILED;
  35.    else status=tap->GetStatus();
  36. }
  37.  
  38. JTAG::~JTAG() {
  39.  if (tap!=NULL) {delete tap;tap=NULL;}
  40. }
  41.  
  42. void JTAG::RESET() {
  43.  #ifdef JTAG_LOG
  44.    puts("RESET");
  45.  #endif
  46.  tap->TCK(0);
  47.  tap->TMS(1);
  48.  tap->update();
  49.  tap->TCK_CLOCK(5);
  50.  tap->update();tap->realize();
  51. }
  52.  
  53.  
  54. void JTAG::IDLE() {
  55.  #ifdef JTAG_LOG
  56.    puts("IDLE");
  57.  #endif
  58.  tap->TMS(0);tap->update();tap->TCK_CLOCK();
  59.  tap->update();tap->realize();
  60. }
  61.  
  62. void JTAG::IRSCAN(char * cmd1,char * out1) {
  63.  #ifdef JTAG_LOG
  64.    printf("IRSCAN: %s\n",cmd1);
  65.  #endif
  66.  tap->TMS(1);tap->update();tap->TCK_CLOCK(2);
  67.  tap->TMS(0);tap->update();tap->TCK_CLOCK(2);
  68.  int i;
  69. // for (i=0;i<strlen((char *)cmd1)-1;i++) {
  70.  for (i=(strlen((char *)cmd1)-1);i>0;i--) {
  71.      tap->update();tap->realize();
  72.      *(out1+i)=tap->TDO()+'0';
  73.      tap->TDI(*(cmd1+i)=='0'?0:1);
  74.      tap->update();tap->TCK_CLOCK();
  75.  }
  76.  tap->update();tap->realize();
  77.  *(out1+i)=tap->TDO()+'0';
  78.  tap->TDI(*(cmd1+i)=='0'?0:1);
  79.  tap->TMS(1);tap->update();tap->TCK_CLOCK(2);
  80.  tap->TMS(0);tap->update();tap->TCK_CLOCK();
  81.  tap->update();tap->realize();
  82. }
  83.  
  84. void JTAG::_IRSCAN(char * cmd1) {
  85.  #ifdef JTAG_LOG
  86.    printf("_IRSCAN: %s\n",cmd1);
  87.  #endif
  88.  tap->TMS(1);tap->update();tap->TCK_CLOCK(2);
  89.  tap->TMS(0);tap->update();tap->TCK_CLOCK(2);
  90.  int i;
  91. // for (i=0;i<strlen((char *)cmd1)-1;i++) {
  92.  for (i=(strlen((char *)cmd1)-1);i>0;i--) {
  93.      tap->TDI(*(cmd1+i)=='0'?0:1);
  94.      tap->update();
  95.      tap->TCK_CLOCK();
  96.  }
  97.  tap->TDI(*(cmd1+i)=='0'?0:1);
  98.  tap->TMS(1);tap->update();tap->TCK_CLOCK(2);
  99.  tap->TMS(0);tap->update();tap->TCK_CLOCK();
  100.  tap->update();tap->realize();
  101. }
  102.  
  103. void JTAG::DRSCAN(char * in1,char * out1) {
  104.  #ifdef JTAG_LOG
  105.    printf("DRSCAN: %s\n",in1);
  106.  #endif
  107.  tap->TMS(1);tap->update();tap->TCK_CLOCK();
  108.  tap->TMS(0);tap->update();tap->TCK_CLOCK(2);
  109.  int i;
  110.  int k=strlen((char *)in1)-1;
  111.  for (i=k;i>0;i--) {
  112.      tap->update();tap->realize();
  113.      *(out1+i)=tap->TDO()+'0';
  114.      tap->TDI(*(in1+i)=='0'?0:1);
  115.      tap->update();tap->TCK_CLOCK();
  116.  }
  117.  tap->update();tap->realize();
  118.  *(out1+i)=tap->TDO()+'0';
  119.  tap->TDI(*(in1+i)=='0'?0:1);
  120.  tap->TMS(1);tap->update();tap->TCK_CLOCK(2);
  121.  tap->TMS(0);tap->update();tap->TCK_CLOCK();
  122.  tap->update();tap->realize();
  123. }
  124.  
  125. void JTAG::_DRSCAN(char * in1) {
  126.  #ifdef JTAG_LOG
  127.    printf("_DRSCAN: %s\n",in1);
  128.  #endif
  129.  tap->TMS(1);tap->update();tap->TCK_CLOCK();
  130.  tap->TMS(0);tap->update();tap->TCK_CLOCK(2);
  131.  DWORD i;
  132.  DWORD k=strlen((char *)in1)-1;
  133.  for (i=k;i>0;i--) {
  134.      tap->TDI(*(in1+i)=='0'?0:1);
  135.      tap->update();
  136.      tap->TCK_CLOCK();
  137.  }
  138.  tap->TDI(*(in1+i)=='0'?0:1);
  139.  tap->TMS(1);tap->update();tap->TCK_CLOCK(2);
  140.  tap->TMS(0);tap->update();tap->TCK_CLOCK();
  141.  tap->update();tap->realize();
  142. }
  143.  
  144.