久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

Linux子系統(tǒng)系列-TTY

 WUCANADA 2012-05-05

Linux子系統(tǒng)系列-TTY

分類: 技術(shù)文檔 175人閱讀 評(píng)論(0) 收藏 舉報(bào)

處理過(guò)幾個(gè)串口的問(wèn)題,,這幾天才稍微有了些時(shí)間來(lái)整理一下這一塊的東西,。

目錄暫時(shí)大致分為以下幾部分吧:

0,背景

1,,串口驅(qū)動(dòng)的結(jié)構(gòu)

2,串口驅(qū)動(dòng)的實(shí)現(xiàn)

3,,關(guān)于TTY core

---------------------------------------------------------------------------------------------------

0,,背景

往常review這塊代碼的時(shí)候,經(jīng)常會(huì)被linux代碼樹(shù)中東一片西一片的uart,,tty,,serial device的代碼搞的暈頭轉(zhuǎn)向。參照l(shuí)inux的驅(qū)動(dòng)設(shè)備模型,,其實(shí)串口驅(qū)動(dòng)被一層層的完美的組裝在一起,。

對(duì) 于用于,直接接觸的是串口(serial interface),,這是在計(jì)算機(jī)或嵌入式設(shè)備上一種應(yīng)用非常廣泛的一個(gè)設(shè)備接口,。我們嘴里經(jīng)常嘮叨的UART其實(shí)只是串口通信的一種硬件實(shí)現(xiàn)方式而 已,,只不過(guò)最早最廣泛使用的是這一種方式,所以大家聽(tīng)到的比較多?,F(xiàn)在在串口后面的硬件實(shí)現(xiàn)方式越來(lái)越多:紅外設(shè)備,,usb設(shè)備等等,口那幾根線后面接的 chip的種類也越來(lái)越多,,每種片子都對(duì)需要不同的驅(qū)動(dòng)來(lái)工作,。Linux領(lǐng)域的大師們就根據(jù)這些情況以及發(fā)展趨勢(shì),將一些通用的接口抽象出來(lái),,形成一個(gè) 支持多種串行通信的子系統(tǒng)-TTY Core,,當(dāng)然也提供了通用的支持linux 設(shè)備模型的接口方便編寫符合linux設(shè)備模型規(guī)范的驅(qū)動(dòng)代碼,:).

note:tty并不是完全指代串口的底層抽象,,后面會(huì)稍加闡述,。

1,串口驅(qū)動(dòng)的結(jié)構(gòu)

對(duì)于一般的UART串口,,它的實(shí)現(xiàn)分為三層,,最底層是TTY Core,中間是UART Core,,最上層是特定的芯片驅(qū)動(dòng),。

最上層的驅(qū)動(dòng)使用UART Core的API簡(jiǎn)單直觀的完成設(shè)備和驅(qū)動(dòng)的注冊(cè),UART Core利用TTY Core中API最終實(shí)現(xiàn)設(shè)備驅(qū)動(dòng)的注冊(cè),。

 

2,,串口驅(qū)動(dòng)的實(shí)現(xiàn)

系統(tǒng)啟動(dòng)時(shí),tty會(huì)作為一個(gè)char設(shè)備早早的注冊(cè)到kernel(driver/char/tty_io.c),,因?yàn)樗浅橄蟮淖罴兇獾模?),。

UART Core沒(méi)有作為一個(gè)模塊注冊(cè)到kernel,它實(shí)現(xiàn)了一些通用的API來(lái)供使用到UART的串口設(shè)備來(lái)調(diào)用,。

最 上層的芯片驅(qū)動(dòng)就根據(jù)芯片的具體特性和參考串行通信的基本模式依賴UART Core的一些API實(shí)現(xiàn)相應(yīng)的功能供用戶層配置和使用,。主要是實(shí)現(xiàn)一些tty_operations里面聲明的一些回調(diào)函數(shù),如果使用UART設(shè)備,,有 一些實(shí)現(xiàn)也會(huì)在UART Core里面實(shí)現(xiàn),。

struct tty_operations {
    struct tty_struct * (*lookup)(struct tty_driver *driver,
            struct inode *inode, int idx);
    int  (*install)(struct tty_driver *driver, struct tty_struct *tty);
    void (*remove)(struct tty_driver *driver, struct tty_struct *tty);
    int  (*open)(struct tty_struct * tty, struct file * filp);
    void (*close)(struct tty_struct * tty, struct file * filp);
    void (*shutdown)(struct tty_struct *tty);
    void (*cleanup)(struct tty_struct *tty);
    int  (*write)(struct tty_struct * tty,
              const unsigned char *buf, int count);
    int  (*put_char)(struct tty_struct *tty, unsigned char ch);
    void (*flush_chars)(struct tty_struct *tty);
    int  (*write_room)(struct tty_struct *tty);
    int  (*chars_in_buffer)(struct tty_struct *tty);
    int  (*ioctl)(struct tty_struct *tty, struct file * file,
            unsigned int cmd, unsigned long arg);
    long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
                 unsigned int cmd, unsigned long arg);
    void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
    void (*throttle)(struct tty_struct * tty);
    void (*unthrottle)(struct tty_struct * tty);
    void (*stop)(struct tty_struct *tty);
    void (*start)(struct tty_struct *tty);
    void (*hangup)(struct tty_struct *tty);
    int (*break_ctl)(struct tty_struct *tty, int state);
    void (*flush_buffer)(struct tty_struct *tty);
    void (*set_ldisc)(struct tty_struct *tty);
    void (*wait_until_sent)(struct tty_struct *tty, int timeout);
    void (*send_xchar)(struct tty_struct *tty, char ch);
    int (*tiocmget)(struct tty_struct *tty, struct file *file);
    int (*tiocmset)(struct tty_struct *tty, struct file *file,
            unsigned int set, unsigned int clear);
    int (*resize)(struct tty_struct *tty, struct winsize *ws);
    int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew);
#ifdef CONFIG_CONSOLE_POLL
    int (*poll_init)(struct tty_driver *driver, int line, char *options,
            void *rx_callback);
    int (*poll_get_char)(struct tty_driver *driver, int line);
    void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
#endif
    const struct file_operations *proc_fops;
};

3,關(guān)于TTY core

TTY在linux領(lǐng)域指的是終端,,它可以指代任意終端設(shè)備,,包括串口設(shè)備,console設(shè)備等等,。

在/dev目錄下,,大家如果看到ttyS*就表示指代的是串口設(shè)備(S'serial' tty),而pty就指的是虛擬/偽終端設(shè)備(Pseudo tty)

TTY 子系統(tǒng)使用tty_driver來(lái)表示一個(gè)在它這個(gè)層次抽象出來(lái)的設(shè)備驅(qū)動(dòng),,TTY實(shí)現(xiàn)了以下API來(lái)完成一個(gè)終端設(shè)備驅(qū)動(dòng)的注冊(cè):

1)alloc_tty_driver()

2)tty_set_operations():建立tty entry point

3)tty_register_driver()

4)tty_register_device()

這樣讓一個(gè)終端驅(qū)動(dòng)的注冊(cè)變的十分清晰,。

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多