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

📄 basic_open_close_functions.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><h3><a name="the_open_function" id="the_open_function">The Open Function</a></h3><div class="level3"><p> The <strong>Open</strong> device driver function is used to set up the process access to the device. Normally the following functions are performed. </p><ul><li class="level1"><div class="li"> Set up a <strong>private data</strong> structure to save the state of the driver</div></li><li class="level1"><div class="li"> Create any memory areas used by the device drivers</div></li><li class="level1"><div class="li"> Manage any locks and semaphores used to control access to the device</div></li></ul><p> The <strong>Open</strong> function should return <strong>0</strong> to indicate success or a  negative <strong>error</strong> code.</p><p>The parameters for the <strong>open</strong> function are as follows </p><ul><li class="level1"><div class="li"> struct inode *inode </div></li><li class="level1"><div class="li"> struct file *file   </div></li></ul><pre class="code">The inode refers to the device node found on the file system The  file is a structure, created by the kernel, to hold thestate of our use of the device within the device driver</pre><p> A typical <strong>Open</strong> Function is shown here</p><pre class="code c"><span class="kw4">static</span> <span class="kw4">unsigned</span> <span class="kw4">long</span> scmd_is_open&nbsp;<span class="kw4">static</span> <span class="kw4">int</span> scmd_open<span class="br0">&#40;</span><span class="kw4">struct</span> inode *inode, <span class="kw4">struct</span> file *file<span class="br0">&#41;</span><span class="br0">&#123;</span>        <span class="co1">// allow only one user</span>        <span class="kw1">if</span><span class="br0">&#40;</span>test_and_set_bit<span class="br0">&#40;</span><span class="nu0">0</span>, &amp;scmd_is_open<span class="br0">&#41;</span><span class="br0">&#41;</span>                <span class="kw1">return</span> -EBUSY;        <span class="co1">// Activate the system</span>        scmd_start<span class="br0">&#40;</span><span class="br0">&#41;</span>;&nbsp;        <span class="kw1">return</span> nonseekable_open<span class="br0">&#40;</span>inode, file<span class="br0">&#41;</span>;<span class="br0">&#125;</span>&nbsp;</pre><p>Note that <strong>nonseekable_open</strong> open is defined in <strong>fs/open.c</strong> </p><pre class="code c">&nbsp;<span class="coMULTI">/* * This is used by subsystems that don't want seekable * file descriptors */</span><span class="kw4">int</span> nonseekable_open<span class="br0">&#40;</span><span class="kw4">struct</span> inode *inode, <span class="kw4">struct</span> file *filp<span class="br0">&#41;</span><span class="br0">&#123;</span>        filp-&gt;f_mode &amp;= ~<span class="br0">&#40;</span>FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE<span class="br0">&#41;</span>;        <span class="kw1">return</span> <span class="nu0">0</span>;<span class="br0">&#125;</span>&nbsp;</pre><p>This is a typical <strong>close</strong> function. It is sometimes called <strong>release</strong>.</p><pre class="code c">&nbsp;<span class="kw4">static</span> <span class="kw4">int</span> scmd_release<span class="br0">&#40;</span><span class="kw4">struct</span> inode *inode, <span class="kw4">struct</span> file *file<span class="br0">&#41;</span><span class="br0">&#123;</span>        <span class="co1">// release the driver for others</span>        clear_bit<span class="br0">&#40;</span><span class="nu0">0</span>, &amp;scmd_is_open<span class="br0">&#41;</span>;&nbsp;        <span class="co1">// we are done</span>        <span class="kw1">return</span> <span class="nu0">0</span>;<span class="br0">&#125;</span></pre></div></body></html>

⌨️ 快捷键说明

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