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

📄 update.cpp

📁 coldfire5206芯片的boot程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//				acMainSysIsValid[0] = 0x00;
//				if (FALSE == WriteEeprom(EEPROM_SYSTEM_FLAG_POS, 1, acMainSysIsValid))
//				{
//					TextOut(40, s_nDisplayPosY[UDI_EEPROM_FAIL], DOING_COLOR, 0, s_aacDisplayInfo[UDI_EEPROM_FAIL]);
//					return FALSE;
//				}

//			}
			while (j < 3)
			{
				if (!WriteFlash(lPos, (UCHAR*)(g_acFileBuffer + g_lFileBufPos), lLen))
					j ++;
				else
				{
					j = 0;
					break;
				}
			}
			if ( j == 3 )
				break;
			g_lFileBufPos += lLen;
//			if (g_stUpdateInfo.stUpdateItemTable[i].nType == SYS_FILE_TYPE)
//			{
//				// 系统首先无效,EEPROM
//				acMainSysIsValid[0] = 0x01;
//				if (FALSE == WriteEeprom(EEPROM_SYSTEM_FLAG_POS, 1, acMainSysIsValid))
//				{
//					TextOut(40, s_nDisplayPosY[UDI_EEPROM_FAIL], DOING_COLOR, 0, s_aacDisplayInfo[UDI_EEPROM_FAIL]);
//					return FALSE;
//				}
//			}
		}

		if (i == g_stUpdateInfo.nFileCount)	
		{
			// 对于8000主控板D版本以前的主控板(都为2M),由于最后FLASH参数BLOCK没有区分,所以会影响系统程序
			// 6000主板则是2M的需要,4M的不需要
//			if ((g_stSysFlag.stFSysFlag.ucFlashCircuitType == FLASH_CIRCUIT_VER_8000_D_BEFORE
//				|| (g_stSysFlag.stFSysFlag.ucFlashCircuitType == FLASH_CIRCUIT_VER_6000 && g_nFlashSizeType == FLASH_SIZE_2M))
//				&& g_stSysFlag.stESysFlag.ucMainSysIsValid == 1)
//			{
//				// 如果系统原本有效,那么无论如何,正确升级后都需要重新将系统置为有效
				// 系统首先无效,EEPROM
//				acMainSysIsValid[0] = 0x01;
//				if (FALSE == WriteEeprom(EEPROM_SYSTEM_FLAG_POS, 1, acMainSysIsValid))
//				{
//					TextOut(40, s_nDisplayPosY[UDI_EEPROM_FAIL], DOING_COLOR, 0, s_aacDisplayInfo[UDI_EEPROM_FAIL]);
//					return FALSE;
//				}
//			}
			DisplayUpateInfo(UDI_WRITE_FLASH, UDI_SUCCEED);
			TextOut(40, s_nDisplayPosY[UDI_OVER_SUCCEED], DONE_COLOR, 0, s_aacDisplayInfo[UDI_OVER_SUCCEED]);
			g_stCurrentSendInfo.commData.renewData.cResultFlag = 1;	
		}
		else
		{
			DisplayUpateInfo(UDI_WRITE_FLASH, UDI_FAIL, TRUE);
			TextOut(40, s_nDisplayPosY[UDI_OVER_FAIL], DONE_COLOR, 0, s_aacDisplayInfo[UDI_OVER_FAIL]);
			g_stCurrentSendInfo.commData.renewData.cResultFlag = 0;	
#ifdef BIOS_DEBUG
			while (1);
#endif
		}

		StartupComm(CST_RENEW);	
		DisplayUpateInfo(UDI_SYS_RESTART, 0);
		for (int j = 0; j < 10; j ++)
		{
			// close time1 for stoping to reset watchdog
			while (SendToSelfPort(pTempSendStr, g_lSendSize) != g_lSendSize);
			Sleep(400);	// all delay 4 s
		}
	}
	else
	{
		DisplayUpateInfo(UDI_TRANSFER_DATA, UDI_FAIL, TRUE);
		TextOut(40, s_nDisplayPosY[UDI_OVER_FAIL], DONE_COLOR, 0, s_aacDisplayInfo[UDI_OVER_FAIL]);
		DisplayUpateInfo(UDI_SYS_RESTART, 0);
		for (int j = 0; j < 100; j ++)
		{
			Sleep(40);	// all delay 4 s
		}
#ifdef BIOS_DEBUG
			while (1);
#endif
	}

//	DisableSysInterrupt(MCF5206::IM_TIMER1);
		
	CloseUpdatePort();
	if (i == g_stUpdateInfo.nFileCount)	// two condition is equal
	{
		return true;
	}
	else
	{
		return false;
	}
}


/*********************************************************************
* 函数名称:		StartupComm
* 说	明:		starup communiction of "nCommType"
* 入口参数:
*				UINT32 nCommType	communication's type to be going to be starup
* 返 回 值:
*				void  -- 无
* 作	者:		Shi Liangcai 
* 时	间:	    2002-09-31 12:07:31 
*********************************************************************/
void StartupComm(UINT32 nCommType)
{
	UCHAR* pTempSendStr	= g_acSendBuffer + NET_FRAME_EXTRA_ADD_HEAD;

	g_stCurrentSendInfo.nCommType = nCommType;

	// clear tramismiting's buffer
	g_clCommProtocol.StartupComm(g_stCurrentSendInfo);

	g_lSendSize = g_clCommProtocol.GetCommSendLength();
	if (g_lSendSize)	// 发送应答或其他数据
	{
		g_clCommProtocol.GetSendData(pTempSendStr);
		while (SendToSelfPort(pTempSendStr, g_lSendSize) != g_lSendSize);
	}


	return;
}

/*********************************************************************
* 函数名称:GetFilesNextComm
* 说明:取得下一个通讯的有关信息
* 入口参数:
* 返回值:
* void  -- 无
* 作者: Shi Liangcai 
* 时间 : 2002-07-26 11:54:31 
*********************************************************************/
void GetFilesNextComm()
{
	switch (g_stCurrentSendInfo.nCommType)
	{
	case CT_NULL:
		g_stCurrentSendInfo.nCommType = CRT_START;
		break;

	case CRT_START:
/*		g_stCurrentSendInfo.nCommType = CRT_VERSION;
		g_stCurrentSendInfo.commData.verData.ver_no = g_stUpdateInfo.nVerNo;
		g_stCurrentSendInfo.commData.verData.soft_no = g_stUpdateInfo.nSoftNo;
		break;

	case CRT_VERSION:
*/
		g_stCurrentSendInfo.nCommType = CRT_FILE;
		g_lFileBufPos = 0;
		g_stUpdateInfo.nCurFileNo = 0;
		g_stCurrentSendInfo.commData.fileData.pcFileInfo = g_acFileBuffer;
		break;

	case CRT_FILE:
		if (g_stUpdateInfo.nCurFileNo == g_stUpdateInfo.nFileCount)
		{
			g_stCurrentSendInfo.nCommType = CRT_BREAK;
		}
		else
		{
			g_stCurrentSendInfo.commData.fileData.pcFileInfo = g_acFileBuffer + g_lFileBufPos;
			g_stUpdateInfo.nCurFileNo ++;
		}
		break;

	case CRT_BREAK:
		g_stCurrentSendInfo.nCommType = CT_NULL;
		break;

	default:
		break;
	}

	return;
}

/*********************************************************************
* 函数名称:AnalyseCommResult
* 说明:分析通讯结果,看是否要继续下一步通讯
* 入口参数:
* 返回值:
* BOOL  -- 1,进行下一步通讯;0,结束通讯!
* 作者: Shi Liangcai 
* 时间 : 2002-07-26 15:03:06 
*********************************************************************/
INT16 AnalyseCommResult()
{
	INT16 nTempFlag;
	UINT32 i, lTempLen;
	// 暂停通讯延时计数

	// 
	nTempFlag = -1;
	switch (g_clCommProtocol.GetEndCommFlag())
	{
	case CCommProtocol::CET_NOT:
		nTempFlag = 0;
		break;

	case CCommProtocol::CET_RESEND_INVALID:
		// 显示通讯出错
#ifdef BIOS_DEBUG
		TextOut(40, 360, 15, 0, "Error: resend is invalid");
#endif
		break;

	case CCommProtocol::CET_NO_DATA:
		// 显示通讯出错
#ifdef BIOS_DEBUG
		TextOut(40, 360, 15, 0, "Error: recieve nothing");
#endif
		break;

	case CCommProtocol::CET_NORMAL:
		g_clCommProtocol.GetRecCommInfo(&g_stCurrentRecieveInfo);
		if (g_stCurrentSendInfo.nCommType == CRT_VERSION)
		{
			memcpy(g_stUpdateInfo.acNewVerNo, g_stCurrentRecieveInfo.commData.verData.ver_info, 4);
//			g_stUpdateInfo.nNewVerNo = g_stCurrentRecieveInfo.commData.verData.ver_no;
			g_stUpdateInfo.nNewSoftNo = g_stCurrentRecieveInfo.commData.verData.soft_no;
		}
		if (g_stCurrentSendInfo.nCommType == CRT_FILE)
		{
			if (g_stUpdateInfo.nCurFileNo == 0)
			{
				g_stUpdateInfo.nFileCount = g_stCurrentRecieveInfo.commData.fileData.lFileLength / sizeof(SYS_UpdateItemInfo);
				memcpy(g_stUpdateInfo.stUpdateItemTable, 
					g_stCurrentRecieveInfo.commData.fileData.pcFileInfo, g_stCurrentRecieveInfo.commData.fileData.lFileLength);
				g_lFileBufPos = 0;
				lTempLen = 0;
				for (i = 0; i < g_stUpdateInfo.nFileCount; i ++)
				{
					lTempLen += g_stUpdateInfo.stUpdateItemTable[i].nLength;
				}
				if (lTempLen > MAX_FILE_BUFFER)
				{
					// 通讯接收的内容超过缓冲,
					DisplayUpateInfo(UDI_OVER_FAIL_FILE_SIZE, 0, TRUE);
					while (1);
				}
			}
			else
			{
				if (g_stUpdateInfo.stUpdateItemTable[g_stUpdateInfo.nCurFileNo - 1].nLength
					== g_stCurrentRecieveInfo.commData.fileData.lFileLength)
				{
					g_lFileBufPos += g_stCurrentRecieveInfo.commData.fileData.lFileLength;
				}
				else
				{
					// 显示通讯出错
#ifdef BIOS_DEBUG
					TextOut(40, 360, 15, 0, "Error: file's length is wrong");
#endif
					break;
				}
			}
		}
		nTempFlag = 1;
		break;

	default:
		break;
	}	

	return nTempFlag;
}

/*********************************************************************
* 函数名称:		InitUpdatePort
* 说	明:		initialize port for updating
* 入口参数:
*				void  -- 无
* 返 回 值:
*				BOOL  -- 1, success; 0, fail 
* 作	者:		Shi Liangcai 
* 时	间:	    2002-09-31 12:07:31 
*********************************************************************/
static BOOL InitUpdatePort()
{
	UCHAR self_port_id = g_stSysFlag.stFSysFlag.ucSelfPortID;
	UCHAR update_port_id = g_stSysFlag.stESysFlag.ucUpdatePortID;

	// init update self-port function
	if (self_port_id != NET_PORT && self_port_id >= UART_MAX)
	{
		return FALSE;
	}
	if (update_port_id != NET_PORT && update_port_id >= UART_MAX)
	{
		return FALSE;
	}
	
	UARTCONFIG config = {BR_MAX, PARITY_EVEN, DATABITS_8, STOPBITS_1, FALSE};
	// init update self-port 
	if (self_port_id == NET_PORT)
	{
		if (!InitNetPort())
			return FALSE;
	}
	else
	{
		config.baudRate = BR_115200;//BR_57600;//BR_38400;//BR_115200;
		InitUart(self_port_id, &config, UART_ENABLE, UART_ENABLE);
	}

	// init update target-port 
	if (self_port_id != update_port_id)
	{
		// if update-uart is not self-uart, set update-uart
		// because target port is not same with selt port, target port must be uart-port
		config.baudRate = (BAUDRATE)g_stSysFlag.stESysFlag.ucUpdateUartBaud;
		InitUart(update_port_id, &config, UART_ENABLE, UART_ENABLE);
		EnableSysInterrupt(g_alUartIMRTable[update_port_id]);
	}

	// open port interrupt
	if (self_port_id == NET_PORT)
	{
		EnableSysInterrupt(MCF5206::IM_EINT4);
	}
	else
	{
		EnableSysInterrupt(g_alUartIMRTable[g_stSysFlag.stFSysFlag.ucSelfPortID]);
	}

	return TRUE;
}

/*********************************************************************
* 函数名称:		CloseUpdatePort
* 说	明:		close port after update end
* 入口参数:
*				void  -- 无
* 返 回 值:
*				void  -- 无
* 作	者:		Shi Liangcai 
* 时	间:	    2002-09-31 12:07:31 
*********************************************************************/
static void CloseUpdatePort()
{
	UCHAR self_port_id = g_stSysFlag.stFSysFlag.ucSelfPortID;
	UCHAR update_port_id = g_stSysFlag.stESysFlag.ucUpdatePortID;

	// close self port interrupt
	if (self_port_id == NET_PORT)
	{
		DisableSysInterrupt(MCF5206::IM_EINT4);
	}
	else
	{
		DisableSysInterrupt(g_alUartIMRTable[self_port_id]);
	}
	
	// close update port interrupt
	if (update_port_id != self_port_id)
	{
		DisableSysInterrupt(g_alUartIMRTable[update_port_id]);
	}

	return;
}

static void DisplayUpateInfo(UINT32 nNormalID, UINT32 nResultID, BOOL bIsFail)
{
	int nDispColor;
	
	if (nResultID != 0)
	{
		if (bIsFail == TRUE)
		{
			nDispColor =  FAIL_COLOR;
		}
		else
		{
			nDispColor = DONE_COLOR;
		}
		char acDisplayString[100];
		strcpy(acDisplayString, s_aacDisplayInfo[nNormalID]);
		strcat(acDisplayString, "......");
		strcat(acDisplayString, s_aacDisplayInfo[nResultID]);
		TextOut(40, s_nDisplayPosY[nNormalID], nDispColor, 0, acDisplayString);
	}
	else
	{
		if (bIsFail == TRUE)
		{
			nDispColor =  FAIL_COLOR;
		}
		else
		{
			nDispColor = DOING_COLOR;
		}
		TextOut(40, s_nDisplayPosY[nNormalID], nDispColor, 0, s_aacDisplayInfo[nNormalID]);
	}

	return;
}

static INT16 SendToSelfPort(UCHAR* string, UINT16 len)
{
	int port_id = g_stSysFlag.stFSysFlag.ucSelfPortID;

	if (port_id == NET_PORT)
	{
		NetWriteString(string, len);
	}
	else
	{
		UartWriteString(port_id, string, len);
	}
}

static INT16 ReceiveFromSelfPort(UCHAR* string, UINT16 len)
{
	int port_id = g_stSysFlag.stFSysFlag.ucSelfPortID;

	if (port_id == NET_PORT)
	{
		NetReadString(string, len);
	}
	else
	{
		UartReadString(port_id, string, len);
	}
}

static INT16 SendToTargetPort(UCHAR* string, UINT16 len)
{
	int port_id = g_stSysFlag.stESysFlag.ucUpdatePortID;

	if (port_id == NET_PORT)
	{
		NetWriteString(string, len);
	}
	else
	{
		UartWriteString(port_id, string, len);
	}
}

static INT16 ReceiveFromTargetPort(UCHAR* string, UINT16 len)
{
	int port_id = g_stSysFlag.stESysFlag.ucUpdatePortID;

	if (port_id == NET_PORT)
	{
		NetReadString(string, len);
	}
	else
	{
		UartReadString(port_id, string, len);
	}
}

⌨️ 快捷键说明

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