📄 bprcmd.cpp
字号:
// BPRCmd.cpp: the implementation of the CBPRCmd class.
//
// This software can be offered for free and used as necessary to aid
// in your program developments.
//
// RENESAS TECHNOLOGY CORPORATION, RENESAS SOLUTIONS CORPORATION,
// and related original software developers assume no responsibility
// for any damage or infringement of any third-party's rights, originating
// in the use of the following software.
// Please use this software under the agreement and acceptance of these conditions.
//
// Copyright(C)1998(2003) RENESAS TECHNOLOGY CORPORATION AND RENESAS SOLUTIONS CORPORATION
// ALL RIGHTS RESERVED
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "M16Cflsh.h"
#include "BPRCmd.h"
#include "PreWriteDlg.h"
#include "PrgssDlg.h"
#include "SetCommDlg.h" // add intervals
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/disappearance
//////////////////////////////////////////////////////////////////////
CBPRCmd::CBPRCmd()
{
}
CBPRCmd::~CBPRCmd()
{
}
//////////// This is the minute when I added later. //////////////////////////////////////////
BOOL CBPRCmd::exec(void)
{
BOOL bResult = FALSE;
CM16CflshApp* pApp = (CM16CflshApp*)AfxGetApp();
MSG msg;
CSetCommDlg dlg2;
// I acquire the communication object.
CSerialComm& comObj = GetSerialComm();
// I acquire the address of the range where writes.
unsigned int nStartAddress = 0;
unsigned int nEndAddress = 0;
if(!GetFileAddress(&nStartAddress, &nEndAddress, ADDRESS_SIZE))
{
return FALSE;
}
// get Intervals time
DWORD ndwintervals = 0;
if(!dlg2.GetIntervals(&ndwintervals))
{
return FALSE;
}
// It ends if the start address is bigger than the end address.
if(!ChkStartToEnd(nStartAddress, nEndAddress))
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_SMALESTART), GetResString(IDS_FLASH_TITLE), MB_ICONWARNING);
return FALSE;
}
// Setting the dialog for the progress report.
CProgressDlg* pDlg;
BOOL bCancel = FALSE;
pDlg = CProgressDlg::Instance(&bCancel, NULL);
pDlg->InitialDialog("Blank check.", "Blank Check",
0, (nEndAddress - nStartAddress - 0x0100) / TO_INT, 0);
// I check the memory range where it was designated blanks.
for(int nSendAddress = nStartAddress; (long)nSendAddress < (long)nEndAddress;
nSendAddress += 0x0100)
{
// I receive data.
BYTE receive[PAGE_SIZE];
if(!DoRead(&comObj, receive, nSendAddress))
{
pDlg->Done();
return FALSE;
}
// I check whether there is blanks.
CString strOther;
for(int nIndex = 0; nIndex < PAGE_SIZE; nIndex++)
{
if(BLANK != receive[nIndex])
{
// It was discovered except for a blank.
CString strFindMsg = GetResString(IDS_FIND_NBLANK);
strFindMsg += HexToStr(nSendAddress + nIndex);
AfxGetMainWnd()->MessageBox(strFindMsg, GetResString(IDS_FLASH_TITLE));
pDlg->Done();
return bResult;
}
}
// The progress bar renewal for the progress report.
pDlg->SetProgressPos(((int)((nSendAddress - nStartAddress) / TO_INT)));
// The implementation of the event.
while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (!pApp->PumpMessage()) {
::PostQuitMessage(0);
break;
}
}
if(bCancel)
{
pDlg->Done();
return FALSE;
}
Sleep(10);
}
pDlg->Done();
// It works whether I may give a note to the memory.
CPreWriteDlg dlg;
dlg.SetAddress(HexToStr(nStartAddress), HexToStr(nEndAddress));
int nResponse = dlg.DoModal();
if(IDCANCEL == nResponse)
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_STOP_PROGRAM), GetResString(IDS_FLASH_TITLE));
return FALSE;
}
// It does status the clear.
BYTE send = 0x50;
comObj.Write(&send, 1);
// I wait until next it becomes a transmission passable.
Sleep(SLEEP_IN);
// Setting the dialog for the progress report.
bCancel = FALSE;
pDlg = CProgressDlg::Instance(&bCancel, NULL);
pDlg->InitialDialog("Program.", "Program",
0, (nEndAddress - nStartAddress - 0x0100) / TO_INT, 0);
// add 99.4.27 for M16C/20 2Mhz
GetSerialComm().SetTimeout(TIMEOUT_PRG);
// I write in the memory range where it was designated.
for(nSendAddress = nStartAddress; (long)nSendAddress < (long)nEndAddress; nSendAddress += 0x0100)
{
// I take Hex data.
BYTE byteData[PAGE_SIZE];
ClearPage(byteData);
int nPage = nSendAddress / 0x0100;
GetPage(byteData, nPage);
// I make the data that transmits it.
BYTE send[3 + PAGE_SIZE];
send[0] = 0x41;
ToSendStyle(nSendAddress, &send[2], &send[1]);
for(int nIndex = 0; nIndex < PAGE_SIZE; nIndex++)
{
send[nIndex + 3] = byteData[nIndex];
}
// It transmits it.
bResult = comObj.Write(send, 3 + PAGE_SIZE);
// The progress bar renewal for the progress report.
pDlg->SetProgressPos((nSendAddress - nStartAddress) / TO_INT);
// The implementation of the event.
while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (!pApp->PumpMessage()) {
::PostQuitMessage(0);
break;
}
}
if(bCancel)
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_STOP_PROGRAM), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
pDlg->Done();
return FALSE;
}
// I wait until next it becomes a transmission passable.
// Sleep(SLEEP_IN); // change set Intervals time
Sleep(ndwintervals);
// add 99.4.27 for 20 2Mhz
// Check Status
bResult = !CheckState(&comObj, "program");
if(!bResult)
{
// AfxGetMainWnd()->MessageBox(GetResString(IDS_PROGRAM_ERROR), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
break;
}
else
{
// AfxGetMainWnd()->MessageBox(GetResString(IDS_PROGRAM_OK), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
}
// add 99.4.27 for 20 2Mhz end
}
// add 99.4.27 for 20 2Mhz
GetSerialComm().SetTimeout(TIMEOUT5);
BOOL bIsEnd = bCancel;
pDlg->Done();
// Setting the dialog for the progress situation report.
bCancel = FALSE;
pDlg = CProgressDlg::Instance(&bCancel, NULL);
pDlg->InitialDialog("Read check.", "Read check.",
0, (nEndAddress - nStartAddress - 0x0100) / TO_INT, 0);
// It does the memory range where it was designated verify.
for(nSendAddress = nStartAddress; (long)nSendAddress < (long)nEndAddress;
nSendAddress += 0x0100)
{
// I receive data.
BYTE receive[PAGE_SIZE];
if(!DoRead(&comObj, receive, nSendAddress))
{
pDlg->Done();
return FALSE;
}
// I take Hex data.
BYTE byteData[PAGE_SIZE];
ClearPage(byteData);
int nPage = nSendAddress / 0x0100;
GetPage(byteData, nPage);
// It does verify.
CString strOther;
for(int nIndex = 0; nIndex < PAGE_SIZE; nIndex++)
{
if(byteData[nIndex] != receive[nIndex])
{
// It came close to differing.
CString strFindMsg = GetResString(IDS_FIND_NFILES);
strFindMsg += HexToStr(nSendAddress + nIndex);
AfxGetMainWnd()->MessageBox(strFindMsg, GetResString(IDS_FLASH_TITLE));
pDlg->Done();
return bResult;
}
}
// The progress bar renewal for the progress report.
pDlg->SetProgressPos((nSendAddress - nStartAddress) / TO_INT);
// The implementation of the event.
while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (!pApp->PumpMessage()) {
::PostQuitMessage(0);
break;
}
}
if(bCancel)
{
break;
}
Sleep(10);
}
pDlg->Done();
if(!bIsEnd)
{
// I check status.
bResult = !CheckState(&comObj, "program");
if(!bResult)
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_PROGRAM_ERROR), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
}
else
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_PROGRAM_OK), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
}
}
return bResult;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -