📄 ezmrview.cpp
字号:
sprintf(LenTxt, "%4d", m_DldLen);
p_EBoxLen->SetWindowText(LenTxt);
CComboBox* p_CBoxVenDir = (CComboBox*)(pwndTBarVen->GetDlgItem(IDC_DIRECTION));
p_CBoxVenDir->SetCurSel(1);
SendOp(OP_VEND_REQST);
m_dldOffset+=MAX_EP0_XFER_SIZE; // get next 4K block if available
}
fclose(fp);
}
#define MAXSTR 256 // Maximum length of Intel Hex file string
int CEzMrView::intel_in(FILE *fpIn, TMemCache* pMemCache, DWORD &ioOffset,
char endianFlags, BOOLEAN spaces)
{
int i;
char str[MAXSTR];
unsigned byte;
int curSeg = 0; // current seg record
int recType;
unsigned addr;
int cnt;
unsigned int totalRead = 0;
int CNTFIELD ;
int ADDRFIELD;
int RECFIELD ;
int DATAFIELD;
// offsets of fields within record -- may change later due to "spaces" setting
CNTFIELD = 1;
ADDRFIELD = 3;
RECFIELD = 7;
DATAFIELD = 9;
if (!fpIn)
return(0);
addr = 0;
pMemCache->nSeg = 0;
while(fgets(str,MAXSTR,fpIn))
{
TRACE("dldhex:%s", str);
if(str[0]!=':')
{
return(-1);
}
/* get the record type */
if (spaces || str[1] == ' ')
{
CNTFIELD = 1 + 1;
ADDRFIELD = 3 + 2;
RECFIELD = 7 + 3;
DATAFIELD = 9 + 4;
}
sscanf(str+RECFIELD,"%2x",&recType);
PCHAR ptr = (PCHAR)pMemCache->pImg;
switch(recType)
{
case 2: /*seg record*/
sscanf(str+DATAFIELD,"%4x",&curSeg);
curSeg *= 0x10;
break;
case 0: /*data record*/
sscanf(str+CNTFIELD,"%2x",&cnt);
sscanf(str+ADDRFIELD,"%4x",&addr);
if(addr >= TGT_IMG_SIZE)
{
theApp.report_error("Error loading file: address out of range\n");
return(totalRead);
}
ptr += addr; // get pointer to location in image
if(pMemCache->nSeg &&
(pMemCache->pSeg[pMemCache->nSeg-1].TAddr ==
addr - pMemCache->pSeg[pMemCache->nSeg-1].Size) &&
(pMemCache->pSeg[pMemCache->nSeg-1].Size + cnt <= MAX_EP0_XFER_SIZE) )
{ // if the segment is contiguous to the last segment, and it's not too big yet
pMemCache->pSeg[pMemCache->nSeg-1].Size += cnt; // append to previous segment
}
else
{ // start a new segment
pMemCache->pSeg[pMemCache->nSeg].TAddr = addr;
pMemCache->pSeg[pMemCache->nSeg].Size = cnt;
pMemCache->pSeg[pMemCache->nSeg].pData = ptr;
pMemCache->nSeg++;
}
for(i=0; i<cnt; i++)
{
sscanf(str+DATAFIELD+i*2,"%2x",&byte);
*(ptr + i) = byte;
totalRead++;
}
break;
case 1: /*end record*/
return(totalRead);
break;
default:
break;
}
}
return(-1); // missing end record
}
void CEzMrView::LoadFile(CString strDldFile)
{
unsigned char* pbuf = (unsigned char *)((CEzMrFrame*)GetParentFrame())->BlkBuf;
unsigned char* pVenbuf = (unsigned char *)((CEzMrFrame*)GetParentFrame())->VenBuf;
strDldFile.MakeLower(); // case insensitive compare
CString strSaveReq;
CString strSaveValue;
CString strSaveLength;
int nSaveDir;
CFileStatus status;
if(strDldFile.Find(".hex") != -1) //intel hex format
{
FILE *fp = fopen(strDldFile, "rb");
if(fp)
{
char endianConversion = 0; // Mask for endian conversion
DWORD offset = 0; // Offset -- set to -1 to get offset from srec or hex file
((CEzMrFrame*)GetParentFrame())->m_EBoxReq.GetWindowText(strSaveReq);
((CEzMrFrame*)GetParentFrame())->m_EBoxVal.GetWindowText(strSaveValue);
((CEzMrFrame*)GetParentFrame())->m_EBoxLen.GetWindowText(strSaveLength);
nSaveDir = ((CEzMrFrame*)GetParentFrame())->m_CBoxVenDir.GetCurSel();
theApp.m_MemCache.pImg = &theApp.m_MemImg;
int result = intel_in(fp, &theApp.m_MemCache, offset, endianConversion, FALSE);
fclose(fp);
for(int k=0; k<theApp.m_MemCache.nSeg; k++)
{ //check for high mem first; load loader first if necessary
if(theApp.m_MemCache.pSeg[k].TAddr >= 0x2000)
{
if((!theApp.m_nUseUserDefinedLoader) && (!theApp.m_nUseNoLoader))
{
if(theApp.m_nTarg)
{ // if Fx2
TRACE("loading Fx2 loader\n");
Ezusb_DownloadIntelHex(Vend_Ax_Fx2);
break;
}
else
{ // if Ezusb
TRACE("loading Ezusb loader\n");
Ezusb_DownloadIntelHex(Vend_Ax);
break;
}
}
}
}
for(int i=0; i<theApp.m_MemCache.nSeg; i++)
{ //load all high mem first
if(theApp.m_MemCache.pSeg[i].TAddr >= 0x2000)
{
char text[80];
memcpy(pVenbuf, theApp.m_MemCache.pSeg[i].pData, theApp.m_MemCache.pSeg[i].Size);
((CEzMrFrame*)GetParentFrame())->m_EBoxReq.SetWindowText("0xA3");
sprintf(text, "0x%x", theApp.m_MemCache.pSeg[i].TAddr);
((CEzMrFrame*)GetParentFrame())->m_EBoxVal.SetWindowText(text);
sprintf(text, "%d", theApp.m_MemCache.pSeg[i].Size);
((CEzMrFrame*)GetParentFrame())->m_EBoxLen.SetWindowText(text);
((CEzMrFrame*)GetParentFrame())->m_CBoxVenDir.SetCurSel(1); //Set Dir Out
SendOp(OP_VEND_REQST);
}
if( ( m_nOpsPending ) >= theApp.m_nMaxOpsPending)
break;
}
if(theApp.m_nAutoHoldRun)
On_8051_HOLD();
for(int j=0; j<theApp.m_MemCache.nSeg; j++)
{ //load all low mem last
if(theApp.m_MemCache.pSeg[j].TAddr < 0x2000)
{
memcpy(pbuf, theApp.m_MemCache.pSeg[j].pData, theApp.m_MemCache.pSeg[j].Size);
m_DldLen = theApp.m_MemCache.pSeg[j].Size;
m_dldOffset = theApp.m_MemCache.pSeg[j].TAddr;
SendOp(OP_ANCHOR_DLD);
}
if( ( m_nOpsPending ) >= theApp.m_nMaxOpsPending)
break;
}
if(theApp.m_nAutoHoldRun)
On_8051_RUN();
((CEzMrFrame*)GetParentFrame())->m_EBoxReq.SetWindowText(strSaveReq);
((CEzMrFrame*)GetParentFrame())->m_EBoxVal.SetWindowText(strSaveValue);
((CEzMrFrame*)GetParentFrame())->m_EBoxLen.SetWindowText(strSaveLength);
((CEzMrFrame*)GetParentFrame())->m_CBoxVenDir.SetCurSel(nSaveDir);
}
else
{
theApp.report_error("Error opening Input file.\n");
}
}
else if(strDldFile.Find(".bix") != -1) //bix format
{
FILE *fp = fopen(strDldFile,"rb");
if (fp)
{
m_DldLen = fread(pbuf, sizeof(unsigned char), MAX_FILE_SIZE, fp);
fclose(fp);
m_dldOffset = 0;
if(theApp.m_nAutoHoldRun)
On_8051_HOLD();
SendOp(OP_ANCHOR_DLD);
if(theApp.m_nAutoHoldRun)
On_8051_RUN();
}
else
{
theApp.report_error("Error opening Input file.\n");
}
}
//////////////////////////////////////////////////////////////////////////////////////////
else if(strDldFile.Find(".ven") != -1) // intel hex format (use User defined Vend_Ax)
{
FILE *fp = fopen(strDldFile, "rb");
if(fp)
{
char endianConversion = 0; // Mask for endian conversion
DWORD offset = 0; // Offset -- set to -1 to get offset from srec or hex file
((CEzMrFrame*)GetParentFrame())->m_EBoxReq.GetWindowText(strSaveReq);
((CEzMrFrame*)GetParentFrame())->m_EBoxVal.GetWindowText(strSaveValue);
((CEzMrFrame*)GetParentFrame())->m_EBoxLen.GetWindowText(strSaveLength);
nSaveDir = ((CEzMrFrame*)GetParentFrame())->m_CBoxVenDir.GetCurSel();
//for(int k=0; k<theApp.m_MemCache.nSeg; k++)
//{ //check for high mem first; load loader first if necessary
//if(theApp.m_MemCache.pSeg[k].TAddr >= 0x2000)
//{
// always load external loader first (due to recursion and use of m_MemCache)
CString tmpDldFile = (theApp.m_nTarg) ?
theApp.m_strPathUSBRoot + "\\Examples\\Fx2\\Vend_Ax\\Vend_Ax.hex" :
theApp.m_strPathUSBRoot + "\\Examples\\Ezusb\\Vend_Ax\\Vend_Ax.hex";
if( CFile::GetStatus( tmpDldFile, status ) )
{
LoadFile(tmpDldFile); //load Vend_Ax file
}
else
{
theApp.report_error("Error Loading Vend_Ax (external loader) file; Load failed.\n");
return;
}
//}
//}
theApp.m_MemCache.pImg = &theApp.m_MemImg;
int result = intel_in(fp, &theApp.m_MemCache, offset, endianConversion, FALSE);
fclose(fp);
for(int i=0; i<theApp.m_MemCache.nSeg; i++)
{ //load all high mem first
if(theApp.m_MemCache.pSeg[i].TAddr >= 0x2000)
{
char text[80];
memcpy(pVenbuf, theApp.m_MemCache.pSeg[i].pData, theApp.m_MemCache.pSeg[i].Size);
((CEzMrFrame*)GetParentFrame())->m_EBoxReq.SetWindowText("0xA3");
sprintf(text, "0x%x", theApp.m_MemCache.pSeg[i].TAddr);
((CEzMrFrame*)GetParentFrame())->m_EBoxVal.SetWindowText(text);
sprintf(text, "%d", theApp.m_MemCache.pSeg[i].Size);
((CEzMrFrame*)GetParentFrame())->m_EBoxLen.SetWindowText(text);
((CEzMrFrame*)GetParentFrame())->m_CBoxVenDir.SetCurSel(1); //Set Dir Out
SendOp(OP_VEND_REQST);
}
if( ( m_nOpsPending ) >= theApp.m_nMaxOpsPending)
break;
}
if(theApp.m_nAutoHoldRun)
On_8051_HOLD();
for(int j=0; j<theApp.m_MemCache.nSeg; j++)
{ //load all low mem last
if(theApp.m_MemCache.pSeg[j].TAddr < 0x2000)
{
memcpy(pbuf, theApp.m_MemCache.pSeg[j].pData, theApp.m_MemCache.pSeg[j].Size);
m_DldLen = theApp.m_MemCache.pSeg[j].Size;
m_dldOffset = theApp.m_MemCache.pSeg[j].TAddr;
SendOp(OP_ANCHOR_DLD);
}
if( ( m_nOpsPending ) >= theApp.m_nMaxOpsPending)
break;
}
if(theApp.m_nAutoHoldRun)
On_8051_RUN();
((CEzMrFrame*)GetParentFrame())->m_EBoxReq.SetWindowText(strSaveReq);
((CEzMrFrame*)GetParentFrame())->m_EBoxVal.SetWindowText(strSaveValue);
((CEzMrFrame*)GetParentFrame())->m_EBoxLen.SetWindowText(strSaveLength);
((CEzMrFrame*)GetParentFrame())->m_CBoxVenDir.SetCurSel(nSaveDir);
}
else
{
theApp.report_error("Error opening Input file.\n");
}
}
//////////////////////////////////////////////////////////////////////////////////////////
else if( (strDldFile.Find(".h00") != -1) // (secret) flash format (banks) (use NO Loader)
|| (strDldFile.Find(".h01") != -1)
|| (strDldFile.Find(".h02") != -1)
|| (strDldFile.Find(".h03") != -1)
|| (strDldFile.Find(".h04") != -1)
|| (strDldFile.Find(".h05") != -1)
|| (strDldFile.Find(".h06") != -1)
|| (strDldFile.Find(".h07") != -1)
|| (strDldFile.Find(".h08") != -1)
)
{
FILE *fp = fopen(strDldFile, "rb");
if(fp)
{
char endianConversion = 0; // Mask for endian conversion
DWORD offset = 0; // Offset -- set to -1 to get offset from srec or hex file
((CEzMrFrame*)GetParentFrame())->m_EBoxReq.GetWindowText(strSaveReq);
((CEzMrFrame*)GetParentFrame())->m_EBoxVal.GetWindowText(strSaveValue);
((CEzMrFrame*)GetParentFrame())->m_EBoxLen.GetWindowText(strSaveLength);
nSaveDir = ((CEzMrFrame*)GetParentFrame())->m_CBoxVenDir.GetCurSel();
theApp.m_MemCache.pImg = &theApp.m_MemImg;
int result = intel_in(fp, &theApp.m_MemCache, offset, endianConversion, FALSE);
fclose(fp);
for(int i=0; i<theApp.m_MemCache.nSeg; i++)
{ //load all special mem with "0xA3"
if(theApp.m_MemCache.pSeg[i].TAddr >= 0x2000) // use 0xA3
{
char text[80];
memcpy(pVenbuf, theApp.m_MemCache.pSeg[i].pData, theApp.m_MemCache.pSeg[i].Size);
((CEzMrFrame*)GetParentFrame())->m_EBoxReq.SetWindowText("0xA3");
sprintf(text, "0x%x", theApp.m_MemCache.pSeg[i].TAddr);
((CEzMrFrame*)GetParentFrame())->m_EBoxVal.SetWindowText(text);
sprintf(text, "%d", theApp.m_MemCache.pSeg[i].Size);
((CEzMrFrame*)GetParentFrame())->m_EBoxLen.SetWindowText(text);
((CEzMrFrame*)GetParentFrame())->m_CBoxVenDir.SetCurSel(1); //Set Dir Out
SendOp(OP_VEND_REQST);
}
if( ( m_nOpsPending ) >= theApp.m_nMaxOpsPending)
break;
}
((CEzMrFrame*)GetParentFrame())->m_EBoxReq.SetWindowText(strSaveReq);
((CEzMrFrame*)GetParentFrame())->m_EBoxVal.SetWindowText(strSaveValue);
((CEzMrFrame*)GetParentFrame())->m_EBoxLen.SetWindowText(strSaveLength);
((CEzMrFrame*)GetParentFrame())->m_CBoxVenDir.SetCurSel(nSaveDir);
}
else
{
theApp.report_error("Error opening Input file.\n");
}
}
//////////////////////////////////////////////////////////////////////////////////////////
else
{
theApp.report_error("Please select .hex or .bix file to download.\n");
}
}
void CEzMrView::OnIDC_DOWN_LOAD()
{
CFileStatus status;
TRACE("TPM:CEzMrView::OnIDC_DOWN_LOAD()\n");
if(m_strDldFile == "")
{
if(theApp.m_nTarg) // if Fx2
m_strDldFile = theApp.m_strPathUSBRoot + "\\Examples\\Fx2";
else // if EzUsb
m_strDldFile = theApp.m_strPathUSBRoot + "\\Examples\\EzUsb";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -