::硬件平台--s3c44b0x
一.驱动程序的初始化(在使用uart之前,必须保证已经对其定义和注册)
int uart_init(void){
printk("registering uart device...");
result = register_chrdev(254,"uart_dev",&uart_fops);
if(result<0){
printk("can not register uart_dev!");
return return ;
}
printk("initializing uart device");
setup_uart(); //初始化 系统寄存器和波特率寄存器等
printk("uart driver installed");
return 0;
}
二、UART的初始化
void setup_uart(int baud) {
UART_UFCON = 0XF7; //设置fifo属性,清楚fifo内容;
UART_UMCON = 0X00; //关闭流控制功能
UART_ULCON = 0X03; //设置8位数据位,1位停止位,无奇偶校验位
UART_UCON = 0X0345; //设置中断为点评触发
UART_UBDIV=((int)(mclk/16/baud+0.5)-1); //设置波特率
}
三、读写UART寄存器
宏定义:
#define UART_URXH *(volatile unsigned char *) 0x1D04024
#define UART_UTXH *(volatile unsigned char *) 0x1D04024
#define UART_UTRSTAT *(volatile unsigned char *) 0x1D04010
static unsigned char uart_getchar(){
if((UART_UTRSTAT&0x1)!=0)
return UART_UTRSTAT;
else
return -1;
}
static int uart_putchar(unsigned char c){
if((UART_UTRSTAT&0x2)!=0){
UART_UTXH = c;
return 0;
}
else
return -1;
}
四、中断的数据收发
void uart_RX_isr(unsigned char *buf,int *len){
*(buf++)=uart_getchar();
*len=*len+1;
}
void uart_TX_isr(){
uart_putchar();
}
五、中断的安装
int uart_init(void){
printk("registering uart device...");
result = register_chrdev(254,"uart_dev",&uart_fops);
if(result<0){
printk("can not register uart_dev!");
return return ;
}
printk("initializing uart device");
setup_uart(); //初始化 系统寄存器和波特率寄存器等
printk("uart driver installed");
request_irq(6,uart_receive_isr,IRQ_FLAG_STD,"uart_dev",NULL);
request_irq(2,uart_send_isr,IRQ_FLAG_STD,"uart_dev",NULL);
return 0;
}
void uart_receive_isr(int irq,void *dev_id,struct pt_regs *regs){
uart_RX_isr(buf,len);
}
void uart_send_isr(int irq,void *dev_id,struct pt_regs *regs){
uart_TX_isr();
}
struct pt_regs:
http://blog.csdn.net/xp_super/article/details/8006184
request_irq函数:
http://blog.csdn.net/xp_super/article/details/8006168
http://blog.csdn.net/xp_super/article/details/8006178