?? serial.c
字號:
/*
* 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)
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 */ //線控制寄存器,將第7位置1是開放除法因子鎖存器地址位
outb_p(0x30,port); /* LS of divisor (48 -> 2400 bps */ //將波特率設為2400(低有效位)
outb_p(0x00,port+1); /* MS of divisor */ //將波特率的最高有效位保存入該寄存器
outb_p(0x03,port+3); /* reset DLAB */ //將DLAB設為0,幀設為8位(通常是8位)
outb_p(0x0b,port+4); /* set DTR,RTS, OUT_2 */ //設置數據終端準備好線(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); //串行口端口3F8的中斷好是0x24
set_intr_gate(0x23,rs2_interrupt); //串行口端口2F8的中斷好是0x23
init(tty_table[1].read_q.data); //初始化2個串行端口
init(tty_table[2].read_q.data);
outb(inb_p(0x21)&0xE7,0x21); //控制中斷控制器對中斷請求線0--7的操作
}
/*
* 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)
{
cli();
if (!EMPTY(tty->write_q))
outb(inb_p(tty->write_q.data+1)|0x02,tty->write_q.data+1); //將寄存器的第2位(傳送位)置1,開放傳送中斷
sti();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -