39 lines
7.3 KiB
HTML
39 lines
7.3 KiB
HTML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>The Be Book - Special Topics - Device Drivers</title><link rel="stylesheet" href="be_book.css" type="text/css" media="all" /><link rel="shortcut icon" type="image/vnd.microsoft.icon" href="./images/favicon.ico" /><!--[if IE]>
|
||
<link rel="stylesheet" type="text/css" href="be_book_ie.css" />
|
||
<![endif]--><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><meta name="keywords" content="Access, BeOS, BeBook, API" /><link rel="start" href="index.html" title="The Be Book" /><link rel="up" href="DeviceDrivers.html" title="Device Drivers" /><link rel="prev" href="DeviceDrivers_WritingModules.html" title="Writing Modules" /><link rel="next" href="DeviceDrivers_area_malloc.html" title="The area_malloc Module" /></head><body><div id="header"><div id="headerT"><div id="headerTL"><a accesskey="p" href="DeviceDrivers_WritingModules.html" title="Writing Modules"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a accesskey="u" href="DeviceDrivers.html" title="Device Drivers"><img src="./images/navigation/up.png" alt="Up" /></a> <a accesskey="n" href="DeviceDrivers_area_malloc.html" title="The area_malloc Module"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="headerTR"><div id="navigpeople"><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div><div class="navigboxed" id="navigindex"><a accesskey="i" href="ClassIndex.html" title="Index">I</a></div><div class="navigboxed" id="naviglang" title="English">en</div></div><div id="headerTC">The Be Book - Special Topics - Device Drivers</div></div><div id="headerB">Prev: <a href="DeviceDrivers_WritingModules.html">Writing Modules</a> Up: <a href="DeviceDrivers.html">Device Drivers</a> Next: <a href="DeviceDrivers_area_malloc.html">The area_malloc Module</a></div><hr /></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h2 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="DeviceDrivers_UsingModules"></a>Using Modules</h2></div></div></div><p>Modules provide a means for multiple drivers to share common
|
||
functionality; for example, if a variety of types of device might be
|
||
accessed on the same bus, a module might be created to provide a common
|
||
interface to the bus.</p><p>Your driver can access these modules via the kernel functions
|
||
<a class="link" href="DeviceDrivers_WritingModules.html#get_module" title="get_module"><code class="function">get_module()</code></a>
|
||
and
|
||
<a class="link" href="DeviceDrivers_WritingModules.html#put_module" title="put_module"><code class="function">put_module()</code></a>,
|
||
which obtain and release references to a specified module. When you call
|
||
<a class="link" href="DeviceDrivers_WritingModules.html#get_module" title="get_module"><code class="function">get_module()</code></a>,
|
||
you obtain a structure that
|
||
provides information about the module, plus pointers to the module's
|
||
functions. The module is defined in a header file provided by the
|
||
module's author, similar to this:</p><pre class="programlisting example c">#define <code class="constant">MY_MODULE_NAME</code> "generic/mymodule/v1"
|
||
|
||
<span class="type">struct my_module_info</span> {
|
||
<span class="type">module_info</span> <code class="varname">module</code>;
|
||
<span class="type">int32</span> (*<code class="varname">function1</code>)();
|
||
<span class="type">int32</span> (*<code class="varname">function2</code>)();
|
||
<span class="type">void</span> (*<code class="varname">configure</code>)(<span class="type">int32</span> <code class="parameter">parameter</code>, <span class="type">int32</span> <code class="parameter">value</code>);
|
||
};</pre><p>When you want to access the module's functions, you call get_module() to
|
||
get a pointer to this structure from the kernel:</p><pre class="programlisting example c"><span class="type">struct my_module_info*</span><code class="varname">minfo</code> = <code class="constant">NULL</code>;
|
||
|
||
<span class="comment">/* get a pointer to the module */</span>
|
||
|
||
<code class="function">get_module</code>(<code class="constant">MY_MODULE_NAME</code>, (<span class="type">module_info**</span>) &<code class="varname">minfo</code>);</pre><p>Once you've done this, you can call the module's functions through the
|
||
structure:</p><pre class="programlisting example c"><code class="varname">minfo</code>-><code class="function">configure</code>(0, 10);</pre><p>When you're done with the module, you should call
|
||
<a class="link" href="DeviceDrivers_WritingModules.html#put_module" title="put_module"><code class="function">put_module()</code></a>
|
||
to release it. The kernel loads and unloads modules as needed, and properly calling
|
||
<a class="link" href="DeviceDrivers_WritingModules.html#put_module" title="put_module"><code class="function">put_module()</code></a>
|
||
lets the kernel do its job.</p><pre class="programlisting example c"><code class="function">put_module</code>(<code class="constant">MY_MODULE_NAME</code>);</pre><p>If you want a better understanding of how modules work, see the
|
||
"<a class="link" href="DeviceDrivers_WritingModules.html" title="Writing Modules">Writing Modules</a>"
|
||
section.</p></div><div id="footer"><hr /><div id="footerT">Prev: <a href="DeviceDrivers_WritingModules.html">Writing Modules</a> Up: <a href="DeviceDrivers.html">Device Drivers</a> Next: <a href="DeviceDrivers_area_malloc.html">The area_malloc Module</a> </div><div id="footerB"><div id="footerBL"><a href="DeviceDrivers_WritingModules.html" title="Writing Modules"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a href="DeviceDrivers.html" title="Device Drivers"><img src="./images/navigation/up.png" alt="Up" /></a> <a href="DeviceDrivers_area_malloc.html" title="The area_malloc Module"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="footerBR"><div><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div></div><div id="footerBC"><a href="http://www.access-company.com/home.html" title="ACCESS Co."><img alt="Access Company" src="./images/access_logo.png" /></a></div></div></div><div id="licenseFooter"><div id="licenseFooterBL"><a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/" title="Creative Commons License"><img alt="Creative Commons License" style="border-width:0" src="https://licensebuttons.net/l/by-nc-nd/3.0/88x31.png" /></a></div><div id="licenseFooterBR"><a href="./LegalNotice.html">Legal Notice</a></div><div id="licenseFooterBC"><span id="licenseText">This work is licensed under a
|
||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Creative
|
||
Commons Attribution-Non commercial-No Derivative Works 3.0 License</a>.</span></div></div></body></html>
|