• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            USB系列之一:列出你的USB設備

             USB現(xiàn)在已經(jīng)成為PC機必不可少的接口之一,幾乎所有的設備都可以接在USB設備上,USB鍵盤、鼠標、打印機、攝像頭,還有常用的U盤等等,從本篇文章開始,將集中篇幅介紹一下在DOS中使用USB設備的方法,具體會有幾篇暫不好定,寫到哪里算哪里吧,三、四篇總是少不了的。
                本文介紹如何使用我以前文章中介紹過的知識在你的機器中找到USB設備,并判定設備類型。
                一個USB系統(tǒng)一般由一個USB主機(HOST)、一個或多個USB集線器(HUB,但不是局域網(wǎng)里的集線器)和一個或多個USB設備節(jié)點(NODE)組成,一個系統(tǒng)中只有一個HOST,我們PC機里的USB實際上就是HOST和HUB兩部分,你的PC機可能會有4個USB口,其實是一個HOST,一個HUB,HUB為你提供了4個端口,我們插在USB口上的器件,一般是USB設備,比如U盤,USB打印機等,當然我們也可以插一個集線器上去,使你的一個USB口擴展成多個。
                實際上我們說在DOS下使用USB,就是對USB系統(tǒng)中的HOST進行編程管理,根據(jù)USB的規(guī)范,HOST將對連接在上面的HUB和USB設備進行管理,不用我們操心。HOST器件目前有三個規(guī)范,OHCI(Open Host Controller Interface)、UHCI(Universal Host Controller Interface)支持USB1.1,EHCI(Enhanced Host Controller Interface)支持USB2.0,以后的文章中,我們將側(cè)重介紹OHCI和EHCI。
                學習USB編程,讀規(guī)范是少不了的,以下是一些應該閱讀的規(guī)范下載:
                OHCI規(guī)范:
            http://blog.hengch.com/specification/usb_ohci_r10a.pdf
                EHCI規(guī)范:http://blog.hengch.com/specification/usb_ehci_r10.pdf
                USB規(guī)范1.1:http://blog.hengch.com/specification/usb_spec11.pdf
                USB規(guī)范2.0:http://blog.hengch.com/specification/usb_spec20.pdf
                本文介紹的內(nèi)容不需要學習規(guī)范。

                下面進入正題,列出你的USB設備,USB的HOST是掛接在PCI總線上的,所以通過PCI設備的遍歷就可以找到你的機器上的所有USB設備,在以前介紹PCI的配置空間時,曾經(jīng)介紹過在配置空間中有一個占三個字節(jié)的分類代碼字段(如果不知道,請參閱我以前的博文
            《遍歷PCI設備》),在偏移為0x0B的字節(jié)叫基本分類代碼,在偏移為0x0A的字節(jié)叫子分類代碼,在偏移為0x09的字節(jié)叫編程接口代碼,對于USB設備類說,基本分類代碼為0x0C,子分類代碼為0x03,對于符合不同規(guī)范的HOST器件而言,編程接口代碼是不同的,UHCI的編程接口代碼是0x00,OHCI的編程接口代碼是0x10,EHCI的編程接口代碼是0x20,我想了解這些就足夠了。
                下面列出USB設備的源程序。
            #include <stdio.h>
            #include <stdlib.h>
            #include <dpmi.h>

            typedef unsigned long      UDWORD;
            typedef short int          WORD;
            typedef unsigned short int UWORD;
            typedef unsigned char      UBYTE;

            typedef union {
              struct {
                UDWORD edi;
                UDWORD esi;
                UDWORD ebp;
                UDWORD res;
                UDWORD ebx;
                UDWORD edx;
                UDWORD ecx;
                UDWORD eax;
              } d;
              struct {
                UWORD di, di_hi;
                UWORD si, si_hi;
                UWORD bp, bp_hi;
                UWORD res, res_hi;
                UWORD bx, bx_hi;
                UWORD dx, dx_hi;
                UWORD cx, cx_hi;
                UWORD ax, ax_hi;
                UWORD flags;
                UWORD es;
                UWORD ds;
                UWORD fs;
                UWORD gs;
                UWORD ip;
                UWORD cs;
                UWORD sp;
                UWORD ss;
              } x;
              struct {
                UBYTE edi[4];
                UBYTE esi[4];
                UBYTE ebp[4];
                UBYTE res[4];
                UBYTE bl, bh, ebx_b2, ebx_b3;
                UBYTE dl, dh, edx_b2, edx_b3;
                UBYTE cl, ch, ecx_b2, ecx_b3;
                UBYTE al, ah, eax_b2, eax_b3;
              } h;
            } X86_REGS;
            /*************************************************************
             * Excute soft interrupt in real mode
             *************************************************************/
            int x86_int(int int_num, X86_REGS *x86_reg) {
              __dpmi_regs d_regs;
              int return_value;

              d_regs.d.edi = x86_reg->d.edi;
              d_regs.d.esi = x86_reg->d.esi;
              d_regs.d.ebp = x86_reg->d.ebp;
              d_regs.d.res = x86_reg->d.res;
              d_regs.d.ebx = x86_reg->d.ebx;
              d_regs.d.ecx = x86_reg->d.ecx;
              d_regs.d.edx = x86_reg->d.edx;
              d_regs.d.eax = x86_reg->d.eax;
              d_regs.x.flags = x86_reg->x.flags;
              d_regs.x.es = x86_reg->x.es;
              d_regs.x.ds = x86_reg->x.ds;
              d_regs.x.fs = x86_reg->x.fs;
              d_regs.x.gs = x86_reg->x.gs;
              d_regs.x.ip = x86_reg->x.ip;
              d_regs.x.cs = x86_reg->x.cs;
              d_regs.x.sp = x86_reg->x.sp;
              d_regs.x.ss = x86_reg->x.ss;

              return_value = __dpmi_int(int_num, &d_regs);

              x86_reg->d.edi = d_regs.d.edi;
              x86_reg->d.esi = d_regs.d.esi;
              x86_reg->d.ebp = d_regs.d.ebp;
              x86_reg->d.res = d_regs.d.res;
              x86_reg->d.ebx = d_regs.d.ebx;
              x86_reg->d.ecx = d_regs.d.ecx;
              x86_reg->d.edx = d_regs.d.edx;
              x86_reg->d.eax = d_regs.d.eax;
              x86_reg->x.flags = d_regs.x.flags;
              x86_reg->x.es = d_regs.x.es;
              x86_reg->x.ds = d_regs.x.ds;
              x86_reg->x.fs = d_regs.x.fs;
              x86_reg->x.gs = d_regs.x.gs;
              x86_reg->x.ip = d_regs.x.ip;
              x86_reg->x.cs = d_regs.x.cs;
              x86_reg->x.sp = d_regs.x.sp;
              x86_reg->x.ss = d_regs.x.ss;

              return return_value;
            }
            /**********************************
             * Read Configuration WORD if PCI
             **********************************/
            UWORD ReadConfigWORD(WORD pciAddr, int reg) {
              X86_REGS inregs;

              inregs.x.ax = 0xB109;    // Read Configuration word
              inregs.x.bx = pciAddr;
              inregs.x.di = reg;       // Register number
              x86_int(0x1A, &inregs);

              return inregs.d.ecx;     // the value
            }
            // main program
            int main(void) {
              UWORD pciAddr;
              UWORD subClass;
              int ehciCount = 0, ohciCount = 0, uhciCount = 0;

              for (pciAddr = 0; pciAddr < 0xffff; pciAddr++) {
                if (ReadConfigWORD(pciAddr, 0) != 0xFFFF) {
                  // Read Class Code
                  if (ReadConfigWORD(pciAddr, 0x000a ) == 0x0c03) {  // Usb Host Controller
                    // Read SubClass Code
                    subClass = ReadConfigWORD(pciAddr, 0x0008);
                    if ((subClass & 0xff00) == 0x2000) {  // uhci
                      ehciCount++;
                    } else if ((subClass & 0xff00) == 0x1000) {  // ohci
                      ohciCount++;
                    } else if ((subClass & 0xff00) == 0x00) {    // uhci
                      uhciCount++;
                    }
                  }
                }
              }
              printf("There are %d ohci device(s).\n", ohciCount);
              printf("There are %d ehci device(s).\n", ehciCount);
              printf("There are %d uhci device(s).\n", uhciCount);
            }

                程序非常簡單,所有概念在以前的博文中均有過介紹,其中的子程序大多是以前程序范例中使用過的,所以在這里就不做更多的解釋了,程序中,我們僅僅列出了設備的數(shù)量,但很顯然,用這種方法,我們可以從配置空間里讀出基地址等信息,這些在以后的文章中會用到。

            posted on 2010-11-24 14:07 wrh 閱讀(766) 評論(0)  編輯 收藏 引用

            導航

            <2010年11月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            統(tǒng)計

            常用鏈接

            留言簿(19)

            隨筆檔案

            文章檔案

            收藏夾

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲精品美女久久久久99小说 | 亚洲精品无码专区久久同性男| 97精品久久天干天天天按摩| 人妻久久久一区二区三区| 国产成人精品白浆久久69| 狠狠久久综合伊人不卡| 亚洲午夜无码AV毛片久久| 亚洲AV无码1区2区久久| 精品久久国产一区二区三区香蕉 | 久久亚洲日韩精品一区二区三区| 2022年国产精品久久久久| 久久强奷乱码老熟女| 人妻无码αv中文字幕久久琪琪布| 久久996热精品xxxx| 久久w5ww成w人免费| 精品久久久一二三区| 久久综合九色综合久99| 久久精品人人做人人爽电影蜜月| 久久99精品国产99久久6| 99热成人精品热久久669| 国产精品久久久久久久久久影院| 久久r热这里有精品视频| 国产激情久久久久久熟女老人| 91久久精品国产免费直播| 好久久免费视频高清| 久久国产劲爆AV内射—百度| 久久久久久一区国产精品| 精品久久人人爽天天玩人人妻| 久久狠狠高潮亚洲精品 | 九九久久99综合一区二区| 一本一本久久A久久综合精品| 久久天天日天天操综合伊人av| 99久久99久久精品国产片果冻| 久久91亚洲人成电影网站| 国产精品久久久久9999高清| 久久夜色精品国产网站| 国产成人久久精品一区二区三区| 18禁黄久久久AAA片| 欧美日韩精品久久免费| 亚洲美日韩Av中文字幕无码久久久妻妇 | 一本色道久久88综合日韩精品 |