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

📄 uart.c

📁 S3C44b0X 的中断程序代码................
💻 C
📖 第 1 页 / 共 2 页
字号:
	}
}

void __irq Uart1_RxFifoErrorInt(void)
{
	rI_ISPC=BIT_UERR01;
	switch(rUERSTAT1)//to clear and check the status of register bits
	{
	case '1':
		Uart_Printf("Overrun error\n");
		break;
	case '2':
		Uart_Printf("Parity error\n");
		break;
	case '4':
		Uart_Printf("Frame error\n");
		break;
	case '8':
		Uart_Printf("Breake detect\n");
		break;
	default :
		break;
	}
	while( (rUFSTAT1&0xf) >0 )
	{
		keyBuf[keyBufWrPt++]=rURXH1;
		if(keyBufWrPt==KEY_BUFLEN)
			keyBufWrPt=0;
	}
}

void Test_Uart1(void)
{
	int key;
	Uart_Port();
	keyBufRdPt=keyBufWrPt=0;
	pISR_UTXD1=(unsigned)Uart1_TxInt;
	pISR_URXD1=(unsigned)Uart1_RxInt;
	/*********** UART1 Tx test with interrupt ***********/
	Uart_Printf("[Uart channel 1 tx Interrupt Test]\n");
	Uart_Printf("Plug the serial cable into ch1 connector!!! \n");
	Uart_Printf("Then, press any key through UART ch1.\n");
	Uart_Select(1);
	Uart_Getch();
	uart1TxStr="UART1 Tx interrupt test is good!!!!\r\n";
	rINTMSK=~(BIT_GLOBAL|BIT_UTXD1);
	// rUCON1 &= 0x3f3;
	// rUCON1 |= 0x4; //needed to set the UTXD0 pending bit.
	rUCON1 = 0x244; //rx:edge,tx:level,error int,normal*2,interrupt(Start)
	Delay(3000);
	/*********** UART1 Tx test with BDMA1 ***********/
	rUCON1 = 0x245;
	Uart_Printf("\n[Uart1 Tx Test by BDMA1]\n");
	uart1TxStr="UART1 Tx Test by BDMA1 is good!!!!\r\n";
	Uart_TxEmpty(1);
	rUCON1=0x4c; //tx:BDMA0 rx:disable
	rBDICNT1=0x0;
	rBDCON1 =0x0;
	rBDISRC1=(unsigned int)uart1TxStr|(0<<30)|(1<<28); // byte,inc
	rBDIDES1=UTXH1 |(1<<30)|(3<<28); //L/B endian,M2IO,fix
	rBDICNT1=strlen((char *)uart1TxStr)|(2<<30)|(1<<26)|(0<<20); //UART1,
	rBDICNT1 |= (1<<20); //enable
	while(!((rBDCON1&0x30)==0x20));
	Uart_TxEmpty(1);
	/*********** UART1 Rx test with interrupt ***********/
	rUCON1=0x45; //tx:int rx:int
	Uart_Printf("\n[Uart channel 1 Rx Interrupt Test]:Type any key!!!\n");
	Uart_Printf("You have to see the typed character. To quit, press Enter key.\n");
	rINTMSK=~(BIT_GLOBAL|BIT_URXD1);
	keyBufRdPt=keyBufWrPt=0;
	while((key=Uart_IntGetkey())!='\r')
	Uart_SendByte(key);
	rINTMSK=~BIT_GLOBAL;
	Uart_Printf("\n");
	Uart_Printf("Plug the serial cable into ch0 as before this test!!!\n");
	Uart_Printf("Then, press any key through UART ch 0.\n");
	Uart_Select(0);
	Uart_Getch();
	Return_Port();
}
void __irq Uart1_RxInt(void)
{
	rI_ISPC=BIT_URXD1;
	keyBuf[keyBufWrPt++]=RdURXH1();
	if(keyBufWrPt==KEY_BUFLEN)
		keyBufWrPt=0;
}

