]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_GCC/freedom-metal/doc/html/devguide/interrupts.html
Base project to replace existing Freedom Studio project using latest Freedom Studio...
[freertos] / FreeRTOS / Demo / RISC-V_RV32_SiFive_HiFive1_GCC / freedom-metal / doc / html / devguide / interrupts.html
1
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5 <html xmlns="http://www.w3.org/1999/xhtml">
6   <head>
7     <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
8     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
9     <title>Interrupt Handlers &#8212; Freedom Metal v201905 documentation</title>
10     <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
11     <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
12     <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
13     <script type="text/javascript" src="../_static/jquery.js"></script>
14     <script type="text/javascript" src="../_static/underscore.js"></script>
15     <script type="text/javascript" src="../_static/doctools.js"></script>
16     <link rel="index" title="Index" href="../genindex.html" />
17     <link rel="search" title="Search" href="../search.html" />
18     <link rel="next" title="Instruction Tightly Integrated Memory" href="itim.html" />
19     <link rel="prev" title="FE310-G00 PLL" href="fe310-g000-pll.html" />
20    
21   <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
22   
23   
24   <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
25
26   </head><body>
27   
28
29     <div class="document">
30       <div class="documentwrapper">
31         <div class="bodywrapper">
32           
33
34           <div class="body" role="main">
35             
36   <div class="section" id="interrupt-handlers">
37 <h1>Interrupt Handlers<a class="headerlink" href="#interrupt-handlers" title="Permalink to this headline">¶</a></h1>
38 <div class="section" id="the-interrupt-heirarchy">
39 <h2>The Interrupt Heirarchy<a class="headerlink" href="#the-interrupt-heirarchy" title="Permalink to this headline">¶</a></h2>
40 <p>Freedom Metal conceptualizes interrupts as a heirarchy of interrupt controllers.
41 This heirarchy is established by the interrupt heirarchy of the target platform
42 itself. Presently, the interrupt heirarchy for a given platform is best documented
43 by the target’s DeviceTree representation, which can be found in
44 <code class="docutils literal notranslate"><span class="pre">bsp/&lt;target-name&gt;/design.dts</span></code>.</p>
45 <p>In Freedom Metal, the heirarchy is a tree. The nodes of the tree consist of
46 <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">metal_interrupt</span></code>:</p>
47 <dl class="class">
48 <dt id="_CPPv315metal_interrupt">
49 <span id="_CPPv215metal_interrupt"></span><span id="metal_interrupt"></span><span class="target" id="structmetal__interrupt"></span><em class="property">struct </em><code class="descname">metal_interrupt</code><br /></dt>
50 <dd><p>A handle for an interrupt. </p>
51 </dd></dl>
52
53 <p>And the vertices of the tree consist of interrupt <code class="docutils literal notranslate"><span class="pre">id</span></code>.</p>
54 <img src="../_images/graphviz-4e69a35c14995622b7f966825bca72b81124fc03.png" alt="digraph int_heirarchy_graph {
55 cpu [label=&quot;CPU&quot;];
56 cpu_int [label=&quot;CPU Interrupt Controller&quot;, shape=box];
57 timer_int [label=&quot;Timer Interrupt Controller&quot;, shape=box];
58 soft_int [label=&quot;Software Interrupt Controller&quot;, shape=box];
59
60 cpu -&gt; cpu_int [label=&quot;ID = 0&quot;];
61 cpu_int -&gt; timer_int [label=&quot;ID = timer_id&quot;];
62 cpu_int -&gt; soft_int [label=&quot;ID = software_id&quot;];
63 }" />
64 </div>
65 <div class="section" id="the-cpu-interrupt-controller">
66 <h2>The CPU Interrupt Controller<a class="headerlink" href="#the-cpu-interrupt-controller" title="Permalink to this headline">¶</a></h2>
67 <p>The CPU interrupt controller is the top of the interrupt heirarchy. It must be
68 initialized before any other interrupt controllers are initialized. In example:</p>
69 <div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span> <span class="n">metal_cpu</span> <span class="o">*</span><span class="n">cpu0</span> <span class="o">=</span> <span class="n">metal_get_cpu</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
70 <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">cpu</span><span class="p">)</span> <span class="p">{</span>
71    <span class="cm">/* Unable to get CPU handle */</span>
72 <span class="p">}</span>
73 <span class="k">struct</span> <span class="n">metal_interrupt</span> <span class="o">*</span><span class="n">cpu_int</span> <span class="o">=</span> <span class="n">metal_cpu_interrupt_controller</span><span class="p">(</span><span class="n">cpu0</span><span class="p">);</span>
74 <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">cpu_int</span><span class="p">)</span> <span class="p">{</span>
75    <span class="cm">/* Unable to get CPU interrupt handle */</span>
76 <span class="p">}</span>
77 <span class="n">metal_interrupt_init</span><span class="p">(</span><span class="n">cpu_int</span><span class="p">);</span>
78 </pre></div>
79 </div>
80 <p>The CPU interrupt must be enabled for the CPU to receive any interrupts, and any
81 enabled interrupts can be masked by disabling the CPU interrupt.</p>
82 <div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="kt">int</span> <span class="n">rc</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
83
84 <span class="cm">/* Enable the CPU interrupt */</span>
85 <span class="n">rc</span> <span class="o">=</span> <span class="n">metal_interrupt_enable</span><span class="p">(</span><span class="n">cpu_int</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
86 <span class="k">if</span><span class="p">(</span><span class="n">rc</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
87    <span class="cm">/* Failed to enable the CPU interrupt */</span>
88 <span class="p">}</span>
89
90 <span class="cm">/* Disable the CPU interrupt */</span>
91 <span class="n">rc</span> <span class="o">=</span> <span class="n">metal_interrupt_disable</span><span class="p">(</span><span class="n">cpu_int</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
92 <span class="k">if</span><span class="p">(</span><span class="n">rc</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
93    <span class="cm">/* Failed to disable the CPU interrupt */</span>
94 <span class="p">}</span>
95 </pre></div>
96 </div>
97 </div>
98 <div class="section" id="id1">
99 <h2>Interrupt Handlers<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h2>
100 <p>Interrupt handlers must conform to the following function signature:</p>
101 <dl class="type">
102 <dt id="_CPPv325metal_interrupt_handler_t">
103 <span id="_CPPv225metal_interrupt_handler_t"></span><span id="metal_interrupt_handler_t"></span><span class="target" id="interrupt_8h_1acf581f8608907e67e50300eef23a130b"></span><em class="property">typedef </em>void (*<code class="descname">metal_interrupt_handler_t</code>)<span class="sig-paren">(</span>int, void *<span class="sig-paren">)</span><br /></dt>
104 <dd><p>Function signature for interrupt callback handlers. </p>
105 </dd></dl>
106
107 <p>Therefore, an interrupt handler might look like:</p>
108 <div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="kt">void</span> <span class="nf">my_interrupt_handler</span><span class="p">(</span><span class="kt">int</span> <span class="n">id</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">priv_data</span><span class="p">)</span> <span class="p">{</span>
109    <span class="cm">/* Contents of handler */</span>
110 <span class="p">}</span>
111 </pre></div>
112 </div>
113 </div>
114 <div class="section" id="registering-an-interrupt-handler">
115 <h2>Registering an Interrupt Handler<a class="headerlink" href="#registering-an-interrupt-handler" title="Permalink to this headline">¶</a></h2>
116 <p>Interrupt handlers are registered with the interrupt controller for the interrupt
117 they are servicing. For example, if we want to register a CPU timer interrupt:</p>
118 <div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span> <span class="n">metal_interrupt</span> <span class="o">*</span><span class="n">timer_int</span> <span class="o">=</span> <span class="n">metal_cpu_timer_interrupt_controller</span><span class="p">(</span><span class="n">cpu0</span><span class="p">);</span>
119 <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">timer_int</span><span class="p">)</span> <span class="p">{</span>
120    <span class="cm">/* Failed to get timer interrupt controller */</span>
121 <span class="p">}</span>
122 <span class="n">metal_interrupt_init</span><span class="p">(</span><span class="n">timer_int</span><span class="p">);</span>
123
124 <span class="kt">int</span> <span class="n">timer_id</span> <span class="o">=</span> <span class="n">metal_cpu_timer_get_interrupt_id</span><span class="p">(</span><span class="n">cpu0</span><span class="p">);</span>
125
126 <span class="kt">int</span> <span class="n">rc</span> <span class="o">=</span> <span class="n">metal_interrupt_register_handler</span><span class="p">(</span><span class="n">timer_int</span><span class="p">,</span> <span class="n">timer_id</span><span class="p">,</span> <span class="n">my_interrupt_handler</span><span class="p">,</span> <span class="n">cpu0</span><span class="p">);</span>
127 <span class="k">if</span><span class="p">(</span><span class="n">rc</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
128    <span class="cm">/* Failed to register interrupt handler */</span>
129 <span class="p">}</span>
130 </pre></div>
131 </div>
132 </div>
133 <div class="section" id="additional-documentation">
134 <h2>Additional Documentation<a class="headerlink" href="#additional-documentation" title="Permalink to this headline">¶</a></h2>
135 <p>Additional documentation for the interrupt handler API can be found in
136 <a class="reference internal" href="../apiref/cpu.html"><span class="doc">the CPU API reference</span></a> and
137 <a class="reference internal" href="../apiref/interrupt.html"><span class="doc">the Interrupt API reference</span></a>.</p>
138 </div>
139 </div>
140
141
142           </div>
143           
144         </div>
145       </div>
146       <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
147         <div class="sphinxsidebarwrapper">
148 <h1 class="logo"><a href="../index.html">Freedom Metal</a></h1>
149
150
151
152
153
154
155
156
157 <h3>Navigation</h3>
158 <ul class="current">
159 <li class="toctree-l1"><a class="reference internal" href="../introduction.html">Introduction to Freedom Metal</a></li>
160 <li class="toctree-l1 current"><a class="reference internal" href="../devguide.html">Developer Guide</a><ul class="current">
161 <li class="toctree-l2"><a class="reference internal" href="exceptions.html">Exception Handlers</a></li>
162 <li class="toctree-l2"><a class="reference internal" href="fe310-g000-pll.html">FE310-G00 PLL</a></li>
163 <li class="toctree-l2 current"><a class="current reference internal" href="#">Interrupt Handlers</a></li>
164 <li class="toctree-l2"><a class="reference internal" href="itim.html">Instruction Tightly Integrated Memory</a></li>
165 <li class="toctree-l2"><a class="reference internal" href="pmps.html">Physical Memory Protection</a></li>
166 <li class="toctree-l2"><a class="reference internal" href="tty.html">Standard I/O</a></li>
167 </ul>
168 </li>
169 <li class="toctree-l1"><a class="reference internal" href="../api.html">API Reference</a></li>
170 </ul>
171
172 <div class="relations">
173 <h3>Related Topics</h3>
174 <ul>
175   <li><a href="../index.html">Documentation overview</a><ul>
176   <li><a href="../devguide.html">Developer Guide</a><ul>
177       <li>Previous: <a href="fe310-g000-pll.html" title="previous chapter">FE310-G00 PLL</a></li>
178       <li>Next: <a href="itim.html" title="next chapter">Instruction Tightly Integrated Memory</a></li>
179   </ul></li>
180   </ul></li>
181 </ul>
182 </div>
183 <div id="searchbox" style="display: none" role="search">
184   <h3>Quick search</h3>
185     <div class="searchformwrapper">
186     <form class="search" action="../search.html" method="get">
187       <input type="text" name="q" />
188       <input type="submit" value="Go" />
189       <input type="hidden" name="check_keywords" value="yes" />
190       <input type="hidden" name="area" value="default" />
191     </form>
192     </div>
193 </div>
194 <script type="text/javascript">$('#searchbox').show(0);</script>
195         </div>
196       </div>
197       <div class="clearer"></div>
198     </div>
199     <div class="footer">
200       &copy;2019, SiFive Inc..
201       
202       |
203       Powered by <a href="http://sphinx-doc.org/">Sphinx 1.7.5</a>
204       &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.11</a>
205       
206       |
207       <a href="../_sources/devguide/interrupts.rst.txt"
208           rel="nofollow">Page source</a>
209     </div>
210
211     
212
213     
214   </body>
215 </html>