?? tty.h
字號(hào):
/** 'tty.h' defines some structures used by tty_io.c and some defines.** NOTE! Don't touch this without checking that nothing in rs_io.s or* con_io.s breaks. Some constants are hardwired into the system (mainly* offsets into 'tty_queue'*//** 'tty.h'中定義了tty_io.c 程序使用的某些結(jié)構(gòu)和其它一些定義。** 注意!在修改這里的定義時(shí),一定要檢查rs_io.s 或con_io.s 程序中不會(huì)出現(xiàn)問(wèn)題。* 在系統(tǒng)中有些常量是直接寫(xiě)在程序中的(主要是一些tty_queue 中的偏移值)。*/#ifndef _TTY_H#define _TTY_H#include <termios.h> // 終端輸入輸出函數(shù)頭文件。主要定義控制異步通信口的終端接口。#define TTY_BUF_SIZE 1024 // tty 緩沖區(qū)大小。// tty 等待隊(duì)列數(shù)據(jù)結(jié)構(gòu)。struct tty_queue{ unsigned long data; // 等待隊(duì)列緩沖區(qū)中當(dāng)前數(shù)據(jù)指針字符數(shù)[??])。// 對(duì)于串口終端,則存放串行端口地址。 unsigned long head; // 緩沖區(qū)中數(shù)據(jù)頭指針。 unsigned long tail; // 緩沖區(qū)中數(shù)據(jù)尾指針。 struct task_struct *proc_list; // 等待進(jìn)程列表。 char buf[TTY_BUF_SIZE]; // 隊(duì)列的緩沖區(qū)。};// 以下定義了tty 等待隊(duì)列中緩沖區(qū)操作宏函數(shù)。(tail 在前,head 在后)。// a 緩沖區(qū)指針前移1 字節(jié),并循環(huán)。#define INC(a) ((a) = ((a)+1) & (TTY_BUF_SIZE-1))// a 緩沖區(qū)指針后退1 字節(jié),并循環(huán)。#define DEC(a) ((a) = ((a)-1) & (TTY_BUF_SIZE-1))// 清空指定隊(duì)列的緩沖區(qū)。#define EMPTY(a) ((a).head == (a).tail)// 緩沖區(qū)還可存放字符的長(zhǎng)度(空閑區(qū)長(zhǎng)度)。#define LEFT(a) (((a).tail-(a).head-1)&(TTY_BUF_SIZE-1))// 緩沖區(qū)中最后一個(gè)位置。#define LAST(a) ((a).buf[(TTY_BUF_SIZE-1)&((a).head-1)])// 緩沖區(qū)滿(mǎn)(如果為1 的話(huà))。#define FULL(a) (!LEFT(a))// 緩沖區(qū)中已存放字符的長(zhǎng)度。#define CHARS(a) (((a).head-(a).tail)&(TTY_BUF_SIZE-1))// 從queue 隊(duì)列項(xiàng)緩沖區(qū)中取一字符(從tail 處,并且tail+=1)。#define GETCH(queue,c) \(void)({c=(queue).buf[(queue).tail];INC((queue).tail);})// 往queue 隊(duì)列項(xiàng)緩沖區(qū)中放置一字符(在head 處,并且head+=1)。#define PUTCH(c,queue) \(void)({(queue).buf[(queue).head]=(c);INC((queue).head);})// 判斷終端鍵盤(pán)字符類(lèi)型。#define INTR_CHAR(tty) ((tty)->termios.c_cc[VINTR]) // 中斷符。#define QUIT_CHAR(tty) ((tty)->termios.c_cc[VQUIT]) // 退出符。#define ERASE_CHAR(tty) ((tty)->termios.c_cc[VERASE]) // 削除符。#define KILL_CHAR(tty) ((tty)->termios.c_cc[VKILL]) // 終止符。#define EOF_CHAR(tty) ((tty)->termios.c_cc[VEOF]) // 文件結(jié)束符。#define START_CHAR(tty) ((tty)->termios.c_cc[VSTART]) // 開(kāi)始符。#define STOP_CHAR(tty) ((tty)->termios.c_cc[VSTOP]) // 結(jié)束符。#define SUSPEND_CHAR(tty) ((tty)->termios.c_cc[VSUSP]) // 掛起符。// tty 數(shù)據(jù)結(jié)構(gòu)。struct tty_struct{ struct termios termios; // 終端io 屬性和控制字符數(shù)據(jù)結(jié)構(gòu)。 int pgrp; // 所屬進(jìn)程組。 int stopped; // 停止標(biāo)志。 void (*write) (struct tty_struct * tty); // tty 寫(xiě)函數(shù)指針。 struct tty_queue read_q; // tty 讀隊(duì)列。 struct tty_queue write_q; // tty 寫(xiě)隊(duì)列。 struct tty_queue secondary; // tty 輔助隊(duì)列(存放規(guī)范模式字符序列),}; // 可稱(chēng)為規(guī)范(熟)模式隊(duì)列。extern struct tty_struct tty_table[]; // tty 結(jié)構(gòu)數(shù)組。/* intr=^C quit=^| erase=del kill=^Ueof=^D vtime=\0 vmin=\1 sxtc=\0start=^Q stop=^S susp=^Z eol=\0reprint=^R discard=^U werase=^W lnext=^Veol2=\0*//* 中斷intr=^C 退出quit=^| 刪除erase=del 終止kill=^U* 文件結(jié)束eof=^D vtime=\0 vmin=\1 sxtc=\0* 開(kāi)始start=^Q 停止stop=^S 掛起susp=^Z 行結(jié)束eol=\0* 重顯reprint=^R 丟棄discard=^U werase=^W lnext=^V* 行結(jié)束eol2=\0*/// 控制字符對(duì)應(yīng)的ASCII 碼值。[8 進(jìn)制]#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"void rs_init (void); // 異步串行通信初始化。(kernel/chr_drv/serial.c, 37)void con_init (void); // 控制終端初始化。 (kernel/chr_drv/console.c, 617)void tty_init (void); // tty 初始化。 (kernel/chr_drv/tty_io.c, 105)int tty_read (unsigned c, char *buf, int n); // (kernel/chr_drv/tty_io.c, 230)int tty_write (unsigned c, char *buf, int n); // (kernel/chr_drv/tty_io.c, 290)void rs_write (struct tty_struct *tty); // (kernel/chr_drv/serial.c, 53)void con_write (struct tty_struct *tty); // (kernel/chr_drv/console.c, 445)void copy_to_cooked (struct tty_struct *tty); // (kernel/chr_drv/tty_io.c, 145)#endif
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -