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

📄 uart.c

📁 基于s3c2410、2440的从SD卡引导Linux内核程序
💻 C
字号:
#include "2440addr.h"
#include <stdarg.h>
#include <stdio.h>
#include "UART.h"

//#define	S3C2440		1	//It's S3C2440
#define	S3C2440		0	//It's S3C2410

extern unsigned int PCLK;

void Uart_Init(int baud)
{
	int i;

	rUFCON0 = 0x0;	//UART channel 0 FIFO control register, FIFO disable
	rUFCON1 = 0x0;	//UART channel 1 FIFO control register, FIFO disable
	rUFCON2 = 0x0;	//UART channel 2 FIFO control register, FIFO disable
	rUMCON0 = 0x0;	//UART chaneel 0 MODEM control register, AFC disable
	rUMCON1 = 0x0;	//UART chaneel 1 MODEM control register, AFC disable
//UART0
	rULCON0 = 0x3;		//Line control register : Normal,No parity,1 stop,8 bits
#if	S3C2440
	rUCON0  = 0x245;	// Control register
#else
	rUCON0  = 0x5;
#endif
	rUBRDIV0=( (int)(PCLK/16/baud) -1 );	//Baud rate divisior register 0
//UART1
	rULCON1 = 0x3;
#if	S3C2440
	rUCON1  = 0x245;
#else
	rUCON1  = 0x5;
#endif
	rUBRDIV1=( (int)(PCLK/16/baud) -1 );
//UART2
	rULCON2 = 0x3;
#if	S3C2440
	rUCON2  = 0x245;
#else
	rUCON2  = 0x5;
#endif
	rUBRDIV2=( (int)(PCLK/16/baud) -1 );    

	for(i=0;i<100;i++);
}

void Uart_SendByte(int whichUart,int data)
{
	if(whichUart==0)
	{
		if(data=='\n')
		{
			while(!(rUTRSTAT0 & 0x2));
			// Delay(1);                 //because the slow response of hyper_terminal 
			WrUTXH0('\r');
		}
		while(!(rUTRSTAT0 & 0x2));   //Wait until THR is empty.
		//  Delay(1);
		WrUTXH0(data);
	}
	else if(whichUart==1)
	{
		if(data=='\n')
		{
			while(!(rUTRSTAT1 & 0x2));
			//Delay(1);                 //because the slow response of hyper_terminal 
			rUTXH1 = '\r';
		}
		while(!(rUTRSTAT1 & 0x2));   //Wait until THR is empty.
		//Delay(1);
		rUTXH1 = data;
	}   
	else if(whichUart==2)
	{
		if(data=='\n')
		{
			while(!(rUTRSTAT2 & 0x2));
			//Delay(1);                 //because the slow response of hyper_terminal 
			rUTXH2 = '\r';
        }
        while(!(rUTRSTAT2 & 0x2));   //Wait until THR is empty.
        //Delay(1);
        rUTXH2 = data;
    }       
}               

//====================================================================
void Uart_SendString(int whichUart,char *pt)
{
    while(*pt)
        Uart_SendByte(whichUart,*pt++);
}

void Uart_Printf(int whichUart,char *fmt,...)
{
    va_list ap;
    char string[256];

    va_start(ap,fmt);
    vsprintf(string,fmt,ap);
    Uart_SendString(whichUart,string);
    va_end(ap);
}

⌨️ 快捷键说明

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