?? tty.h
字號:
/** 'tty.h'中定義了tty_io.c 程序使用的某些結(jié)構(gòu)和其它一些定義。** 注意!在修改這里的定義時,一定要檢查rs_io.s 或con_io.s 程序中不會出現(xiàn)問題。* 在系統(tǒng)中有些常量是直接寫在程序中的(主要是一些tty_queue 中的偏移值)。*/#ifndef _TTY_H#define _TTY_H#include <termios.h> // 終端輸入輸出函數(shù)頭文件。主要定義控制異步通信口的終端接口。#define TTY_BUF_SIZE 1024 // tty 緩沖區(qū)大小。// tty 等待隊列數(shù)據(jù)結(jié)構(gòu)。struct tty_queue{ unsigned long data; // 等待隊列緩沖區(qū)中當前數(shù)據(jù)指針字符數(shù)[??])。// 對于串口終端,則存放串行端口地址。 unsigned long head; // 緩沖區(qū)中數(shù)據(jù)頭指針。 unsigned long tail; // 緩沖區(qū)中數(shù)據(jù)尾指針。 struct task_struct *proc_list; // 等待進程列表。 char buf[TTY_BUF_SIZE]; // 隊列的緩沖區(qū)。};// 以下定義了tty 等待隊列中緩沖區(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))// 清空指定隊列的緩沖區(qū)。#define EMPTY(a) ((a).head == (a).tail)// 緩沖區(qū)還可存放字符的長度(空閑區(qū)長度)。#define LEFT(a) (((a).tail-(a).head-1)&(TTY_BUF_SIZE-1))// 緩沖區(qū)中最后一個位置。#define LAST(a) ((a).buf[(TTY_BUF_SIZE-1)&((a).head-1)])// 緩沖區(qū)滿(如果為1 的話)。#define FULL(a) (!LEFT(a))// 緩沖區(qū)中已存放字符的長度。#define CHARS(a) (((a).head-(a).tail)&(TTY_BUF_SIZE-1))// 從queue 隊列項緩沖區(qū)中取一字符(從tail 處,并且tail+=1)。#define GETCH(queue,c) \(void)(c=(queue).buf[(queue).tail],INC((queue).tail))//(void)({c=(queue).buf[(queue).tail];INC((queue).tail);})
// 往queue 隊列項緩沖區(qū)中放置一字符(在head 處,并且head+=1)。#define PUTCH(c,queue) \(void)( (queue).buf[(queue).head]=(c), INC((queue).head) )
//(void)({(queue).buf[(queue).head]=(c);INC((queue).head);})
// 判斷終端鍵盤字符類型。#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]) // 開始符。#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; // 所屬進程組。 int stopped; // 停止標志。 void (*write) (struct tty_struct * tty); // tty 寫函數(shù)指針。 struct tty_queue read_q; // tty 讀隊列。 struct tty_queue write_q; // tty 寫隊列。 struct tty_queue secondary; // tty 輔助隊列(存放規(guī)范模式字符序列),}; // 可稱為規(guī)范(熟)模式隊列。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* 開始start=^Q 停止stop=^S 掛起susp=^Z 行結(jié)束eol=\0* 重顯reprint=^R 丟棄discard=^U werase=^W lnext=^V* 行結(jié)束eol2=\0*/// 控制字符對應的ASCII 碼值。[8 進制]#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
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -