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

📄 2410lib.c

📁 基于arm9 s3c2410 的GPRS源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
                uart_printf("\b \b");
                pString--;
            }
        }
        else 
        {
            *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 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);
}

void beep(int nBeepStatus)
{
	if (nBeepStatus==0)
		rGPBDAT |= 0x1;
	else
		rGPBDAT &= 0x7fe;

}
/*********************************************************************************************
* 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)  //0:16us,1:32us 2:64us 3:128us
{
    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

	//Watch-dog timer enable & interrupt  disable
//	rWTCON = rWTCON |(1<<5) & !(1<<2);	 //?
    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);
}


//========================[ MPLL ]=================================
void change_value_MPLL(int nMdiv,int nPdiv,int nSdiv)
{
    rMPLLCON = (nMdiv<<12) | (nPdiv<<4) | nSdiv;
}


//========================[ HCLK, PCLK ]===========================
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;    
    
//    if(nHdiv)
//        MMU_SetAsyncBusMode();
//    else 
//        MMU_SetFastBusMode();
}


//========================**[ UPLL ]==============================*
void ChangeUPllValue(int nMdiv,int nPdiv,int nSdiv)
{
    rUPLLCON = (nMdiv<<12) | (nPdiv<<4) | nSdiv;
}


//========================*[ General Library ]=====================*
/*void * smalloc(unsigned nByte) 
//Very simple; Use malloc() & free() like Stack
//void *malloc_pt=Image_RW_Limit;
{
    void *pReturnPt = Image_RW_Limit;

    malloc_pt = (int *)malloc_pt+nByte/4+((nByte%4)>0); //To align 4byte

    if( (int)malloc_pt > HEAPEND )
    {
        malloc_pt = pReturnPt;
        return NULL;
    }
    return pReturnPt;
}		  

//-------------------------------------------------------------------
void sfree(void *pString)
{
    malloc_pt = pString;
}			 */

/*********************************************************************************************
* 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:		__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 + -