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

📄 test.cpp

📁 coldfire5206芯片平台的自捡程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
#include "bastype.h"
#include "netdrv.h"
#include "flash.h"
#include "fpga.h"
#include "test.h"

#if defined(RESOLVING_800_600)
#include "8k9k_800_600_fpga.h"
#include "6k_800_600_fpga.h"
#else
#if defined(RESOLVING_640_480)
#include "8k9k_640_480_fpga.h"
#endif
#endif
// 随机产生的一个唯一标志ID
UINT32 g_alMonitorId[2];

VOID TextOut( INT16 x, INT16 y, CHAR color, CHAR bcolor, CHAR* text );

#pragma pack(1)		// pack
typedef struct _soft_component_info
{
	UCHAR	ucType;
	UINT32	lComLen;
	UCHAR	acVer[4];
	UINT32  lComChecksum;
	UCHAR	acReserved[47];
	UINT32	lChecksum;
} SOFTCOMINFO;
#pragma pack(0)		// pack defination is over

#define LOCAL_LOOP

unsigned char *TestResult;

static unsigned int  gBootFile[] = 
{
#if defined(RESOLVING_800_600)
	#include "h_boot.txt"
#else
#if defined(RESOLVING_640_480)
	#include "l_boot.txt"
#endif
#endif
};

/**************************************************************************/
#define BUFFSIZE           0x30000

static MBusPackType sDS1337ReadPack[DS1337_READ_PACKQUE_LEN];
static MBusPackType sDS1337WritePack[DS1337_WRITE_PACKQUE_LEN];
MBusPackQueType gDS1337ReadPackQue =
                      {0, 0, DS1337_READ_PACKQUE_LEN, sDS1337ReadPack};
MBusPackQueType gDS1337WritePackQue =
                      {0, 0, DS1337_WRITE_PACKQUE_LEN, sDS1337WritePack};


/**
 *  Global variables define: Packet queue manager
 */
MBusPackQueType gRS5C372AReadPackQue =
                      {0, 0, RS5C372A_READ_PACKQUE_LEN, sRS5C372AReadPack};

MBusPackQueType gRS5C372AWritePackQue =
                      {0, 0, RS5C372A_WRITE_PACKQUE_LEN, sRS5C372AWritePack};

MBusPackQueType gX1203ReadPackQue =
                      {0, 0, X1203_READ_PACKQUE_LEN, sX1203ReadPack};

MBusPackQueType gX1203WritePackQue =
                      {0, 0, X1203_WRITE_PACKQUE_LEN, sX1203WritePack};

MBusPackQueType gPCF8591ReadPackQue =
                      {0, 0, PCF8591_READ_PACKQUE_LEN, sPCF8591ReadPack};

MBusPackQueType gPCF8591WritePackQue =
                      {0, 0, PCF8591_WRITE_PACKQUE_LEN, sPCF8591WritePack};

MBusPackQueType gCAT24C021ReadPackQue =
                      {0, 0, CAT24C021_READ_PACKQUE_LEN, sCAT24C021ReadPack};

MBusPackQueType gCAT24C021WritePackQue =
                      {0, 0, CAT24C021_WRITE_PACKQUE_LEN, sCAT24C021WritePack};

// because all queue are processed in turning, so remember these queues
static MBusPackQueType *sMBusPackQues[PACKQUE_NUMBER] = {
                         &gRS5C372AReadPackQue,
                         &gX1203ReadPackQue,
                         &gPCF8591ReadPackQue,
                         &gCAT24C021ReadPackQue,

                         &gRS5C372AWritePackQue,
                         &gX1203WritePackQue,
                         &gPCF8591WritePackQue,
                         &gCAT24C021WritePackQue
                      };


static  UNCHAR  sMBusCmds[260];

// current command to be processed
static  SHORT sCurrentCmd;

// where is the data to be transmitted
static  UNCHAR  *sTransmitPtr;

// where is the data received to be saved.
static  UNCHAR  *sReceivePtr;

static UNCHAR  sTime[7] = {0, 0, 0};
//--------------------SERIAL IO -------------------------------
SHORT	Timer1Cnt = 0;
SHORT	Timer2Cnt = 0;
SHORT	FPGAIntType;
Stime Tsys;

enum MBUSCmd{ CMD_TRANSMIT,           // normal transmit
              CMD_TRANSMIT_STOP,      // a stop after transmitting
              CMD_TRANSMIT_RECEIVE,   // change to receive mode after transmit
              CMD_RESTART_TRANSMIT,   // restart then transmit
              CMD_RECEIVE_ACK,        // receive with acknowledge
              CMD_RECEIVE_NOACK,      // receive without acknowledge
              CMD_RECEIVE_STOP        // receive then stop
            };
/************************END OF MBUS ***************************************/



CHAR *gInfos[] =
{
   "Done",
   "Unlocking blocks...",
   "Erasing chip...",
   "Writing NetLoader...",
   "Writing SysProgram...",
   "Verifying... ",
   "Fail"
};

#define  TRUE		1
#define  FALSE		0

CHAR  gErrInfomation[30][100] = {""};
CHAR *gErrInfo_6000[] = 
{
	"FLASH ROM ERROR",
	"TIMER1 ERROR",
	"TIMER2 ERROR",
	"CPU UART1 ERROR",
	"CPU UART2 ERROR",
	"FPGA UART1 POLL ERROR",
	"FPGA UART2 POLL ERROR",
	"FPGA UART3 POLL ERROR",
	"FPGA UART4 POLL ERROR",
	"FPGA UART5 POLL ERROR",
	"FPGA UART6 POLL ERROR",

	"FPGA UART7 POLL ERROR",
	"FPGA UART8 POLL ERROR",

	"FPGA UART1 INT ERROR",
	"FPGA UART2 INT ERROR",
	"FPGA UART3 INT ERROR",
	"FPGA UART4 INT ERROR",
	"FPGA UART5 INT ERROR",
	"FPGA UART6 INT ERROR",

	"FPGA UART7 INT ERROR",
	"FPGA UART8 INT ERROR",

	"MBUS CLOCK ERROR",
	"MBUS EEPROM ERROR",
	"AD ERROR",
	"NET ERROR"
};
CHAR *gErrInfo_other[] = 
{
	"FLASH ROM ERROR",
	"TIMER1 ERROR",
	"TIMER2 ERROR",
	"CPU UART1 ERROR",
	"CPU UART2 ERROR",
	"FPGA UART1 POLL ERROR",
	"FPGA UART2 POLL ERROR",
	"FPGA UART3 POLL ERROR",
	"FPGA UART4 POLL ERROR",
	"FPGA UART5 POLL ERROR",
	"FPGA UART6 POLL ERROR",

	"FPGA UART1 INT ERROR",
	"FPGA UART2 INT ERROR",
	"FPGA UART3 INT ERROR",
	"FPGA UART4 INT ERROR",
	"FPGA UART5 INT ERROR",
	"FPGA UART6 INT ERROR",

	"MBUS CLOCK ERROR",
	"MBUS EEPROM ERROR",
	"AD ERROR",
	"NET ERROR"
};

CHAR *gBatErrInfo[] = 
{
	"5V Low!",
	"5V High!",
	"12V Low!",
	"12V High!",
	"Battery Low!",
	"Battery High!",
	"3.3V High!",
	"3.3V Low!",
};

CHAR	*gSuccessInfo_6000[] = 
{
	"Display Test OK            Flash ROM Test OK            Timer 1 Test OK",
	"Timer 2 Test OK            UART1 Test OK                UART2 Test OK",
	"FPGA UART1  Poll Test OK   FPGA UART2  Poll Test OK     FPGA UART3  Poll Test OK",
	"FPGA UART4  Poll Test OK   FPGA UART5  Poll Test OK     FPGA UART6  Poll Test OK",

	"FPGA UART7  Poll Test OK   FPGA UART8  Poll Test OK",

	"FPGA UART1  Int Test  OK   FPGA UART2  Int Test OK      FPGA UART3  Int Test OK",
	"FPGA UART4  Int Test  OK   FPGA UART5  Int Test OK      FPGA UART6  Int Test OK",

	"FPGA UART7  Int Test  OK	 FPGA UART8  Int Test OK",

	"MBUS CLOCK Test OK         MBUS EEPROM Test OK          A/D Test OK",
	"NET TEST OK"
};
CHAR	*gSuccessInfo_other[] = 
{
	"Display Test OK            Flash ROM Test OK            Timer 1 Test OK",
	"Timer 2 Test OK            UART1 Test OK                UART2 Test OK",
	"FPGA UART1  Poll Test OK   FPGA UART2  Poll Test OK     FPGA UART3  Poll Test OK",
	"FPGA UART4  Poll Test OK   FPGA UART5  Poll Test OK     FPGA UART6  Poll Test OK",

	"FPGA UART1  Int Test  OK   FPGA UART2  Int Test OK      FPGA UART3  Int Test OK",
	"FPGA UART4  Int Test  OK   FPGA UART5  Int Test OK      FPGA UART6  Int Test OK",

	"MBUS CLOCK Test OK         MBUS EEPROM Test OK          A/D Test OK",
	"NET TEST OK"

};

UINT32 gError = 0;

#define FPGA_2M_FLASH_ADDR	0xD000
#define FPGA_4M_FLASH_ADDR	0x3C0000
#define LANG_2M_FLASH_ADDR	0x1E0000
#define LANG_4M_FLASH_ADDR	0x260000
#define CONFIG_2M_FLASH_ADDR	0x1F8000
#define CONFIG_4M_FLASH_ADDR	0x3E0000

BOOL WriteFlashSystemInfo()
{
	// FLASH开始的64个字节
	// 前面8个字节的STACK和START POS和后面56字节的系统标志
	UCHAR	acFlashCfgInfo[64];
	UCHAR ucMonitorID[8];
	UINT32 lPos, lTempValue;

	// 先取得标志信息
	memset(acFlashCfgInfo, 0x00, 64);
	// sp
	lPos = 0;
	lTempValue = 0x400000;
	memcpy(acFlashCfgInfo + lPos, &lTempValue, 4);
	lPos += 4;
	//start
	lTempValue = 0x800040;
	memcpy(acFlashCfgInfo + lPos, &lTempValue, 4);
	lPos += 4;
	// machine self type, self update port, bios ver, reserved 1
	acFlashCfgInfo[lPos] = MT_PM_NET_COMMON;
	lPos ++;
	acFlashCfgInfo[lPos] = UT_SELF_VALUE;
	lPos ++;
	acFlashCfgInfo[lPos] = BIOS_VER;
	lPos ++;
	acFlashCfgInfo[lPos] = 0x00;
	lPos ++;
	// machine ID
	memcpy(acFlashCfgInfo + lPos, (UCHAR*)(&g_alMonitorId), 8);
	lPos += 8;
	// flash size flag, flash circuit flag, reserved 2
	acFlashCfgInfo[lPos] = g_nFlashSizeType;
	lPos ++;
	acFlashCfgInfo[lPos] = g_nFlashCircuitType;
	lPos ++;
//	lTempValue = ( (g_nFlashSizeType << 24) & 0xff000000 )
//		+ ( (g_nFlashCircuitType << 16) & 0x00ff0000 );
//	memcpy(acFlashCfgInfo + lPos, &lTempValue, 4);
	if (g_nFlashSizeType == FLASH_SIZE_2M)
	{
		lTempValue = FPGA_2M_FLASH_ADDR + FLASH_BASE_ADDRESS;
		memcpy(acFlashCfgInfo + lPos, &lTempValue, 4);
		lPos += 4;
		lTempValue = LANG_2M_FLASH_ADDR + FLASH_BASE_ADDRESS;
		memcpy(acFlashCfgInfo + lPos, &lTempValue, 4);
		lPos += 4;
		lTempValue = CONFIG_2M_FLASH_ADDR + FLASH_BASE_ADDRESS;
		memcpy(acFlashCfgInfo + lPos, &lTempValue, 4);
		lPos += 4;

	}
	else
	{
		lTempValue = FPGA_4M_FLASH_ADDR + FLASH_BASE_ADDRESS;
		memcpy(acFlashCfgInfo + lPos, &lTempValue, 4);
		lPos += 4;
		lTempValue = LANG_4M_FLASH_ADDR + FLASH_BASE_ADDRESS;
		memcpy(acFlashCfgInfo + lPos, &lTempValue, 4);
		lPos += 4;
		lTempValue = CONFIG_4M_FLASH_ADDR + FLASH_BASE_ADDRESS;
		memcpy(acFlashCfgInfo + lPos, &lTempValue, 4);
		lPos += 4;
	}
	// checksum
	lPos = 60;
	lTempValue = 0;
	for (int i = 8; i < 64; i += 2)
		lTempValue += *((UINT16*)(acFlashCfgInfo + i));
	memcpy(acFlashCfgInfo + lPos, &lTempValue, 4);
	lPos += 4;

	// 写FLASH
	lTempValue = 0;
	lTempValue +=  !WriteFlash(0x00, acFlashCfgInfo, 64);

	return !lTempValue;
}

UINT32 MYPROGRAMMER()
{
	UCHAR	acFlashCfgInfo[64];
	UCHAR ucMonitorID[8];
	UINT32 lPos, lTempValue;
	int i;

	lTempValue = 0;
	lTempValue += !WriteFlashSystemInfo();
	// 写引导程序
	lTempValue += !WriteFlash(0x40, (UCHAR*)gBootFile, sizeof(gBootFile));

	// 写FPGA
	UINT32 fpga_data_len;
	UCHAR* p_fpga_data;
	SOFTCOMINFO comInfo;
	memset(&comInfo, 0x00, sizeof(SOFTCOMINFO));

#if defined(RESOLVING_800_600)
	if (g_nFlashCircuitType == FLASH_CIRCUIT_VER_6000)
	{
		fpga_data_len = sizeof(fpga_6k_800_600);
		p_fpga_data = 	(UCHAR*)fpga_6k_800_600;
		comInfo.ucType = 0x01;
	}
	else
	{
		fpga_data_len = sizeof(fpga_8k9k_800_600);
		p_fpga_data = 	(UCHAR*)fpga_8k9k_800_600;
		comInfo.ucType = 0x00;
	}
#else
#if defined(RESOLVING_640_480)
	// 640× 480没有用于6000产品
	if (g_nFlashCircuitType == FLASH_CIRCUIT_VER_6000)
	{
		TextOut( 100, 160, BLINKRED, 0, "640*480 is not supported by PM6000");
		//HaltCpu();
		while(1);
	}
	else
	{
		fpga_data_len = sizeof(fpga_8k9k_640_480);
		p_fpga_data = 	(UCHAR*)fpga_8k9k_640_480;
		comInfo.ucType = 0x00;
	}
#endif
#endif
	// data in flash rom
	comInfo.lComLen = fpga_data_len;
	comInfo.acVer[0] = 0x01;
	UINT32 lChecksum = 0x00;
	for (i = 0; i < fpga_data_len / 2; i ++)
	{
		lChecksum += *((UINT16*)p_fpga_data + i);
	}
	comInfo.lComChecksum = lChecksum;
	lChecksum = 0x00;
	for (i = 0; i < (sizeof(SOFTCOMINFO) - 4) / 2; i ++)
	{
		lChecksum += *((UINT16*)(&comInfo) + i);
	}
	comInfo.lChecksum = lChecksum;

	lTempValue = 0;
	if (g_nFlashSizeType == FLASH_SIZE_2M)
	{
		lTempValue +=  !WriteFlash(FPGA_2M_FLASH_ADDR, (UCHAR*)&comInfo, sizeof(SOFTCOMINFO));
		lTempValue +=  !WriteFlash(FPGA_2M_FLASH_ADDR + sizeof(SOFTCOMINFO), p_fpga_data, fpga_data_len);
	}
	else
	{
		lTempValue +=  !WriteFlash(FPGA_4M_FLASH_ADDR, (UCHAR*)&comInfo, sizeof(SOFTCOMINFO));
		lTempValue +=  !WriteFlash(FPGA_4M_FLASH_ADDR + sizeof(SOFTCOMINFO), p_fpga_data, fpga_data_len);
	}

	return lTempValue;
}

void  TextOut(INT16 x, INT16 y, CHAR color, CHAR bcolor, CHAR *text);

unsigned int Mbar = 0x60000000;//,Cot=2000,IntCode=2;

static UINT32  sUartParityError[8];
static UINT32  sUartFrameError[8];
static UINT32  sUartOverRunError[8];

static UINT32  sParityError;
static UINT32  sFrameError;
static UINT32  sOverRunError;

static UINT32  sUartErrorCnt;
UNCHAR		TestData = 0;
UNSHORT	UARTTestResult = 0;
UNSHORT	ReceiveData = 0;

UCHAR	FpgaSendData, CpuSendData;

static char	SentFlag = 0, UartSentFlag = 0;
static UNCHAR	RxData;
static UCHAR	UartTestData;
static UCHAR	UartRxData;


unsigned char *	gCharScreenRamBuf;

unsigned short k = 0;

#define WAVEHEIGHT		300
#define PHYWAVESCNWIDTH 320
#define WPORT			0x540000    

#define	WAVE_WIDTH_ADDR		0x600000
#define WAVE1_POSADDR		0x600002
#define WAVE2_POSADDR		0x600004
#define WAVE3_POSADDR		0x600006
#define WAVE4_POSADDR		0x600008
#define WAVE5_POSADDR		0x60000a
#define WAVE6_POSADDR		0x60000c
#define WAVE7_POSADDR		0x60000e

#define WAVE1_X_POS_ADDR	0x600010
#define WAVE2_X_POS_ADDR	0x600012
#define WAVE3_X_POS_ADDR	0x600014
#define WAVE4_X_POS_ADDR	0x600016
#define WAVE5_X_POS_ADDR	0x600018
#define WAVE6_X_POS_ADDR	0x60001a
#define WAVE7_X_POS_ADDR	0x60001c
#define WAVE8_X_POS_ADDR	0x60001e

#define CHARSCRSTART	    22
#define	SCRWIDTH			319		// 屏幕宽度
#define	SCRHEIGHT			239		// 屏幕高度
#define WAVE_XSTART			0
#define WAVE_XEND			560
#define SCRN_XEND			319
#define WAVEWIDTH			640

VOID  PutPixel( INT16 x, INT16 y, CHAR color )
{
	UCHAR * tmptr;
	UCHAR * vtmptr;

	tmptr = ( UCHAR * )( &gCharScreenRamBuf[0] + y * SCN_WIDTH / 2 + x / 2 );
	vtmptr = ( UCHAR * )( ( UCHAR * )VPORT + y * SCN_WIDTH / 2 + x / 2 );

	if ( x & 0x1 )  
	{
		*tmptr &= 0xf0;
		*tmptr |= color;
		*vtmptr = *tmptr;
	}
	else 
	{
		 color <<= 4;
		*tmptr &= 0x0f;
		*tmptr |= color;
		*vtmptr = *tmptr;
	}

	return ;
}


VOID Line( INT16 x1, INT16 y1, INT16 x2, INT16 y2, CHAR color )
{
	UINT16 i, ylen, xlen, e, tx, ty;
	
	if ( ( x1 == x2 ) && ( y1 == y2 ) ) 
	{
		PutPixel( x1, y1, color );
		return;
	}
	
	if( x1 == x2 ) 

⌨️ 快捷键说明

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