📄 programming-with-ecos.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>Programming With eCos</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="Programming With eCos"HREF="user-guide-programming.html"><LINKREL="NEXT"TITLE="Configuring and Building eCos from Source"HREF="configuring-and-building-ecos-from-source.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="user-guide-programming.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="configuring-and-building-ecos-from-source.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="CHAPTER"><H1><ANAME="PROGRAMMING-WITH-ECOS">Chapter 10. Programming With <SPANCLASS="PRODUCTNAME">eCos</SPAN></H1><P>The following chapters of this manual comprise a simple tutorialfor configuring and building <SPANCLASS="PRODUCTNAME">eCos</SPAN>, building and running <SPANCLASS="PRODUCTNAME">eCos</SPAN> tests,and finally building three stand-alone example programs which usethe <SPANCLASS="PRODUCTNAME">eCos</SPAN> API to perform some simple tasks.</P><P>You will need a properly installed <SPANCLASS="PRODUCTNAME">eCos</SPAN> system, with the correctversions of the GNU toolchain. On Windowsyou will be using the bash command line interpreter that comes withCygwin, with the environment variables set as described in thetoolchain documentation.</P><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="DEVELOPMENT-PROCESS">The Development Process</H1><P>Most development projects using <SPANCLASS="PRODUCTNAME">eCos</SPAN> would contain some (ormost) of the following:</P><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN471"><SPANCLASS="PRODUCTNAME">eCos</SPAN> Configuration</H2><P><SPANCLASS="PRODUCTNAME">eCos</SPAN> is configured to provide the desired API (the inclusionof libc, uitron, and the disabling of certain undesired funtions,etc.), and semantics (selecting scheduler, mutex behavior, etc.).See <AHREF="configuring-and-building-ecos-from-source.html">Chapter 11</A>.</P><P>It would normally make sense to enable <SPANCLASS="PRODUCTNAME">eCos</SPAN> assertion checkingat this time as well, to catch as many programming errors duringthe development phase as possible.</P><P>Note that it should not be necessary to spend much time on<SPANCLASS="PRODUCTNAME">eCos</SPAN> configuration initially. It may be important to perform finetuning to reduce the memory footprint and to improve performancelater when the product reaches a testable state.</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN481">Integrity check of the <SPANCLASS="PRODUCTNAME">eCos</SPAN> configuration</H2><P>While we strive to thoroughly test <SPANCLASS="PRODUCTNAME">eCos</SPAN>, the vast numberof configuration permutations mean that the particular configurationparameters used for your project may not have been tested. Therefore,we advise running the <SPANCLASS="PRODUCTNAME">eCos</SPAN> tests after the project's<SPANCLASS="PRODUCTNAME">eCos</SPAN> configuration has been determined. See <AHREF="running-an-ecos-test-case.html">Chapter 12</A>.</P><P>Obviously, this should be repeated if the configuration changeslater on in the development process.</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN490">Application Development - Target Neutral Part</H2><P>While your project is probably targeting a specific architectureand platform, possibly custom hardware, it may be possible to performpart of the application development using simulated or synthetictargets.</P><P>There are three good reasons for doing this:</P><P></P><UL><LI><P>It may be possible by this means to perform applicationdevelopment in parallel with the design/implementationof the target hardware, thus providing more time for developingand testing functionality, and reducing time-to-market.</P></LI><LI><P>The build-run-debug-cycle may be faster when the applicationdoes not have to be downloaded to a target via a serial interface.Debugging is also likely to be more responsive when you do not have toto communicate with the remote GDB stubs in RedBoot via serial. Italso removes the need for manually or automatically resetting thetarget hardware.</P></LI><LI><P>New hardware can often be buggy. Comparing the behaviour of theprogram on the hardware and in the simulator or synthetic target mayallow you to identify where the problems lie.</P></LI></UL><P>This approach is possible because all targets (includingsimulators and synthetic ones) provide the same basic API: thatis, kernel, libc, libm, uitron, infra, and to some extent, HAL andIO.</P><P>Synthetic targets are especially suitable as they allow youto construct simulations of elaborate devices by interaction withthe host system, where an IO device API can hide the details fromthe application. When switching to hardware later in the developmentcycle, the IO driver is properly implemented.</P><P>Simulators can also do this, but it all depends on thedesign and capabilities of the simulator you use. Some, like<AHREF="http://sources.redhat.com/sid"TARGET="_top">SID</A> or<AHREF="http://bochs.sourceforge.net/"TARGET="_top">Bochs</A> providecomplete hardware emulation, while others just support enough of theinstruction set to run compiled code.</P><P>Therefore, select a simulator or synthetic target and useit for as long as possible for application development. That is,configure for the selected target, build <SPANCLASS="PRODUCTNAME">eCos</SPAN>, build the applicationand link with <SPANCLASS="PRODUCTNAME">eCos</SPAN>, run and debug. Repeat the latter two steps untilyou are happy with it.</P><P>Obviously, at some time you will have to switch to the intendedtarget hardware, for example when adding target specific featuresupport, for memory footprint/performance characterization,and for final tuning of <SPANCLASS="PRODUCTNAME">eCos</SPAN> and the application.</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN511">Application Development - Target Specific Part</H2><P>Repeat the build-run-debug-cycle while performing final tuningand debugging of application. Remember to disable <SPANCLASS="PRODUCTNAME">eCos</SPAN> assertionchecking if you are testing any performance-related aspects, it canmake a big difference.</P><P>It may be useful to switch between this and the previous steprepeatedly through the development process; use the simulator/synthetictarget for actual development, and use the target hardware to continuallycheck memory footprint and performance. There should be little costin switching between the two targets when using two separate buildtrees. </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="user-guide-programming.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="configuring-and-building-ecos-from-source.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Programming With <SPANCLASS="PRODUCTNAME">eCos</SPAN></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="user-guide-programming.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Configuring and Building <SPANCLASS="PRODUCTNAME">eCos</SPAN> from Source</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -