📄 debugtooldlg.cpp
字号:
else
{
nData = StrToHex(sData);
readcmd = 0x00000010; // kenichi 06 +
}
Jtag.FlashWrite(nAddr,readcmd);
if (!Jtag.FlashWrite(nAddr,nData))
msg(m_index++, "write fail !");
else
msg(m_index++, "write success !");
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
}
/****************************************/
// function: read data from flash
// input:
// CString charstr
// output:
// BYTE
/****************************************/
void CDebugToolDlg::OnFlashRead()
{
CString sReadAddr = _T("");
CString sRead = _T("");
CString str = _T("");
unsigned int nRet=0;
unsigned char cTemp[2] = {0};
int nReadAddr = 0;
int nBit = 0;
CString sAddr = _T("");
CString sResult = _T("");
GetDlgItem(IDC_ReadAddr)->GetWindowText(sReadAddr);
// get address value
if((sReadAddr.GetAt(1) == 'x')||(sReadAddr.GetAt(1) == 'X'))
{
for(int i = 2; i<sReadAddr.GetLength(); i++)
{
sAddr = sAddr + sReadAddr.GetAt(i);
}
}
else
{
sAddr = sReadAddr;
}
nReadAddr = StrToHex(sAddr);
msg(m_index++, "Read data(hex):");
for(int m = 0; m<4; m++)
{
Jtag.FlashWrite(0x00000000,0x00ff0000);
sResult.Format("%s %4.4x %4.4x %4.4x %4.4x",sAddr,Jtag.FlashRead(nReadAddr),Jtag.FlashRead(nReadAddr+0x00000002),Jtag.FlashRead(nReadAddr+0x00000004),Jtag.FlashRead(nReadAddr+0x00000006));
msg(m_index++, sResult);
nReadAddr = nReadAddr + 0x0000008;
sAddr.Format("%x",nReadAddr);
nBit = sAddr.GetLength();
while(nBit<8)
{
sAddr = "0"+sAddr;
nBit++;
}
}
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
}
/****************************************/
// function: erase flash
// input:
// none
// output:
// none
/****************************************/
void CDebugToolDlg::OnErase()
{
int nAddr=0x00000000;
bool flag = true;
int timer = 0;
CString s = _T("");
for(int i = 0; i<64; i++)
{
timer = 1000;
if (!Jtag.FlashWrite(nAddr,0x00200000))
{
flag = false;
break;
}
if (!Jtag.FlashWrite(nAddr,0x00D00000))
{
flag = false;
break;
}
Jtag.FlashWrite(nAddr, 0x00700000);
while((Jtag.FlashRead(nAddr) != 0x80) && (timer-- != 0))
;
if (timer > 0 && flag)
s.Format("erase block %d success!", nAddr / (1024 * 128));
else
s.Format("erase block %d fail!", nAddr / (1024 * 128));
msg(m_index++, s);
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
nAddr=nAddr+1024*128;
}
}
/****************************************/
// function: check programme is over?
// input:
// none
// output:
// none
/****************************************/
void checkover()
{
int temp = 0;
while (1)
{
temp = Jtag.UsbJtagRead(0x90000020);
if (temp & 0x0001)
{
// msg(m_index++, "progamme run over !");
break;
}
}
_endthread();
return;
}
/****************************************/
// function: run
// input:
// none
// output:
// none
/****************************************/
void CDebugToolDlg::OnRun()
{
// TODO: Add your control notification handler code here
int temp = 0;
int pcAddr = 0;
CString tmp;
// resume cpu0 to execute
Jtag.UsbJtagWrite(0x90000020, 0x0000);
if (m_inbp)
{
while (1)
{
pcAddr = Jtag.UsbJtagRead(0x90400010);
if (pcAddr == m_bpAddr)
break;
}
// kenichi 20070817 >>
// draw pc icon
int tmpindex = (pcAddr - 0x0c000000) / 4;
delpc(tmpindex); // clear old pointer
if ((tmpindex / 20) > 0)
{
m_pc.SetTopIndex((tmpindex / 20) * 20);
m_Disas.SetTopIndex((tmpindex / 20) * 20);
}
showpc(tmpindex, ">>");
//<<
tmp.Format("Stop WatchPoint Address: 0x%8.8x", m_bpAddr);
msg(m_index++, tmp);
m_inbp = false;
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
return;
}
/*
while (1)
{
temp = Jtag.UsbJtagRead(0x90000020);
if (temp & 0x0001)
{
msg(m_index++, "progamme run over !");
break;
}
}
*/
if(_beginthread(checkover, 0, this) < 0)
{
msg(m_index++, "progamme run fail !");
}
msg(m_index++, "progamme is running !");
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
}
/****************************************/
// function: stop
// input:
// none
// output:
// none
/****************************************/
void CDebugToolDlg::OnStop()
{
int pcAddr = 0;
// TODO: Add your control notification handler code here
Jtag.UsbJtagWrite(0x90000020, 0xffff);
// kenichi >> 2007.0817
// update pointer to current pc addr
pcAddr = Jtag.UsbJtagRead(0x90400010);
delpc(m_pcindex); // clear old pointer
m_pcindex = (pcAddr - 0x0c000000) / 4;
if (pcAddr >= m_prePc )
{
m_pc.SetTopIndex((m_pcindex / 20) * 20);
m_Disas.SetTopIndex((m_pcindex / 20) * 20);
}
else
{
m_pc.SetTopIndex(((((m_prePc - 0x0c000000) / 4) - ((m_prePc - pcAddr) / 4))/20) * 20);
m_Disas.SetTopIndex(((((m_prePc - 0x0c000000) / 4) - ((m_prePc - pcAddr) / 4))/20) * 20);
}
showpc(m_pcindex, ">>");
m_prePc = pcAddr;
// <<
msg(m_index++, "progamme is stopped !");
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
}
/****************************************/
// function: debug step by step
// input:
// none
// output:
// none
/****************************************/
void CDebugToolDlg::OnStep()
{
// TODO: Add your control notification handler code here
int pcAddr = 0;
CString tmp;
Jtag.UsbJtagWrite(0x90000020, 0x10000);
pcAddr = Jtag.UsbJtagRead(0x90400010);
tmp.Format("cpu address : 0x%8.8x", pcAddr);
msg(m_index++, tmp);
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
// kenichi >> 2007.0817 >>
// run to breakpoint
if (pcAddr == m_bpAddr)
{
tmp.Format("Stop WatchPoint Address: 0x%8.8x", m_bpAddr);
msg(m_index++, tmp);
m_inbp = false;
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
// clear breakpoint icon
delpc((m_bpAddr - 0x0c000000)/4);
}
//<<
// kenichi >> 2007.0817
// update pointer to current pc addr
delpc(m_pcindex); // clear old pointer
m_pcindex = (pcAddr - 0x0c000000) / 4;
if (pcAddr >= m_prePc )
{
m_pc.SetTopIndex((m_pcindex / 20) * 20);
m_Disas.SetTopIndex((m_pcindex / 20) * 20);
}
else
{
m_pc.SetTopIndex(((((m_prePc - 0x0c000000) / 4) - ((m_prePc - pcAddr) / 4))/20) * 20);
m_Disas.SetTopIndex(((((m_prePc - 0x0c000000) / 4) - ((m_prePc - pcAddr) / 4))/20) * 20);
}
showpc(m_pcindex, ">>");
m_prePc = pcAddr;
// <<
}
/****************************************/
// function: set debug breakpoint
// input:
// none
// output:
// none
/****************************************/
void CDebugToolDlg::OnSetBP()
{
// TODO: Add your control notification handler code here
CString sSetBP = _T("");
CString sRead = _T("");
CString str;
unsigned int nRet = 0;
unsigned char cTemp[2] = {0};
int nBpAddr = 0;
CString sAddr = _T("");
CString sResult = _T("");
GetDlgItem(IDC_BPADDR)->GetWindowText(sSetBP);
//judge is 0x begin
if((sSetBP.GetAt(1) == 'x')||(sSetBP.GetAt(1) == 'X'))
{
for(int i = 2; i<sSetBP.GetLength(); i++)
{
sAddr = sAddr+sSetBP.GetAt(i);
}
}
else
{
sAddr = sSetBP;
}
nBpAddr = StrToHex(sAddr);
//
m_bpAddr = nBpAddr;
// set breakpoint address
Jtag.UsbJtagWrite(0x90400060, nBpAddr + 1);
Jtag.UsbJtagWrite(0x90400064, 0xfffffffc);
// kenichi >> 2007.08.17
// draw breakpoint
int bpindex = (m_bpAddr - 0x0c000000) / 4;
delpc(bpindex); // clear old pointer
showpc(bpindex, "*");
if ((bpindex / 20) > 0)
{
m_pc.SetTopIndex((bpindex / 20) * 20);
m_Disas.SetTopIndex((bpindex / 20) * 20);
}
// <<
str.Format("Set Breakpoint: 0x%8.8x OK !", nBpAddr);
msg(m_index++, str);
m_inbp = true;
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
}
/****************************************/
// function: open SVF file
// input:
// none
// output:
// none
/****************************************/
void CDebugToolDlg::OnOpenSvf()
{
// TODO: Add your control notification handler code here
CString sFile = _T("");
CString sFileLen = _T("");
CFileDialog fwFileDlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
"binary file (*.svf)|*.svf|all file (*.*)|*.*||",NULL); //二进制,感觉是XML文件
if(fwFileDlg.DoModal() == IDCANCEL)
m_svfName.Empty();
else
{
m_svfName = fwFileDlg.GetPathName();
GetDlgItem(IDC_SVFPATH)->SetWindowText(m_svfName);
msg(m_index++, "SVF Path: " + m_svfName);
CFile f(m_svfName,CFile::modeRead);
DWORD dwLength = f.GetLength();
f.Close();
sFileLen.Format("SVF File length: %4d byte",dwLength);
msg(m_index++, sFileLen);
}
UpdateData(FALSE);
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
}
/****************************************/
// function: UpLoad svf to FPGA
// input:
// none
// output:
// none
/****************************************/
void CDebugToolDlg::OnUpLoadSvf()
{
// TODO: Add your control notification handler code here
long status;
CString str;
// kenichi 01 2007.7.27 >>
OpenJtagType nOpenJtag = Jtag.OpenJtag();
if(nOpenJtag == IceOpenSuccess)
{
LPTSTR svfpath = (LPTSTR)(LPCTSTR)m_svfName;
status = Jtag.execute_svf(AMTXHAL_PORT_ID_DEFAULT, svfpath);
if (status == AMTXHAL_STATUS_SUCCESS)
{
str.Format("Download %s successfully! ", svfpath);
msg(m_index++, str);
msg(m_index++, "");
}
}
else if(nOpenJtag==IceNotConnection)
{
m_bOpen = false;
msg(m_index++, "Amontec AmtXHAL : PORT of ICE has not connection!");
}
else if(nOpenJtag==IceNotInitialized)
{
m_bOpen = false;
msg(m_index++, "Amontec AmtXHAL : ICE cannot be initialized!");
}
else if(nOpenJtag==IceNotAvailable)
{
m_bOpen = false;
msg(m_index++, "Amontec AmtXHAL : ICE is not available!");
}
else
{
m_bOpen = false;
msg(m_index++, "can not open jtag port !");
}
// kenichi 01 2007.7.27 <<
if (Jtag.CloseJtag())
m_bOpen = false;
else
msg(m_index++, "close jtag ice fail");
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
}
void CDebugToolDlg::ipTest(CString ipname)
{
int result = 0;
OnRun();
result = Jtag.UsbJtagRead(0x0d000000);
if (result == 0xff888888)
msg(m_index++, ipname + " test success !");
else
msg(m_index++, ipname + " test fail!");
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
}
void CDebugToolDlg::OnSch()
{
// TODO: Add your control notification handler code here
CString ip = "sch";
ipTest(ip);
}
void CDebugToolDlg::OnSms4()
{
// TODO: Add your control notification handler code here
CString ip = "sms4";
ipTest(ip);
}
void CDebugToolDlg::OnTimer()
{
// TODO: Add your control notification handler code here
OnRun();
}
void CDebugToolDlg::OnFlash()
{
// TODO: Add your control notification handler code here
CString ip = "flash";
ipTest(ip);
}
void CDebugToolDlg::OnI2c()
{
// TODO: Add your control notification handler code here
CString ip = "i2c";
ipTest(ip);
}
void CDebugToolDlg::OnXram()
{
// TODO: Add your control notification handler code here
CString ip = "xram";
ipTest(ip);
}
void CDebugToolDlg::OnGpio()
{
// TODO: Add your control notification handler code here
CString ip = "gpio";
ipTest(ip);
}
void CDebugToolDlg::OnApbuart()
{
// TODO: Add your control notification handler code here
CString ip = "apbuart";
ipTest(ip);
}
void CDebugToolDlg::On7816()
{
// TODO: Add your control notification handler code here
CString ip = "7816";
ipTest(ip);
}
void CDebugToolDlg::OnSysReg()
{
// TODO: Add your control notification handler code here
int y_reg = 0xffffffff;
int psr_reg = 0xffffffff;
int wim_reg = 0xffffffff;
int tbr_reg = 0xffffffff;
int pc_reg = 0xffffffff;
int npc_reg = 0xffffffff;
int fsr_reg = 0xffffffff;
int cfsr_reg = 0xffffffff;
y_reg = Jtag.UsbJtagRead(0x90400000);
psr_reg = Jtag.UsbJtagRead(0x90400004);
wim_reg = Jtag.UsbJtagRead(0x90400008);
tbr_reg = Jtag.UsbJtagRead(0x9040000c);
pc_reg = Jtag.UsbJtagRead(0x90400010);
npc_reg = Jtag.UsbJtagRead(0x90400014);
fsr_reg = Jtag.UsbJtagRead(0x90400018);
cfsr_reg = Jtag.UsbJtagRead(0x9040001c);
CString info;
info.Format("Y register : 0x%8.8x", y_reg);
msg(m_index++, info);
info.Format("PSR register : 0x%8.8x", psr_reg);
msg(m_index++, info);
info.Format("WIM register : 0x%8.8x", wim_reg);
msg(m_index++, info);
info.Format("TBR register : 0x%8.8x", tbr_reg);
msg(m_index++, info);
info.Format("PC register : 0x%8.8x", pc_reg);
msg(m_index++, info);
info.Format("NPC register : 0x%8.8x", npc_reg);
msg(m_index++, info);
info.Format("FSR register : 0x%8.8x", fsr_reg);
msg(m_index++, info);
info.Format("CFSR register : 0x%8.8x", cfsr_reg);
msg(m_index++, info);
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -