参考:
1)《USER'S MANUAL-S3C6410X》第31章 UART
2)u-boot uart初始化及读写:u-boot-x.x.x/board/samsumg/smdk6410/lowlevel_init.S
u-boot-x.x.x/cpu/s3c64xx/serial.c
3) 内核串口驱动:linux-x.x.x/driver/tty/serial/s3c6400.c samsung.c serial_core.c
代码:
uart.c
#include "uart.h" #define GPACON (*((volatile unsigned long *)0x7f008000)) #define ULCON0 (*((volatile unsigned long *)0x7f005000))
#define UCON0 (*((volatile unsigned long *)0x7f005004))
#define UFCON0 (*((volatile unsigned long *)0x7f005008))
#define UMCON0 (*((volatile unsigned long *)0x7f00500c))
#define UTRSTAT0 (*((volatile unsigned long *)0x7f005010))
#define UERSTAT0 (*((volatile unsigned long *)0x7f005014))
#define UFSTAT0 (*((volatile unsigned long *)0x7f005018))
#define UMSTAT0 (*((volatile unsigned long *)0x7f00501c))
#define UTXH0 (*((volatile unsigned long *)0x7f005020))
#define URXH0 (*((volatile unsigned long *)0x7f005024))
#define UBRDIV0 (*((volatile unsigned long *)0x7f005028))
#define UDIVSLOT0 (*((volatile unsigned long *)0x7f00502c))
#define UINTP0 (*((volatile unsigned long *)0x7f005030))
#define UINTSP0 (*((volatile unsigned long *)0x7f005034))
#define UINTM0 (*((volatile unsigned long *)0x7f005038)) void uart0_init(void)
{
GPACON &= ~0xff;
GPACON |= 0X22; ULCON0 = 0x03; //data frame: 8n1
/*
clk: pclk
tx int type: level
rx int type: pulse
rx err int enable
tx/rx mode: interrupt or polling
*/
UCON0 = 0x245;
UFCON0 = 0x00; //disable fifo;
UMCON0 = 0X00; //disable auto flow control(AFC)
/*
DIV_VAL = UBRDIV + (num of 1's in UDIVSLOT)/16
DIV_VAL = (PCLK/(bps*16))-1 = (66000000/115200)-1=34.8
UBRDIV = 34;
num of 1's in UDIVSLOT = 13;
*/
UBRDIV0 = 0x22;
UDIVSLOT0 = 0x1fff;
} int uart0_getc(void)
{
while (!(UTRSTAT0 & 0x1));
return (URXH0 & 0xff);
} void uart0_putc(const char c)
{
while (!(UTRSTAT0 & 0x2));
UTXH0 = c;
if (c == '\n')
{
uart0_putc('\r');
}
} void uart0_puts(const char *s)
{
while (*s)
{
uart0_putc(*s++);
}
}