📄 programming-concepts-techniques.sgml
字号:
<!-- {{{ Banner -->
<!-- =============================================================== -->
<!-- -->
<!-- programming-concepts-techniques.sgml -->
<!-- -->
<!-- eCos User Guide -->
<!-- -->
<!-- =============================================================== -->
<!-- ####COPYRIGHTBEGIN#### -->
<!-- -->
<!-- =============================================================== -->
<!-- Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 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 obtained from the copyright holder -->
<!-- =============================================================== -->
<!-- -->
<!-- ####COPYRIGHTEND#### -->
<!-- =============================================================== -->
<!-- #####DESCRIPTIONBEGIN#### -->
<!-- -->
<!-- ####DESCRIPTIONEND#### -->
<!-- =============================================================== -->
<!-- }}} -->
<PART id="ecos-programming-concepts-and-techniques">
<TITLE><productname>eCos</productname> Programming Concepts and Techniques</TITLE>
<PARTINTRO id="programming-partintro">
<PARA>Programming with <productname>eCos</productname> is somewhat different from programming
in more traditional environments. <productname>eCos</productname> is a configurable open
source system, and you are able to configure and build a system
specifically to meet the needs of your application. </PARA>
<PARA>Various different directory hierarchies are involved in
configuring and building the system: the <EMPHASIS>component
repository</EMPHASIS>, the <EMPHASIS>build tree</EMPHASIS>,
and the <EMPHASIS>install tree</EMPHASIS>. These directories
exist in addition to the ones used to develop
applications.</PARA>
</PARTINTRO>
<CHAPTER id="cdl-concepts">
<TITLE>CDL Concepts</TITLE>
<SECT1 id="cdl-concepts-about">
<TITLE>About this chapter</TITLE>
<PARA>This chapter serves as a brief introduction to the
concepts involved in <productname>eCos</productname> (Embedded Configurable Operating
System). It describes the configuration architecture and the
underlying technology to a level required for the embedded
systems developer to configure <productname>eCos</productname>. It does not describe in
detail aspects such as how to write reusable components for
<productname>eCos</productname>: this information is given in the <citetitle>Component
Writer’s Guide</citetitle>.</PARA>
<SECT2>
<TITLE>Background</TITLE>
<PARA>Software solutions for the embedded space place
particularly stringent demands on the developer, typically
represented as requirements for small memory footprint, high
performance and robustness. These demands are addressed in
<productname>eCos</productname> by providing the ability to perform compile-time
specialization: the developer can tailor the operating
system to suit the needs of the application. In order to
make this process manageable, <productname>eCos</productname> is built in the context
of a Configuration Infrastructure: a set of tools including
a <application>Configuration Tool</application> and a formal
description of the process of configuration by means of a
<EMPHASIS>Component Definition Language</EMPHASIS>.</PARA>
</SECT2>
<SECT2>
<TITLE>Configurations</TITLE>
<PARA><productname>eCos</productname> is tailored at source level (that is, before
compilation or assembly) in order to create an <productname>eCos</productname>
<EMPHASIS>configuration</EMPHASIS>. In concrete terms, an
<productname>eCos</productname> configuration takes the form of a configuration save
file (with extension .ecc) and set of files used to build
user applications (including, when built, a library file
against which the application is linked). </PARA>
</SECT2>
</SECT1>
<SECT1 id="cdl-component-repository">
<TITLE>Component Repository</TITLE>
<PARA><productname>eCos</productname> is shipped in source in the form of a
<EMPHASIS>component repository</EMPHASIS> - a directory
hierarchy that contains the sources and other files which
are used to build a configuration. The component repository
can be added to by, for example, downloading from the
net.</PARA>
</SECT1>
<SECT1 id="cdl-component-definition-language">
<TITLE>Component Definition Language</TITLE>
<PARA>Part of the component repository is a set of files
containing a definition of its structure. The form used for
this purpose is the <EMPHASIS>Component Definition
Language</EMPHASIS> (CDL). CDL defines the relationships
between components and other information used by tools such
as the <productname>eCos</productname><APPLICATION>Configuration Tool</APPLICATION>.
CDL is generally formulated by the writers of components: it
is not necessary to write or understand CDL in order for the
embedded systems developer to construct an <productname>eCos</productname>
configuration. </PARA>
</SECT1>
<SECT1 id="cdl-packages">
<TITLE>Packages</TITLE>
<PARA>The building blocks of an <productname>eCos</productname> configuration are called
<EMPHASIS>packages</EMPHASIS>. Packages are the units of
software distribution. A set of core packages (such as
kernel, C library and math library) is provided by Red Hat:
additional third-party packages will be available in
future.</PARA>
<PARA>A package may exist in one of a number of <EMPHASIS>versions</EMPHASIS>.
The default version is the <EMPHASIS>current</EMPHASIS> version.
Only one version of a given package may be present in the component
repository at any given time.</PARA>
<PARA>Packages are organized in a tree hierarchy. Each package
is either at the top-level or is the child of another package.</PARA>
<PARA>The <productname>eCos</productname> <application> Package Administration Tool</application> can be used to add or remove
packages from the component repository. The <productname>eCos</productname> <APPLICATION>Configuration Tool</APPLICATION> can be used to include or exclude packages from the configuration
being built.</PARA>
</SECT1>
<SECT1 id="cdl-configuration-items">
<TITLE>Configuration Items</TITLE>
<PARA><EMPHASIS>Configuration items</EMPHASIS> are the
individual entities that form a configuration. Each item
corresponds to the setting of a C pre-processor macro (for
example,
<literal>CYGHWR_HAL_ARM_PID_GDB_BAUD</literal>).
The code of <productname>eCos</productname> itself is written to test such pre-processor
macros so as to tailor the code. User code can do
likewise.</PARA>
<PARA>Configuration items come in the following flavors:</PARA>
<ITEMIZEDLIST>
<LISTITEM>
<PARA><EMPHASIS>None</EMPHASIS>: such entities serve only as
place holders in the hierarchy, allowing other entities to be grouped
more easily.</PARA>
</LISTITEM>
<LISTITEM>
<PARA><EMPHASIS>Boolean</EMPHASIS> entities are the most common
flavor; they correspond to units of functionality that can be either
enabled or disabled. If the entity is enabled then there will be
a #define; code will check the setting using, for example, #ifdef</PARA>
</LISTITEM>
<LISTITEM>
<PARA><EMPHASIS>Data</EMPHASIS> entities encapsulate some arbitrary
data. Other properties such as a set or range of legal values can
be used to constrain the actual values, for example to an integer
or floating point value within a certain range.</PARA>
</LISTITEM>
<LISTITEM>
<PARA><EMPHASIS>Booldata</EMPHASIS> entities combine the attributes
of <EMPHASIS>Boolean</EMPHASIS> and <EMPHASIS>Data</EMPHASIS>: they
can be enabled or disabled and, if enabled, will hold a data value.</PARA>
</LISTITEM>
</ITEMIZEDLIST>
<PARA>Like packages, configuration items exist in a tree-based hierarchy:
each configuration item has a parent which may be another configuration
item or a package. Under some conditions (such as when packages
are added or removed from a configuration), items may be “re-parented” such
that their position in the tree changes. </PARA>
<SECT2>
<TITLE>Expressions</TITLE>
<PARA>Expressions are relationships between CDL items. There are
three types of expression in CDL:</PARA>
<table id="cdl-expressions">
<title>CDL Expressions</title>
<tgroup cols="3">
<thead>
<row>
<entry>Expression Type</entry>
<entry>Result</entry>
<entry>Common Use (see <xref linkend="table-configuration-properties">)</entry></row>
</thead>
<tbody>
<row>
<entry>Ordinary</entry>
<entry>A single value</entry>
<entry>legal_values property</entry>
</row>
<row>
<entry>List</entry><entry>A range of
values (for example “1 to 10”)</entry>
<entry>legal_values property </entry></row>
<row>
<entry>Goal</entry><entry>True or False</entry>
<entry>requires and active_if properties</entry></row>
</tbody>
</tgroup>
</table>
</SECT2>
<SECT2>
<TITLE>Properties</TITLE>
<PARA>Each configuration item has a set of properties. The following
table describes the most commonly used:</PARA>
<table id="table-configuration-properties">
<title>Configuration properties</title>
<tgroup cols="2">
<thead><row>
<entry><emphasis>Property</emphasis></entry>
<entry><emphasis>Use </emphasis></entry></row>
</thead>
<tbody>
<row>
<entry>Flavor</entry>
<entry>The “type” of the item, as
described above </entry></row>
<row>
<entry>Enabled</entry><entry>Whether
the item is enabled </entry></row>
<row>
<entry>Current_value</entry>
<entry>The current value of the item </entry></row>
<row>
<entry>Default_value</entry>
<entry>An ordinary expression defining the default value of the
item</entry></row>
<row>
<entry>Legal_values</entry><entry>A
list expression defining the values the item may hold (for example,
1 to10) </entry></row>
<row>
<entry>Active_if</entry><entry>A
goal expression denoting the requirement for this item to be active
(see below: <emphasis>Inactive Items</emphasis>) </entry></row>
<row>
<entry>Requires</entry><entry>A goal
expression denoting requirements this item places on others (see
below: <emphasis>Conflicts</emphasis>) </entry></row>
<row>
<entry>Calculated</entry><entry>Whether
the item as non-modifiable </entry></row>
<row>
<entry>Macro</entry><entry>The corresponding
C pre-processor macro </entry></row>
<row>
<entry>File</entry><entry>The C header
file in which the macro is defined </entry></row>
<row>
<entry>URL</entry><entry>The URL of
a documentation page describing the item </entry></row>
<row>
<entry>Hardware</entry><entry>Indicates
that a particular package is related to specific hardware</entry></row>
</tbody>
</tgroup>
</table>
<PARA>A complete description of properties is contained in the <citetitle>Component
Writer’s Guide</citetitle>.</PARA>
</SECT2>
<SECT2>
<TITLE>Inactive Items</TITLE>
<PARA>Descendants of an item that is disabled are inactive: their
values may not be changed. Items may also become <EMPHASIS>inactive</EMPHASIS> if
an active_if expression is used to make the item dependent
on an expression involving other items. </PARA>
</SECT2>
</SECT1>
<SECT1 id="cdl-conflicts">
<TITLE>Conflicts</TITLE>
<PARA>Not all settings of configuration items will lead to a
coherent configuration; for example, the use of a timeout
facility might require the existence of timer support, so if
the one is required the other cannot be removed. Coherence
is policed by means of consistency rules (in particular, the
goal expressions that appear as CDL items
<EMPHASIS>requires</EMPHASIS> and
<EMPHASIS>active_if</EMPHASIS> attributes [see
above]). A violation of consistency rules creates a
<EMPHASIS>conflict</EMPHASIS>, which must be resolved in
order to ensure a consistent configuration. Conflict
resolution can be performed manually or with the assistance
of the <productname>eCos</productname> tools. Conflicts come in the following
flavors:</PARA>
<ITEMIZEDLIST>
<LISTITEM>
<PARA>An <EMPHASIS>unresolved</EMPHASIS> conflict means that
there is a reference to an entity that is not yet in the current
configuration </PARA>
</LISTITEM>
<LISTITEM>
<PARA>An <EMPHASIS>illegal value</EMPHASIS> conflict is caused
when a configuration item is set to a value that is not permitted
(that is, a <EMPHASIS>legal_values</EMPHASIS> goal expression
is failing) </PARA>
</LISTITEM>
<LISTITEM>
<PARA>An <EMPHASIS>evaluation exception</EMPHASIS> conflict
is caused when the evaluation of an expression would fail (for example,
because of a division by zero) </PARA>
</LISTITEM>
<LISTITEM>
<PARA>An <EMPHASIS>unsatisfied goal</EMPHASIS> conflict is caused
by a failing <EMPHASIS>requires</EMPHASIS> goal expression </PARA>
</LISTITEM>
<LISTITEM>
<PARA>A <EMPHASIS>bad data</EMPHASIS> conflict arises only rarely,
and corresponds to badly constructed CDL. Such a conflict can only
be resolved by reference to the CDL writer.</PARA>
</LISTITEM>
</ITEMIZEDLIST>
</SECT1>
<SECT1 id="cdl-templates">
<TITLE>Templates</TITLE>
<PARA>A <EMPHASIS>template</EMPHASIS> is a saved configuration
- that is, a set of packages and configuration item
settings. Templates are provided with <productname>eCos</productname> to allow you to
get started quickly by instantiating (copying) a saved
configuration corresponding to one of a number of common
scenarios; for example, a basic <productname>eCos</productname> configuration template
is supplied that contains the infrastructure, kernel, C and
math libraries, plus their support packages.</PARA>
</SECT1>
</CHAPTER>
<CHAPTER id="component-repo-and-working-dirs">
<TITLE>The Component Repository and Working Directories</TITLE>
<PARA>Each of the file trees involved in <productname>eCos</productname> development has a
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -