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

📄 main.c

📁 支持三星原产的S3C2413开发板
💻 C
📖 第 1 页 / 共 5 页
字号:
						   (LCD_VFPD			<<  6) |   /* VFPD		  :   2							  */
						   (LCD_VSPW			<<  0) ;   /* VSPW		  :   1							  */

	s2413LCD->LCDCON3   =  (LCD_HBPD		<< 19) |   /* HBPD		  :   6							  */
						   (LCD_HOZVAL_TFT  	<<  8) |   /* HOZVAL_TFT	: 240 - 1						  */
						   (LCD_HFPD			<<  0) ;   /* HFPD		  :   2							  */


	s2413LCD->LCDCON4   =  (LCD_MVAL		<<  8) |   /* MVAL		  :  13							  */
						   (LCD_HSPW			<<  0) ;   /* HSPW		  :   4							  */

	s2413LCD->LCDCON5   =  (0	   << 12) |	   /* BPP24BL	   : LSB valid						*/
						   (1		   << 11) |	   /* FRM565 MODE   : 5:6:5 Format					 */
						   (0		   << 10) |	   /* INVVCLK	   : VCLK Falling Edge				*/
						   (1		   <<  9) |	   /* INVVLINE	  : Inverted Polarity				*/
						   (1		   <<  8) |	   /* INVVFRAME	 : Inverted Polarity				*/
						   (0		   <<  7) |	   /* INVVD		 : Normal						   */
						   (0		   <<  6) |	   /* INVVDEN	   : Normal						   */
						   (0		   <<  5) |	   /* Reserved : should be '0'. before, INVPWREN	  : Normal						   */
						   (0		   <<  4) |	   /* INVENDLINE	: Normal						   */
						   (0/*1*/		<<  3) |	/* Reserved : should be '0'. before, PWREN		 : Disable PWREN					*/
						   (0		   <<  2) |	   /* ENLEND		: Disable LEND signal			  */
						   (0		   <<  1) |	   /* BSWP		  : Swap Disable					 */
						   (1		   <<  0) ;	   /* HWSWP		 : Swap Enable					  */

	s2413LCD->LCDSADDR1 = ((IMAGE_FRAMEBUFFER_DMA_BASE >> 22)	 << 21) | 
						  ((M5D(IMAGE_FRAMEBUFFER_DMA_BASE >> 1)) <<  0);

	s2413LCD->LCDSADDR2 = M5D((IMAGE_FRAMEBUFFER_DMA_BASE + (LCD_XSIZE_TFT * LCD_YSIZE_TFT * 2)) >> 1);

	s2413LCD->LCDSADDR3 = (((LCD_XSIZE_TFT - LCD_XSIZE_TFT) / 1) << 11) | (LCD_XSIZE_TFT / 1);		

	s2413LCD->LCDINTMSK|=(3); // MASK LCD Sub Interrupt
#ifdef SMDK2413_REV14
	s2413LCD->TCONSEL = 0;
#else
	s2413LCD->TCONSEL&=(~7); // Disable LPC3600
#endif
	s2413LCD->TPAL=0; // Disable Temp Palette
	// Display a bitmap image on the LCD...
	//
	//memcpy((void *)IMAGE_FRAMEBUFFER_UA_BASE, ScreenBitmap, LCD_ARRAY_SIZE_TFT_16BIT);

	s2413LCD->LCDCON1|=1; // ENVID=ON
	
	//while (1) ;//

}
//================================================================

/*
	@func   void | SetIP | Accepts IP address from user input.
	@rdesc  N/A.
	@comm	
	@xref   
*/

static void SetIP(PBOOT_CFG pBootCfg)
{
	CHAR   szDottedD[16];   // The string used to collect the dotted decimal IP address.
	USHORT cwNumChars = 0;
	USHORT InChar = 0;

	EdbgOutputDebugString("\r\nEnter new IP address: ");

	while(!((InChar == 0x0d) || (InChar == 0x0a)))
	{
		InChar = OEMReadDebugByte();
		if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA) 
		{
			// If it's a number or a period, add it to the string.
			//
			if (InChar == '.' || (InChar >= '0' && InChar <= '9')) 
			{
				if (cwNumChars < 16) 
				{
					szDottedD[cwNumChars++] = (char)InChar;
					OEMWriteDebugByte((BYTE)InChar);
				}
			}
			// If it's a backspace, back up.
			//
			else if (InChar == 8) 
			{
				if (cwNumChars > 0) 
				{
					cwNumChars--;
					OEMWriteDebugByte((BYTE)InChar);
				}
			}
		}
	}

	// If it's a carriage return with an empty string, don't change anything.
	//
	if (cwNumChars) 
	{
		szDottedD[cwNumChars] = '\0';
		pBootCfg->EdbgAddr.dwIP = inet_addr(szDottedD);
	}
}


/*
	@func   void | SetMask | Accepts subnet mask from user input.
	@rdesc  N/A.
	@comm	
	@xref   
*/
static void SetMask(PBOOT_CFG pBootCfg)
{
	CHAR szDottedD[16]; // The string used to collect the dotted masks.
	USHORT cwNumChars = 0;
	USHORT InChar = 0;

	EdbgOutputDebugString("\r\nEnter new subnet mask: ");

	while(!((InChar == 0x0d) || (InChar == 0x0a)))
	{
		InChar = OEMReadDebugByte();
		if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA) 
		{
			// If it's a number or a period, add it to the string.
			//
			if (InChar == '.' || (InChar >= '0' && InChar <= '9')) 
			{
				if (cwNumChars < 16) 
				{
					szDottedD[cwNumChars++] = (char)InChar;
					OEMWriteDebugByte((BYTE)InChar);
				}
			}
			// If it's a backspace, back up.
			//
			else if (InChar == 8) 
			{
				if (cwNumChars > 0) 
				{
					cwNumChars--;
					OEMWriteDebugByte((BYTE)InChar);
				}
			}
		}
	}

	// If it's a carriage return with an empty string, don't change anything.
	//
	if (cwNumChars) 
	{
		szDottedD[cwNumChars] = '\0';
		pBootCfg->SubnetMask = inet_addr(szDottedD);
	}
}


/*
	@func   void | SetDelay | Accepts an autoboot delay value from user input.
	@rdesc  N/A.
	@comm	
	@xref   
*/
static void SetDelay(PBOOT_CFG pBootCfg)
{
	CHAR szCount[16];
	USHORT cwNumChars = 0;
	USHORT InChar = 0;

	EdbgOutputDebugString("\r\nEnter maximum number of seconds to delay [1-255]: ");

	while(!((InChar == 0x0d) || (InChar == 0x0a)))
	{
		InChar = OEMReadDebugByte();
		if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA) 
		{
			// If it's a number or a period, add it to the string.
			//
			if ((InChar >= '0' && InChar <= '9')) 
			{
				if (cwNumChars < 16) 
				{
					szCount[cwNumChars++] = (char)InChar;
					OEMWriteDebugByte((BYTE)InChar);
				}
			}
			// If it's a backspace, back up.
			//
			else if (InChar == 8) 
			{
				if (cwNumChars > 0) 
				{
					cwNumChars--;
					OEMWriteDebugByte((BYTE)InChar);
				}
			}
		}
	}

	// If it's a carriage return with an empty string, don't change anything.
	//
	if (cwNumChars) 
	{
		szCount[cwNumChars] = '\0';
		pBootCfg->BootDelay = atoi(szCount);
		if (pBootCfg->BootDelay > 255)
		{
			pBootCfg->BootDelay = 255;
		} 
		else if (pBootCfg->BootDelay < 1)
		{
			pBootCfg->BootDelay = 1;
		}
	}
}


static ULONG mystrtoul(PUCHAR pStr, UCHAR nBase)
{
	UCHAR nPos=0;
	BYTE c;
	ULONG nVal = 0;
	UCHAR nCnt=0;
	ULONG n=0;

	// fulllibc doesn't implement isctype or iswctype, which are needed by
	// strtoul, rather than including coredll code, here's our own simple strtoul.

	if (pStr == NULL)
		return(0);

	for (nPos=0 ; nPos < strlen(pStr) ; nPos++)
	{
		c = tolower(*(pStr + strlen(pStr) - 1 - nPos));
		if (c >= '0' && c <= '9')
			c -= '0';
		else if (c >= 'a' && c <= 'f')
		{
			c -= 'a';
			c  = (0xa + c);
		}

		for (nCnt = 0, n = 1 ; nCnt < nPos ; nCnt++)
		{
			n *= nBase;
		}
		nVal += (n * c);
	}

	return(nVal);
}


static void CvtMAC(USHORT MacAddr[3], char *pszDottedD ) 
{
	DWORD cBytes;
	char *pszLastNum;
	int atoi (const char *s);
	int i=0;	
	BYTE *p = (BYTE *)MacAddr;

	// Replace the dots with NULL terminators
	pszLastNum = pszDottedD;
	for(cBytes = 0 ; cBytes < 6 ; cBytes++)
	{
		while(*pszDottedD != '.' && *pszDottedD != '\0')
		{
			pszDottedD++;
		}
		if (pszDottedD == '\0' && cBytes != 5)
		{
			// zero out the rest of MAC address
			while(i++ < 6)
			{
				*p++ = 0;
			}
			break;
		}
		*pszDottedD = '\0';
		*p++ = (BYTE)(mystrtoul(pszLastNum, 16) & 0xFF);
		i++;
		pszLastNum = ++pszDottedD;
	}
}


static void SetCS8900MACAddress(PBOOT_CFG pBootCfg)
{
	CHAR szDottedD[24];
	USHORT cwNumChars = 0;
	USHORT InChar = 0;

	memset(szDottedD, '0', 24);

	EdbgOutputDebugString ( "\r\nEnter new MAC address in hexadecimal (hh.hh.hh.hh.hh.hh): ");

	while(!((InChar == 0x0d) || (InChar == 0x0a)))
	{
		InChar = OEMReadDebugByte();
		InChar = tolower(InChar);
		if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA) 
		{
			// If it's a hex number or a period, add it to the string.
			//
			if (InChar == '.' || (InChar >= '0' && InChar <= '9') || (InChar >= 'a' && InChar <= 'f')) 
			{
				if (cwNumChars < 17) 
				{
					szDottedD[cwNumChars++] = (char)InChar;
					OEMWriteDebugByte((BYTE)InChar);
				}
			}
			else if (InChar == 8)	   // If it's a backspace, back up.
			{
				if (cwNumChars > 0) 
				{
					cwNumChars--;
					OEMWriteDebugByte((BYTE)InChar);
				}
			}
		}
	}

	EdbgOutputDebugString ( "\r\n");

	// If it's a carriage return with an empty string, don't change anything.
	//
	if (cwNumChars) 
	{
		szDottedD[cwNumChars] = '\0';
		CvtMAC(pBootCfg->EdbgAddr.wMAC, szDottedD);

		EdbgOutputDebugString("INFO: MAC address set to: %x:%x:%x:%x:%x:%x\r\n",
				  pBootCfg->EdbgAddr.wMAC[0] & 0x00FF, pBootCfg->EdbgAddr.wMAC[0] >> 8,
				  pBootCfg->EdbgAddr.wMAC[1] & 0x00FF, pBootCfg->EdbgAddr.wMAC[1] >> 8,
				  pBootCfg->EdbgAddr.wMAC[2] & 0x00FF, pBootCfg->EdbgAddr.wMAC[2] >> 8);
	}
	else
	{
		EdbgOutputDebugString("WARNING: SetCS8900MACAddress: Invalid MAC address.\r\n");
	}
}


/*
	@func   BOOL | MainMenu | Manages the Samsung bootloader main menu.
	@rdesc  TRUE == Success and FALSE == Failure.
	@comm	
	@xref   
*/

static BOOL MainMenu(PBOOT_CFG pBootCfg)
{
	BYTE KeySelect = 0;
	BOOL bConfigChanged = FALSE;
	BOOLEAN bDownload = TRUE;
	int i=0;

	// DonGo test
	g_pBootCfg->EdbgAddr.dwIP = 0x264a8c0;	// 192.168.100.2
	g_pBootCfg->SubnetMask = 0xffffff;		// 255.255.255.0
	g_pBootCfg->EdbgAddr.wMAC[0] = 0x33<<8 | 0x22<<0;
	g_pBootCfg->EdbgAddr.wMAC[1] = 0x55<<8 | 0x44<<0;
	g_pBootCfg->EdbgAddr.wMAC[2] = 0x77<<8 | 0x66<<0;	

	while(TRUE)
	{
		KeySelect = 0;

		EdbgOutputDebugString ( "\r\nEthernet Boot Loader Configuration:\r\n\r\n");
		EdbgOutputDebugString ( "0) IP address: %s\r\n",inet_ntoa(pBootCfg->EdbgAddr.dwIP));
		EdbgOutputDebugString ( "1) Subnet mask: %s\r\n", inet_ntoa(pBootCfg->SubnetMask));
		EdbgOutputDebugString ( "2) DHCP: %s\r\n", (pBootCfg->ConfigFlags & CONFIG_FLAGS_DHCP)?"Enabled":"Disabled");
		EdbgOutputDebugString ( "3) Boot delay: %d seconds\r\n", pBootCfg->BootDelay);
		EdbgOutputDebugString ( "4) Reset to factory default configuration\r\n");
		EdbgOutputDebugString ( "5) Startup image: %s\r\n", (g_pBootCfg->ConfigFlags & BOOT_TYPE_DIRECT) ? "LAUNCH EXISTING" : "DOWNLOAD NEW");
		EdbgOutputDebugString ( "6) Program disk image into SmartMedia card: %s\r\n", (pBootCfg->ConfigFlags & TARGET_TYPE_NAND)?"Enabled":"Disabled");
		EdbgOutputDebugString ( "7) Program CS8900 MAC address (%B:%B:%B:%B:%B:%B)\r\n",
							   g_pBootCfg->EdbgAddr.wMAC[0] & 0x00FF, g_pBootCfg->EdbgAddr.wMAC[0] >> 8,
							   g_pBootCfg->EdbgAddr.wMAC[1] & 0x00FF, g_pBootCfg->EdbgAddr.wMAC[1] >> 8,
							   g_pBootCfg->EdbgAddr.wMAC[2] & 0x00FF, g_pBootCfg->EdbgAddr.wMAC[2] >> 8);
		EdbgOutputDebugString ( "8) Kernel Debugger: %s\r\n", (g_pBootCfg->ConfigFlags & CONFIG_FLAGS_DEBUGGER) ? "ENABLED" : "DISABLED");
		EdbgOutputDebugString ( "9) Format Boot Media for BinFS\r\n");

		// N.B: we need this option here since BinFS is really a RAM image, where you "format" the media
		// with an MBR. There is no way to parse the image to say it's ment to be BinFS enabled.
		EdbgOutputDebugString ( "F) Low-level format the Smart Media card\r\n");
		EdbgOutputDebugString ( "D) Download image now\r\n");
		EdbgOutputDebugString ( "L) LAUNCH existing Boot Media image\r\n");
		EdbgOutputDebugString ( "R) Read Configuration \r\n");
        	EdbgOutputDebugString ( "U) DOWNLOAD image now(USB)\r\n");
		EdbgOutputDebugString ( "W) Write Configuration Right Now\r\n");
		EdbgOutputDebugString ( "C) Erase NAND Block 0\r\n");
//EdbgOutputDebugString ( "N) Read NAND Pages\r\n");
		EdbgOutputDebugString ( "A) Erase Eboot Block[%d~%d]\r\n", EBOOT_BLOCK, RESERVED_BOOT_BLOCKS);	
		EdbgOutputDebugString ( "M) clear sdMemory \r\n");
		EdbgOutputDebugString ( "\r\nEnter your selection: ");


		while (! ( ( (KeySelect >= '0') && (KeySelect <= '9') ) ||
				( (KeySelect == 'D') || (KeySelect == 'd') ) ||
				( (KeySelect == 'F') || (KeySelect == 'f') ) ||
				( (KeySelect == 'L') || (KeySelect == 'l') ) ||
				( (KeySelect == 'R') || (KeySelect == 'r') ) ||
				( (KeySelect == 'U') || (KeySelect == 'u') )  ||
				( (KeySelect == 'W') || (KeySelect == 'w') ) ||
				( (KeySelect == '(') || (KeySelect == '(') )  ||
				( (KeySelect == 'A') || (KeySelect == 'a') )  ||
				( (KeySelect == 'M') || (KeySelect == 'm') )  ||
				( (KeySelect == 'N') || (KeySelect == 'n') )  ||				
				( (KeySelect == 'C') || (KeySelect == 'c') ) ) )

		{
		//EdbgOutputDebugString ( ".");

			KeySelect = OEMReadDebugByte();
		}

		EdbgOutputDebugString ( "%c\r\n", KeySelect);

		switch(KeySelect)
		{
		case '0':		   // Change IP address.
			SetIP(pBootCfg);
			pBootCfg->ConfigFlags &= ~CONFIG_FLAGS_DHCP;   // clear DHCP flag
			bConfigChanged = TRUE;
			break;
		case '1':		   // Change subnet mask.
			SetMask(pBootCfg);
			bConfigChanged = TRUE;
			break;
		case '2':		   // Toggle static/DHCP mode.
			pBootCfg->ConfigFlags = (pBootCfg->ConfigFlags ^ CONFIG_FLAGS_DHCP);
			bConfigChanged = TRUE;
			break;
		case '3':		   // Change autoboot delay.
			SetDelay(pBootCfg);
			bConfigChanged = TRUE;
			break;
		case '4':		   // Reset the bootloader configuration to defaults.

⌨️ 快捷键说明

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