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

📄 building-and-running-sample-appliations.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
字号:
<!-- Copyright (C) 2003 Red Hat, Inc.                                --><!-- This material may be distributed only subject to the terms      --><!-- and conditions set forth in the Open Publication License, v1.0  --><!-- or later (the latest version is presently available at          --><!-- http://www.opencontent.org/openpub/).                           --><!-- Distribution of the work or derivative of the work in any       --><!-- standard (paper) book form is prohibited unless prior           --><!-- permission is obtained from the copyright holder.               --><HTML><HEAD><TITLE>Building and Running Sample Applications</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos User Guide"HREF="ecos-user-guide.html"><LINKREL="UP"TITLE="Programming With eCos"HREF="user-guide-programming.html"><LINKREL="PREVIOUS"TITLE="Testing Filters"HREF="testing-filters.html"><LINKREL="NEXT"TITLE="A Sample Program with Two Threads"HREF="sample-twothreads.html"></HEAD><BODYCLASS="CHAPTER"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos User Guide</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="testing-filters.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sample-twothreads.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="CHAPTER"><H1><ANAME="BUILDING-AND-RUNNING-SAMPLE-APPLIATIONS">Chapter 13. Building and Running Sample Applications</H1><DIVCLASS="TOC"><DL><DT><B>Table of Contents</B></DT><DT><AHREF="building-and-running-sample-appliations.html#ECOS-HELLO-WORLD"><SPANCLASS="PRODUCTNAME">eCos</SPAN> Hello World</A></DT><DT><AHREF="sample-twothreads.html">A Sample Program with Two Threads</A></DT></DL></DIV><P>The example programs in this tutorial are included, alongwith a <TTCLASS="FILENAME">Makefile</TT>, in the <TTCLASS="FILENAME">examples</TT> directoryof the <SPANCLASS="PRODUCTNAME">eCos</SPAN> distribution. The first program you will run is a <SPANCLASS="emphasis"><ICLASS="EMPHASIS">helloworld</I></SPAN>-style application, then you will run a more complexapplication that demonstrates the creation of threads and the useof cyg_thread_delay(), and finally you will runone that uses clocks and alarm handlers.</P><P>The <TTCLASS="FILENAME">Makefile</TT> depends on an externallydefined variable to find the <SPANCLASS="PRODUCTNAME">eCos</SPAN> library and header files. Thisvariable is <TTCLASS="LITERAL">INSTALL_DIR</TT> and must be set to thepathname of the install directory created in <AHREF="using-configtool-windows-linux.html">the Section called <I>Configuration Tool on Windows and Linux Quick Start</I> in Chapter 11</A>.</P><P><TTCLASS="LITERAL">INSTALL_DIR</TT> may be either be set in the shellenvironment or may be supplied on the command line. To set it in theshell do the following in a <BCLASS="COMMAND">bash</B> shell:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">$ export INSTALL_DIR=BASE_DIR/ecos-work/arm_install</PRE></TD></TR></TABLE><P>You can then run <BCLASS="COMMAND">make</B> without any extra parametersto build the examples.</P><P>Alternatively, if you can do the following:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">$ make INSTALL_DIR=BASE_DIR/ecos-work/arm_install</PRE></TD></TR></TABLE><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="ECOS-HELLO-WORLD"><SPANCLASS="PRODUCTNAME">eCos</SPAN> Hello World</H1><P>The following code is found in the file <TTCLASS="FILENAME">hello.c</TT>in the <TTCLASS="FILENAME">examples</TT> directory: </P><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN835"><SPANCLASS="PRODUCTNAME">eCos</SPAN> hello world program listing</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">/* this is a simple hello world program */#include &lt;stdio.h&#62;int main(void){ printf("Hello, eCos world!\n"); return 0;}</PRE></TD></TR></TABLE><P>To compile this or any other program that is not part of the<SPANCLASS="PRODUCTNAME">eCos</SPAN> distribution, you can follow the procedures described below. Typethis explicit compilation command (assuming your current workingdirectory is also where you built the <SPANCLASS="PRODUCTNAME">eCos</SPAN> kernel):</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">$ <TTCLASS="REPLACEABLE"><I>TARGET-</I></TT>gcc -g -I<TTCLASS="REPLACEABLE"><I>BASE_DIR</I></TT>/ecos-work/install/include hello.c -L<TTCLASS="REPLACEABLE"><I>BASE_DIR</I></TT>/ecos-work/install/lib -Ttarget.ld -nostdlib</PRE></TD></TR></TABLE><P>The compilation command above contains some standard GCCoptions (for example, <TTCLASS="OPTION">-g</TT> enables debugging), as wellas some mention of paths(<TTCLASS="OPTION">-I<TTCLASS="REPLACEABLE"><I>BASE_DIR</I></TT>/ecos-work/install/include</TT> allows fileslike <TTCLASS="FILENAME">cyg/kernel/kapi.h</TT> to be found, and<TTCLASS="OPTION">-L<TTCLASS="REPLACEABLE"><I>BASE_DIR</I></TT>/ecos-work/install/lib</TT> allows the linker tofind <TTCLASS="OPTION">-Ttarget.ld</TT>). </P><P>The executable program will be called <TTCLASS="FILENAME">a.out</TT>. </P><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>Some target systems require special options to be passed togcc to compile correctly for that system. Please examine the Makefilein the examples directory to see if this applies to your target.</P></BLOCKQUOTE></DIV><P>You can now run the resulting program using GDB in exactly thesame the way you ran the test case before. The procedure will be thesame, but this time run<BCLASS="COMMAND"><TTCLASS="REPLACEABLE"><I>TARGET-</I></TT>gdb</B> specifying<TTCLASS="OPTION">-nw a.out</TT> on the command line:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">$ <TTCLASS="REPLACEABLE"><I>TARGET-</I></TT>gdb -nw a.out</PRE></TD></TR></TABLE><P>For targets other than the synthetic linux target, you shouldnow run the usual GDB commands described earlier. Once this is done,typing the command "continue" at the (gdb) prompt ("run" forsimulators) will allow the program to execute and print the string"Hello, eCos world!" on your screen.</P><P>On the synthetic linux target, you may use the "run" commandimmediately - you do not need to connect to the target, nor use the"load" command.</P></DIV></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="testing-filters.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-user-guide.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="sample-twothreads.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Testing Filters</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="user-guide-programming.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">A Sample Program with Two Threads</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

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