📄 flashwriterdlg.cpp
字号:
{
MessageBox("NF write erro!!");
return;
}
data[0]=0;
data[1]=0;
Sleep(20);
Status = USBICE_Read(&data[0], 64);
ProgramData=ProgramData+512/2;
if (CSFlag)
{
StartAddress+=512;
}
else
{
StartAddress+=256;
}
Temp_Counter++;
ProgressPrg(Temp_Counter);
}while (ProgramData<&TimeTable[TableDataLength]);
ProgramData = &TimeTable[0];
StartAddress = 0x478000; //NFStartAddress;
if (!VerifyFlash( (BYTE *)ProgramData , StartAddress , TableDataLength*2,TableDataLength*2,CSFlag)) //TableDataLength
{
m_Status = "Verify File Error!";
UpdateData(false);
delete [] TimeTable;
return;
}
UsbSucessClose();
MessageBox("NorFlash write ok!");
}
else
{
MessageBox("NF erase erro!!");
return;
}
}
else
{
MessageBox("NF read erro!!");
return;
}
delete []TimeTable;
//delete TimeTable;
}
}
}
/*
//----Read File Manager in NF Block0 Page 0------------------
//Jack Dele 2007.06.29
//m_Status = "1: Read File Info";
//UpdateData(false);
//End Dele
//Jack Add 2007.06.29
m_Status = "Read File Info...";
UpdateData(false);
//End Add
Sleep(100);
FileName = m_SourceFile;
CFile f_tmp;
unsigned long FileLength,DownloadLength;
BYTE *ProgramData;
if (!f_tmp.Open(FileName, CFile::modeRead))
{
AfxMessageBox("File could not be opened",MB_OK,0);
return;
}
FileLength = f_tmp.GetLength();
if(0==m_CS)
{
if (FileLength > 0x80000)
{
AfxMessageBox("File is too large",MB_OK,0);
return;
}
}
ReadFlashID(FlashAddress);
OnEraseFlash();
//Jack Add 3007.06.29
short MaxIndex = 0;
//End Add
UINT k = FileLength / 512 ;
if ( FileLength <= 512 )
{
//Jack Add 2007.06.29
MaxIndex = k;
//End Add
DownloadLength = 512;
}
else if ( ! ( FileLength % 512 ) )
{
//Jack Add 2007.06.29
MaxIndex = k;
//End Add
DownloadLength = FileLength;
}
else
{
//Jack Add 2007.06.29
MaxIndex = k + 1;
//End Add
DownloadLength = ( k + 1 ) * 512;
}
ProgramData = new BYTE[DownloadLength];
FillMemory(ProgramData,DownloadLength,0xFF);
f_tmp.Read(ProgramData,FileLength);
f_tmp.Close();
//----Calculate File Start Address----------------------------
UINT StartAddress;
if ( m_FileInforCount == 0 )
{
StartAddress=0;//0x10000; // Program file from Block 1 , Block 0 is File manager
}
else
{
StartAddress =0;
}
//Jack Dele 2007.06.29
//m_Status = "2: Program";
//UpdateData(false);
//End Dele
//Jack Add 2007.06.29
m_Status = "Program...";
UpdateData(false);
//End Add
Sleep(100);
// VerifyFlash( ProgramData , StartAddress , DownloadLength/2,FileLength/2);
FileDataPtr=&ProgramData[0];
Temp_Counter = 0;
//Jack Add 2007.06.29
SetProgress(MaxIndex);
//End Add
ProgressPrg(0);
//for (i=0,i<DownloadLength,i+=512
do//for (i=0,i<DownloadLength,i+=512
{
if ( ! NFlashWrite(FileDataPtr,StartAddress,512) )
{
m_Status = "2: Program Error";
UpdateData(false);
delete [] ProgramData;
return;
}
data[0]=0;
data[1]=0;
Sleep(20);
Status = USBICE_Read(&data[0], 64);
FileDataPtr=FileDataPtr+512;
if (CSFlag)
{
StartAddress+=512;
}
else
{
StartAddress+=256;
}
Temp_Counter++;
ProgressPrg(Temp_Counter);
// if (Temp_Counter >= 20)
// {
// m_Status.Format("%d",StartAddress*2);
// UpdateData(false);
// Temp_Counter = 0;
// }
}while (FileDataPtr<&ProgramData[DownloadLength]);
//----Update File Manager-------------------------------------
m_FileInformation[m_FileInforCount].StartAddress = StartAddress;
m_FileInformation[m_FileInforCount].Size = DownloadLength;
m_FileInforCount++;
m_Status = "Update File Info...";
UpdateData(false);
Sleep(100);
m_Status = "Read File Info...";
UpdateData(false);
Sleep(100);
//-----------------------------------------------------------
m_Status = "Verify File...";
UpdateData(false);
Sleep(100);
FileDataPtr=&ProgramData[0];
if(0==m_Debug)
{
StartAddress=0x0;
}
else
{
StartAddress=((FlashAddress&0xff)<<16);
}
//Jack Add 2007.06.29
short programIndx = 0;
SetProgress((FileLength/4096));
ProgressPrg(programIndx);
//End Add
// StartAddress=VerifyStartAddress;//(FlashAddress&0xff)<<16;//0;
do
{
if (FileLength>4096)
Temp_Counter = 4096;
else
Temp_Counter = FileLength;
if (!VerifyFlash( FileDataPtr , StartAddress , 4096,Temp_Counter,CSFlag))
{
m_Status = "Verify File Error!";
UpdateData(false);
delete [] ProgramData;
return;
}
FileDataPtr+=4096;
if (FileLength<=4096)
{
//Jack Add 2007.06.29
if (programIndx < 4096)
{
ProgressPrg(4096);
}
//End Add
break;
}
FileLength-=4096;
if(0==m_Debug)
{
StartAddress+=4096;
}
else
{
if (CSFlag)
{
StartAddress+=4096; //CS2 is 8bit mode
}
else
{
StartAddress+=2048; //CS1 is 16bit mode
}
}
//Jack Add 2007.06.29
programIndx ++ ;
ProgressPrg(programIndx);
//End Add
}while (Temp_Counter>=4096);
delete [] ProgramData;
//-----------------------------------------------------------
m_Status = "Program OK!";
UpdateData(false);
//Jack Add 2007.06.29
MessageBox(_T("Program OK!"));
SetProgress(0);
UpdateData(false);
//End Add
}
else
{
//Jack Add 2007.06.22
MessageBox(_T("Please select the file(s) first!"));
//End Add
//Jack Dele 2007.07.22
//MessageBox("请先选择文件!");
//End Dele
}
*/
Set_USB_Close(0x00);
}
bool CFlashWriterDlg::ReFlash()
{
m_FileInforCount = 0;
UINT READ_BLOCK0_SIZE=512;
BYTE data[512];
UINT Tmp1,Tmp2,k=0;
if ( ! NFlashRead(&data[0], 0, READ_BLOCK0_SIZE,m_Debug) ) // Read Block 0 - Page 0
return 0;
for (UINT i=0 ; i < READ_BLOCK0_SIZE / 8 ; i++ )
{
Tmp1 = 0;
Tmp2 = data[k++];
Tmp1 = Tmp1 | ( Tmp2 << 16 ) ;
Tmp2 = data[k++];
Tmp1 = Tmp1 | ( Tmp2 << 24 ) ;
Tmp2 = data[k++];
Tmp1 = Tmp1 | ( Tmp2 << 0 ) ;
Tmp2 = data[k++];
Tmp1 = Tmp1 | ( Tmp2 << 8 ) ;
m_FileInformation[i].StartAddress = Tmp1;
Tmp1 = 0;
Tmp2 = data[k++];
Tmp1 = Tmp1 | ( Tmp2 << 16 ) ;
Tmp2 = data[k++];
Tmp1 = Tmp1 | ( Tmp2 << 24 ) ;
Tmp2 = data[k++];
Tmp1 = Tmp1 | ( Tmp2 << 0 ) ;
Tmp2 = data[k++];
Tmp1 = Tmp1 | ( Tmp2 << 8 ) ;
m_FileInformation[i].Size = Tmp1;
if ( ( m_FileInformation[i].StartAddress != 0xFFFFFFFF ) &&
( m_FileInformation[i].Size != 0xFFFFFFFF ) )
{
m_FileInforCount++;
}
else
{
break;
}
}//end for
CString Space;
UINT Size=0;
for ( i = 0 ; i < m_FileInforCount ; i++ )
Size = Size + m_FileInformation[i].Size;
Space.Format("0x%-8x",Size);
m_NFlashSpace = Space;
m_TotalFiles = m_FileInforCount;
UpdateData(false);
return 1;
}
bool CFlashWriterDlg::OnReFlash()
{
m_FileInforCount = 0;
UINT READ_BLOCK0_SIZE=512;
UINT Tmp1,Tmp2,k=0;
BYTE data[512];
int StartAddress=0;
if ( ! NFlashRead(&data[0], StartAddress, READ_BLOCK0_SIZE,m_Debug) ) // Read Block 0 - Page 0
return 0;
Set_USB_Close(0x00);
for (UINT i=0 ; i < READ_BLOCK0_SIZE / 8 ; i++ )
{
Tmp1 = 0;
Tmp2 = data[k++];
Tmp1 = Tmp1 | ( Tmp2 << 16 ) ;
Tmp2 = data[k++];
Tmp1 = Tmp1 | ( Tmp2 << 24 ) ;
Tmp2 = data[k++];
Tmp1 = Tmp1 | ( Tmp2 << 0 ) ;
Tmp2 = data[k++];
Tmp1 = Tmp1 | ( Tmp2 << 8 ) ;
m_FileInformation[i].StartAddress = Tmp1;
Tmp1 = 0;
Tmp2 = data[k++];
Tmp1 = Tmp1 | ( Tmp2 << 16 ) ;
Tmp2 = data[k++];
Tmp1 = Tmp1 | ( Tmp2 << 24 ) ;
Tmp2 = data[k++];
Tmp1 = Tmp1 | ( Tmp2 << 0 ) ;
Tmp2 = data[k++];
Tmp1 = Tmp1 | ( Tmp2 << 8 ) ;
m_FileInformation[i].Size = Tmp1;
m_FileInforCount++;
}//end for
CString Space;
UINT Size=0;
for ( i = 0 ; i < m_FileInforCount ; i++ )
Size = Size + m_FileInformation[i].Size;
Space.Format("0x%-8x",Size);
m_NFlashSpace = Space;
m_TotalFiles = m_FileInforCount;
UpdateData(false);
return 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -