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

📄 uart.c

📁 基于ARM7的S3C44BO基础测试实验:异步串行通信实验.
💻 C
字号:
#include <string.h>
#include <stdlib.h>
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\def.h"


#define KEY_BUFLEN 100
#define AFC_BUFLEN 0x100

char Uart_IntGetkey(void);
void Uart_Port(void);
void Return_Port(void);
void __irq Uart1_RxInt(void);
void __irq Uart1_TxInt(void);


static unsigned char keyBuf[KEY_BUFLEN];
volatile static int keyBufRdPt=0;
volatile static int keyBufWrPt=0;
volatile char out=1;
volatile static char *uart0TxStr;
volatile static char *uart1TxStr;

volatile U32 save_UC,save_UE,save_UF,save_UPC,save_UPE,save_UPF;

void Uart_Port(void)
{
    save_UC=rPCONC;//for nRTS0,nCTS0
    save_UE=rPCONE;//for TxD0,RxD0
    save_UF=rPCONF;//for nRTS1,TxD1,RxD1,nCTS1
    save_UPC=rPUPC;
    save_UPE=rPUPE;
    save_UPF=rPUPF;

    rPCONC |=0xf0000000;
    rPUPC |=0xc000;//Uart port pull-up disable
    rPCONE=(rPCONE &0x3ffeb)|0x28;
    rPUPE |=0x6; 
    rPCONF=(rPCONF &0x3ff)+0x124800;
    rPUPF |=0x1e0;
}


void Return_Port(void)
{
    rPCONC=save_UC;
    rPCONE=save_UE;
    rPCONF=save_UF;
    rPUPC=save_UPC;
    rPUPE=save_UPE;
    rPUPF=save_UPF;
}


char Uart_IntGetkey(void)	
{
    if(keyBufRdPt==KEY_BUFLEN)
	keyBufRdPt=0;

    while(keyBufWrPt==keyBufRdPt);  //until FIFO is triggered
    return keyBuf[keyBufRdPt++];
}



void Test_Uart0(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 0 tx Interrupt Test]\n");
    Uart_Printf("Plug the serial cable into ch0 connector!!! \n");
    Uart_Printf("Then, press any key through UART ch0.\n");
   // Uart_Select(1);
   // Uart_Getch();

    uart1TxStr="UART0 Tx interrupt test is good!!!!\r\n";
    rINTMSK=~(BIT_GLOBAL|BIT_UTXD1);
    rUCON1 = 0x244; //rx:edge,tx:level,error int,normal*2,interrupt(Start)
    Delay(3000);
	

    /*********** UART1 Tx test with BDMA1 ***********/
    rUCON1 = 0x245;

    Uart_Printf("\n[Uart0 Tx Test by BDMA1]\n");
    uart1TxStr="UART0 Tx Test by BDMA1 is good!!!!\r\n";
    Uart_TxEmpty(0);

    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=0x245;
    Return_Port();
	Uart_Printf("\n[Uart channel 0 Rx Interrupt Test]:Type any key!!!\n");
	Uart_Printf("You have to see the typed character. To quit, press Enter key.\n");
	
	key=Uart_GetIntNum();

   
    rINTMSK=~BIT_GLOBAL;
    Uart_Printf("\n");

  }


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
}










⌨️ 快捷键说明

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