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

📄 serial.c

📁 arm7 s3c44b0x开发板fs44b的bios启动源代码及使用说明 下载方法等
💻 C
字号:
#include "../inc/def.h"
#include "../inc/config.h"
#include "../inc/board.h"
#include "44b.h"
#include "option.h"

static U16 SerialPortSel = 0;

U16 SerialSwitch(U16 port)
{
#ifdef	SERIAL_PORTS_SWITCH
	SerialPortSel = port?1:0;
#else
	SerialPortSel = 0;
#endif
	return SerialPortSel;
}

/*******************************************************************
[功能说明] 设置波特率
*******************************************************************/
void SerialChgBaud(U32 baud)
{
	U32 mclk =  GetMasterClock();
	
	rUFCON0 = 0x0;		//FIFO disable
	rUFCON1 = 0x0;
	rUMCON0 = 0x0;
	rUMCON1 = 0x0;
//UART0
//	rULCON0  = 0x7;		//Normal,No parity,2 stop,8 bit
	rULCON0  = 0x3;		//Normal,No parity,1 stop,8 bit
	rUCON0   = 0x245;	//rx=edge,tx=level,disable timeout int.,enable rx error int.,normal,interrupt or polling
	rUBRDIV0 = ((int)(mclk/16./baud + 0.5) -1);
//UART1
//	rULCON1  = 0x7;		//Normal,No parity,2 stop,8 bit
	rULCON1  = 0x3;		//Normal,No parity,1 stop,8 bit
	rUCON1   = 0x245;	//rx=edge,tx=level,disable timeout int.,enable rx error int.,normal,interrupt or polling
	rUBRDIV1 = ((int)(mclk/16./baud + 0.5) -1);
}

/*******************************************************************
[功能说明] 等待发送缓冲器为空
*******************************************************************/
void SerialTxEmpty(void)
{
	if(SerialPortSel == 1)
		while(!(rUTRSTAT1 & 0x4)); //wait unti1 tx shifter is empty.
	else
		while(!(rUTRSTAT0 & 0x4)); //wait unti0 tx shifter is empty.
}

/*******************************************************************
[功能说明] 发送一个字符
*******************************************************************/
void SerialTxChar(char data)
{
	if(SerialPortSel == 1) 
	{
    	while(!(rUTRSTAT1 & 0x2));
		if(data=='\n') 
		{
			WrUTXH1('\r');
			while(!(rUTRSTAT1 & 0x2));//because the slow response of hyper_terminal 
		}
		WrUTXH0(data);
    } 
    else 
    {
    	while(!(rUTRSTAT0 & 0x2));
		if(data=='\n') 
		{
			WrUTXH0('\r');
			while(!(rUTRSTAT0 & 0x2));//because the slow response of hyper_terminal 
		}
		WrUTXH0(data);
    }
}

/*******************************************************************
[功能说明] 发送字符串
*******************************************************************/
void SerialTxString(char *s)
{
	 while(*s)
	 {
	 	SerialTxChar(*s++);
	 }
}

/*******************************************************************
[功能说明] 接收数据缓冲器准备好
*******************************************************************/
int SerialRxReady(void)
{
	if(SerialPortSel == 1)
		return (rUTRSTAT1 & 0x1);	//Receive data ready
	else 
		return (rUTRSTAT0 & 0x1);	//Receive data ready
}

/*******************************************************************
[功能说明] 接收一个字符
*******************************************************************/
char SerialRxKey(void)
{
	if(SerialPortSel == 1) 
	{
		if((rUTRSTAT1 & 0x1)) //Receive data ready
			return RdURXH1();
	}
	else 
	{
		if((rUTRSTAT0 & 0x1)) //Receive data ready
			return RdURXH0();
	}
	return 0;
}

/*******************************************************************
[功能说明] 接收一个字符
*******************************************************************/
char SerialRxChar(void)
{
	if(SerialPortSel == 1) 
	{
		while(!(rUTRSTAT1 & 0x1)); //Receive data ready
		return RdURXH1();
	} 
	else 
	{
		while(!(rUTRSTAT0 & 0x1)); //Receive data ready
		return RdURXH0();
	}
}

/*******************************************************************
[功能说明] 接收一个字符到指定的缓冲器中
*******************************************************************/
int SerialRxToBuf(char *b)
{
	if(SerialPortSel == 1) 
	{
		if(rUTRSTAT1 & 0x1)    //Receive data ready
			*b = RdURXH1();
		else
		    return 0;
    }
    else 
    {
		if(rUTRSTAT0 & 0x1)    //Receive data ready
		    *b = RdURXH0();
		else
		    return 0;
    }
    
    return 1;
}

⌨️ 快捷键说明

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