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

📄 uart.c

📁 44b0x的U盘源代码
💻 C
字号:
/*************************************************************************/
/*                                                                       */
/* FILE NAME                                      VERSION                */
/*                                                                       */
/* source\UART.C                                   1.1                   */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*     UART CODE for MBA-44B0(S3C44B0X)                                  */
/*                                                                       */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/* FUNCTIONS : UART CH0.1 ROUTINE                                        */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*                                                                       */
/* NAME:    Nicolas Park                                                 */
/* The last Modification date:  18.April.2002                            */
/* REMARKS:  Created initial version 1.1                                 */
/*                                                                       */
/*                                Copyright (C) 2002 AIJISYSTEM CO.,LTD  */
/*************************************************************************/

#include "..\inc\44b.h"
#include "..\inc\44blib.h"


#define KEY_BUFLEN 100
#define AFC_BUFLEN 0x100

char Uart_IntGetkey(void);

void __irq Uart0_RxInt(void);
void __irq Uart0_TxInt(void);

void __irq Uart1_RxInt(void);
void __irq Uart1_TxInt(void);

void __irq Exint2(void);

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


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;

    keyBufRdPt=keyBufWrPt=0;
    pISR_UTXD0=(unsigned)Uart0_TxInt;
    pISR_URXD0=(unsigned)Uart0_RxInt;
    
    /*********** UART0 Tx test with interrupt ***********/  
    Uart_Printf("[Uart channel 0 tx Interrupt Test]\n");
    Uart_TxEmpty(0); //wait until tx shifter is empty.

    uart0TxStr="UART0 Tx interrupt test is good!!!!\r\n";

    rINTMSK=~(BIT_GLOBAL|BIT_UTXD0);
    rUCON0 = 0x244; //tx:level,rx:edge,error int,normal*2,interrupt(Start)
    Delay(3000);

    /*********** UART0 Rx test with interrupt ***********/
    rUCON0=0x45;    //tx:int rx:int

    Uart_Printf("\n[Uart channel 0 Rx Interrupt Test]:Type any key!!!\n");
    Uart_Printf("You will see the typed character. To quit, press Enter key.\n");
    Uart_TxEmpty(0);

    rINTMSK=~(BIT_GLOBAL|BIT_URXD0);

    keyBufRdPt=keyBufWrPt=0;
    while((key=Uart_IntGetkey())!='\r')
	    Uart_SendByte(key);

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

}


void Test_Uart1(void)
{
    int key;

    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 = 0x244; //rx:edge,tx:level,error int,normal*2,interrupt(Start)
    Delay(3000);

    /*********** 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();
}


////////UART 0,1 INTERRUPT SERVICE ROUTINE ////////////////

void __irq Uart0_RxInt(void)
{
    rI_ISPC=BIT_URXD0;

    keyBuf[keyBufWrPt++]=RdURXH0();
    if(keyBufWrPt==KEY_BUFLEN)
		keyBufWrPt=0;
}

void __irq Uart0_TxInt(void)
{
    if(*uart0TxStr != '\0')
    {
	WrUTXH0(*uart0TxStr++);
	rI_ISPC=BIT_UTXD0;
    }
    else
    {
	rUCON0 &= 0x3f3;//workaround
	rI_ISPC=BIT_UTXD0;
	rINTMSK|=BIT_UTXD0;
    }
}



void __irq Uart1_RxInt(void)
{
    rI_ISPC=BIT_URXD1;

    keyBuf[keyBufWrPt++]=RdURXH1();
    if(keyBufWrPt==KEY_BUFLEN)
	keyBufWrPt=0;
}


void __irq Uart1_TxInt(void)
{
    if(*uart1TxStr != '\0')
    {
	WrUTXH1(*uart1TxStr++);
	rI_ISPC=BIT_UTXD1;
    }
    else
    {
	rUCON1 &= 0x3f3;//workaround
	rI_ISPC=BIT_UTXD1;
	rINTMSK|=BIT_UTXD1;
    }
}

⌨️ 快捷键说明

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