⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 device_classes.html

📁 ADI 公司blackfin系列的用户使用文挡。
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head>  <title></title>  <link rel="stylesheet" media="screen" type="text/css" href="./style.css" />  <link rel="stylesheet" media="screen" type="text/css" href="./design.css" />  <link rel="stylesheet" media="print" type="text/css" href="./print.css" />  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><a href=start.html>start</a></br><div class="toc"><div class="tocheader toctoggle" id="toc__header">Table of Contents</div><div id="toc__inside"><ul class="toc"><li class="clear"><ul class="toc"><li class="clear"><ul class="toc"><li class="level3"><div class="li"><span class="li"><a href="#device_classes" class="toc">Device Classes</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#major_numbers" class="toc">Major Numbers</a></span></div></li></ul></li><li class="level2"><div class="li"><span class="li"><a href="#minor_numbers" class="toc">Minor Numbers</a></span></div><ul class="toc"><li class="level3"><div class="li"><span class="li"><a href="#major_number_allocation" class="toc">Major number allocation</a></span></div></li></ul></li></ul></li></ul></div></div><h3><a name="device_classes" id="device_classes">Device Classes</a></h3><div class="level3"><p> Devices come in three &ldquo;flavors&rdquo;: Character, Block and Network. </p><ul><li class="level1"><div class="li"> Character:</div></li></ul><ul><li class="level1"><div class="li"> Serial Access</div></li><li class="level3"><div class="li"> (Normally) Single word (byte) at a time</div></li><li class="level3"><div class="li"> Completes as it is called</div></li></ul><ul><li class="level1"><div class="li"> Block:</div></li></ul><ul><li class="level1"><div class="li"> Random Access</div></li><li class="level3"><div class="li"> Multiple words (bytes) at a time</div></li><li class="level3"><div class="li"> Uses Buffer Cache</div></li><li class="level3"><div class="li"> Delayed actual completion</div></li></ul><ul><li class="level1"><div class="li"> Network:</div></li></ul><ul><li class="level1"><div class="li"> Interrupt Push</div></li><li class="level3"><div class="li"> Different &ldquo;device&rdquo; structure</div></li><li class="level3"><div class="li"> Manipulation Tools</div></li></ul><p> Character and Block devices are accessed by <strong>device nodes</strong>. These are created using the <strong>mknod</strong> command (more later) and , by convention, are placed in  a special <strong>/dev</strong> directory. They can exist anywhere and do not need the device driver </p><p>NOTE These are not real files but special files that allow user tasks to communicate with the kernel based driver. The key elements in these files are: </p><ul><li class="level1"><div class="li"> Device class (block or char)</div></li><li class="level1"><div class="li"> Major Number</div></li><li class="level1"><div class="li"> Minor Number</div></li></ul><p>This is an example of some possible entries in this directory. </p><pre class="code">b = blockc = char           owner  grp    maj,min   date             name                                                                 brw-rw----     1   root   disk    3,0      May   5   1998   hda  brw-rw----     1   root   disk    3,1      May   5   1998   hda1 brw-rw----     1   root   disk    3,10     May   5   1998   hda10.                                                                brw-rw----     1   root   disk    3,64     May   5   1998   hdb  brw-rw----     1   root   disk    3,65     May   5   1998   hdb1 .                                                                crw-rw-r       1   root   root    10,1     May   5   17:14  psaux.                                                                crw-rw-rw-     1   root   root    5,0      May   5   1998   tty  crw-------     1   root   root    4,0      May   5   1998   tty0 crw-------     1   root   tty     4,1      Feb   23  20:06  tty1 crw-rw----     1   root   uucp    19,0     Apr   17  1999   ttyC0                                                                                                                                  </pre></div><!-- SECTION [1-2149] --><h3><a name="major_numbers" id="major_numbers">Major Numbers</a></h3><div class="level3"><p> To look at the drivers installed on your system use the command: </p><pre class="code">                                  cat /proc/devices                 </pre><p> You should get an output of a number followed by a name like this: </p><pre class="code">                                                        (Major Number/ Device Name )                            Character devices:            1 mem                       2 pty                       3 ttyp                      4 ttyS                      5 cua                       7 vcs                      10 misc                     14 sound                   128 ptm                     136 pts                     254 pcmcia                                              Block devices:                1 ramdisk                   2 fd                        3 ide0                     22 ide1                                                                            </pre><p> The same major number can be used by both a char and a block driver.</p><p>The major number provides the main link between the device, the kernel driver, and the user software. The user opens a device represented by a device node file (created by mknod). This special file was given a class (b-block or c- char) and a major number when it was created.</p><p>The major number refers to a device driver that was registered within the kernel as servicing that particular class of device.</p><p>Looking at </p><pre class="code"> /proc/devices</pre><p> you can see all the currently registered major numbers for both char and block devices.</p></div><!-- SECTION [2150-3728] --><h2><a name="minor_numbers" id="minor_numbers">Minor Numbers</a></h2><div class="level2"><p> The minor number is also specified by the special file (created by mknod). The main driver is referenced by the major number, but the minor number can be used to pick a particular instance of the device controlled by the driver.</p><p>A serial driver may control several serial ports; in this the minor number may direct the driver to a particular port.</p><p>In some cases the minor number can refer to a completely different set of read/ write operations.</p><pre class="code">                                                                                                                                    [root@train /root]# ls -l /dev/random                             crw-r--r--   1 root     root       1,   8 May  5  1998 /dev/random[root@train /root]# ls -l /dev/zero                               crw-rw-rw-   1 root     root       1,   5 May  5  1998 /dev/zero                                                                    </pre><p> The random and zero devices both have the same major number, but the different minor numbers result in different responses to read/write operations.</p><pre class="code">                                                                                                                                                                                                   [root@train /root]# ls -l /dev/ttyS*                             crw-------   1 root     tty        4,  64 May 28 13:08 /dev/ttyS0crw-rw-rw-   1 root     tty        4,  65 Jun  7 23:08 /dev/ttyS1crw-------   1 root     tty        4,  66 Apr 28 09:47 /dev/ttyS2crw-------   1 root     tty        4,  67 May  5  1998 /dev/ttyS3                                                                                                                                                                                                   </pre><p> The serial driver uses the same software for each serial port. The minor number is used to change the actual physical address of the device being referenced.</p></div><!-- SECTION [3729-5747] --><h3><a name="major_number_allocation" id="major_number_allocation">Major number allocation</a></h3><div class="level3"><p> The main document used to determine the pre allocated device major numbers is </p><ul><li class="level1"><div class="li"> linux-2.6.x/Documentation/devices.txt</div></li></ul><p>There is a move in more recent system to move away from a fixed allocation scheme and use dynamic device allocation for newer systems. This has some drawbacks for embedded systems since extra code is needed, as the device driver is set up, to determine the correct major numbers for a dynamically allocated driver.</p><p>The <strong>devfs</strong> system was used in embedded systems to provide a means of automatically creating the entries in the <strong>/dev</strong> directory as each device was registered.</p><p>This approach is being deprecated in the 2.6 kernels in favor of the kernel object filesystem <strong>sysfs</strong>.</p></div><!-- SECTION [5748-] --></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -