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

📄 uart_irq.h

📁 3个串口接收
💻 H
📖 第 1 页 / 共 2 页
字号:

#include 	"config.h"		// 包含工程模板配制头文件
#include	"com_cfg.h"
#include	"irq.h"
#include   <stdlib.h>
#include   <string.h>

char 		string[64];
char		*strpt = string;
//int tc = 0;
extern int tc;

//GPS sentence module
char	buf0[1024];
char	buf1[1024];
//Hdg & Hdt sentence module
char    buf2[1024];
char    buf3[1024];
//水深、温度数据
char    buf4[1024];
char    buf5[1024];
int counter1 = 0;
int counter2 = 0;
int counter3 = 0;
int cnt1 = 0;
int cnt2 = 0;
int cnt3 = 0;
char *p0 = buf0;
char *p1 = buf1;
int plast0 = 0;
int pline0 = 0;
int pline1 = 0;
int plast1= 0;
int flag0  = 0;
int tx_busy1 = 0;
int rx_ready0 = 0;		     //0:no ready 1:data is ready 
int send_ready0 = 0;		 //0:no ready 1:data is ready to send >> must be clean after send
char * rx;			         //input from nmea-in
char * send;		         //output to ep93
int pSend1 = 0;		         //last send ptr			  
int pRead;
int send_req;		         //0:idle 1:request to send
char *p2 = buf2;
char *p3 = buf3;
int pline2 = 0;
int plast2 = 0;
int pline3 = 0;
int plast3 = 0;
int flag = 0;
int tx_busy2=0;
int rx_ready1 = 0;		 //0:no ready 1:data is ready 
int send_ready1 = 0;		 //0:no ready 1:data is ready to send >> must be clean after send
int pSend2 = 0;			 //last send ptr
char *p4 = buf4;
char *p5 = buf5;
int pline4 = 0;
int plast4 = 0;
int pline5 = 0;
int flag3 = 0;
int tx_busy3=0; 
int rx_ready2 = 0;		 //0:no ready 1:data is ready 
int send_ready2 = 0;		 //0:no ready 1:data is ready to send >> must be clean after send

         //output to ep93

int pSend3 = 0;			 //last send ptr

int rx_ready3 = 0;		 //0:no ready 1:data is ready 
int send_ready3 = 0;		 //0:no ready 1:data is ready to send >> must be clean after send



/*
COM_CONTROL uctl; 	//UART control(声明一个名为utcl的COM_CONTROL类型的结构体变量)


void reset_com(int i) //始初化com
{
	PORT_DATA *p;		//声明一个PORT_DATA 类型的指针p
	p = &uctl.com[i];	//指针p指向 COM_CONTROL类型的变量utcl中的PORT_DATA 类型名为com[i]的数组
	p->pLine = 0;		//p指向结构体变量com当中的成员,并将全部成员置0
	p->pRead = 0;
	p->pSend = 0;
	//
	p->rx_ready = 0;
	p->send_ready = 0;
	//
	switch(i)
	{
	case 0: //com0
			p->rx = buf0;
			p->send = buf1;
			break;
	case 1: //com1
			p->rx = buf2;
			p->send = buf3;
			break;
	default: //com2
			p->rx = buf4;
			p->send = buf5;
			break;
	}
}
void init_uctl(void)
{
	//init com[0];
	reset_com(0);
	//init com[1];
	reset_com(1);
	//init com[2];
	reset_com(2);
	//
	uctl.send_req = 0;
}
*/

uint32    U0Rcv_New = 0;						// 为1时表明接收到新数据
uint32    U1Rcv_New = 0;						// 为1时表明接收到新数据
uint32    U2Rcv_New = 0;	
uint32    U3Rcv_New = 0;	

char time1[3] =  {" 1"};
char time2[3] =  {" 2"};
char time3[3] =  {" 3"};


/*********************************************************************************************************
** 函数名称 :UART0_SendByte
** 函数功能 :以查询方式发送一字节数据
** 入口参数 :dat	要发送的数据
** 出口参数 :无
*********************************************************************************************************/
void UART0_SendByte(char dat)
{
	U0THR = dat;
	while ((U0LSR & 0x40) == 0);			// 等待数据发送完毕
}

/**********************************************************************************************************
** 函数名称 :UART0_SendStr
** 函数功能 :向串口发送一字符串
** 入口参数 :str	要发送的字符串的指针
** 出口参数 :无
**********************************************************************************************************/
void UART0_SendStr(char *str)
{
	while (1)
	{
		if (*str == '\0')	
		{
			break;							// 遇到结束符,退出
		}
		UART0_SendByte(*str++);			
	}
}


/*********************************************************************************************************
** 函数名称 :UART1_ReBuf
** 函数功能 :转存数据到0
** 入口参数 :uint32  snd_n:  发送数据的个数。snd_n 小于8
**			  uint8* RcvBufPt:缓存地址  
** 出口参数 :无
**********************************************************************************************************/

void UART1_RBuf()
{
   // VICIntEnClr  |= 1 << UART1_INT;			// 保护字符接收数组不被其它中断破坏
	//strcpy(buf1,buf0);

	p0 = &buf0[0];
	p1 = &buf1[0];
	//plast0 = buf0;
	//pline0 = buf0;
	send_ready1 = 1;
//	VICIntEnable |= 1 << UART1_INT;			
}

void UART2_RBuf()
{
    //VICIntEnClr  |= 1 << UART2_INT;			// 保护字符接收数组不被其它中断破坏
	//strcpy(buf3,buf2);
	p2 = &buf2[0];
	p3 = &buf3[0];
	//plast2 = 0;
	//pline2 = 0;
	send_ready2 = 1;

//	VICIntEnable |= 1 << UART2_INT;	
}

void UART3_RBuf()
{
    //VICIntEnClr  |= 1 << UART3_INT;			// 保护字符接收数组不被其它中断破坏
	//strcpy(buf5,buf4);
	
	p4 = &buf4[0];
	p5 = &buf5[0];
	//plast4 = buf4;
	//pline4 = buf4;
	send_ready3 = 1;
    
//	VICIntEnable |= 1 << UART3_INT;		
}




/*********************************************************************************************************
** 函数名称 :IRQ_UART0Recv
** 函数功能 :串口0接收中断服务程序
** 入口参数 :无
** 出口参数 :无
*******************************************************************************************************/


void __irq IRQ_UART0Recv(void)
{
	uint32 i   = 0;
	uint32 IIR = 0;

	// 			UART0接收中断处理 			
	while (((IIR = U0IIR) & 0x01) == 0)		// 若尚有中断待处理
	{
		
		switch (IIR & 0x0e)
		{
			
			// RDA中断处理入口 
			case 0x04:					
				U0Rcv_New = 1;	
				buf0[i] = U0RBR;                // 读空FIFO,清除RDA中断
				p0++;
				
				break;
								
			// CTI中断处理入口 
			case 0x0c:
				U0Rcv_New = 1;
				if( *p0 != '\0')
				{
					buf0[i] = U0RBR;
					p0++;
					
				}
				else
				{
					rx_ready0 = 1;
					break;
				}

	
			default:
				break;
				
				
		}
	}
		
	VICVectAddr = 0x00;						
}

/*********************************************************************************************************
** 函数名称 :UART1_SendByte
** 函数功能 :向串口1发送一字节数据,并等待发送完毕,查询方式
** 入口参数 :dat	要发送的数据
** 出口参数 :无
*********************************************************************************************************/
void UART1_SendByte (char dat)
{
	U1THR = dat;
	while ((U1LSR & 0x40) == 0);			// 等待数据发送完毕           
}

/**********************************************************************************************************
** 函数名称 :UART1_SendStr
** 函数功能 :向串口1发送一个字符串
** 入口参数 :str	要发送的字符串的指针
** 出口参数 :无
**********************************************************************************************************/
void UART1_SendStr (char *str)
{
	while (1)
	{
		if (*str == '\0')	
		{
			break;							// 遇到结束符,退出
		}
		UART1_SendByte(*str++);				// 发送数据
	}
}

/*********************************************************************************************************
** 函数名称 :IRQ_UART2Recv
** 函数功能 :串口0接收中断服务程序
** 入口参数 :无
** 出口参数 :无
*******************************************************************************************************/

void __irq IRQ_UART2Recv(void)
{
	uint32 i   = 0;
	uint32 IIR = 0;

	// 			UART0接收中断处理 			
	while (((IIR = U2IIR) & 0x01) == 0)		// 若尚有中断待处理
	{ 
	   // tc=5;
		
		
		switch (IIR & 0x0e)
		{
			
			// RDA中断处理入口 
			case 0x04:
			   					
		        //tc=3;
				*(buf2+pline2)= U2RBR;			
			 
			       
			        if(*(buf2+pline2)==0x0a)
				  	   {  
				  		
					   
					  	 if(tx_busy2==0)
					  	 {
					  	    pline2++;
					  	  	flag = 0;
					  	  	if (pline2 > plast2)
					  	  	{					  	  
					  	 	memcpy(p3,buf2+plast2,pline2-plast2);
					  	  	p3 += (pline2-plast2);
					  	  	pline3 += (pline2-plast2);
					  	  	}
					  	  
					  	  	if (pline2 < plast2)
					  	  	{
					  	  	memcpy(p3,buf2+plast2,1024-plast2);
					  	  	p3 += (1024-plast2);
					  	  	pline3 += (1024-plast2);
					  	  	memcpy(p3,buf2,pline2);					  	  
					  	  	p3 += pline2;
					  	  	pline3 += pline2;					  	   
					  	  	} 
					  	   
					  	    flag = 1;					  	  
					  	    plast2 = pline2;
					  	 
					  	  
					  	  }
					  	  else
					  	     pline2++;
				           
					   
				  	    }
				  	
			        else 
			     		     pline2++;
			            
			         
			            
			            
			       if(pline2>1023)
				        
				       pline2 = 0;
				   if(pline3 > 900)
				   
				     {
				       memset(buf3,0,1024);
				       p3 = buf3;
				       pline3 = 0;
				     }
				        
			             	  	 
		        
                    
				break;
								
			// CTI中断处理入口 
			case 0x0c:
			    
				U2Rcv_New = 1;
				if(*(buf2+pline2) != '\0')
				{   
				    //tc=3;
					*(buf2+pline2)= U2RBR;
				
							
		
	             if(*(buf2+pline2)==0x0a)
				  	   {  
				  		
					   
					  	 if(tx_busy2==0)
					  	 {
					  	    pline2++;
					  	  	flag = 0;
					  	  	if (pline2 > plast2)
					  	  	{					  	  
					  	 	 memcpy(p3,buf2+plast2,pline2-plast2);
					  	  	p3 += (pline2-plast2);
					  	  	}
					  	  

⌨️ 快捷键说明

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