void __irq Uart1_TxInt(void)
{
	// rI_ISPC=BIT_UTXD1;
	if(*uart1TxStr != '\0')
	{
		WrUTXH1(*uart1TxStr++);
		rI_ISPC=BIT_UTXD1;
	}
	else
	/* {
	rUCON1 &= 0x3f3;//workaround for ES1, ES2
	rI_ISPC=BIT_UTXD1;
	rINTMSK|=BIT_UTXD1;
	}*/
	{ //ES3
		rINTMSK |= BIT_UTXD1; //ES3
		rI_ISPC=BIT_UTXD1; //ES3
	} //ES3
}
////////Auto Flow Control TEST(Tx)////////////////
volatile unsigned char * volatile tx0,* tx1,*tx2,tx_end=0;
volatile int i;
volatile int tx_cnt=0;
void Test_UartAFC_Tx(void)
{
	Uart_Port();
	tx_cnt=0;
	tx0=(unsigned char *)malloc(AFC_BUFLEN);
	tx1=tx0;
	tx2=tx0;
	Uart_Printf("!!!tx0=0x%x\n",tx0);
	for(i=0;i<AFC_BUFLEN;i++)
		*tx1++=i;
	pISR_UTXD1=(unsigned)U1AFC_TxInt;
	// Led_Display(0xf); //LED off
	Uart_Printf("[UART AFC Tx Test]\n");
	Uart_Printf("This test should be configured two boards.\n");
	Uart_Printf("Connect twitsted(rx/tx, nCTS/nRTS) cable com2 to other board's com1 port.\n");
	Uart_Printf("Start Rx first and press any key and,.\n");
	Uart_TxEmpty(0);
	Uart_Getch();
	rUCON1=(1<<9)|(0<<8)|(0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<2)|(1);
	rUFCON1=0x0; //FIFO disable
	rUMCON1=0x10; //Uart1 AFC enable
	Uart_Printf("Now... Tx with AFC\n");
	Uart_TxEmpty(0);
	rINTMSK=~(BIT_GLOBAL|BIT_UTXD1);
	while(!tx_end);
	Led_Display(0x0); //LED on
	Uart_Printf("\nEnd Tx, transfer data count=%d\n",tx_cnt);
	Return_Port();
	free((void *)tx0);
	tx_end=0;
	tx_cnt=0;
}
void __irq U1AFC_TxInt(void)
{
	if(tx_cnt < (AFC_BUFLEN))
	{
		Uart_Printf("%d,",*tx2);
		WrUTXH1(*tx2++);
		rI_ISPC=BIT_UTXD1;
		tx_cnt++;
	}
	else
	{
		Uart_TxEmpty(1);
		/* rUCON1 &= 0x3f3;//workaround for ES1,2
		rI_ISPC=BIT_UTXD1;
		rINTMSK|=BIT_UTXD1;*/
		rINTMSK |= BIT_UTXD0; //ES3
		rI_ISPC=BIT_UTXD0; //ES3
		tx_end=1;
	}
}
////////Auto Flow Control TEST(Rx with FIFO)////////////////
volatile unsigned char *rx0,*rx1,*rx2,rx_end=0;
volatile int rx_cnt=0;
void Test_UartAFC_Rx(void)
{
	unsigned int i;
	unsigned int err_cnt=0;
	Uart_Port();
	Uart_Printf("[UART AFC Rx Test]\n");
	Uart_Printf("This test should be configured two boards.\n");
	Uart_Printf("Connect twisted(rx/tx, nCTS/nRTS) cable com1 to other board's com2 port.\n");
	Uart_Printf("Then, change connected cable between host and com1, host to com2.\n");
	Uart_Printf("Press any key to com2 and start Rx first.\n");
	Uart_TxEmpty(0);
	Uart_Select(1);
	Uart_Getch();
	rx0=(unsigned char *)malloc(AFC_BUFLEN);
	rx1=rx0;
	rx2=rx0;
	pISR_URXD0=(unsigned)U0AFC_RxInt;
	pISR_UERR01=(unsigned)U0AFC_RxErrorInt;
	Led_Display(0xf); //LED off
	rUMCON0=0x10; //Uart0 AFC enable
	rUCON0=(1<<9)|(0<<8)|(1<<7)|(1<<6)|(0<<5)|(0<<4)|(1<<2)|(1);
	rUFCON0=(2<<6)|(1<<4)|(1<<2)|(1<<1)|(1);
	Uart_Printf("Now... Rx with AFC\n");
	Uart_TxEmpty(1);
	rINTMSK=~(BIT_GLOBAL|BIT_URXD0|BIT_UERR01);
	while(!rx_end);
	Delay(1000);
	rINTMSK=BIT_GLOBAL;
	Uart_Printf("\nEnd Rx, receive data count=%d\n",rx_cnt);
	Led_Display(0x0); //LED on
	Uart_Printf("Now, change connected cable between host and com2, host to com1.\n");
	Uart_Printf("Then, press any key.\n");
	Uart_Init(0,115200);
	Uart_Select(0);
	Uart_Getch();
	for(i=0;i<AFC_BUFLEN;i++)
	{
		if(i-(*rx1++))
		{
			Uart_Printf("i=%d\n",i);
			err_cnt++;
		}
	}
	if(err_cnt)
		Uart_Printf("AFC test fail!! Error count=%d\n",err_cnt);
	else
		Uart_Printf("AFC test is good!!\n");
	Return_Port();
	free((void *)rx0);
	rx_end=0;
	rx_cnt=0;
}

void __irq U0AFC_RxInt(void)
{
	rI_ISPC=BIT_URXD0;
	while( (rUFSTAT0 & 0x100) || ((rUFSTAT0 & 0xf) >0) )
	{
		Delay(1000);
		*rx2++=rURXH0;
		Uart_Printf("%d,",*(rx2-1));
		rx_cnt++;
	}
	if(rx_cnt == (AFC_BUFLEN))
		rx_end=1;
}
void __irq U0AFC_RxErrorInt(void)
{
	rI_ISPC=BIT_UERR01;
	switch(rUERSTAT0)//to clear and check the status of register bits
	{
	case 1:
		WrUTXH1('!');
		break;
	case 2:
		WrUTXH1('#');
		break;
	case 4:
		WrUTXH1('$');
		break;
	case 8:
		WrUTXH1('@');
		break;
	default :
		WrUTXH1('*');
		break;
	}
}
char _done=0, error=0;
void Test_BDMA(void)
{
	char *_buf,i;
	char *_temp2;
	int *_temp;
	_buf=(char *)malloc(100);
	_temp=(int *)malloc(1);
	_temp2=_buf;
	rINTMSK=~(BIT_GLOBAL|BIT_BDMA0|BIT_UERR01);
	pISR_BDMA0=(unsigned)Test_Done;
	pISR_UERR01=(unsigned)Error;
	Uart_Init(0,115200);
	Uart_Printf("[Read BDCON0 register in Rxing...]\n");
	Uart_TxEmpty(0);
	rBDISRC0=(0<<30)+(3<<28)+(int)URXH0; //byte,inc,Rx-buf
	rBDIDES0=(2<<30)+(1<<28)+(int)_buf; //M2IO,fix,IISFIF
	rBDICNT0=(2<<30)+(1<<26)+(3<<22)+(1<<21)+(0<<20)+700;
	//Uart0,reserve,done_int,auto-reload/start,DMA disable,COUNT
	rBDICNT0 |= (1<<20);//enable
	rBDCON0 = 0x0<<2;
	rUCON0=0x2c6; //tx:polling rx:BDMA0
	while(!_done)
	{
		*_temp=rBDCON0;
		if((rBDCON0 & 0xf))
		{
			Uart_Printf("!!Error0x%x!!,",rBDCON0);
			break;
		}
	}
	Uart_Printf("!END!\n");
	if(error)
	Uart_Printf("[rUERSTAT=0x%x]\n",rUERSTAT0);
	rINTMSK=BIT_GLOBAL;
	// rUCON0 &= 0x3fd;//Rx disable
	rBDICNT0=0x0; //BDMA stop
	for(i=0;i<10;i++)
	Uart_Printf("%d=0x%x,",i,*_temp2++);
	Uart_Printf("\n0x%x,",*_temp);
	free(_buf);
	_done=0;
}
void __irq Test_Done(void)
{
	rI_ISPC=BIT_BDMA0; //clear pending bit
	_done=1;
}
void __irq Error(void)
{
	rI_ISPC=BIT_UERR01;
	error=1;
}

⌨️ 快捷键说明

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