#include<s3c2440.h>
#define FCLK 202800000
#define HCLK (202800000/2)
#define PCLK (202800000/4)
#define UART0 0x0 // UART symbol
#define UART1 0x1
#define UART2 0xBB
#define _ISR_STARTADDRESS 0x33ffff00
#define pISR_UART0 (*(unsigned *)(_ISR_STARTADDRESS+0x90))
/*********************************************************************************************
* name: uart_init
* func: initialize uart channel
* para: nMainClk -- input, the MCLK value of current system
* nBaud -- input, baud rate value for UARTx
* nChannel -- input, UART0, UART1 or UART2
* ret: none
* modify:
* comment:
*********************************************************************************************/
void uart_init(int nMainClk, int nBaud, int nChannel)
{
// int i;
if(nMainClk == 0)
nMainClk = PCLK;
switch (nChannel)
{
case UART0:
UFCON0 = 0x0; //UART channel 0 FIFO control register, FIFO disable
UMCON0 = 0x0; //UART chaneel 0 MODEM control register, AFC disable
ULCON0 = 0x3; //Line control register : Normal,No parity,1 stop,8 bits
// [10] [9] [8] [7] [6] [5] [4] [3:2] [1:0]
// Clock Sel, Tx Int, Rx Int, Rx Time Out, Rx err, Loop-back, Send break, Transmit Mode, Receive Mode
// 0 1 0, 0 1 0 0, 01 01
// PCLK Level Pulse Disable Generate Normal Normal Interrupt or Polling
UCON0 = 0x345; // Control register
// rUBRDIV0=( (int)(nMainClk/16./nBaud) -1 ); // Baud rate divisior register 0
UBRDIV0=( (int)(nMainClk/16./nBaud+0.5) -1 ); // Baud rate divisior register 0
break;
case UART1:
UFCON1 = 0x0; //UART channel 1 FIFO control register, FIFO disable
UMCON1 = 0x0; //UART chaneel 1 MODEM control register, AFC disable
ULCON1 = 0x3;
UCON1 = 0x245;
UBRDIV1=( (int)(nMainClk/16/nBaud) -1 );
break;
default:
break;
}
// for(i=0;i<100;i++);
// delay(400);
}
void uart_sendbyte(int nData)
{
UTXH0 = nData;
while(!(UTRSTAT0 & 0x2));
}
void __irq uart_int(void)
{
int temp ;
temp = URXH0;
UTXH0= temp;
SUBSRCPND |= 1;
ClearPending(1<<28);
}
/*********************************************************************************************
* name: uart_sendstring
* func: Send string to uart channel
* para: pString -- input, string
* ret: none
* modify:
* comment:
*********************************************************************************************/
void uart_sendstring(char *pString)
{
while(*pString != '\0')
uart_sendbyte(*pString++);
}
void uart_printf(char *fmt)
{
uart_sendstring(fmt);
}
int main()
{
WTCON = 0;
CLKDIVN = (1<<1) | 1; //设置 1:2:4
MPLLCON = (0xa1<<12) | (0x3<<4) | 0x1; // Fin=12MHz FCLK=202.8MHz
//=== PORT H GROUP
//Ports : GPH10 GPH9 GPH8 GPH7 GPH6 GPH5 GPH4 GPH3 GPH2 GPH1 GPH0
//Signal : GPH10 CLKOUT0 SD_WP CTS1 RTS1 RXD1 TXD1 RXD0 TXD0 nRTS0 nCTS0
//Setting: Output CLKOUT0 GPH8 nCTS1 nRTS1 RXD1 TXD1 RXD0 TXD0 nRTS0 nCTS0
//Binary : 10, 10 10, 11 11, 10 10, 10 10, 10 10
GPHCON = 0x2afaaa;
GPHUP = 0x7ff; // The pull up function is disabled GPH[10:0]
pISR_UART0 = (unsigned int )uart_int;
uart_init(PCLK, 115200, UART0);
uart_sendbyte('\n');
uart_printf ("boot success...");
uart_sendbyte('\n');
uart_printf("please enter a char");
uart_sendbyte('\n');
uart_sendbyte('>');
uart_sendbyte('$');
SRCPND = SRCPND; // clear all interrupt
INTPND = INTPND; // clear all interrupt;
INTSUBMSK = INTSUBMSK & ~(1<<0);
INTMSK = INTMSK & ~(1<<28);
while(1);
}