?? 2410lib.c
字號:
char str[30];
char *pString = str;
int base = 10;
int minus = 0;
int nResult = 0;
int lastIndex;
int i;
uart_getstring(pString);
if(pString[0]=='-')
{
minus = 1;
pString++;
}
if(pString[0]=='0' && (pString[1]=='x' || pString[1]=='X'))
{
base = 16;
pString += 2;
}
lastIndex = strlen(pString) - 1;
if(lastIndex<0)
return -1;
if(pString[lastIndex]=='h' || pString[lastIndex]=='H' )
{
base = 16;
pString[lastIndex] = 0;
lastIndex--;
}
if(base==10)
{
nResult = atoi(pString);
nResult = minus ? (-1*nResult):nResult;
}
else
{
for(i=0;i<=lastIndex;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 = minus ? (-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(f_nWhichUart==1)
{
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;
}
else if(f_nWhichUart==2)
{
if(nData=='\n')
{
while(!(rUTRSTAT2 & 0x2));
delay(10); //because the slow response of hyper_terminal
rUTXH2 = '\r';
}
while(!(rUTRSTAT2 & 0x2)); //Wait until THR is empty.
delay(10);
rUTXH2 = 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: If you don't use vsprintf(), the code size is reduced very much.
*********************************************************************************************/
void uart_printf(char *fmt,...)
{
va_list ap;
char pString[256];
va_start(ap,fmt);
vsprintf(pString,fmt,ap);
uart_sendstring(pString);
va_end(ap);
}
/*********************************************************************************************
* 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 divider)
{
rWTCON = ((PCLK/1000000-1)<<8)|(divider<<3); //Watch-dog timer control register
rWTDAT = 0xffff; //Watch-dog timer data register
rWTCNT = 0xffff; //Watch-dog count register
rWTCON = rWTCON | (1<<5) | ~(1<<2); //May 06, 2002 SOP
}
/*********************************************************************************************
* name: timer_stop
* func: stop timer
* para: none
* ret: -- int, timer count
* modify:
* comment:
*********************************************************************************************/
int timer_stop(void)
{
rWTCON = ((PCLK/1000000-1)<<8);
return (0xffff - rWTCNT);
}
/*********************************************************************************************
* name: change_value_MPLL
* func: change MPLL value
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void change_value_MPLL(int nMdiv,int nPdiv,int nSdiv)
{
rMPLLCON = (nMdiv<<12) | (nPdiv<<4) | nSdiv;
}
/*********************************************************************************************
* name: change_clock_divider
* func: change the clock frequance
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void change_clock_divider(int nHdiv,int nPdiv)
{
// nHdiv,nPdiv FCLK:HCLK:PCLK
// 0,0 1:1:1
// 0,1 1:1:2
// 1,0 1:2:2
// 1,1 1:2:4
rCLKDIVN = (nHdiv<<1) | nPdiv;
}
/*********************************************************************************************
* name: ChangeUPllValue
* func: change the parameter nMdiv,nPdiv,nSdiv
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void ChangeUPllValue(int nMdiv,int nPdiv,int nSdiv)
{
rUPLLCON = (nMdiv<<12) | (nPdiv<<4) | nSdiv;
}
/*********************************************************************************************
* name: delay
* func: delay time
* para: nTime -- input, nTime=0: nAdjust the delay function by WatchDog timer.
* nTime>0: the number of loop time, 100us resolution.
* ret: none
* modify:
* comment:
*********************************************************************************************/
void delay(int nTime)
{
// time=0: adjust the Delay function by WatchDog timer.
// time>0: the number of loop time
// resolution of time is 100us.
int i,adjust=0;
if(nTime==0)
{
nTime = 200;
adjust = 1;
delayLoopCount = 400;
//PCLK/1M,Watch-dog disable,1/64,interrupt disable,reset disable
rWTCON = ((PCLK/1000000-1)<<8)|(2<<3);
rWTDAT = 0xffff; //for first update
rWTCNT = 0xffff; //resolution=64us @any PCLK
rWTCON = ((PCLK/1000000-1)<<8)|(2<<3)|(1<<5); //Watch-dog timer start
}
for(;nTime>0;nTime--)
for(i=0;i<delayLoopCount;i++);
if(adjust==1)
{
rWTCON = ((PCLK/1000000-1)<<8)|(2<<3); //Watch-dog timer stop
i = 0xffff - rWTCNT; //1count->64us, 200*400 cycle runtime = 64*i us
delayLoopCount = 8000000/(i*64); //200*400:64*i=1*x:100 -> x=80000*100/(64*i)
}
}
/*********************************************************************************************
* name: EnableMMU
* func: Enable the MMU
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void EnableMMU()
{
unsigned int ctl;
ctl = ARM_ReadControl();
ctl |= (1 << 0);
ARM_WriteControl(ctl);
}
/*********************************************************************************************
* name: InitMMU
* func: Initialization the MMU
* para: pTranslationTable-TranslationTable Address
* ret: none
* modify:
* comment:
*********************************************************************************************/
void InitMMU(unsigned int *pTranslationTable)
{
int i;
// Program the TTB
ARM_WriteTTB((unsigned int) pTranslationTable);
// Program the domain access register
ARM_WriteDomain(0xC0000000); // domain 15: access are not checked
// Reset table entries
for (i = 0; i < 0x200; ++i)
pTranslationTable[i] = 0;
// Program level 1 page table entry
pTranslationTable[0x0] =
(0x300 << 20) | // Physical Address
(1 << 10) | // Access in supervisor mode
(15 << 5) | // Domain
1 << 4 |
0x2; // Set as 1 Mbyte section
pTranslationTable[0x1] =
(0x301 << 20) | // Physical Address
(1 << 10) | // Access in supervisor mode
(15 << 5) | // Domain
1 << 4 |
0x2; // Set as 1 Mbyte section
pTranslationTable[0x2] =
(0x302 << 20) | // Physical Address
(1 << 10) | // Access in supervisor mode
(15 << 5) | // Domain
1 << 4 |
0x2; // Set as 1 Mbyte section
pTranslationTable[0x3] =
(0x303 << 20) | // Physical Address
(1 << 10) | // Access in supervisor mode
(15 << 5) | // Domain
1 << 4 |
0x2; // Set as 1 Mbyte section
for(i = 0x200; i < 0xFFF; ++i)
pTranslationTable[i] =
(i << 20) | // Physical Address
(1 << 10) | // Access in supervisor mode
(15 << 5) | // Domain
1 << 4 |
0x2; // Set as 1 Mbyte section
EnableMMU(); // Enable the MMU
}
/*********************************************************************************************
* name: __gccmain
* func: the entry point of gcc library
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void __gccmain(void)
{
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -