📄 main.c
字号:
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"
#define KEY_BUFLEN 100
#define AFC_BUFLEN 0x100
#define IrDA_BUFLEN 0x100
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
char Uart_IntGetkey(void);
void __irq Uart0_TxFifoInt(void);
void __irq Uart0_RxFifoInt(void);
void __irq Uart0_RxFifoErrorInt(void);
static unsigned char keyBuf[KEY_BUFLEN];
volatile static int IrDA_BAUD,keyBufRdPt=0;
volatile static int keyBufWrPt=0;
volatile char out=1;
static char *uart0TxStr;
void Main(void)
{
U8 aa;
int key=0;
rSYSCFG=SYSCFG_8KB;
#if (PLLON==1)
ChangePllValue(PLL_M,PLL_P,PLL_S);
#endif
Isr_Init();
Port_Init();
Uart_Init(0,115200);
Uart_Select(0);
Uart_Printf("\n* 杭州莱顿电子 *");
Uart_Printf("\n* -S3C44B0X功能部件:串口0实验fifo测试- *");
Uart_Printf("\n* Version 1.1 *");
Uart_Printf("\n* Email:aedkhz@163.com *");
Uart_Printf("\n* UART Config--COM:115.2kbps,8Bit,NP,UART0 *");
Uart_Printf("\n*------------------Begin to Start 串口0实验fifo测试,OK? (Y/N)----------*");
Uart_Printf("\n");
aa= Uart_Getch();
if((aa=='Y')||(aa=='y'))
keyBufRdPt=keyBufWrPt=0;
pISR_UTXD0=(unsigned)Uart0_TxFifoInt;
pISR_URXD0=(unsigned)Uart0_RxFifoInt;
pISR_UERR01=(unsigned)Uart0_RxFifoErrorInt;
/*********** UART0 Tx FIFO test with interrupt ***********/
Uart_Printf("[Uart channel 0 tx FIFO Interrupt Test]\n");
Uart_TxEmpty(0); //wait until tx shifter is empty.
uart0TxStr="123456789abcdef";//UART0 Tx FIFO interrupt test is good!!!!\r\n";
rUFCON0=(2<<6)|(1<<4)|(6)|1;
//FIFO trigger:tx/rx:8byte,tx/rx_fifo reset(will be cleared),FIFO enable.
rUCON0 = 0x244; //tx:levl,rx:edge,error int,normal*2,interrupt(Start)
rINTMSK=~(BIT_GLOBAL|BIT_UTXD0);
Delay(500);
/*********** UART0 Tx FIFO test with BDMA0 ***********/
Uart_Init(0,115200);
Uart_Printf("\n[Uart0 FIFO Tx Test by BDMA0]\n");
uart0TxStr="UART0 Tx FIFO Test by BDMA0 is good!!!!\r\n";
Uart_TxEmpty(0);
rUCON0=0x48; //tx:BDMA0 rx:disable
rBDICNT0=0;
rBDCON0 =0x0;
rBDISRC0=(unsigned int)uart0TxStr|(0<<30)|(1<<28); // byte,inc
rBDIDES0=UTXH0 |(1<<30)|(3<<28); //L/B endian,M2IO,fix
rBDICNT0=strlen(uart0TxStr)|(2<<30)|(1<<26)|(1<<20); //UART0,start,polling
while(!((rBDCON0&0x30)==0x20));
Uart_TxEmpty(0);
/*********** UART0 Rx FIFO test with interrupt ***********/
rUCON0=0x245|0x80; //tx:level,rx:edge,tx/rx:int,rcv_time_out enabled,error int enable
Uart_Printf("\n[Uart channel 0 FIFO 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_URXD0|BIT_UERR01);
while( (rUFSTAT0&0xf) >0 )
key=RdURXH0(); //To clear the Rx FIFO
// rUERSTAT0; //To clear the error state
while((key=Uart_IntGetkey())!='\r')
Uart_SendByte(key);
rUFCON0=(2<<6)|(1<<4)|(6)|0;
//FIFO trigger:tx/rx:8byte, txrx_fifo reset(will be cleared), FIFO disable.
rINTMSK=~BIT_GLOBAL;
rUCON0=0x45; //rcv_time_out disabled
Uart_Printf("\n");
}
/////////////////////////////////////////////////////////////////////////////
void __irq Uart0_TxFifoInt(void)
{
// rI_ISPC=BIT_UTXD0;
int i;
// while( !(rUFSTAT0 & 0x200) && (*uart0TxStr != '\0') ) //until tx fifo full or end of string
while( !(rUFSTAT0 == 16) && (*uart0TxStr != '\0') ) //until tx fifo full or end of string
{
rUTXH0=*uart0TxStr++;
for(i=0;i<700;i++); //to avoid overwriting FIFO
}
rI_ISPC=BIT_UTXD0;
if(*uart0TxStr == '\0')
{
rUCON0 &= 0x3f3;
rI_ISPC=BIT_UTXD0;
rINTMSK|=BIT_UTXD0;
}
}
void __irq Uart0_RxFifoInt(void)
{
rI_ISPC=BIT_URXD0;
// if(rUFSTAT0==0)
// Uart_Printf("time out\n");
while( (rUFSTAT0&0xf) >0 ) //until FIFO is empty
{
keyBuf[keyBufWrPt++]=rURXH0;//rx buffer->keyBuf[]
if(keyBufWrPt==KEY_BUFLEN)
keyBufWrPt=0;
}
}
void __irq Uart0_RxFifoErrorInt(void)
{
rI_ISPC=BIT_UERR01;
switch(rUERSTAT0)//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( (rUFSTAT0&0xf) >0 )
{
keyBuf[keyBufWrPt++]=rURXH0;
if(keyBufWrPt==KEY_BUFLEN)
keyBufWrPt=0;
}
}
/////////////////////////////////////////////////////////////////////////////
char Uart_IntGetkey(void)
{
if(keyBufRdPt==KEY_BUFLEN)
keyBufRdPt=0;
while(keyBufWrPt==keyBufRdPt); //until FIFO is triggered
return keyBuf[keyBufRdPt++];
}
/////////////////////////////////////////////////////////////////////////////
void Isr_Init(void)
{
U32 i;
pISR_UNDEF=(unsigned)HaltUndef;
pISR_SWI =(unsigned)HaltSwi;
pISR_PABORT=(unsigned)HaltPabort;
pISR_DABORT=(unsigned)HaltDabort;
for(i=_RAM_STARTADDRESS;i<(_RAM_STARTADDRESS+0x20);i+=4)
{
*((volatile unsigned *)i)=0xEA000000+0x1FFE;
}
//rINTCON=0x1; // Vectored Int. IRQ enable,FIQ disable
rINTCON=0x5; // Non-vectored,IRQ enable,FIQ disable
rINTMOD=0x0; // All=IRQ mode
rINTMSK|=BIT_GLOBAL|BIT_EINT3; // All interrupt is masked.
}
void HaltUndef(void)
{
Uart_Printf("Undefined instruction exception!!!\n");
while(1);
}
void HaltSwi(void)
{
Uart_Printf("SWI exception!!!\n");
while(1);
}
void HaltPabort(void)
{
Uart_Printf("Pabort exception!!!\n");
while(1);
}
void HaltDabort(void)
{
Uart_Printf("Dabort exception!!!\n");
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -