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

📄 monitor.c

📁 WinCE 3.0 BSP, 包含Inter SA1110, Intel_815E, Advantech_PCM9574 等
💻 C
📖 第 1 页 / 共 5 页
字号:
		stat = KBD_STAT;

	KBD_DATA = 0x07;
#endif

	return 0;
}

/*****************************************************************************
 * Function: GetKbdMouse
 * Gets data from keyboard or mouse 
 *****************************************************************************/
int Command_GetKbdMouse()
{
#if ((SH_PLATFORM == PLATFORM_ASPEN)||(SH_PLATFORM==PLATFORM_BIGSUR))
	/* Wait for 3 data items */
	OutputFormatString("Unimplemented yet...\r\n");

	return 0;

#else ((SH_PLATFORM == PLATFORM_ASPEN)||(SH_PLATFORM==PLATFORM_BIGSUR))
	unsigned short stat;
	unsigned short mask;
	unsigned char ctmp;
	
	WriteDbgOutput(DEB_FLOW, ("+GetKbdMouse()\n"));

	/* See whether interrupts are masked on keybd/mouse. */
	if( (INTR_MASK & (KBD_INTR | MOUSE_INTR)) ) {
		WriteOutput("GetKbdMouse called with interrupts on keybd/mouse masked. mask = 0x%x\n", INTR_MASK);
		return;
	}

	stat = INTR_STAT;
	/* Check out the interrupt status register to see whether you got any interrupts */
	while( !(stat & (KBD_INTR | MOUSE_INTR))) { 
		// WriteDbgOutput(DEB_KBD, ("stat=0x%x\n", stat));
		stat = INTR_STAT;
	}

	/* Check whether it is a keybd or a mouse interrupt. */
	if(stat & KBD_INTR) {
		WriteDbgOutput(DEB_KBD, ("Keyboard interrupt...\n"));

		/* Get Data from keyboard. */
		stat = KBD_STAT; while(0x02 & KBD_STAT);
		KBD_STAT = 0x60;
		stat = KBD_STAT; while(0x02 & KBD_STAT);
		KBD_DATA = 0x34;
		stat = KBD_STAT; while(0x02 & KBD_STAT);
		ctmp = KBD_DATA;
		stat = KBD_STAT; while(0x01 & KBD_STAT);

		ctmp = KBD_DATA;
		WriteDbgOutput(DEB_KBD, ("data = 0x%x\n", ctmp));

		/* Clear Keyboard interrupt. */
		KbdMouseInterruptEnable();
	}
	else if(stat & MOUSE_INTR) {
		WriteDbgOutput(DEB_KBD, ("Mouse interrupt...\n"));

		/* Get Data from keyboard. */

		/* Clear Keyboard interrupt. */
		KbdMouseInterruptEnable();
	}
	return 0;
#endif ((SH_PLATFORM == PLATFORM_ASPEN)||(SH_PLATFORM==PLATFORM_BIGSUR))
}

#endif TEST_KBD

   typedef unsigned int uint32;
   typedef void (*start_func)() ;


/* arg == 1: look for executable at 80010000.
 *        0: look at specified address. */
int nano_main(int arg, unsigned argc, unsigned *argv)
{
   uint32 i;               //32-bit unsigned int
   uint32 stored_size;
   uint32 *ram_ptr;         //pointer to 32-bit unsigned int
   uint32 *flash_ptr;
   uint32 *size_ptr, *bias_ptr, *image_ptr;
   start_func *start_ptr;
   start_func startup_entry;

	uint32 offset_image;

	WriteDbgOutput(DEB_FLOW, ("+nano_main(arg=%d, argc=%d, argv=0x%x0)\n", arg, argc, argv));

	if(arg == 0) {
		offset_image = 0x80010000;
	}
	else if(arg == 1) {
		offset_image = argv[0];
	}
	else {
		WriteOutput("Unknown option passed to nano_main\n");
		return 1;
	}


   flash_ptr   = (uint32 *)   offset_image;  // start of ram block

   bias_ptr  = (uint32 *)     (offset_image + 0x10);  // physical address bias
   image_ptr = (uint32 *)     (offset_image + 0x14);  // physical address of image

   size_ptr  = (uint32 *)     (offset_image + 0x24);  // location of stored_size field
   start_ptr = (start_func *) (offset_image + 0xc);  // location of startup_vaddr field

	WriteDbgOutput(DEB_INFO, ("*flash_ptr=0x%x, *size_ptr=0x%x\n", *flash_ptr, *size_ptr));

   if ( *flash_ptr == (uint32)0x00ff7eeb ) {

      ram_ptr = (uint32 *)(*bias_ptr + *image_ptr);


      stored_size = *size_ptr;

      startup_entry = *start_ptr;

		WriteDbgOutput(DEB_INFO, ("flash_ptr=0x%x, ram_ptr=0x%x, stored_size=0x%x, startup_entry=0x%x\n", flash_ptr, ram_ptr, stored_size, startup_entry));

      for (i=0; i<stored_size; i+=4) {
              *ram_ptr++ = *flash_ptr++;
      }

      startup_entry();

      return 0;

   }else {

	  	if(arg == 1) {
			WriteOutput("Invalid signature of the image *(0x%x) = 0x%x\n", flash_ptr, *flash_ptr);
		}
      return 1;

   }
}

void Command_TestVM(void)
{
	TestWriteVideoMem();
}

unsigned MemoryWriteLong(unsigned addr, unsigned data)
{
	*(volatile unsigned *)addr = data;
	return 0;
}

unsigned MemoryReadLong(unsigned addr)
{
	return *(volatile unsigned *)addr;
}

// Prototypes for Ethernet memory read/write functions.
// Actual functions appear in the Ethernet section of this file
int EthMemoryWriteLong(unsigned addr, unsigned data);
unsigned EthMemoryReadLong(unsigned addr);

/* There are two ways this routine can be called.
 *   Normal:  Thru the command line on the debugger by the command mt.
 *   Special: Eg. Thru the command emt, which is testing of ethernet card SRAM
 * 
 * If expected_argc is 0, it means that it is not the Normal invocation of the
 * command. in that case, argc contains the subcode of the command.
 *  Valid values for argc are :-
 *        1: Test all SDRAM
 *        2: Test Video Memory
 *        3: Test Ethernet SRAM
 */
void Command_Test_Memory(unsigned sub_command, unsigned expected_argc, unsigned argc, unsigned *argv)
{
	unsigned start, end, tmp, tmpend;
	unsigned val, ret;
	func_ptr_t read_func, write_func;
	unsigned WalkAddressBits = 1;		// Do we test out walking on address bits also (or only data bits)
	unsigned ExhaustiveTest = 1;		// Test first 64 k of memory exhaustively.
	unsigned ContinuousTest = 0;
	int error = 0;						// Did an error occur.
	
	// Default memory read and write functions.
	read_func = MemoryReadLong;
	write_func = MemoryWriteLong;

	// If the user just gave the command, "mt" test out all sdram.
	// Set values so that it goes into test SDRAM case of switch stmt.
	if(argc == 0) {
		expected_argc = 0;
		argc = 1;
	}

	// Check to see whether it is a special invocation. 
	if(expected_argc == 0) {
		switch(argc) {
			case 1:
				// Test out full SDRAM
				start = 0xad000000;
				end   = 0xae000000;
				break;

			case 2:
				// Unimplemented yet.
				WriteOutput("Not implemented yet.\n");
				return;
		
			case 3:
				// Test out Ethernet chip's SRAM
				read_func = EthMemoryReadLong;
				write_func = EthMemoryWriteLong;
				start = 0x0;
				end   = (2 * 1024);	// 2k to begin with. Actually 128k
				WalkAddressBits = 0;
				ExhaustiveTest = 0;
				ContinuousTest = 1;
				break;

			default:
				WriteOutput("Not implemented yet.\n");
				return;
		}
	}
	else if(expected_argc == argc) {
		// Align start and end on 64 bit (8 byte) boundary.
		start = (argv[0] | 0xA0000000) & 0xFFFFFFF8; // Always perform the tests in uncached, unmapped region.
		end   = (argv[1] | 0xA0000000) & 0xFFFFFFF8;
	}
	else {
		WriteOutput("Command_Test_Memory called with invalid number of arguments (%d).\r\n", argc);
		return;
	}

do {
	WriteOutput("Testing memory from 0x%x to 0x%x...\r\n", start, end);
	if(start >= end) {
		WriteOutput("Memory chunk specified is too less to test. Must be at least 8 bytes big\r\n");
		return;
	}

	// Write 0xFF... to 64 bits of data.
	WriteOutput("Check any bit tied to 0...");	
	write_func(start, 0xFFFFFFFF);
	write_func(start+4, 0xFFFFFFFF);

	// Read back.
	if( ( (ret = read_func(start)) != 0xFFFFFFFF) ) {
		WriteOutput("\r\nError: Bits that are 0 in 0x%x are tied to 0 at addr 0x%x\r\n", ret, start);
		error = 1;
		// return;
	}

	if( ( (ret = read_func(start+4)) != 0xFFFFFFFF) ) {
		WriteOutput("\r\nError: Bits that are 0 in 0x%x are tied to 0 at addr 0x%x\r\n", ret,  start+4);
		error = 1;
		// return;
	}
	WriteOutput("Done.\r\n");	

	// Write 0x00... to 64 bits of data.
	WriteOutput("Check any bit tied to 1...");	
	write_func(start, 0x00000000);
	write_func(start+4, 0x00000000);

	// Read back.
	if( ( (ret = read_func(start)) != 0x00000000) ) {
		WriteOutput("\r\nError: Bits that are 1 in 0x%x are tied to 1 at addr 0x%x\r\n", ret, start);
		error = 1;
		// return;
	}

	if( ( (ret = read_func(start+4)) != 0x00000000) ) {
		WriteOutput("\r\nError: Bits that are 1 in 0x%x are tied to 1 at addr 0x%x\r\n", ret,  start+4);
		error = 1;
		// return;
	}
	WriteOutput("Done.\r\n");	

	// Write 0xFF... to 64 bits of data.
	WriteOutput("Check any two adjacent pins tied together by writing 0x55555555...");	
	write_func(start, 0x55555555);
	write_func(start+4, 0x55555555);

	// Read back.
	if( ( (ret = read_func(start)) != 0x55555555) ) {
		WriteOutput("\r\nError: Adjacent pins shorted. Got 0x%x at addr 0x%x instead of 0x55555555.\r\n", ret, start);
		error = 1;
		// return;
	}

	if( ( (ret = read_func(start+4)) != 0x55555555) ) {
		WriteOutput("\r\nError: Adjacent pins shorted. Got 0x%x at addr 0x%x instead of 0x55555555.\r\n", ret,  (start+4) );
		error = 1;
		// return;
	}
	WriteOutput("Done.\r\n");	

	// Write 0xFF... to 64 bits of data.
	WriteOutput("Check any two pins adjacent tied together by writing 0xAAAAAAAA...");	
	write_func(start, 0xAAAAAAAA);
	write_func(start+4, 0xAAAAAAAA);

	// Read back.
	if( ( (ret = read_func(start)) != 0xAAAAAAAA) ) {
		WriteOutput("\r\nError: Adjacent pins shorted. Got 0x%x at addr 0x%x instead of 0xAAAAAAAA.\r\n", ret, start);
		error = 1;
		// return;
	}

	if( ( (ret = read_func(start+4)) != 0xAAAAAAAA) ) {
		WriteOutput("\r\nError: Adjacent pins shorted. Got 0x%x at addr 0x%x instead of 0xAAAAAAAA.\r\n", ret,  (start+4) );
		error = 1;
		// return;
	}
	WriteOutput("Done.\r\n");	

	// If there was an error till this stage, no point in contnuing further.
	if(error)
		return;

	WriteOutput("Walking 1...");
	val = 0;
	do {
		// Initial value of val
		if(val == 0)
			val = 1;
		else
			val <<= 1;

		// WriteOutput("Writing 0x%x to 0x%x\r\n", val ,start);
		write_func(start, val);
		write_func(start+4, val);

		// Read back.
		if( ( (ret = read_func(start)) != val) ) {
			WriteOutput("\r\nError: Walking 1 test failed. Wrote 0x%x, got back 0x%x at addr 0x%x.\r\n", val, ret, start);
			error = 1;
			// return;
		}
	
		if( ( (ret = read_func(start+4)) != val) ) {
			WriteOutput("\r\nError: Walking 1 test failed. Wrote 0x%x, got back 0x%x at addr 0x%x.\r\n", val, ret, start+4);
			error = 1;
			// return;
		}

	} while(val != 0x80000000);
	WriteOutput("Done.\r\n");

	WriteOutput("Walking 0...");
	val = 0;
	do {
		// Initial value of val
		if(val == 0)
			val = 0xFFFFFFFE;
		else
			val = (val << 1) | 1;

		// WriteOutput("Writing 0x%x to 0x%x\r\n", val ,start);
		write_func(start, val);
		write_func(start+4, val);

		// Read back.
		if( ( (ret = read_func(start)) != val) ) {
			WriteOutput("\r\nError: Walking 1 test failed. Wrote 0x%x, got back 0x%x at addr 0x%x.\r\n", val, ret, start);
			error = 1;
			// return;
		}
	
		if( ( (ret = read_func(start+4)) != val) ) {
			WriteOutput("\r\nError: Walking 1 test failed. Wrote 0x%x, got back 0x%x at addr 0x%x.\r\n", val, ret, start+4);
			error = 1;
			// return;
		}

	} while(val != 0xEFFFFFFF);

	WriteOutput("Done.\r\n");

	if(error)
		return;


  // Now do testing on Address bits, by dividing the address range into 64 k chunks.
  if(WalkAddressBits == 1) {

	// Align both start and end to a 64 k boundary.
	start = start & 0xFFFF0000;
	end   = end   & 0xFFFF0000;

	WriteOutput("Testing address bits from 0x%x to 0x%x...", start, end);

	// Write all locations.
	tmp = start;

	do {
		write_func(tmp, tmp);
		tmp = tmp + 0x10000;
	} while (tmp < end);

	// Now read back
	tmp = start;

	do {
		if( (ret = read_func(tmp)) != (unsigned) tmp ) {
			WriteOutput("\r\nError: Walking Address bits test failed. Wrote 0x%x, got back 0x%x at addr 0x%x.\r\n", tmp, ret, tmp);
			// r

⌨️ 快捷键说明

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