gnuk/ChibiOS_2.0.2/docs/html/group___a_r_m7.html
2010-08-10 12:11:02 +09:00

129 lines
11 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>ChibiOS/RT: ARM7TDMI</title>
<link href="custom.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<table style="text-align: center; width: 100%;" border="0"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="width: 80px;"><img alt="ChibiOS/RT Logo" src="logo_small.png"></td>
<td><big><big>ChibiOS/RT</big></big><br><br>Architecture - Reference Manual - Guides</td>
<td style="width: 80px;"></td>
</tr>
</tbody>
</table>
<hr size="1">
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
</div>
<div class="contents">
<h1>ARM7TDMI<br/>
<small>
[<a class="el" href="group__ports.html">Ports</a>]</small>
</h1>
<p><div class="dynheader">
Collaboration diagram for ARM7TDMI:</div>
<div class="dynsection">
<center><table><tr><td><img src="group___a_r_m7.png" border="0" alt="" usemap="#group______a__r__m7_map"/>
<map name="group______a__r__m7_map" id="group______a__r__m7">
<area shape="rect" href="group__ports.html" title="Ports" alt="" coords="7,101,52,125"/>
<area shape="rect" href="group___a_t91_s_a_m7.html" title="AT91SAM7 specific support." alt="" coords="236,5,353,29"/>
<area shape="rect" href="group___a_r_m7___c_o_r_e.html" title="ARM7 specific port code, structures and macros." alt="" coords="225,53,364,77"/>
<area shape="rect" href="group___a_r_m7___s_t_a_r_t_u_p.html" title="ARM7 startup code support." alt="" coords="247,101,343,125"/>
<area shape="rect" href="group___a_r_m7___c_o_n_f.html" title="ARM7 specific configuration options." alt="" coords="232,149,357,173"/>
<area shape="rect" href="group___l_p_c214x.html" title="LPC214x specific support." alt="" coords="243,197,347,221"/>
</map></td></tr></table></center>
</div>
</p>
<hr/><a name="_details"></a><h2>Description</h2>
<p>The ARM7 architecture is quite complex for a microcontroller and some explanations are required about the port choices.</p>
<h2><a class="anchor" id="ARM7_NOTES">
The ARM7 modes</a></h2>
<p>The ARM7 port supports three modes:</p>
<ul>
<li>Pure ARM mode, this is the preferred mode for code speed. The code size is larger however. This mode is enabled when all the modules are compiled in ARM mode, see the Makefiles.</li>
<li>Pure THUMB mode, this is the preferred mode for code size. In this mode the execution speed is slower than the ARM mode. This mode is enabled when all the modules are compiled in THUMB mode, see the Makefiles.</li>
<li>Interworking mode, when in the system there are ARM modules mixed with THUMB modules then the interworking compiler option is enabled. This is usually the slowest mode and the code size is not as good as in pure THUMB mode.</li>
</ul>
<h2><a class="anchor" id="ARM7_STATES">
Mapping of the System States in the ARM7 port</a></h2>
<p>The ChibiOS/RT logical <a class="el" href="concepts.html#system_states">System States</a> are mapped as follow in the ARM7 port:</p>
<ul>
<li><b>Init</b>. This state is represented by the startup code and the initialization code before <code><a class="el" href="group__system.html#gafe2c7de6567e98e487e009e81e3be10b" title="ChibiOS/RT initialization.">chSysInit()</a></code> is executed. It has not a special hardware state associated, usually the CPU goes through several hardware states during the startup phase.</li>
<li><b>Normal</b>. This is the state the system has after executing <code><a class="el" href="group__system.html#gafe2c7de6567e98e487e009e81e3be10b" title="ChibiOS/RT initialization.">chSysInit()</a></code>. In this state the ARM7TDMI has both the interrupt sources (IRQ and FIQ) enabled and is running in ARM System Mode.</li>
<li><b>Suspended</b>. In this state the IRQ sources are disabled but the FIQ sources are served, the core is running in ARM System Mode.</li>
<li><b>Disabled</b>. Both the IRQ and FIQ sources are disabled, the core is running in ARM System Mode.</li>
<li><b>Sleep</b>. The ARM7 code does not have any built-in low power mode but there are clock stop modes implemented in custom ways by the various silicon vendors. This state is implemented in each microcontroller support code in a different way, the core is running (or freezed...) in ARM System Mode.</li>
<li><b>S-Locked</b>. IRQ sources disabled, core running in ARM System Mode.</li>
<li><b>I-Locked</b>. IRQ sources disabled, core running in ARM IRQ Mode. Note that this state is not different from the SRI state in this port, the <code>chSysLockI()</code> and <code>chSysUnlockI()</code> APIs do nothing (still use them in order to formally change state because this may change).</li>
<li><b>Serving Regular Interrupt</b>. IRQ sources disabled, core running in ARM IRQ Mode. See also the I-Locked state.</li>
<li><b>Serving Fast Interrupt</b>. IRQ and FIQ sources disabled, core running in ARM FIQ Mode.</li>
<li><b>Serving Non-Maskable Interrupt</b>. There are no asynchronous NMI sources in ARM7 architecture but synchronous SVC, ABT and UND exception handlers can be seen as belonging to this category.</li>
<li><b>Halted</b>. Implemented as an infinite loop after disabling both IRQ and FIQ sources. The ARM state is whatever the processor was running when <code><a class="el" href="group__system.html#gad43b78f160a2c983792af3041cc4a536" title="Halts the system.">chSysHalt()</a></code> was invoked.</li>
</ul>
<h2><a class="anchor" id="ARM7_NOTES">
The ARM7 modes</a></h2>
<p>The ARM7 port makes some assumptions on the application code organization:</p>
<ul>
<li>The <code>main()</code> function is invoked in system mode.</li>
<li>Each thread has a private user/system stack, the system has a single interrupt stack where all the interrupts are processed.</li>
<li>The threads are started in system mode.</li>
<li>The threads code can run in system mode or user mode, however the code running in user mode cannot invoke the ChibiOS/RT APIs directly because privileged instructions are used inside.<br/>
The kernel APIs can be eventually invoked by using a SWI entry point that handles the switch in system mode and the return in user mode.</li>
<li>Other modes are not preempt-able because the system code assumes the threads running in system mode. When running in supervisor or other modes make sure that the interrupts are globally disabled.</li>
<li>Interrupts nesting is not supported in the ARM7 code because their implementation, even if possible, is not really efficient in this architecture.</li>
<li>FIQ sources can preempt the kernel (by design) so it is not possible to invoke the kernel APIs from inside a FIQ handler. FIQ handlers are not affected by the kernel activity so there is not added jitter.</li>
</ul>
<h2><a class="anchor" id="ARM7_IH">
ARM7 Interrupt Handlers</a></h2>
<p>ARM7 Interrupt handlers do not save function-saved registers so you need to make sure your code saves them or does not use them (this happens because in the ARM7 port all the OS interrupt handler functions are declared naked).<br/>
Function-trashed registers (R0-R3, R12, LR, SR) are saved/restored by the system macros <code><a class="el" href="group__system.html#ga0d78c6e90e5f0a4eb52aaab37e45a494" title="IRQ handler enter code.">CH_IRQ_PROLOGUE()</a></code> and <code><a class="el" href="group__system.html#ga864d6b8056d7d8f56322bbfcc8515d77" title="IRQ handler exit code.">CH_IRQ_EPILOGUE()</a></code>.<br/>
The easiest way to ensure this is to just invoke a normal function from within the interrupt handler, the function code will save all the required registers.<br/>
Example: </p>
<div class="fragment"><pre class="fragment"> <a class="code" href="group__system.html#ga52426c607fac82b1e0ad975b367f95e9" title="Standard normal IRQ handler declaration.">CH_IRQ_HANDLER</a>(irq_handler) {
<a class="code" href="group__system.html#ga0d78c6e90e5f0a4eb52aaab37e45a494" title="IRQ handler enter code.">CH_IRQ_PROLOGUE</a>();
serve_interrupt();
VICVectAddr = 0; <span class="comment">// This is LPC214x-specific.</span>
<a class="code" href="group__system.html#ga864d6b8056d7d8f56322bbfcc8515d77" title="IRQ handler exit code.">CH_IRQ_EPILOGUE</a>();
}
</pre></div><p> This is not a bug but an implementation choice, this solution allows to have interrupt handlers compiled in thumb mode without have to use an interworking mode (the mode switch is hidden in the macros), this greatly improves code efficiency and size. You can look at the serial driver for real examples of interrupt handlers. </p>
<table border="0" cellpadding="0" cellspacing="0">
<tr><td colspan="2"><h2>Modules</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___a_r_m7___c_o_n_f.html">Configuration Options</a></td></tr>
<p><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><p>ARM7 specific configuration options. </p>
<br/></td></tr>
</p>
<tr><td class="memItemLeft" align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___a_r_m7___c_o_r_e.html">Core Port Implementation</a></td></tr>
<p><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><p>ARM7 specific port code, structures and macros. </p>
<br/></td></tr>
</p>
<tr><td class="memItemLeft" align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___a_r_m7___s_t_a_r_t_u_p.html">Startup Support</a></td></tr>
<p><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><p>ARM7 startup code support. </p>
<br/></td></tr>
</p>
<tr><td class="memItemLeft" align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___a_t91_s_a_m7.html">AT91SAM7 Support</a></td></tr>
<p><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><p>AT91SAM7 specific support. </p>
<br/></td></tr>
</p>
<tr><td class="memItemLeft" align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___l_p_c214x.html">LPC214x Support</a></td></tr>
<p><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><p>LPC214x specific support. </p>
<br/></td></tr>
</p>
</table>
</div>
<hr size="1"><address style="text-align: right;"><small>
Generated on Sun Jul 11 13:13:18 2010 for ChibiOS/RT by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.6.3</small></address>
</body>
</html>