📄 erasecmd.cpp
字号:
// EraseCmd.cpp: the implementation of the CEraseCmd 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 "EraseCmd.h"
#include "SaveIni.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
//Construction/disappearance
//////////////////////////////////////////////////////////////////////
CEraseCmd::CEraseCmd()
{
}
CEraseCmd::~CEraseCmd()
{
}
//////////////////////////////////////////////////////////////////////
//It is Erase command implementation.
BOOL CEraseCmd::exec(void)
{
BOOL bResult = FALSE;
BOOL bResult0 = FALSE;
BOOL bResult1 = FALSE;
BOOL bResult2 = FALSE;
BOOL bResult3 = FALSE;
BYTE send[4];
BYTE e_type = 0; // erace type normal = 0, apple_old =1
CString D_Type = "-a"; // f_sptr type nomal = -a, apple = +a
//I acquire the communication object.
CSerialComm& comObj = GetSerialComm();
// check version
// Get result.
{
BYTE send = 0xFB;
BYTE btVER[8];
BYTE ctVER[8];
ctVER[0] = 'V';
ctVER[1] = 'E';
ctVER[2] = 'R';
ctVER[3] = '.';
ctVER[4] = '2';
ctVER[5] = '.';
ctVER[6] = '0';
ctVER[7] = '3';
ctVER[8] = '\0';
comObj.Write(&send, 1);
if(!comObj.Read(btVER, 8))
{
//CommError();
//return FALSE;
btVER[0] = 'E';
btVER[1] = 'R';
btVER[2] = 'R';
btVER[3] = 'O';
btVER[4] = 'R';
btVER[5] = '\0';
}
else
{
btVER[8] = '\0';
}
if(strcmp ( (const char *)btVER, (const char *)ctVER) >0 )
{
e_type = 0; // apple old
}else{
e_type = 1; // normal
}
#if _DEBUG
printf(" chip ver = %s \n",btVER);
printf(" check ver = %s \n",ctVER);
#endif
}
CSaveIni objInit;
#if _DEBUG
printf(" check func type = %s\n", objInit.LoadDType());
#endif
if(NULL != objInit.LoadDType())
{
objInit.GetDType(&D_Type);
}
#if _DEBUG
printf(" func type = %s\n", D_Type);
printf(" ver flg 1:old 0:new = %i \n", e_type);
printf("elase if \n");
#endif
if( e_type == 1 && D_Type == "+a"){
//It does status the clear.
send[0] = 0x50;
comObj.Write(&send[0], 1);
//I wait until next it becomes a transmission passable.
Sleep(SLEEP_IN);
//A command is transmitted.
send[0] = 0x75;
comObj.Write(&send[0], 1);
Sleep(SLEEP_IN);
send[0] = 0x20;
send[1] = 0xff;
send[2] = 0x0f;
send[3] = 0xd0;
bResult = comObj.Write(send, 4);
//I wait until next it becomes a transmission passable.
Sleep(SLEEP_IN);
// add M16C/20 2Mhz
GetSerialComm().SetTimeout(TIMEOUT_ELS);
//I check status.
bResult0 = !CheckState(&comObj, "erase");
// if(!bResult0)
// {
// AfxGetMainWnd()->MessageBox(GetResString(IDS_ERASE_ERROR), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
// }
// else
// {
// AfxGetMainWnd()->MessageBox(GetResString(IDS_ERASE_OK), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
// }
//A command is transmitted.
send[0] = 0x75;
comObj.Write(&send[0], 1);
Sleep(SLEEP_IN);
send[0] = 0x20;
send[1] = 0xbf;
send[2] = 0x0f;
send[3] = 0xd0;
bResult = comObj.Write(send, 4);
//I wait until next it becomes a transmission passable.
Sleep(SLEEP_IN);
// add M16C/20 2Mhz
GetSerialComm().SetTimeout(TIMEOUT_ELS);
//I check status.
bResult1 = !CheckState(&comObj, "erase");
// if(!bResult1)
// {
// AfxGetMainWnd()->MessageBox(GetResString(IDS_ERASE_ERROR), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
// }
// else
// {
// AfxGetMainWnd()->MessageBox(GetResString(IDS_ERASE_OK), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
// }
GetSerialComm().SetTimeout(TIMEOUT5);
// add M16C/20 2Mhz end
//A command is transmitted.
send[0] = 0x75;
comObj.Write(&send[0], 1);
Sleep(SLEEP_IN);
send[0] = 0x20;
send[1] = 0x9f;
send[2] = 0x0f;
send[3] = 0xd0;
bResult = comObj.Write(send, 4);
//I wait until next it becomes a transmission passable.
Sleep(SLEEP_IN);
// add M16C/20 2Mhz
GetSerialComm().SetTimeout(TIMEOUT_ELS);
//I check status.
bResult2 = !CheckState(&comObj, "erase");
// if(!bResult2)
// {
// AfxGetMainWnd()->MessageBox(GetResString(IDS_ERASE_ERROR), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
// }
// else
// {
// AfxGetMainWnd()->MessageBox(GetResString(IDS_ERASE_OK), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
// }
GetSerialComm().SetTimeout(TIMEOUT5);
// add M16C/20 2Mhz end
//A command is transmitted.
send[0] = 0x75;
comObj.Write(&send[0], 1);
Sleep(SLEEP_IN);
send[0] = 0x20;
send[1] = 0x7f;
send[2] = 0x0f;
send[3] = 0xd0;
bResult = comObj.Write(send, 4);
//I wait until next it becomes a transmission passable.
Sleep(SLEEP_IN);
// add M16C/20 2Mhz
GetSerialComm().SetTimeout(TIMEOUT_ELS);
//I check status.
bResult3 = !CheckState(&comObj, "erase");
if((!bResult0) && (!bResult1) &&(!bResult2) &&(!bResult3))
{
bResult = FALSE;
}
if(!bResult)
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_ERASE_ERROR), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
}
else
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_ERASE_OK), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
}
GetSerialComm().SetTimeout(TIMEOUT5);
// add M16C/20 2Mhz end
}
else{ // normal
//I acquire the communication object.
CSerialComm& comObj = GetSerialComm();
//It does status the clear.
send[0] = 0x50;
comObj.Write(&send[0], 1);
//I wait until next it becomes a transmission passable.
Sleep(SLEEP_IN);
//A command is transmitted.
send[0] = 0x75;
comObj.Write(&send[0], 1);
Sleep(SLEEP_IN);
send[0] = 0xa7;
send[1] = 0xd0;
bResult = comObj.Write(send, 2);
//I wait until next it becomes a transmission passable.
Sleep(SLEEP_IN);
// add M16C/20 2Mhz
GetSerialComm().SetTimeout(TIMEOUT_ELS);
//I check status.
bResult = !CheckState(&comObj, "erase");
if(!bResult)
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_ERASE_ERROR), GetResString(IDS_FLASH_TITLE), MB_ICONERROR);
}
else
{
AfxGetMainWnd()->MessageBox(GetResString(IDS_ERASE_OK), GetResString(IDS_FLASH_TITLE), MB_ICONINFORMATION);
}
GetSerialComm().SetTimeout(TIMEOUT5);
// add M16C/20 2Mhz end
}
return bResult;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -