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

📄 44blib.c

📁 bios for s3C44B0
💻 C
📖 第 1 页 / 共 2 页
字号:
char uart_getkey(void)
{
    if(f_nWhichUart==0)
    {	    
		if(rUTRSTAT0 & 0x1)    //Receive data ready
    	    return RdURXH0();
		else
		    return 0;
    }
    else
    {
		if(rUTRSTAT1 & 0x1)    //Receive data ready
		    return rURXH1;
		else
		    return 0;
    }
}

/*********************************************************************************************
* name:		uart_getString
* func:		Get string from uart channel and store the result to input address (*pString)
* para:		pString	-- 	input, string
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void uart_getstring(char *pString)
{
	char *pString2 = pString;
	char c;
	while((c = uart_getch())!= '\r')
    {
		if(c == '\b')
		{
		    if(	(int)pString2 < (int)pString )
		    {
				uart_printf("\b \b");
				pString--;
		    }
		}
		else // store and echo on uart channel
		{
		    *pString ++= c;
		    uart_sendbyte(c);
		}
    }
    *pString = '\0';
    uart_sendbyte('\n');
}

/*********************************************************************************************
* name:		uart_getintnum
* func:		Get a numerical (Dec - default or Hex fromat) from the uart, with or without a signed
* para:		none
* ret:		nResult: the valid number which user input from uart
* 					-- Dec format number (default)
* 					-- Hex format number ('H/h' suffix or '0x' ahead)
* modify:
* comment:		
*********************************************************************************************/
int uart_getintnum(void)
{
	char	pStr[30];
	char	*pString =  pStr;
	int		nLastIndex;
	int		nBase    =  10;
	int		nMinus   =  0;
	int		nResult  =  0;
	int		i;
	
	uart_getstring(pString);
	
	if(pString[0] == '-')
	{
		nMinus = 1;
		pString++ ;
	}
	
	// if '0x' ahead
	if(pString[0] == '0' && (pString[1] == 'x' || pString[1] == 'X'))
	{
		nBase = 16;
		pString += 2;
	}
	
	// if 'H' or 'h' suffix
	nLastIndex = strlen(pString)-1;
	if( pString[nLastIndex] == 'h' || pString[nLastIndex] == 'H' )
	{
		nBase = 16;
		pString[nLastIndex] = 0;
		nLastIndex--;
	}

	// without ahead or suffix -- default numerical 
	if(nBase == 10)
	{
		nResult = atoi(pString);
		nResult = nMinus ? (-1*nResult) : nResult;
	}
	else // Hex numerical
	{
		for(i = 0;i <= nLastIndex;i++ )
		{
			if(isalpha(pString[i]))
			{
				if(isupper(pString[i]))
					nResult = (nResult<<4) + pString[i]-'A' + 10;
				else
				    nResult = (nResult<<4) + pString[i]-'a' + 10;
			}
			else
			{
				nResult = (nResult<<4) + pString[i]-'0';
			}
		}
		nResult = nMinus ? (-1*nResult) : nResult;
	}
	return nResult;
}

/*********************************************************************************************
* name:		uart_sendbyte
* func:		Send one byte to uart channel
* para:		nData	-- 	input, byte
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void uart_sendbyte(int nData)
{
	if(f_nWhichUart == 0)
    {
		if(nData == '\n')
		{
		    while(!(rUTRSTAT0 & 0x2));
		    delay(10);									// because the slow response of hyper_terminal 
		    WrUTXH0('\r');
		}
		while(!(rUTRSTAT0 & 0x2)); 						// Wait until THR is empty.
		delay(10);
		WrUTXH0(nData);
   	}
	else
    {
		if(nData=='\n')
		{
			while(!(rUTRSTAT1 & 0x2));
			delay(10);									// because the slow response of hyper_terminal 
			rUTXH1 = '\r';
		}
		while(!(rUTRSTAT1 & 0x2));  					// Wait until THR is empty.
		delay(10);
		rUTXH1 = nData;
    }	
}		

/*********************************************************************************************
* name:		uart_sendstring
* func:		Send string to uart channel
* para:		pString	-- 	input, string
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void uart_sendstring(char *pString)
{
    while(*pString)
    {
		uart_sendbyte(*pString++);
	}
}

/*********************************************************************************************
* name:		uart_printf
* func:		print format string
* para:		fmt	-- 	input,  
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void uart_printf(char *fmt,...)
{
    va_list 	ap;
    char 		szString[256];

    va_start(ap, fmt);
    vsprintf(szString, fmt, ap);
    uart_sendstring(szString);
    va_end(ap);
}

					//----------------------------------------------------------//
					//							Timer							//
					//----------------------------------------------------------//
					
/*********************************************************************************************
* name:		timer_start
* func:		start timer
* para:		nDivider	-- 	input, 0:16us,1:32us 2:64us 3:128us
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void timer_start(int nDivider)
{
    rWTCON = ((MCLK/1000000-1)<<8) | (nDivider<<3);
    rWTDAT = 0xffff;
    rWTCNT = 0xffff;   

    // 1/16/(65+1), nRESET, interrupt disable
    rWTCON = ((MCLK/1000000-1)<<8) | (nDivider<<3) | (1<<5);	
}

/*********************************************************************************************
* name:		timer_stop
* func:		stop timer
* para:		none
* ret:			--	int, timer count
* modify:
* comment:		
*********************************************************************************************/
int timer_stop(void)
{
    rWTCON = ((MCLK/1000000-1)<<8);
    return (0xffff-rWTCNT);
}


					//----------------------------------------------------------//
					//							General Library					//
					//----------------------------------------------------------//
					
/*********************************************************************************************
* name:		cache_flush
* func:		flush cache
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void cache_flush(void)
{
    int nSaveSyscfg;
    int i;
    
    nSaveSyscfg = rSYSCFG;
    rSYSCFG = SYSCFG_0KB; 		      
    for(i=0x10004000; i<0x10004800; i+=16)    
    {					   
		*((int*)i)=0x0;		   
    }
    rSYSCFG = nSaveSyscfg; 			    
}

/*********************************************************************************************
* name:		sys_init
* func:		Initilaize interrupt, port and UART
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void sys_init()
{
	// Using 8KB Cache
	rSYSCFG = CACHECFG;   							

	// Initial 44B0X's I/O port
	port_init();									

	// Initilaize interrupt
	uhal_init_interrupts();

    // Initilaize external interrupt
	rEXTINT = 0x22222222;                  			// Level mode
	rEXTINTPND = 0xf;								// Clear EXTINTPND reg
	
	// Initial delay time
    delay(0);
//	beep(1);
	delay(1000);
//	beep(0);

	// Initial Serial port 1
	uart_init(0,115200);
	uart_printf("\nboot success...\n");

}

⌨️ 快捷键说明

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