⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ceprcmd.cpp

📁 m16c flash startor 源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// CEPRCmd.cpp: the implementation of the CCEPRCmd class.
// add CEPRCommand function
//
// 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 "CEPRCmd.h"

#include "SetCommDlg.h"

#include "PrgssDlg.h"

#include "PreWriteDlg.h"

#include "SaveIni.h"
#include	"S_PrgDlg.h"
#include "IDCheckDlg.h"

// extern int CIDCheckDlg::s_MpuIndex;

extern BYTE g_send[SEND_ID];

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// CCEPRCommand Class
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
// Construction/disappearance
//////////////////////////////////////////////////////////////////////

CCEPRCmd::CCEPRCmd()
{

}

CCEPRCmd::~CCEPRCmd()
{

}


//////////// This is the minute when I added later. //////////////////////////////////////////
BOOL CCEPRCmd::exec(void)
{
	// standart time data command
	//Initialize the serial communication object.  
	DWORD dwBaudrate = DEFAULT_BAUDRATE;
	BYTE btByteSize = DEFAULT_BYTESIZE;
	BYTE btParity = DEFAULT_PARITY;
	BYTE btStopBits = DEFAULT_STOPBITS;
	((CM16CflshApp*)AfxGetApp())->SetFirstSerialState(GetSerialComm(), dwBaudrate, btByteSize, btParity, btStopBits);

	CString Z_Type = "-Z";
	{
		CSaveIni objInit;
		if(NULL != objInit.LoadZType())
		{
			objInit.GetZType(&Z_Type);
		}
		objInit.SetZType(Z_Type);
	}

#if	_DEBUG
	printf(" First send = %s\n", Z_Type);
#endif
	GetSerialComm().SetTimeout(TIMEOUT5);
//  set First send data
//	BYTE btCommChkW = 0xB0;
	BYTE btCommChkW;
	if( Z_Type == "+Z" )
	{
		btCommChkW = 0xB0;
	} else {
		btCommChkW = 0x00;
	}

	BYTE btCommChkR = 0;
	Sleep(SLEEP_IN);
	GetSerialComm().CleanUp(NULL);
	GetSerialComm().Write(&btCommChkW, 1);
	btCommChkW = 0xB0;

	Sleep(SLEEP_IN);
	for(int i = 0; i < SEND_00_TIMES  ; i++)
	{
		BYTE BtSnd0 = 0x00;
		GetSerialComm().Write(&BtSnd0, 1);
		Sleep(20);
	}
	Sleep(SLEEP_IN);
	btCommChkW = 0xB0;
	GetSerialComm().Write(&btCommChkW, 1);
	Sleep(SLEEP_IN);

	BOOL bCommChk = GetSerialComm().Read(&btCommChkR, 1);
	if(!bCommChk || btCommChkR != btCommChkW)
	{
#if _DEBUG
		CString str;
		// int i = GetLastError();
		str.Format("bCommChk = %d, %s  btCommChkR = %d %s ", bCommChk,bCommChk,btCommChkR,btCommChkR);
		AfxGetMainWnd()->MessageBox(str);
#endif
		if( bCommChk == 1){
			// return b0H 
		}
		else {
//		DWORD bbb;
        ((CM16CflshApp*)AfxGetApp())->CommError();
		return FALSE;
//		if ( bbb == 0 ){
//			return FALSE;
//		}
		}
	}

	Sleep(SLEEP_ONE);
	GetSerialComm().CleanUp(NULL);
  
	CSaveIni objInit;
	if(NULL != objInit.LoadComm())
	{
		objInit.GetComm(&dwBaudrate, &btByteSize, &btParity, &btStopBits);
		dwBaudrate = ((CM16CflshApp*)AfxGetApp())->SetSerialState(GetSerialComm(), dwBaudrate, btByteSize, btParity, btStopBits, IDS_SET_BAUDRATE_1);
	}

	//I make transmission data.
    //		BYTE send[SEND_ID];
	
	//A command is transmitted.  
	GetSerialComm().Write(g_send, 12);
	Sleep(SLEEP_IN);

	// ID check command	
{
	int bResult = 0;

	//I acquire the communication object.  
	CSerialComm& comObj = GetSerialComm();

	//I acquire status.  
	BYTE send = 0x70;
	BYTE btSRD[2];
	GetSerialComm().Write(&send, 1);
	if(!GetSerialComm().Read(btSRD, 2))
	{
			((CM16CflshApp*)AfxGetApp())->CommError();
	}
    //I check ID status.  
	int nStateID = 3 & (btSRD[1] >> 2);
	if(0 == nStateID)
	{
	//ID is not passing.  
			GetSerialComm().CleanUp(NULL);
			SetAcceptedID(FALSE);
			AfxGetMainWnd()->MessageBox(GetResString(IDS_NID), GetResString(IDS_FLASH_TITLE), MB_ICONWARNING);
	}
	else if(1 == nStateID)
	{
	//ID is not passing.  
			GetSerialComm().CleanUp(NULL);
			SetAcceptedID(FALSE);
			AfxGetMainWnd()->MessageBox(GetResString(IDS_NID), GetResString(IDS_FLASH_TITLE), MB_ICONWARNING);
	}
	else if(3 == nStateID)
	{
			//ID is passing.  
			SetAcceptedID(TRUE);
	}


}
	// Erase command 
	{
		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(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"){// apple old
#if	_DEBUG
		printf("apple old  \n");
#endif
		//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] = 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");

		//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");

		GetSerialComm().SetTimeout(TIMEOUT5);
		// add M16C/20 2Mhz end

		//A command is transmitted.
		send[0] = 0x75;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -