gnuk/ChibiOS_2.0.2/docs/html/shell_8c_source.html

345 lines
35 KiB
HTML
Raw Normal View History

2010-08-10 03:11:02 +00:00
<!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: shell.c Source File</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 class="current"><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="files.html"><span>File&nbsp;List</span></a></li>
<li><a href="globals.html"><span>Globals</span></a></li>
</ul>
</div>
<h1>shell.c</h1><a href="shell_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio.</span>
<a name="l00003"></a>00003 <span class="comment"></span>
<a name="l00004"></a>00004 <span class="comment"> This file is part of ChibiOS/RT.</span>
<a name="l00005"></a>00005 <span class="comment"></span>
<a name="l00006"></a>00006 <span class="comment"> ChibiOS/RT is free software; you can redistribute it and/or modify</span>
<a name="l00007"></a>00007 <span class="comment"> it under the terms of the GNU General Public License as published by</span>
<a name="l00008"></a>00008 <span class="comment"> the Free Software Foundation; either version 3 of the License, or</span>
<a name="l00009"></a>00009 <span class="comment"> (at your option) any later version.</span>
<a name="l00010"></a>00010 <span class="comment"></span>
<a name="l00011"></a>00011 <span class="comment"> ChibiOS/RT is distributed in the hope that it will be useful,</span>
<a name="l00012"></a>00012 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00013"></a>00013 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<a name="l00014"></a>00014 <span class="comment"> GNU General Public License for more details.</span>
<a name="l00015"></a>00015 <span class="comment"></span>
<a name="l00016"></a>00016 <span class="comment"> You should have received a copy of the GNU General Public License</span>
<a name="l00017"></a>00017 <span class="comment"> along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<a name="l00018"></a>00018 <span class="comment"></span>
<a name="l00019"></a>00019 <span class="comment"> ---</span>
<a name="l00020"></a>00020 <span class="comment"></span>
<a name="l00021"></a>00021 <span class="comment"> A special exception to the GPL can be applied should you wish to distribute</span>
<a name="l00022"></a>00022 <span class="comment"> a combined work that includes ChibiOS/RT, without being obliged to provide</span>
<a name="l00023"></a>00023 <span class="comment"> the source code for any proprietary components. See the file exception.txt</span>
<a name="l00024"></a>00024 <span class="comment"> for full details of how and when the exception can be applied.</span>
<a name="l00025"></a>00025 <span class="comment">*/</span>
<a name="l00026"></a>00026 <span class="comment"></span>
<a name="l00027"></a>00027 <span class="comment">/**</span>
<a name="l00028"></a>00028 <span class="comment"> * @file shell.c</span>
<a name="l00029"></a>00029 <span class="comment"> * @brief Simple CLI shell code.</span>
<a name="l00030"></a>00030 <span class="comment"> * @addtogroup SHELL</span>
<a name="l00031"></a>00031 <span class="comment"> * @{</span>
<a name="l00032"></a>00032 <span class="comment"> */</span>
<a name="l00033"></a>00033
<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00036"></a>00036
<a name="l00037"></a>00037 <span class="preprocessor">#include &quot;<a class="code" href="ch_8h.html" title="ChibiOS/RT main include file.">ch.h</a>&quot;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &quot;<a class="code" href="hal_8h.html" title="HAL subsystem header.">hal.h</a>&quot;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &quot;<a class="code" href="shell_8h.html" title="Simple CLI shell header.">shell.h</a>&quot;</span>
<a name="l00040"></a>00040
<a name="l00041"></a>00041 <span class="preprocessor">#if SHELL_USE_IPRINTF</span>
<a name="l00042"></a>00042 <span class="preprocessor"></span><span class="preprocessor">#define sprintf siprintf</span>
<a name="l00043"></a>00043 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="comment"></span>
<a name="l00045"></a>00045 <span class="comment">/**</span>
<a name="l00046"></a>00046 <span class="comment"> * @brief Shell termination event source.</span>
<a name="l00047"></a>00047 <span class="comment"> */</span>
<a name="l00048"></a><a class="code" href="group___s_h_e_l_l.html#ga168440e44c637282589a4e28eb3a91b8">00048</a> <a class="code" href="struct_event_source.html" title="Event Source structure.">EventSource</a> <a class="code" href="group___s_h_e_l_l.html#ga168440e44c637282589a4e28eb3a91b8" title="Shell termination event source.">shell_terminated</a>;
<a name="l00049"></a>00049
<a name="l00050"></a>00050 <span class="preprocessor">#if defined(WIN32)</span>
<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="comment">/*</span>
<a name="l00052"></a>00052 <span class="comment"> * MinGW does not seem to have this function...</span>
<a name="l00053"></a>00053 <span class="comment"> */</span>
<a name="l00054"></a>00054 <span class="keyword">static</span> <span class="keywordtype">char</span> *strtok_r(<span class="keywordtype">char</span> *str, <span class="keyword">const</span> <span class="keywordtype">char</span> *delim, <span class="keywordtype">char</span> **saveptr) {
<a name="l00055"></a>00055 <span class="keywordtype">char</span> *token;
<a name="l00056"></a>00056 <span class="keywordflow">if</span> (str)
<a name="l00057"></a>00057 *saveptr = str;
<a name="l00058"></a>00058 token = *saveptr;
<a name="l00059"></a>00059
<a name="l00060"></a>00060 <span class="keywordflow">if</span> (!token)
<a name="l00061"></a>00061 <span class="keywordflow">return</span> NULL;
<a name="l00062"></a>00062
<a name="l00063"></a>00063 token += strspn(token, delim);
<a name="l00064"></a>00064 *saveptr = strpbrk(token, delim);
<a name="l00065"></a>00065 <span class="keywordflow">if</span> (*saveptr)
<a name="l00066"></a>00066 *(*saveptr)++ = <span class="charliteral">&#39;\0&#39;</span>;
<a name="l00067"></a>00067
<a name="l00068"></a>00068 <span class="keywordflow">return</span> *token ? token : NULL;
<a name="l00069"></a>00069 }
<a name="l00070"></a>00070 <span class="preprocessor">#endif</span>
<a name="l00071"></a>00071 <span class="preprocessor"></span>
<a name="l00072"></a>00072 <span class="keyword">static</span> <span class="keywordtype">void</span> usage(<a class="code" href="struct_base_channel.html" title="Base channel class.">BaseChannel</a> *chp, <span class="keywordtype">char</span> *p) {
<a name="l00073"></a>00073
<a name="l00074"></a>00074 <a class="code" href="group___s_h_e_l_l.html#ga4660b06c861d5506fb35d9844e2d8288" title="Prints a string.">shellPrint</a>(chp, <span class="stringliteral">&quot;Usage: &quot;</span>);
<a name="l00075"></a>00075 <a class="code" href="group___s_h_e_l_l.html#ga7bffb6aa1f0ec1e12dfaa86c3b692330" title="Prints a string with a final newline.">shellPrintLine</a>(chp, p);
<a name="l00076"></a>00076 }
<a name="l00077"></a>00077
<a name="l00078"></a>00078 <span class="keyword">static</span> <span class="keywordtype">void</span> list_commands(<a class="code" href="struct_base_channel.html" title="Base channel class.">BaseChannel</a> *chp, <span class="keyword">const</span> <a class="code" href="struct_shell_command.html" title="Custom command entry type.">ShellCommand</a> *scp) {
<a name="l00079"></a>00079
<a name="l00080"></a>00080 <span class="keywordflow">while</span> (scp-&gt;<a class="code" href="struct_shell_command.html#afb689607842aa2cf6844eebdb8b36236" title="Command name.">sc_name</a> != NULL) {
<a name="l00081"></a>00081 <a class="code" href="group___s_h_e_l_l.html#ga4660b06c861d5506fb35d9844e2d8288" title="Prints a string.">shellPrint</a>(chp, scp-&gt;<a class="code" href="struct_shell_command.html#afb689607842aa2cf6844eebdb8b36236" title="Command name.">sc_name</a>);
<a name="l00082"></a>00082 <a class="code" href="group___s_h_e_l_l.html#ga4660b06c861d5506fb35d9844e2d8288" title="Prints a string.">shellPrint</a>(chp, <span class="stringliteral">&quot; &quot;</span>);
<a name="l00083"></a>00083 scp++;
<a name="l00084"></a>00084 }
<a name="l00085"></a>00085 }
<a name="l00086"></a>00086
<a name="l00087"></a>00087 <span class="keyword">static</span> <span class="keywordtype">void</span> cmd_info(<a class="code" href="struct_base_channel.html" title="Base channel class.">BaseChannel</a> *chp, <span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]) {
<a name="l00088"></a>00088
<a name="l00089"></a>00089 (void)argv;
<a name="l00090"></a>00090 <span class="keywordflow">if</span> (argc &gt; 0) {
<a name="l00091"></a>00091 usage(chp, <span class="stringliteral">&quot;info&quot;</span>);
<a name="l00092"></a>00092 <span class="keywordflow">return</span>;
<a name="l00093"></a>00093 }
<a name="l00094"></a>00094
<a name="l00095"></a>00095 <a class="code" href="group___s_h_e_l_l.html#ga4660b06c861d5506fb35d9844e2d8288" title="Prints a string.">shellPrint</a>(chp, <span class="stringliteral">&quot;Kernel version: &quot;</span>);
<a name="l00096"></a>00096 <a class="code" href="group___s_h_e_l_l.html#ga7bffb6aa1f0ec1e12dfaa86c3b692330" title="Prints a string with a final newline.">shellPrintLine</a>(chp, <a class="code" href="group__kernel__info.html#gaf90f447ef5aa797647cbe5d1a6a958c3" title="Kernel version string.">CH_KERNEL_VERSION</a>);
<a name="l00097"></a>00097 <span class="preprocessor">#ifdef __GNUC__</span>
<a name="l00098"></a>00098 <span class="preprocessor"></span> <a class="code" href="group___s_h_e_l_l.html#ga4660b06c861d5506fb35d9844e2d8288" title="Prints a string.">shellPrint</a>(chp, <span class="stringliteral">&quot;GCC Version: &quot;</span>);
<a name="l00099"></a>00099 <a class="code" href="group___s_h_e_l_l.html#ga7bffb6aa1f0ec1e12dfaa86c3b692330" title="Prints a string with a final newline.">shellPrintLine</a>(chp, __VERSION__);
<a name="l00100"></a>00100 <span class="preprocessor">#endif</span>
<a name="l00101"></a>00101 <span class="preprocessor"></span> <a class="code" href="group___s_h_e_l_l.html#ga4660b06c861d5506fb35d9844e2d8288" title="Prints a string.">shellPrint</a>(chp, <span class="stringliteral">&quot;Architecture: &quot;</span>);
<a name="l00102"></a>00102 <a class="code" href="group___s_h_e_l_l.html#ga7bffb6aa1f0ec1e12dfaa86c3b692330" title="Prints a string with a final newline.">shellPrintLine</a>(chp, <a class="code" href="group__core.html#gaee128c531d64d5a635def6857fef3179" title="Name of the implemented architecture.">CH_ARCHITECTURE_NAME</a>);
<a name="l00103"></a>00103 <span class="preprocessor">#ifdef CH_CORE_VARIANT_NAME</span>
<a name="l00104"></a>00104 <span class="preprocessor"></span> <a class="code" href="group___s_h_e_l_l.html#ga4660b06c861d5506fb35d9844e2d8288" title="Prints a string.">shellPrint</a>(chp, <span class="stringliteral">&quot;Core Variant: &quot;</span>);
<a name="l00105"></a>00105 <a class="code" href="group___s_h_e_l_l.html#ga7bffb6aa1f0ec1e12dfaa86c3b692330" title="Prints a string with a final newline.">shellPrintLine</a>(chp, <a class="code" href="group___a_v_r___c_o_r_e.html#gad807bcd87b78f852f9cdf25022c0f11b" title="Name of the architecture variant (optional).">CH_CORE_VARIANT_NAME</a>);
<a name="l00106"></a>00106 <span class="preprocessor">#endif</span>
<a name="l00107"></a>00107 <span class="preprocessor"></span><span class="preprocessor">#ifdef PLATFORM_NAME</span>
<a name="l00108"></a>00108 <span class="preprocessor"></span> <a class="code" href="group___s_h_e_l_l.html#ga4660b06c861d5506fb35d9844e2d8288" title="Prints a string.">shellPrint</a>(chp, <span class="stringliteral">&quot;Platform: &quot;</span>);
<a name="l00109"></a>00109 <a class="code" href="group___s_h_e_l_l.html#ga7bffb6aa1f0ec1e12dfaa86c3b692330" title="Prints a string with a final newline.">shellPrintLine</a>(chp, <a class="code" href="group___h_a_l___l_l_d.html#gaa4688daf0f1e6dda714351a6e5a394c2" title="Platform name.">PLATFORM_NAME</a>);
<a name="l00110"></a>00110 <span class="preprocessor">#endif</span>
<a name="l00111"></a>00111 <span class="preprocessor"></span><span class="preprocessor">#ifdef BOARD_NAME</span>
<a name="l00112"></a>00112 <span class="preprocessor"></span> <a class="code" href="group___s_h_e_l_l.html#ga4660b06c861d5506fb35d9844e2d8288" title="Prints a string.">shellPrint</a>(chp, <span class="stringliteral">&quot;Board: &quot;</span>);
<a name="l00113"></a>00113 <a class="code" href="group___s_h_e_l_l.html#ga7bffb6aa1f0ec1e12dfaa86c3b692330" title="Prints a string with a final newline.">shellPrintLine</a>(chp, BOARD_NAME);
<a name="l00114"></a>00114 <span class="preprocessor">#endif</span>
<a name="l00115"></a>00115 <span class="preprocessor"></span>}
<a name="l00116"></a>00116
<a name="l00117"></a>00117 <span class="keyword">static</span> <span class="keywordtype">void</span> cmd_systime(<a class="code" href="struct_base_channel.html" title="Base channel class.">BaseChannel</a> *chp, <span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]) {
<a name="l00118"></a>00118 <span class="keywordtype">char</span> buf[12];
<a name="l00119"></a>00119
<a name="l00120"></a>00120 (void)argv;
<a name="l00121"></a>00121 <span class="keywordflow">if</span> (argc &gt; 0) {
<a name="l00122"></a>00122 usage(chp, <span class="stringliteral">&quot;systime&quot;</span>);
<a name="l00123"></a>00123 <span class="keywordflow">return</span>;
<a name="l00124"></a>00124 }
<a name="l00125"></a>00125 sprintf(buf, <span class="stringliteral">&quot;%lu&quot;</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)<a class="code" href="group__time.html#ga137c8f67c450f34416a786d169be90e2" title="Current system time.">chTimeNow</a>());
<a name="l00126"></a>00126 <a class="code" href="group___s_h_e_l_l.html#ga7bffb6aa1f0ec1e12dfaa86c3b692330" title="Prints a string with a final newline.">shellPrintLine</a>(chp, buf);
<a name="l00127"></a>00127 }
<a name="l00128"></a>00128 <span class="comment"></span>
<a name="l00129"></a>00129 <span class="comment">/**</span>
<a name="l00130"></a>00130 <span class="comment"> * @brief Array of the default commands.</span>
<a name="l00131"></a>00131 <span class="comment"> */</span>
<a name="l00132"></a>00132 <span class="keyword">static</span> <a class="code" href="struct_shell_command.html" title="Custom command entry type.">ShellCommand</a> local_commands[] = {
<a name="l00133"></a>00133 {<span class="stringliteral">&quot;info&quot;</span>, cmd_info},
<a name="l00134"></a>00134 {<span class="stringliteral">&quot;systime&quot;</span>, cmd_systime},
<a name="l00135"></a>00135 {NULL, NULL}
<a name="l00136"></a>00136 };
<a name="l00137"></a>00137
<a name="l00138"></a>00138 <span class="keyword">static</span> <a class="code" href="group__types.html#ga7556af1cb61728b53228fa3af1c851de" title="Boolean, recommended the fastest signed.">bool_t</a> cmdexec(<span class="keyword">const</span> <a class="code" href="struct_shell_command.html" title="Custom command entry type.">ShellCommand</a> *scp, <a class="code" href="struct_base_channel.html" title="Base channel class.">BaseChannel</a> *chp,
<a name="l00139"></a>00139 <span class="keywordtype">char</span> *name, <span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]) {
<a name="l00140"></a>00140
<a name="l00141"></a>00141 <span class="keywordflow">while</span> (scp-&gt;<a class="code" href="struct_shell_command.html#afb689607842aa2cf6844eebdb8b36236" title="Command name.">sc_name</a> != NULL) {
<a name="l00142"></a>00142 <span class="keywordflow">if</span> (strcasecmp(scp-&gt;<a class="code" href="struct_shell_command.html#afb689607842aa2cf6844eebdb8b36236" title="Command name.">sc_name</a>, name) == 0) {
<a name="l00143"></a>00143 scp-&gt;<a class="code" href="struct_shell_command.html#ad95f7461ff8fdf89ce55d90ce99c632d" title="Command function.">sc_function</a>(chp, argc, argv);
<a name="l00144"></a>00144 <span class="keywordflow">return</span> FALSE;
<a name="l00145"></a>00145 }
<a name="l00146"></a>00146 scp++;
<a name="l00147"></a>00147 }
<a name="l00148"></a>00148 <span class="keywordflow">return</span> TRUE;
<a name="l00149"></a>00149 }
<a name="l00150"></a>00150 <span class="comment"></span>
<a name="l00151"></a>00151 <span class="comment">/**</span>
<a name="l00152"></a>00152 <span class="comment"> * @brief Shell thread function.</span>
<a name="l00153"></a>00153 <span class="comment"> *</span>
<a name="l00154"></a>00154 <span class="comment"> * @param[in] p pointer to a @p BaseChannel object</span>
<a name="l00155"></a>00155 <span class="comment"> * @return Termination reason.</span>
<a name="l00156"></a>00156 <span class="comment"> * @retval RDY_OK terminated by command.</span>
<a name="l00157"></a>00157 <span class="comment"> * @retval RDY_RESET terminated by reset condition on the I/O channel.</span>
<a name="l00158"></a>00158 <span class="comment"> */</span>
<a name="l00159"></a>00159 <span class="keyword">static</span> <a class="code" href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3" title="Message, use signed pointer equivalent.">msg_t</a> shell_thread(<span class="keywordtype">void</span> *p) {
<a name="l00160"></a>00160 <span class="keywordtype">int</span> n;
<a name="l00161"></a>00161 <a class="code" href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3" title="Message, use signed pointer equivalent.">msg_t</a> msg = <a class="code" href="group__scheduler.html#gae1c86078318e11c2fa57ee3c2ec69f61" title="Default thread wakeup low level message.">RDY_OK</a>;
<a name="l00162"></a>00162 <a class="code" href="struct_base_channel.html" title="Base channel class.">BaseChannel</a> *chp = ((<a class="code" href="struct_shell_config.html" title="Shell descriptor type.">ShellConfig</a> *)p)-&gt;sc_channel;
<a name="l00163"></a>00163 <span class="keyword">const</span> <a class="code" href="struct_shell_command.html" title="Custom command entry type.">ShellCommand</a> *scp = ((<a class="code" href="struct_shell_config.html" title="Shell descriptor type.">ShellConfig</a> *)p)-&gt;sc_commands;
<a name="l00164"></a>00164 <span class="keywordtype">char</span> *lp, *cmd, *tokp, line[<a class="code" href="group___s_h_e_l_l.html#ga0aee139645cf59df04bc31635f553024" title="Shell maximum input line length.">SHELL_MAX_LINE_LENGTH</a>];
<a name="l00165"></a>00165 <span class="keywordtype">char</span> *args[<a class="code" href="group___s_h_e_l_l.html#ga730dd92884d4fce406efb6678aea8062" title="Shell maximum arguments per command.">SHELL_MAX_ARGUMENTS</a> + 1];
<a name="l00166"></a>00166
<a name="l00167"></a>00167 <a class="code" href="group___s_h_e_l_l.html#ga7bffb6aa1f0ec1e12dfaa86c3b692330" title="Prints a string with a final newline.">shellPrintLine</a>(chp, <span class="stringliteral">&quot;&quot;</span>);
<a name="l00168"></a>00168 <a class="code" href="group___s_h_e_l_l.html#ga7bffb6aa1f0ec1e12dfaa86c3b692330" title="Prints a string with a final newline.">shellPrintLine</a>(chp, <span class="stringliteral">&quot;ChibiOS/RT Shell&quot;</span>);
<a name="l00169"></a>00169 <span class="keywordflow">while</span> (TRUE) {
<a name="l00170"></a>00170 <a class="code" href="group___s_h_e_l_l.html#ga4660b06c861d5506fb35d9844e2d8288" title="Prints a string.">shellPrint</a>(chp, <span class="stringliteral">&quot;ch&gt; &quot;</span>);
<a name="l00171"></a>00171 <span class="keywordflow">if</span> (<a class="code" href="group___s_h_e_l_l.html#ga1c7aadcfefdc616bd8450117b6972274" title="Reads a whole line from the input channel.">shellGetLine</a>(chp, line, <span class="keyword">sizeof</span>(line))) {
<a name="l00172"></a>00172 <a class="code" href="group___s_h_e_l_l.html#ga4660b06c861d5506fb35d9844e2d8288" title="Prints a string.">shellPrint</a>(chp, <span class="stringliteral">&quot;\nlogout&quot;</span>);
<a name="l00173"></a>00173 <span class="keywordflow">break</span>;
<a name="l00174"></a>00174 }
<a name="l00175"></a>00175 lp = strtok_r(line, <span class="stringliteral">&quot; \009&quot;</span>, &amp;tokp);
<a name="l00176"></a>00176 cmd = lp;
<a name="l00177"></a>00177 n = 0;
<a name="l00178"></a>00178 <span class="keywordflow">while</span> ((lp = strtok_r(NULL, <span class="stringliteral">&quot; \009&quot;</span>, &amp;tokp)) != NULL) {
<a name="l00179"></a>00179 <span class="keywordflow">if</span> (n &gt;= <a class="code" href="group___s_h_e_l_l.html#ga730dd92884d4fce406efb6678aea8062" title="Shell maximum arguments per command.">SHELL_MAX_ARGUMENTS</a>) {
<a name="l00180"></a>00180 <a class="code" href="group___s_h_e_l_l.html#ga7bffb6aa1f0ec1e12dfaa86c3b692330" title="Prints a string with a final newline.">shellPrintLine</a>(chp, <span class="stringliteral">&quot;too many arguments&quot;</span>);
<a name="l00181"></a>00181 cmd = NULL;
<a name="l00182"></a>00182 <span class="keywordflow">break</span>;
<a name="l00183"></a>00183 }
<a name="l00184"></a>00184 args[n++] = lp;
<a name="l00185"></a>00185 }
<a name="l00186"></a>00186 args[n] = NULL;
<a name="l00187"></a>00187 <span class="keywordflow">if</span> (cmd != NULL) {
<a name="l00188"></a>00188 <span class="keywordflow">if</span> (strcasecmp(cmd, <span class="stringliteral">&quot;exit&quot;</span>) == 0) {
<a name="l00189"></a>00189 <span class="keywordflow">if</span> (n &gt; 0)
<a name="l00190"></a>00190 usage(chp, <span class="stringliteral">&quot;exit&quot;</span>);
<a name="l00191"></a>00191 <span class="keywordflow">break</span>;
<a name="l00192"></a>00192 }
<a name="l00193"></a>00193 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcasecmp(cmd, <span class="stringliteral">&quot;help&quot;</span>) == 0) {
<a name="l00194"></a>00194 <span class="keywordflow">if</span> (n &gt; 0)
<a name="l00195"></a>00195 usage(chp, <span class="stringliteral">&quot;help&quot;</span>);
<a name="l00196"></a>00196 <a class="code" href="group___s_h_e_l_l.html#ga4660b06c861d5506fb35d9844e2d8288" title="Prints a string.">shellPrint</a>(chp, <span class="stringliteral">&quot;Commands: help exit &quot;</span>);
<a name="l00197"></a>00197 list_commands(chp, local_commands);
<a name="l00198"></a>00198 <span class="keywordflow">if</span> (scp != NULL)
<a name="l00199"></a>00199 list_commands(chp, scp);
<a name="l00200"></a>00200 <a class="code" href="group___s_h_e_l_l.html#ga7bffb6aa1f0ec1e12dfaa86c3b692330" title="Prints a string with a final newline.">shellPrintLine</a>(chp, <span class="stringliteral">&quot;&quot;</span>);
<a name="l00201"></a>00201 }
<a name="l00202"></a>00202 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cmdexec(local_commands, chp, cmd, n, args) &amp;&amp;
<a name="l00203"></a>00203 ((scp == NULL) || cmdexec(scp, chp, cmd, n, args))) {
<a name="l00204"></a>00204 <a class="code" href="group___s_h_e_l_l.html#ga4660b06c861d5506fb35d9844e2d8288" title="Prints a string.">shellPrint</a>(chp, cmd);
<a name="l00205"></a>00205 <a class="code" href="group___s_h_e_l_l.html#ga7bffb6aa1f0ec1e12dfaa86c3b692330" title="Prints a string with a final newline.">shellPrintLine</a>(chp, <span class="stringliteral">&quot; ?&quot;</span>);
<a name="l00206"></a>00206 }
<a name="l00207"></a>00207 }
<a name="l00208"></a>00208 }
<a name="l00209"></a>00209 <a class="code" href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42" title="Enters the kernel lock mode.">chSysLock</a>();
<a name="l00210"></a>00210 <a class="code" href="group__events.html#gaa24d9bed5b676b577200c4a8ebe3b8a3" title="Signals all the Event Listeners registered on the specified Event Source.">chEvtBroadcastI</a>(&amp;shell_terminated);
<a name="l00211"></a>00211 <span class="keywordflow">return</span> msg;
<a name="l00212"></a>00212 }
<a name="l00213"></a>00213 <span class="comment"></span>
<a name="l00214"></a>00214 <span class="comment">/**</span>
<a name="l00215"></a>00215 <span class="comment"> * @brief Shell manager initialization.</span>
<a name="l00216"></a>00216 <span class="comment"> */</span>
<a name="l00217"></a>00217 <span class="keywordtype">void</span> <a class="code" href="group___s_h_e_l_l.html#ga0b1dba28bb03cb29749f32a595d5ec57" title="Shell manager initialization.">shellInit</a>(<span class="keywordtype">void</span>) {
<a name="l00218"></a>00218
<a name="l00219"></a>00219 <a class="code" href="group__events.html#gab8d0fdc09be629dfb438c32a0523db42" title="Initializes an Event Source.">chEvtInit</a>(&amp;shell_terminated);
<a name="l00220"></a>00220 }
<a name="l00221"></a>00221 <span class="comment"></span>
<a name="l00222"></a>00222 <span class="comment">/**</span>
<a name="l00223"></a>00223 <span class="comment"> * @brief Spawns a new shell.</span>
<a name="l00224"></a>00224 <span class="comment"> *</span>
<a name="l00225"></a>00225 <span class="comment"> * @param[in] scp pointer to a @p ShellConfig object</span>
<a name="l00226"></a>00226 <span class="comment"> * @param[in] size size of the shell working area to be allocated</span>
<a name="l00227"></a>00227 <span class="comment"> * @param[in] prio the priority level for the new shell</span>
<a name="l00228"></a>00228 <span class="comment"> *</span>
<a name="l00229"></a>00229 <span class="comment"> * @return A pointer to the shell thread.</span>
<a name="l00230"></a>00230 <span class="comment"> * @retval NULL thread creation failed because memory allocation.</span>
<a name="l00231"></a>00231 <span class="comment"> */</span>
<a name="l00232"></a>00232 <a class="code" href="struct_thread.html" title="Structure representing a thread.">Thread</a> *<a class="code" href="group___s_h_e_l_l.html#gaa1ede2e94e6d3eba37cdda717f6c1656" title="Spawns a new shell.">shellCreate</a>(<span class="keyword">const</span> <a class="code" href="struct_shell_config.html" title="Shell descriptor type.">ShellConfig</a> *scp, <span class="keywordtype">size_t</span> size, <a class="code" href="group__types.html#ga5f2488ba73e5969cbc0f7033735374ee" title="Priority, use the fastest unsigned type.">tprio_t</a> prio) {
<a name="l00233"></a>00233
<a name="l00234"></a>00234 <span class="keywordflow">return</span> <a class="code" href="group__threads.html#ga50b84e3e82a4e09c1066e1d422e4c780" title="Creates a new thread allocating the memory from the heap.">chThdCreateFromHeap</a>(NULL, size, prio, shell_thread, (<span class="keywordtype">void</span> *)scp);
<a name="l00235"></a>00235 }
<a name="l00236"></a>00236 <span class="comment"></span>
<a name="l00237"></a>00237 <span class="comment">/**</span>
<a name="l00238"></a>00238 <span class="comment"> * @brief Prints a string.</span>
<a name="l00239"></a>00239 <span class="comment"> *</span>
<a name="l00240"></a>00240 <span class="comment"> * @param[in] chp pointer to a @p BaseChannel object</span>
<a name="l00241"></a>00241 <span class="comment"> * @param[in] msg pointer to the string</span>
<a name="l00242"></a>00242 <span class="comment"> */</span>
<a name="l00243"></a>00243 <span class="keywordtype">void</span> <a class="code" href="group___s_h_e_l_l.html#ga4660b06c861d5506fb35d9844e2d8288" title="Prints a string.">shellPrint</a>(<a class="code" href="struct_base_channel.html" title="Base channel class.">BaseChannel</a> *chp, <span class="keyword">const</span> <span class="keywordtype">char</span> *msg) {
<a name="l00244"></a>00244
<a name="l00245"></a>00245 <span class="keywordflow">while</span> (*msg)
<a name="l00246"></a>00246 <a class="code" href="group__io__channels.html#ga5b8537016d3027eedd3e63b708b57bf7" title="Channel blocking byte write.">chIOPut</a>(chp, *msg++);
<a name="l00247"></a>00247 }
<a name="l00248"></a>00248 <span class="comment"></span>
<a name="l00249"></a>00249 <span class="comment">/**</span>
<a name="l00250"></a>00250 <span class="comment"> * @brief Prints a string with a final newline.</span>
<a name="l00251"></a>00251 <span class="comment"> *</span>
<a name="l00252"></a>00252 <span class="comment"> * @param[in] chp pointer to a @p BaseChannel object</span>
<a name="l00253"></a>00253 <span class="comment"> * @param[in] msg pointer to the string</span>
<a name="l00254"></a>00254 <span class="comment"> */</span>
<a name="l00255"></a>00255 <span class="keywordtype">void</span> <a class="code" href="group___s_h_e_l_l.html#ga7bffb6aa1f0ec1e12dfaa86c3b692330" title="Prints a string with a final newline.">shellPrintLine</a>(<a class="code" href="struct_base_channel.html" title="Base channel class.">BaseChannel</a> *chp, <span class="keyword">const</span> <span class="keywordtype">char</span> *msg) {
<a name="l00256"></a>00256
<a name="l00257"></a>00257 <a class="code" href="group___s_h_e_l_l.html#ga4660b06c861d5506fb35d9844e2d8288" title="Prints a string.">shellPrint</a>(chp, msg);
<a name="l00258"></a>00258 <a class="code" href="group___s_h_e_l_l.html#ga4660b06c861d5506fb35d9844e2d8288" title="Prints a string.">shellPrint</a>(chp, <span class="stringliteral">&quot;\r\n&quot;</span>);
<a name="l00259"></a>00259 }
<a name="l00260"></a>00260 <span class="comment"></span>
<a name="l00261"></a>00261 <span class="comment">/**</span>
<a name="l00262"></a>00262 <span class="comment"> * @brief Reads a whole line from the input channel.</span>
<a name="l00263"></a>00263 <span class="comment"> *</span>
<a name="l00264"></a>00264 <span class="comment"> * @param[in] chp pointer to a @p BaseChannel object</span>
<a name="l00265"></a>00265 <span class="comment"> * @param[in] line pointer to the line buffer</span>
<a name="l00266"></a>00266 <span class="comment"> * @param[in] size buffer maximum length</span>
<a name="l00267"></a>00267 <span class="comment"> *</span>
<a name="l00268"></a>00268 <span class="comment"> * @return The operation status.</span>
<a name="l00269"></a>00269 <span class="comment"> * @retval TRUE the channel was reset or CTRL-D pressed.</span>
<a name="l00270"></a>00270 <span class="comment"> * @retval FALSE operation successful.</span>
<a name="l00271"></a>00271 <span class="comment"> */</span>
<a name="l00272"></a>00272 <a class="code" href="group__types.html#ga7556af1cb61728b53228fa3af1c851de" title="Boolean, recommended the fastest signed.">bool_t</a> <a class="code" href="group___s_h_e_l_l.html#ga1c7aadcfefdc616bd8450117b6972274" title="Reads a whole line from the input channel.">shellGetLine</a>(<a class="code" href="struct_base_channel.html" title="Base channel class.">BaseChannel</a> *chp, <span class="keywordtype">char</span> *line, <span class="keywordtype">unsigned</span> size) {
<a name="l00273"></a>00273 <span class="keywordtype">char</span> *p = line;
<a name="l00274"></a>00274
<a name="l00275"></a>00275 <span class="keywordflow">while</span> (TRUE) {
<a name="l00276"></a>00276 <span class="keywordtype">short</span> c = (short)<a class="code" href="group__io__channels.html#ga9ebccb48ead8398cf97ca7a564fe0a25" title="Channel blocking byte read.">chIOGet</a>(chp);
<a name="l00277"></a>00277 <span class="keywordflow">if</span> (c &lt; 0)
<a name="l00278"></a>00278 <span class="keywordflow">return</span> TRUE;
<a name="l00279"></a>00279 <span class="keywordflow">if</span> (c == 4) {
<a name="l00280"></a>00280 <a class="code" href="group___s_h_e_l_l.html#ga7bffb6aa1f0ec1e12dfaa86c3b692330" title="Prints a string with a final newline.">shellPrintLine</a>(chp, <span class="stringliteral">&quot;^D&quot;</span>);
<a name="l00281"></a>00281 <span class="keywordflow">return</span> TRUE;
<a name="l00282"></a>00282 }
<a name="l00283"></a>00283 <span class="keywordflow">if</span> (c == 8) {
<a name="l00284"></a>00284 <span class="keywordflow">if</span> (p != line) {
<a name="l00285"></a>00285 <a class="code" href="group__io__channels.html#ga5b8537016d3027eedd3e63b708b57bf7" title="Channel blocking byte write.">chIOPut</a>(chp, (<a class="code" href="group___s_t_m8___c_o_r_e.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a>)c);
<a name="l00286"></a>00286 <a class="code" href="group__io__channels.html#ga5b8537016d3027eedd3e63b708b57bf7" title="Channel blocking byte write.">chIOPut</a>(chp, 0x20);
<a name="l00287"></a>00287 <a class="code" href="group__io__channels.html#ga5b8537016d3027eedd3e63b708b57bf7" title="Channel blocking byte write.">chIOPut</a>(chp, (<a class="code" href="group___s_t_m8___c_o_r_e.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a>)c);
<a name="l00288"></a>00288 p--;
<a name="l00289"></a>00289 }
<a name="l00290"></a>00290 <span class="keywordflow">continue</span>;
<a name="l00291"></a>00291 }
<a name="l00292"></a>00292 <span class="keywordflow">if</span> (c == <span class="charliteral">&#39;\r&#39;</span>) {
<a name="l00293"></a>00293 <a class="code" href="group___s_h_e_l_l.html#ga7bffb6aa1f0ec1e12dfaa86c3b692330" title="Prints a string with a final newline.">shellPrintLine</a>(chp, <span class="stringliteral">&quot;&quot;</span>);
<a name="l00294"></a>00294 *p = 0;
<a name="l00295"></a>00295 <span class="keywordflow">return</span> FALSE;
<a name="l00296"></a>00296 }
<a name="l00297"></a>00297 <span class="keywordflow">if</span> (c &lt; 0x20)
<a name="l00298"></a>00298 <span class="keywordflow">continue</span>;
<a name="l00299"></a>00299 <span class="keywordflow">if</span> (p &lt; line + size - 1) {
<a name="l00300"></a>00300 <a class="code" href="group__io__channels.html#ga5b8537016d3027eedd3e63b708b57bf7" title="Channel blocking byte write.">chIOPut</a>(chp, (<a class="code" href="group___s_t_m8___c_o_r_e.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a>)c);
<a name="l00301"></a>00301 *p++ = (char)c;
<a name="l00302"></a>00302 }
<a name="l00303"></a>00303 }
<a name="l00304"></a>00304 }
<a name="l00305"></a>00305 <span class="comment"></span>
<a name="l00306"></a>00306 <span class="comment">/** @} */</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>
Generated on Sun Jul 11 13:13:01 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>