📄 jtagport.cpp
字号:
#include "stdafx.h"
#include "FluteD.h"
#include "JTAGPort.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CJTAGPort::CJTAGPort(/* int n, int rst*/)
{
// set up variables
// nInstLength = n;
nCable = -1;
error = -1;
nResetType = -1;
// setup port address
nDataPort[0] = 0x03bc;
nStatPort[0] = 0x03bd;
nCtrlPort[0] = 0x03be;
nDataPort[1] = 0x0378;
nStatPort[1] = 0x0379;
nCtrlPort[1] = 0x037a;
nDataPort[2] = 0x0278;
nStatPort[2] = 0x0279;
nCtrlPort[2] = 0x027a;
}
CJTAGPort::~CJTAGPort()
{
}
int CJTAGPort::Setup(int rst)
{
AddLog("\n[Setup JTAG Port]\n");
// set reset type
nResetType = rst;
nCable = 1;
return ERR_FALSE;
}
unsigned long CJTAGPort::GetIDR(int length)
{
unsigned long id;
AddLog("Get ID Register ... ");
#ifdef _LOG
fprintf(lp, "Move to Capture_DR -> ");
#endif
Signal(0,0); // move to Capture_DR
#ifdef _LOG
fprintf(lp, "Move to Shift_DR -> ");
#endif
Signal(0,0); // move to Shift_DR
id = ScanBin(length);
// move to Exit1_DR already in ScanBin
#ifdef _LOG
fprintf(lp, "Move to Update_DR -> ");
#endif
Signal(0,1); // move to Update_DR
#ifdef _LOG
fprintf(lp, "Move to Select_DR -> ");
#endif
Signal(0,1); // move to Select_DR_Scan
// STOPPED AT Select_DR_Scan
return id;
}
int CJTAGPort::Signal(int tdi, int tms, int stop, int update)
{
int tdo = 0;
int data;
data = MASK_TRT;
if(tdi)
{
data |= MASK_TDI;
}
if(tms)
{
data |= MASK_TMS;
}
_outp(nDataPort[nCable], data);
if(update) tdo = (_inp(nStatPort[nCable]) & MASK_TDO);
_outp(nDataPort[nCable], (data | MASK_TCK));
if(stop) _outp(nDataPort[nCable], data);
#ifdef _LOG
fprintf(lp, "TDI:%1d TDO:%1d TMS:%1d STOP:%1d UPDATA:%1d\n",
tdi, tdo, tms, stop, update);
#endif
return tdo;
}
int CJTAGPort::On()
{
if(nCable >= 0)
{
// reset TAP
_outp(nDataPort[nCable], MASK_TRT); // TRST=1
_outp(nDataPort[nCable], 0); // TRST=0
_outp(nDataPort[nCable], MASK_TRT); // TRST=1
#ifdef _LOG
fprintf(lp, "Cable power ON & nTRST -> 1\n");
#endif
Sleep(1);
}
return ERR_FALSE;
}
int CJTAGPort::Off()
{
if(nCable >= 0)
{
for(int i=0; i<8; i++) Signal(1,1); // move to TEST_LOGIC/RESET
_outp(nDataPort[nCable], MASK_TRT^0xff); // TRST=0
#ifdef _LOG
fprintf(lp,"Cable power OFF\n");
#endif
}
return ERR_FALSE;
}
unsigned long CJTAGPort::ScanBin(int length, unsigned long indata)
{
unsigned long seed, value;
int i, end;
#ifdef _LOG
fprintf(lp, "Scan Bin: 0x%lx, %d\n", indata, length);
#endif
seed = (1 << (length-1));
value = 0;
for(i = 0, end = 0; i < length; i++)
{
#ifdef _LOG
fprintf(lp, "B%d -> ", i);
#endif
value >>= 1;
if (i==(length-1)) end = 1;
if(Signal( (indata & 0x01) , end, end)) // IMPORTANT last signal push the both data and state
{
value |= seed;
}
indata >>= 1;
}
return value;
}
void CJTAGPort::Reset()
{
for(int i=0; i<8; i++) Signal(1,1); // move to TEST_LOGIC/RESET
Sleep(1); // wait a while
Signal(0,0); // move to Run_Test/Idle
Signal(0,1); // move to Select_DR_Scan
}
unsigned long CJTAGPort::ScanIR(int length, unsigned long dt)
{
unsigned long result;
#ifdef _LOG
fprintf(lp, "Scan IR: 0x%lx , %d\n", dt, length);
#endif
// START FROM Select_DR_Scan
Signal(0,1); // move to Select_IR_Scan
Signal(0,0); // move to Capture_IR
Signal(0,0); // move to Shift_IR
result = ScanBin( length, dt );
// move to Exit1_IR already in ScanBin
Signal(0,1); // move to Update_IR
Signal(0,1); // move to Select_DR_Scan
// STOP AT Select_DR_Scan
return result;
}
void CJTAGPort::ScanDR(int length, int * inchain, int *outchain)
{
// START FROM Select_DR_Scan
int *pt_in;
int *pt_out;
int i, end;
#ifdef _LOG
fprintf(lp, "Scan DR: %d\n", length);
#endif
pt_in = inchain;
pt_out = outchain;
#ifdef _LOG
fprintf(lp, "Move to Capture_DR -> ");
#endif
Signal(0,0); // move to Capture_DR
#ifdef _LOG
fprintf(lp, "Move to Shift_DR -> ");
#endif
Signal(0,0); // move to Shift_DR
if(pt_out == NULL)
{
for(i = 0, end = 0; i < length; i++)
{
#ifdef _LOG
fprintf(lp, "D%d -> ", i);
#endif
if(i==(length-1)) end = 1;
Signal( *pt_in , end, end, 0); // end shift and goto Exit1_DR
pt_in++;
}
}
else if(pt_in == NULL)
{
for(i = 0, end = 0; i < length; i++)
{
#ifdef _LOG
fprintf(lp, "D%d -> ", i);
#endif
if(i==(length-1)) end = 1;
*pt_out = Signal( 1 , end, end, 0); // end shift and goto Exit1_DR
pt_out++;
}
}
else
{
for(i = 0, end = 0; i < length; i++)
{
#ifdef _LOG
fprintf(lp, "D%d -> ", i);
#endif
if(i==(length-1)) end = 1;
*pt_out = Signal( (*pt_in != 0) , end, end); // end shift and goto Exit1_DR
pt_in++;
pt_out++;
}
}
// move to Exit1_DR in previous data shift
#ifdef _LOG
fprintf(lp, "Move to Update_DR -> ");
#endif
Signal(0,1); // move to Update_DR
#ifdef _LOG
fprintf(lp, "Move to Select_DR -> ");
#endif
Signal(0,1); // move to Select_DR_Scan
// STOP AT Select_DR_Scan
}
int CJTAGPort::SetRstpin(int rst)
{
return ERR_FALSE;
}
int CJTAGPort::Dump()
{
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -