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

📄 monitor.c

📁 WinCE 3.0 BSP, 包含Inter SA1110, Intel_815E, Advantech_PCM9574 等
💻 C
📖 第 1 页 / 共 5 页
字号:
    WriteOutput("Memory                 : 32 MB of Flash\r\n");
    WriteOutput("                         64 MB of SDRAM (Area 3)\r\n");
}


/************************************************************************************
 * Function: Command_SelfTest
 * Input:    None.
 * Output:   None.
 * Purpose:  Run Self-Tests
 ***********************************************************************************/
void Command_SelfTest(unsigned sub_command, unsigned expected_argc, unsigned argc, unsigned *argv) {
	/* Test the RAM */
	TestRAM(0);

#if (SH_PLATFORM == PLATFORM_ASPEN)
	/* Test the Flash */
	// Naresh: Removed this temporarily 
	//TestFlash(0);
#endif (SH_PLATFORM == PLATFORM_ASPEN)

}

/***************************** Cache related functions. **********************/
extern int Set_CCR(unsigned value);
extern int Get_CCR();

void enable_cache(void)
{
	unsigned retval;
	// invalidate cache.
	// Enable cache in Write through mode.
	Set_CCR(0x808);
	retval = Set_CCR(0x103);
	OutputFormatString("Cache enabled. CCR = 0x%X\r\n", retval);
}

void disable_cache(void)
{
	unsigned retval;
	// Invalidate cache.
	retval = Set_CCR(0x808);
	OutputFormatString("Cache disabled. CCR = 0x%X\r\n", retval);
}

void Command_cache_state(void)
{
	unsigned retval;
	retval = Get_CCR();

	OutputFormatString("Cache is %s, CCR = 0x%x\r\n", 
					(retval & 0x103) ? "enabled" : "disabled", retval);
}


void Command_Load(int pport)
{
	unsigned int StartAddr, vAddr;
	func_ptr_t run;

	OutputFormatString("+Command_Load(pport = %d)\r\n", pport);

	enable_cache();

	// If parallel port is defined, try download a bin file thru parallel port
	if(pport) {
		DownloadImage(NULL, &vAddr, 1);
		// TODO: IN DownloadImage, disable cache.
	}
	else {
		// Only SRE files can be download thru serial port at present. 
		// Adding bin files is not difficult. It's just whether it is useful
		// or not. If it is required, i'll put it in later.
		StartAddr = DownloadSreFile(pport); 

		disable_cache();

		if(to_flash) {
			OutputFormatString("\r\nDownload to Flash successful...\r\n");
			OutputFormatString("Please switch off the platform, and flip the switch S1-1 for Flash boot\r\n  to run this image...\r\n");
		}
		else {
			WriteOutput("Download complete. Jumping to Address = 0x%x\r\n", StartAddr);
			// Jump to this image.
			run = (func_ptr_t) StartAddr;

			// Did this to remove warning. Not tested yet.
			(*run)();
		}
	}
	disable_cache();
}

// Get one line from the parallel port.
int ParallelGetLine(char *line, int max)
{
	int result;
	int cb = 0;

	while((cb < max) && (result = OEMParallelPortGetByte()) != -1) {
		cb ++;
		*line = (unsigned char)result;
		if((*line == '\r') || (*line == '\n')) {
			break;
		}
	}
	return cb;	
}

/*--------------------------------------------------------------*/
/* Convert character to hex number                              */
/*                                                              */
/* unsigned char RGetHex(char c)                                */
/*                                                              */
/* return:  converted character or -1 for error                 */
/*--------------------------------------------------------------*/

int
RGetHex (int c)
{
    if (c >= '0' && c <= '9')
      return ((unsigned char) (c - '0'));
    else if (c >= 'A' && c <= 'F')
      return ((unsigned char) (c - ('A' - 10)));
    else if (c >= 'a' && c <= 'f')
      return ((unsigned char) (c - ('a' - 10)));
    else
      return (-1);      /* error */
}

/* Get one character from the parallel port. */
static int gc (int pport) 
{
    char c;
	
	if(pport)
		c = OEMParallelPortGetByte();
	else
		while ((c = OEMReadDebugByte ())==OEM_DEBUG_READ_NODATA);
    return c;
}

void Command_InitDisplay()
{
	/* Before you can initialize the DisplayDriver you need to enumerate the PCI
	 * Bus and enable the display card.
	 */
	// Command_Enumerate();
	DispDrvrInitialize();
}

/* Get two bytes from the parallel port and convert them into a hex number */
static int
getbyte (int pport)
{
    char c = gc (pport);
    unsigned int high = RGetHex (c);
    c = gc (pport);
    return (high << 4) | RGetHex (c);

}

/******************************************************************************
 * Function: Command_Copy
 * Input:    int expected_args: Number of arguments required by this command
 *			 int argc: Actual number of arguments passed.
 *			 unsigned *argv: Pointer to the arguments.
 * Output:   None.
 *****************************************************************************/
void Command_Copy(unsigned sub_command, unsigned expected_argc, unsigned argc, unsigned *argv)
{
	unsigned char *src;
	unsigned char *dst;
	unsigned count;

	WriteDbgOutput(DEB_FLOW, ("+Command_Copy(expected_argc=%d, argc=%d, argv=0x%x)\n", expected_argc, argc, argv));

	if(argc != expected_argc) {
		WriteOutput("Command_Copy called with invalid number of arguments (%d).\n", argc);
		return;
	}

	src = (unsigned char *)argv[0];
	dst = (unsigned char *)argv[1];
	count = argv[2];

	WriteOutput("copying 0x%x bytes from 0x%x to 0x%x...\n", count, src, dst);

	if(count == 0)
		return;
	
	/* If src, dst and count are 4 byte aligned, make the copying 4 times faster
	 * by copying longs instead of bytes.
	 * This is very useful when you copy large chunks of data.
	 */
	if( ! (((unsigned)dst | (unsigned)src | count) & 0x3) ) {
		unsigned long *slong = (unsigned long *)src;
		unsigned long *dlong = (unsigned long *)dst;

		WriteDbgOutput(DEB_FLOW, ("-Source, destination, count are 4 byte aligned. Copying longs instead of bytes\n"));
		count = count / 4;
		while(count --) {
			*dlong ++ = *slong ++;
		}
		WriteDbgOutput(DEB_FLOW, ("-Command_Copy()\n"));
		return;
	}

	while(count --) {
		*dst ++ = *src ++;
	}
	WriteDbgOutput(DEB_FLOW, ("-Command_Copy()\n"));
}

/******************************************************************************
 * Function: Command_Fill
 * Input:    int expected_args: Number of arguments required by this command
 *			 int argc: Actual number of arguments passed.
 *			 unsigned *argv: Pointer to the arguments.
 * Output:   None.
 *****************************************************************************/
void Command_Fill(unsigned sub_command, unsigned expected_argc, unsigned argc, unsigned *argv)
{
	unsigned *src;
	unsigned count;
	unsigned data;

	WriteDbgOutput(DEB_FLOW, ("+Command_Fill(expected_argc=%d, argc=%d, argv=0x%x)\n", expected_argc, argc, argv));

	if(argc != expected_argc) {
		WriteOutput("Command_Fill called with invalid number of arguments (%d).\n", argc);
		return;
	}

	src = (unsigned *)argv[0];
	data = (unsigned) argv[1];
	count = argv[2];

	/* Align count and src. */
	if(count % 4 != 0) 
		count = count / 4 + 1;
	else
		count = count / 4;

	src = (unsigned *) ( (unsigned)src & ~0x3) ;

	WriteOutput("Filling 0x%x bytes starting at 0x%x with 0x%x\n", count*4, src, data);

	if(count == 0)
		return;

	
	while(count --) {
		*src ++ = data;
	}
	WriteDbgOutput(DEB_FLOW, ("-Command_Copy()\n"));
}

/* Command Related to PCI */
void OEM_WriteConfigDword( DWORD dwBusNo, DWORD dwDevNo, DWORD dwFuncNo, DWORD dwOffset, DWORD dwData );
void OEM_ReadConfigDword( DWORD dwBusNo, DWORD dwDevNo, DWORD dwFuncNo, DWORD dwOffset, DWORD *pdwData );

/******************************************************************************
 * Function: Command_Scan
 * Input:    int expected_args: Number of arguments required by this command
 *			 int argc: Actual number of arguments passed.
 *			 unsigned *argv: Pointer to the arguments.
 * Output:   None.
 *****************************************************************************/
void Command_Scan(unsigned sub_command, unsigned expected_argc, unsigned argc, unsigned *argv)
{
	unsigned val;
	int i;
	int RIODevNo = 0;
	WriteDbgOutput(DEB_FLOW, ("+Command_Go(expected_argc=%d, argc=%d, argv=0x%x)\n", expected_argc, argc, argv));

	// Look up the PCI bus, idsel 3 and get device ID and vendor ID
	for(i = 0; i < 21; i ++) {
		OEM_ReadConfigDword( 0, i, 0, 0x0, &val);
		WriteOutput("DevNo = %d, Device ID = 0x%x, Vendor ID = 0x%x\n", i, val >> 16, val & 0xFFFF);
		if( 0x8086 == (val & 0xffff) )
		{
			RIODevNo = i;
		}
	}

	// Some trial code on the RIO Card.
	// void OEM_ReadConfigDword( DWORD dwBusNo, DWORD dwDevNo, DWORD dwFuncNo, DWORD dwOffset, DWORD *pwData );
#if 1
	if(RIODevNo != 0) {
		WriteOutput("RIO Card found at Device Number %d\n", RIODevNo);

		// Get Status, Command register on the card
		OEM_ReadConfigDword( 0, RIODevNo, 0, 0x4, &val);
		WriteOutput("Status = 0x%H, Command = 0x%H\n", val >> 16, val & 0xFFFF);

		OEM_ReadConfigDword( 0, RIODevNo, 0, 0x8, &val);
		WriteOutput("Class Code, Rev ID = 0x%X\n", val);

		OEM_ReadConfigDword( 0, RIODevNo, 0, 0xc, &val);
		WriteOutput("BIST, HT, LT, CLS = 0x%X\n", val);
		
	}
#endif
}


void Command_RCD(unsigned sub_command, unsigned expected_argc, unsigned argc, unsigned *argv)
{
	unsigned bus, dev, fun, off;
	unsigned data;
	if(expected_argc != argc) {
		WriteOutput("Command_RCD. Error: expected_argc = %d, argc = %d\n", expected_argc, argc);
		return;
	}

	bus = argv[0];
	dev = argv[1];
	fun = argv[2];
	off = argv[3];

	if(sub_command == 0) {
		OEM_ReadConfigDword(bus, dev, fun, off, &data);
		WriteOutput("Bus:%x, Dev:%x, Fun:%x, Off:%x, Data=" F_L "\n", bus, dev, fun, off, data);
	}
	if(sub_command == 1) {
		data = argv[4];
		OEM_WriteConfigDword(bus, dev, fun, off, data);
	}
}

int my_RAW, my_TP, my_Single;
/******************************************************************************
 * Function: SDBTEST_Single
 * Input:    int expected_args: Number of arguments required by this command
 *			 int argc: Actual number of arguments passed.
 *			 unsigned *argv: Pointer to the arguments.
 * Output:   None.
 *****************************************************************************/
void SDBTEST_Single(unsigned sub_command, unsigned expected_argc, unsigned argc, unsigned *argv)
{
	int size, phase;

	if(expected_argc != argc) {
		WriteOutput("Command_SDBTEST_Single. Error: expected_argc = %d, argc = %d\n", expected_argc, argc);
		return;
	}

	switch(argv[0]) {
		case 1:
		case 2:
		case 4:
			break;

		default:
			WriteOutput("SDBTEST_Single: Wrong data size: Valid values are 1,2,4\n", phase, size);
			break;
	}

	my_RAW = size = argv[0] * 8;
	my_TP = phase = argv[1];

	WriteOutput("+Testing Phase %d size %d bytes\n", phase, size);

	my_Single = 1;
	
	SDBTEST_main();

	my_Single = 0;
}

#include "pci.h"

int RIO_Initialize(unsigned sub_command, unsigned expected_argc, unsigned argc, unsigned *argv) 
{
	unsigned val;
	int i;
	int RIODevNo = 0;
	unsigned dwPCISharedRAMBase;
	PCIDevAddrRec RIO, *pRIO; 
	unsigned dwRIOContigRAMSize = 0x100000;
	unsigned bRAMAccessWidth = 4;
	unsigned bRAMTestPhase = 0;

	/* Initialize the PCI host bridge. */
	OEM_InitPCIHostBridge( ) ;

	// Look up the PCI bus, find a RIO device.
	for(i = 0; i < 21; i ++) {
		OEM_ReadConfigDword( 0, i, 0, 0x0, &val);
		WriteOutput("DevNo = %d, Device ID = 0x%x, Vendor ID = 0x%x\n", i, val >> 16, val & 0xFFFF);
		if( 0x8086 == (val & 0xffff) )
		{
			RIODevNo = i;
		}
	}

	if(RIODevNo != 0) {
		WriteOutput("Found RIO card. Device Number = %d\n", RIODevNo);
		pRIO = &RIO;
		/* Initialize the RIO Data structure */
		RIO.bBusNo = 0;
		RIO.bDevNo = RIODevNo;
		RIO.bParentDevNo = 0xFF;

		ClearPCIBridgeStatus( pRIO );
		// Do a dummy read and write on the RIO.
		OEM_ReadConfigDword( 0, i, 0, 0x0, &val);
		GetPCIBridgeStatus(pRIO);
		ClearPCIBridgeStatus( pRIO );
		OEM_WriteConfigDword( 0, i, 0, 0xc, 0xFF);
		GetPCIBridgeStatus(pRIO);
		ClearPCIBridgeStatus( pRIO );

⌨️ 快捷键说明

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