?? serial.c
字號:
/** 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.*//** serial.c* 該程序用于實現(xiàn)rs232 的輸入輸出功能* void rs_write(struct tty_struct *queue);* void rs_init(void);* 以及與傳輸IO 有關系的所有中斷處理程序。*/#include <linux/tty.h> /* tty 頭文件,定義了有關tty_io,串行通信方面的參數(shù)、常數(shù) */#include <linux/sched.h> /* 調度程序頭文件,定義了任務結構task_struct、初始任務0 的數(shù)據(jù)*/ // 還有一些有關描述符參數(shù)設置和獲取的嵌入式匯編函數(shù)宏語句。#include <asm/system.h> /* 段操作頭文件。定義了有關段寄存器操作的嵌入式匯編函數(shù)*/#include <asm/io.h> /* io 頭文件。定義硬件端口輸入/輸出宏匯編語句*/#define WAKEUP_CHARS (TTY_BUF_SIZE/4) /* 當寫隊列中含有WAKEUP_CHARS 個字符時,就開始發(fā)送*/extern void rs1_interrupt (void); /* 串行口1 的中斷處理程序(rs_io.s, 34) */extern void rs2_interrupt (void); /* 串行口2 的中斷處理程序(rs_io.s, 38) *///// 初始化串行端口// port: 串口1 - 0x3F8,串口2 - 0x2F8。static void init (int port){ outb_p (0x80, port + 3); /* set DLAB of line control reg */ /* 設置線路控制寄存器的DLAB 位(位7) */ outb_p (0x30, port); /* LS of divisor (48 -> 2400 bps */ /* 發(fā)送波特率因子低字節(jié),0x30->2400bps */ outb_p (0x00, port + 1); /* MS of divisor */ /* 發(fā)送波特率因子高字節(jié),0x00 */ outb_p (0x03, port + 3); /* reset DLAB */ /* 復位DLAB 位,數(shù)據(jù)位為8 位 */ outb_p (0x0b, port + 4); /* set DTR,RTS, OUT_2 */ /* 設置DTR,RTS,輔助用戶輸出2 */ outb_p (0x0d, port + 1); /* enable all intrs but writes */ /* 除了寫(寫保持空)以外,允許所有中斷源中斷 */ (void) inb (port); /* read data port to reset things (?) */ /* 讀數(shù)據(jù)口,以進行復位操作(?) */}// 初始化串行中斷程序和串行接口。void rs_init (void){ set_intr_gate(0x24, rs1_interrupt); /* 設置串行口1 的中斷門向量(硬件IRQ4 信號)。*/ set_intr_gate (0x23, rs2_interrupt); /* 設置串行口2 的中斷門向量(硬件IRQ3 信號)。*/ init (tty_table[1].read_q.data); /* 初始化串行口1(.data 是端口號)。*/ init (tty_table[2].read_q.data); /* 初始化串行口2。*/ outb (inb_p (0x21) & 0xE7, 0x21); /* 允許主8259A 芯片的IRQ3,IRQ4 中斷信號請求。*/}/** 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);*//** 在tty_write()已將數(shù)據(jù)放入輸出(寫)隊列時會調用下面的子程序。必須首先* 檢查寫隊列是否為空,并相應設置中斷寄存器。*///// 串行數(shù)據(jù)發(fā)送輸出。// 實際上只是開啟串行發(fā)送保持寄存器已空中斷標志,在UART 將數(shù)據(jù)發(fā)送出去后允許發(fā)中斷信號。void rs_write (struct tty_struct *tty){ cli (); // 如果寫隊列不空,則從0x3f9(或0x2f9) 首先讀取中斷允許寄存器內容,添上發(fā)送保持寄存器 // 中斷允許標志(位1)后,再寫回該寄存器。 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 + -