📄 serial.c.bak
字号:
/* * linux/kernel/serial.c * * (C) 1991 Linus Torvalds *//* * serial.c * * This module implements the rs232 io functions * void rs_write(struct tty_struct * queue); * void rs_init(void); * and all interrupts pertaining to serial IO. */#include <linux/tty.h>#include <linux/sched.h>#include <asm/system.h>#include <asm/io.h>#define WAKEUP_CHARS (TTY_BUF_SIZE/4)/*当写队列中含有WAKEUP_CHARS时就开始发送*/extern void rs1_interrupt(void);extern void rs2_interrupt(void);static void init(int port)/*初始化串行端口*/{ outb_p(0x80,port+3); /* set DLAB of line control reg */ outb_p(0x30,port); /* LS of divisor (48 -> 2400 bps */ outb_p(0x00,port+1); /* MS of divisor */ outb_p(0x03,port+3); /* reset DLAB */ outb_p(0x0b,port+4); /* set DTR,RTS, OUT_2 */ outb_p(0x0d,port+1); /* enable all intrs but writes */ (void)inb(port); /* read data port to reset things (?) */}void rs_init(void)/*初始化串行设备*/{ set_intr_gate(0x24,rs1_interrupt);/*设置串口1的中断向量*/ set_intr_gate(0x23,rs2_interrupt);/*设置串口2的中断向量*/ init(tty_table[1].read_q.data);/*初始化串口1(.data为端口的基地址)*/ init(tty_table[2].read_q.data);/*初始化串口2*/ outb(inb_p(0x21)&0xE7,0x21);}/* * This routine gets called when tty_write has put something into * the write_queue. It must check wheter the queue is empty, and * set the interrupt register accordingly * * void _rs_write(struct tty_struct * tty); */void rs_write(struct tty_struct * tty)/*串行数据发送输出(仅开启发送保持寄存器已空中断标志,此后当发送保持寄存器空时,UART就会产生中断请求,随后中断处理程序将会取走寄存器中的数据,随即UART又会产生中断,直到写队列为空位置)*/{ cli(); if (!EMPTY(tty->write_q)) outb(inb_p(tty->write_q.data+1)|0x02,tty->write_q.data+1); sti();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -