?? 44blib.c
字號:
}
/*********************************************************************************************
* 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("*******************************************************************\n");
uart_printf("** Embest S3CEV40 APPLICATION EXAMPLES **\n");
uart_printf("*******************************************************************\n");
}
void ChangePllValue(int mdiv,int pdiv,int sdiv)
{
rPLLCON=(mdiv<<12)|(pdiv<<4)|sdiv;
}
/*********************************************************************************************
* name: DelayTime
* func: delay time
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void DelayTime(int num)
{
int i;
for( i = 0 ; i < num ; i++ )
;
}
//*********************************************************************************************
void DelayMs(int ms_time)
{
int i;
for( i = 0 ; i < 1000*ms_time ; i++ );
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -