1 |
786 |
skrzyp |
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
eCos Programming Concepts and Techniques
|
32 |
|
|
|
33 |
|
|
Programming with eCos is somewhat different from programming
|
34 |
|
|
in more traditional environments. eCos is a configurable open
|
35 |
|
|
source system, and you are able to configure and build a system
|
36 |
|
|
specifically to meet the needs of your application.
|
37 |
|
|
Various different directory hierarchies are involved in
|
38 |
|
|
configuring and building the system: the component
|
39 |
|
|
repository, the build tree,
|
40 |
|
|
and the install tree. These directories
|
41 |
|
|
exist in addition to the ones used to develop
|
42 |
|
|
applications.
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
CDL Concepts
|
46 |
|
|
|
47 |
|
|
About this chapter
|
48 |
|
|
This chapter serves as a brief introduction to the
|
49 |
|
|
concepts involved in eCos (Embedded Configurable Operating
|
50 |
|
|
System). It describes the configuration architecture and the
|
51 |
|
|
underlying technology to a level required for the embedded
|
52 |
|
|
systems developer to configure eCos. It does not describe in
|
53 |
|
|
detail aspects such as how to write reusable components for
|
54 |
|
|
eCos: this information is given in the Component
|
55 |
|
|
Writer’s Guide.
|
56 |
|
|
|
57 |
|
|
Background
|
58 |
|
|
Software solutions for the embedded space place
|
59 |
|
|
particularly stringent demands on the developer, typically
|
60 |
|
|
represented as requirements for small memory footprint, high
|
61 |
|
|
performance and robustness. These demands are addressed in
|
62 |
|
|
eCos by providing the ability to perform compile-time
|
63 |
|
|
specialization: the developer can tailor the operating
|
64 |
|
|
system to suit the needs of the application. In order to
|
65 |
|
|
make this process manageable, eCos is built in the context
|
66 |
|
|
of a Configuration Infrastructure: a set of tools including
|
67 |
|
|
a Configuration Tool and a formal
|
68 |
|
|
description of the process of configuration by means of a
|
69 |
|
|
Component Definition Language.
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
Configurations
|
73 |
|
|
eCos is tailored at source level (that is, before
|
74 |
|
|
compilation or assembly) in order to create an eCos
|
75 |
|
|
configuration. In concrete terms, an
|
76 |
|
|
eCos configuration takes the form of a configuration save
|
77 |
|
|
file (with extension .ecc) and set of files used to build
|
78 |
|
|
user applications (including, when built, a library file
|
79 |
|
|
against which the application is linked).
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
Component Repository
|
84 |
|
|
eCos is shipped in source in the form of a
|
85 |
|
|
component repository - a directory
|
86 |
|
|
hierarchy that contains the sources and other files which
|
87 |
|
|
are used to build a configuration. The component repository
|
88 |
|
|
can be added to by, for example, downloading from the
|
89 |
|
|
net.
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
Component Definition Language
|
93 |
|
|
Part of the component repository is a set of files
|
94 |
|
|
containing a definition of its structure. The form used for
|
95 |
|
|
this purpose is the Component Definition
|
96 |
|
|
Language (CDL). CDL defines the relationships
|
97 |
|
|
between components and other information used by tools such
|
98 |
|
|
as the eCosConfiguration Tool.
|
99 |
|
|
CDL is generally formulated by the writers of components: it
|
100 |
|
|
is not necessary to write or understand CDL in order for the
|
101 |
|
|
embedded systems developer to construct an eCos
|
102 |
|
|
configuration.
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
Packages
|
106 |
|
|
The building blocks of an eCos configuration are called
|
107 |
|
|
packages. Packages are the units of
|
108 |
|
|
software distribution. A set of core packages (such as
|
109 |
|
|
kernel, C library and math library) is provided by Red Hat:
|
110 |
|
|
additional third-party packages will be available in
|
111 |
|
|
future.
|
112 |
|
|
A package may exist in one of a number of versions.
|
113 |
|
|
The default version is the current version.
|
114 |
|
|
Only one version of a given package may be present in the component
|
115 |
|
|
repository at any given time.
|
116 |
|
|
Packages are organized in a tree hierarchy. Each package
|
117 |
|
|
is either at the top-level or is the child of another package.
|
118 |
|
|
The eCos Package Administration Tool can be used to add or remove
|
119 |
|
|
packages from the component repository. The eCos Configuration Tool can be used to include or exclude packages from the configuration
|
120 |
|
|
being built.
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
Configuration Items
|
124 |
|
|
Configuration items are the
|
125 |
|
|
individual entities that form a configuration. Each item
|
126 |
|
|
corresponds to the setting of a C pre-processor macro (for
|
127 |
|
|
example,
|
128 |
|
|
CYGHWR_HAL_ARM_PID_GDB_BAUD).
|
129 |
|
|
The code of eCos itself is written to test such pre-processor
|
130 |
|
|
macros so as to tailor the code. User code can do
|
131 |
|
|
likewise.
|
132 |
|
|
Configuration items come in the following flavors:
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
None: such entities serve only as
|
136 |
|
|
place holders in the hierarchy, allowing other entities to be grouped
|
137 |
|
|
more easily.
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
Boolean entities are the most common
|
141 |
|
|
flavor; they correspond to units of functionality that can be either
|
142 |
|
|
enabled or disabled. If the entity is enabled then there will be
|
143 |
|
|
a #define; code will check the setting using, for example, #ifdef
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
Data entities encapsulate some arbitrary
|
147 |
|
|
data. Other properties such as a set or range of legal values can
|
148 |
|
|
be used to constrain the actual values, for example to an integer
|
149 |
|
|
or floating point value within a certain range.
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
Booldata entities combine the attributes
|
153 |
|
|
of Boolean and Data: they
|
154 |
|
|
can be enabled or disabled and, if enabled, will hold a data value.
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
Like packages, configuration items exist in a tree-based hierarchy:
|
158 |
|
|
each configuration item has a parent which may be another configuration
|
159 |
|
|
item or a package. Under some conditions (such as when packages
|
160 |
|
|
are added or removed from a configuration), items may be “re-parented” such
|
161 |
|
|
that their position in the tree changes.
|
162 |
|
|
|
163 |
|
|
Expressions
|
164 |
|
|
Expressions are relationships between CDL items. There are
|
165 |
|
|
three types of expression in CDL:
|
166 |
|
|
167 |
|
|
CDL Expressions
|
168 |
|
|
|
169 |
|
|
170 |
|
|
|
|
171 |
|
|
Expression Type
|
172 |
|
|
Result
|
173 |
|
|
Common Use (see )
|
174 |
|
|
|
|
175 |
|
|
176 |
|
|
|
|
177 |
|
|
Ordinary
|
178 |
|
|
A single value
|
179 |
|
|
legal_values property
|
180 |
|
|
|
181 |
|
|
|
|
182 |
|
|
ListA range of
|
183 |
|
|
values (for example “1 to 10”)
|
184 |
|
|
legal_values property
|
185 |
|
|
|
|
186 |
|
|
GoalTrue or False
|
187 |
|
|
requires and active_if properties
|
188 |
|
|
|
|
189 |
|
|
|
190 |
|
|
|
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
Properties
|
194 |
|
|
Each configuration item has a set of properties. The following
|
195 |
|
|
table describes the most commonly used:
|
196 |
|
|
197 |
|
|
Configuration properties
|
198 |
|
|
|
199 |
|
|
200 |
|
|
Property
|
201 |
|
|
Use
|
202 |
|
|
|
|
203 |
|
|
204 |
|
|
|
|
205 |
|
|
Flavor
|
206 |
|
|
The “type” of the item, as
|
207 |
|
|
described above
|
208 |
|
|
|
|
209 |
|
|
EnabledWhether
|
210 |
|
|
the item is enabled
|
211 |
|
|
|
|
212 |
|
|
Current_value
|
213 |
|
|
The current value of the item
|
214 |
|
|
|
|
215 |
|
|
Default_value
|
216 |
|
|
An ordinary expression defining the default value of the
|
217 |
|
|
item
|
218 |
|
|
|
|
219 |
|
|
Legal_valuesA
|
220 |
|
|
list expression defining the values the item may hold (for example,
|
221 |
|
|
1 to10)
|
222 |
|
|
|
|
223 |
|
|
Active_ifA
|
224 |
|
|
goal expression denoting the requirement for this item to be active
|
225 |
|
|
(see below: Inactive Items)
|
226 |
|
|
|
|
227 |
|
|
RequiresA goal
|
228 |
|
|
expression denoting requirements this item places on others (see
|
229 |
|
|
below: Conflicts)
|
230 |
|
|
|
|
231 |
|
|
CalculatedWhether
|
232 |
|
|
the item as non-modifiable
|
233 |
|
|
|
|
234 |
|
|
MacroThe corresponding
|
235 |
|
|
C pre-processor macro
|
236 |
|
|
|
|
237 |
|
|
FileThe C header
|
238 |
|
|
file in which the macro is defined
|
239 |
|
|
|
|
240 |
|
|
URLThe URL of
|
241 |
|
|
a documentation page describing the item
|
242 |
|
|
|
|
243 |
|
|
HardwareIndicates
|
244 |
|
|
that a particular package is related to specific hardware
|
245 |
|
|
|
|
246 |
|
|
|
247 |
|
|
|
|
248 |
|
|
|
249 |
|
|
A complete description of properties is contained in the Component
|
250 |
|
|
Writer’s Guide.
|
251 |
|
|
|
252 |
|
|
|
253 |
|
|
Inactive Items
|
254 |
|
|
Descendants of an item that is disabled are inactive: their
|
255 |
|
|
values may not be changed. Items may also become inactive if
|
256 |
|
|
an active_if expression is used to make the item dependent
|
257 |
|
|
on an expression involving other items.
|
258 |
|
|
|
259 |
|
|
|
260 |
|
|
|
261 |
|
|
Conflicts
|
262 |
|
|
Not all settings of configuration items will lead to a
|
263 |
|
|
coherent configuration; for example, the use of a timeout
|
264 |
|
|
facility might require the existence of timer support, so if
|
265 |
|
|
the one is required the other cannot be removed. Coherence
|
266 |
|
|
is policed by means of consistency rules (in particular, the
|
267 |
|
|
goal expressions that appear as CDL items
|
268 |
|
|
requires and
|
269 |
|
|
active_if attributes [see
|
270 |
|
|
above]). A violation of consistency rules creates a
|
271 |
|
|
conflict, which must be resolved in
|
272 |
|
|
order to ensure a consistent configuration. Conflict
|
273 |
|
|
resolution can be performed manually or with the assistance
|
274 |
|
|
of the eCos tools. Conflicts come in the following
|
275 |
|
|
flavors:
|
276 |
|
|
|
277 |
|
|
|
278 |
|
|
An unresolved conflict means that
|
279 |
|
|
there is a reference to an entity that is not yet in the current
|
280 |
|
|
configuration
|
281 |
|
|
|
282 |
|
|
|
283 |
|
|
An illegal value conflict is caused
|
284 |
|
|
when a configuration item is set to a value that is not permitted
|
285 |
|
|
(that is, a legal_values goal expression
|
286 |
|
|
is failing)
|
287 |
|
|
|
288 |
|
|
|
289 |
|
|
An evaluation exception conflict
|
290 |
|
|
is caused when the evaluation of an expression would fail (for example,
|
291 |
|
|
because of a division by zero)
|
292 |
|
|
|
293 |
|
|
|
294 |
|
|
An unsatisfied goal conflict is caused
|
295 |
|
|
by a failing requires goal expression
|
296 |
|
|
|
297 |
|
|
|
298 |
|
|
A bad data conflict arises only rarely,
|
299 |
|
|
and corresponds to badly constructed CDL. Such a conflict can only
|
300 |
|
|
be resolved by reference to the CDL writer.
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
|
305 |
|
|
Templates
|
306 |
|
|
A template is a saved configuration
|
307 |
|
|
- that is, a set of packages and configuration item
|
308 |
|
|
settings. Templates are provided with eCos to allow you to
|
309 |
|
|
get started quickly by instantiating (copying) a saved
|
310 |
|
|
configuration corresponding to one of a number of common
|
311 |
|
|
scenarios; for example, a basic eCos configuration template
|
312 |
|
|
is supplied that contains the infrastructure, kernel, C and
|
313 |
|
|
math libraries, plus their support packages.
|
314 |
|
|
|
315 |
|
|
|
316 |
|
|
|
317 |
|
|
The Component Repository and Working Directories
|
318 |
|
|
Each of the file trees involved in eCos development has a
|
319 |
|
|
different role.
|
320 |
|
|
|
321 |
|
|
Component Repository
|
322 |
|
|
The eCos component repository
|
323 |
|
|
contains directories for all the packages that are shipped
|
324 |
|
|
with eCos or provided by third parties.
|
325 |
|
|
The component repository should not be modified as part of
|
326 |
|
|
application development.
|
327 |
|
|
|
332 |
|
|
|
333 |
|
|
Component repository
|
334 |
|
|
![]()
|
335 |
|
|
|
336 |
|
|
|
337 |
|
|
Purpose
|
338 |
|
|
The component repository is the master copy of source code
|
339 |
|
|
for all system and third party components. It also contains some
|
340 |
|
|
files needed to administer and build the system, such as ecosadmin.tcl.
|
341 |
|
|
|
342 |
|
|
|
343 |
|
|
How is it modified?
|
344 |
|
|
You modify it by importing new versions of packages from a
|
345 |
|
|
distribution or removing existing packages. These activities are
|
346 |
|
|
undertaken using the eCos Package Administration Tool.
|
347 |
|
|
|
348 |
|
|
|
349 |
|
|
When is it edited manually?
|
350 |
|
|
Files in the component repository should only be edited manually
|
351 |
|
|
as determined by the component maintainer.
|
352 |
|
|
|
353 |
|
|
|
354 |
|
|
User Applications
|
355 |
|
|
User application source code should not go
|
356 |
|
|
into the component repository.
|
357 |
|
|
|
358 |
|
|
|
359 |
|
|
Examples of files in this hierarchy:
|
360 |
|
|
|
361 |
|
|
|
362 |
|
|
BASE_DIR/doc/ref/ecos-ref.html
|
363 |
|
|
|
364 |
|
|
The top level HTML file for the
|
365 |
|
|
eCos Reference
|
366 |
|
|
Manual.
|
367 |
|
|
|
368 |
|
|
|
369 |
|
|
|
370 |
|
|
BASE_DIR/prebuilt/pid/tests/kernel/&Version;/tests/thread_gdb.exe
|
371 |
|
|
|
372 |
|
|
|
373 |
|
|
|
374 |
|
|
|
375 |
|
|
|
376 |
|
|
BASE_DIR/prebuilt/linux/tests/kernel/&Version;/tests/thread_gdb.exe
|
377 |
|
|
|
378 |
|
|
Pre-built tests for the supported platforms, and
|
379 |
|
|
the synthetic Linux target.
|
380 |
|
|
|
381 |
|
|
|
382 |
|
|
|
383 |
|
|
BASE_DIR/examples/twothreads.c
|
384 |
|
|
|
385 |
|
|
One of the example programs.
|
386 |
|
|
|
387 |
|
|
|
388 |
|
|
|
389 |
|
|
BASE_DIR/ecosadmin.tcl
|
390 |
|
|
|
391 |
|
|
The Tcl program which is used to import new versions of packages
|
392 |
|
|
from a distribution or remove existing packages.
|
393 |
|
|
|
394 |
|
|
|
395 |
|
|
|
396 |
|
|
BASE_DIR/packages/language/c/libm/&Version;/src/double/portable-api/s_tanh.c
|
397 |
|
|
|
398 |
|
|
Implementation of the hyperbolic tangent function in the standard
|
399 |
|
|
math library.
|
400 |
|
|
|
401 |
|
|
|
402 |
|
|
|
403 |
|
|
BASE_DIR/pkgconf/rules.mak
|
404 |
|
|
|
405 |
|
|
A file with make rules, used
|
406 |
|
|
by the makefile.
|
407 |
|
|
|
408 |
|
|
|
409 |
|
|
|
410 |
|
|
|
411 |
|
|
|
412 |
|
|
|
413 |
|
|
Build Tree
|
414 |
|
|
The build tree is the directory
|
415 |
|
|
hierarchy in which all generated files
|
416 |
|
|
are placed. Generated files consist of the
|
417 |
|
|
makefile, the compiled object files,
|
418 |
|
|
and a dependency file (with a .d
|
419 |
|
|
extension) for each source file.
|
420 |
|
|
|
421 |
|
|
Purpose
|
422 |
|
|
The build tree is where all intermediate object files are
|
423 |
|
|
placed.
|
424 |
|
|
|
425 |
|
|
|
426 |
|
|
How is it modified?
|
427 |
|
|
Recompiling can modify the object files.
|
428 |
|
|
|
429 |
|
|
|
430 |
|
|
User applications
|
431 |
|
|
User application source or binary code should
|
432 |
|
|
not go in the build tree.
|
433 |
|
|
|
434 |
|
|
|
435 |
|
|
Examples of files in this hierarchy
|
436 |
|
|
|
437 |
|
|
|
438 |
|
|
ecos-work/language/c/libc/&Version;/src
|
439 |
|
|
|
440 |
|
|
The directory in which object files for
|
441 |
|
|
the C library are built.
|
442 |
|
|
|
443 |
|
|
|
444 |
|
|
|
445 |
|
|
|
446 |
|
|
|
447 |
|
|
|
448 |
|
|
Install Tree
|
449 |
|
|
The install tree is the location
|
450 |
|
|
for all files needed for application development. The
|
451 |
|
|
libtarget.a library, which contains the
|
452 |
|
|
custom-built eCos kernel and other components, is placed
|
453 |
|
|
in the install tree, along with all packages’ public
|
454 |
|
|
header files. If you build the tests, the test executable
|
455 |
|
|
programs will also be placed in the install
|
456 |
|
|
tree.
|
457 |
|
|
By default, the install tree is created by
|
458 |
|
|
ecosconfig in a subdirectory of the build
|
459 |
|
|
tree called install. This can be
|
460 |
|
|
modified with the option (see
|
461 |
|
|
).
|
462 |
|
|
|
463 |
|
|
|
464 |
|
|
Purpose
|
465 |
|
|
The install tree is where the custom-built
|
466 |
|
|
libtarget.a library, which contains
|
467 |
|
|
the eCos kernel and other components, is located. The
|
468 |
|
|
install tree is also the location for all the header files
|
469 |
|
|
that are part of a published interface for their
|
470 |
|
|
component.
|
471 |
|
|
|
472 |
|
|
|
473 |
|
|
How is it modified?
|
474 |
|
|
Recompiling can replace
|
475 |
|
|
libtarget.a and the test
|
476 |
|
|
executables.
|
477 |
|
|
|
478 |
|
|
|
479 |
|
|
When is it edited manually?
|
480 |
|
|
Where a memory layout requires modification without
|
481 |
|
|
use of the eCos Configuration Tool, the memory layout
|
482 |
|
|
files must be edited directly in the install tree. These
|
483 |
|
|
files are located at
|
484 |
|
|
install/include/pkgconf/mlt_*.*.
|
485 |
|
|
Note that subsequent modification of the install tree
|
486 |
|
|
using the Configuration Tool will result in such manual
|
487 |
|
|
edits being lost.
|
488 |
|
|
|
489 |
|
|
|
490 |
|
|
User applications
|
491 |
|
|
User application source or binary code should
|
492 |
|
|
not go in the install tree.
|
493 |
|
|
|
494 |
|
|
|
495 |
|
|
Examples of files in this hierarchy
|
496 |
|
|
|
497 |
|
|
|
498 |
|
|
install/lib/libtarget.a
|
499 |
|
|
|
500 |
|
|
The library containing the kernel and other components.
|
501 |
|
|
|
502 |
|
|
|
503 |
|
|
|
504 |
|
|
install/include/cyg/kernel/kapi.h
|
505 |
|
|
|
506 |
|
|
The header file for the kernel C language API.
|
507 |
|
|
|
508 |
|
|
|
509 |
|
|
|
510 |
|
|
install/include/pkgconf/mlt_arm_pid_ram.ldi
|
511 |
|
|
|
512 |
|
|
The linker script fragment describing the memory
|
513 |
|
|
layout for linking applications intended for
|
514 |
|
|
execution on an ARM PID development board using RAM
|
515 |
|
|
startup.
|
516 |
|
|
|
517 |
|
|
|
518 |
|
|
|
519 |
|
|
install/include/stdio.h
|
520 |
|
|
|
521 |
|
|
The C library header file for standard I/O.
|
522 |
|
|
|
523 |
|
|
|
524 |
|
|
|
525 |
|
|
|
526 |
|
|
|
527 |
|
|
|
528 |
|
|
Application Build Tree
|
529 |
|
|
This tree is not part of eCos itself: it is the
|
530 |
|
|
directory in which eCos end users write their own
|
531 |
|
|
applications.
|
532 |
|
|
Example applications and their
|
533 |
|
|
Makefile are located in the component
|
534 |
|
|
repository, in the directory
|
535 |
|
|
BASE_DIR/examples.
|
536 |
|
|
|
537 |
|
|
|
538 |
|
|
There is no imposed format on this directory, but there
|
539 |
|
|
are certain compiler and linker flags that must be used to
|
540 |
|
|
compile an eCos application. The basic set of flags is shown
|
541 |
|
|
in the example Makefile, and additional
|
542 |
|
|
details can be found in .
|
543 |
|
|
|
544 |
|
|
|
545 |
|
|
|
546 |
|
|
Compiler and Linker Options
|
547 |
|
|
|
548 |
|
|
eCos is built using
|
549 |
|
|
the GNU C and C++ compilers. eCos relies on certain features of these
|
550 |
|
|
tools such as constructor priority ordering and selective linking
|
551 |
|
|
which are not part of other toolchains.
|
552 |
|
|
|
553 |
|
|
|
554 |
|
|
Some GCC options are required for eCos,
|
555 |
|
|
and others can be useful. This chapter gives a brief description
|
556 |
|
|
of the required options as well as some recommended eCos-specific options.
|
557 |
|
|
All other GCC options (described in the GCC manuals)
|
558 |
|
|
are available.
|
559 |
|
|
|
560 |
|
|
Compiling a C Application
|
561 |
|
|
The following command lines demonstrate the
|
562 |
|
|
minimum set of options required to
|
563 |
|
|
compile and link an eCos program written in C.
|
564 |
|
|
|
565 |
|
|
Remember that when this manual shows
|
566 |
|
|
TARGET-gcc
|
567 |
|
|
you should use the full name of the cross compiler,
|
568 |
|
|
e.g. i386-elf-gcc,
|
569 |
|
|
arm-elf-gcc, or
|
570 |
|
|
sh-elf-gcc. When compiling for the
|
571 |
|
|
synthetic Linux target, use the native
|
572 |
|
|
gcc which must have the features
|
573 |
|
|
required by eCos.
|
574 |
|
|
|
575 |
|
|
|
576 |
|
|
$ TARGET-gcc -c -IINSTALL_DIR/include file.c
|
577 |
|
|
$ TARGET-gcc -o program file.o -LINSTALL_DIR/lib -Ttarget.ld -nostdlib
|
578 |
|
|
|
579 |
|
|
|
580 |
|
|
Certain targets may require extra options, for example
|
581 |
|
|
the SPARClite architectures require the option
|
582 |
|
|
. Examine the
|
583 |
|
|
BASE_DIR/examples/Makefile
|
584 |
|
|
or the “Global compiler flags” option
|
585 |
|
|
(CYGBLD_GLOBAL_CFLAGS) in your generated
|
586 |
|
|
eCos configuration) to see if any extra options are
|
587 |
|
|
required, and if so, what they are.
|
588 |
|
|
The following command lines use some other options
|
589 |
|
|
which are recommended because they use the
|
590 |
|
|
selective linking feature:
|
591 |
|
|
$ TARGET-gcc -c -IINSTALL_DIR/include -I. -ffunction-sections -fdata-sections -g -O2 file.c
|
592 |
|
|
$ TARGET-gcc -o program file.o -ffunction-sections -fdata-sections -Wl,--gc-sections -g -O2 \
|
593 |
|
|
-LINSTALL_DIR/lib -Ttarget.ld -nostdlib
|
594 |
|
|
|
595 |
|
|
|
596 |
|
|
|
597 |
|
|
|
598 |
|
|
|
599 |
|
|
Compiling a C++ Application
|
600 |
|
|
The following command lines demonstrate the
|
601 |
|
|
minimum set of options required to
|
602 |
|
|
compile and link an eCos program written in C++.
|
603 |
|
|
|
604 |
|
|
|
605 |
|
|
Remember that when this manual shows
|
606 |
|
|
TARGET-g++
|
607 |
|
|
you should use the full name of the cross compiler,
|
608 |
|
|
e.g. i386-elf-g++,
|
609 |
|
|
arm-elf-g++, or
|
610 |
|
|
sh-elf-g++. When compiling for the
|
611 |
|
|
synthetic Linux target, use the native
|
612 |
|
|
g++ which must have the features
|
613 |
|
|
required by eCos.
|
614 |
|
|
|
615 |
|
|
$ TARGET-g++ -c -IINSTALL_DIR/include -fno-rtti -fno-exceptions file.cxx
|
616 |
|
|
$ TARGET-g++ -o program file.o -LINSTALL_DIR/lib -Ttarget.ld -nostdlib
|
617 |
|
|
|
618 |
|
|
|
619 |
|
|
|
620 |
|
|
Certain targets may require extra options,
|
621 |
|
|
for example the SPARClite architectures require the option
|
622 |
|
|
. Examine the
|
623 |
|
|
BASE_DIR/packages/targets
|
624 |
|
|
file or BASE_DIR/examples/Makefile
|
625 |
|
|
or the “Global compiler flags” option
|
626 |
|
|
(CYGBLD_GLOBAL_CFLAGS) in your generated
|
627 |
|
|
eCos configuration) to see if any extra options are
|
628 |
|
|
required, and if so, what they are.
|
629 |
|
|
The following command lines use some other options
|
630 |
|
|
which are recommended because they use the
|
631 |
|
|
selective linking feature:
|
632 |
|
|
|
633 |
|
|
$ TARGET-g++ -c -IINSTALL_DIR/include -I. -ffunction-sections -fdata-sections -fno-rtti \
|
634 |
|
|
-fno-exceptions -finit-priority -g -O2 file.cxx
|
635 |
|
|
$ TARGET-g++ -o program file.o -W1,--gc-sections -g -O2 -LINSTALL_DIR/lib -Ttarget.ld -nostdlib
|
636 |
|
|
|
637 |
|
|
|
638 |
|
|
|
639 |
|
|
|
640 |
|
|
|
641 |
|
|
Debugging Techniques
|
642 |
|
|
eCos applications and components can be debugged in
|
643 |
|
|
traditional ways, with printing statements and debugger
|
644 |
|
|
single-stepping, but there are situations in which these
|
645 |
|
|
techniques cannot be used. One example of this is when a
|
646 |
|
|
program is getting data at a high rate from a real-time
|
647 |
|
|
source, and cannot be slowed down or interrupted.
|
648 |
|
|
eCos’s infrastructure module provides a
|
649 |
|
|
tracing formalism, allowing the
|
650 |
|
|
kernel’s tracing macros to be configured in many useful
|
651 |
|
|
ways. eCos’s kernel provides instrumentation
|
652 |
|
|
buffers which also collect specific
|
653 |
|
|
(configurable) data about the system’s history and
|
654 |
|
|
performance.
|
655 |
|
|
|
656 |
|
|
Tracing
|
657 |
|
|
To use eCos’s tracing facilities you must first
|
658 |
|
|
configure your system to use tracing.
|
659 |
|
|
You should enable the Asserts and Tracing component
|
660 |
|
|
() and the
|
661 |
|
|
component within it
|
662 |
|
|
(). These
|
663 |
|
|
options can be enabled with the Configuration
|
664 |
|
|
Tool or by editing the file
|
665 |
|
|
BUILD_DIR/pkgconf/infra.h
|
666 |
|
|
manually.
|
667 |
|
|
You should then examine all the tracing-related options in
|
668 |
|
|
the Package: Infrastructure chapter of the eCos Reference
|
669 |
|
|
Manual. One useful set of configuration options are: CYGDBG_INFRA_DEBUG_FUNCTION_REPORTS and CYGDBG_INFRA_DEBUG_TRACE_MESSAGE,
|
670 |
|
|
which are both enabled by default when tracing is enabled.
|
671 |
|
|
The following “Hello world with tracing” shows
|
672 |
|
|
the output from running the hello world program (from ) that was
|
673 |
|
|
built with tracing enabled:
|
674 |
|
|
|
675 |
|
|
Hello world with tracing
|
676 |
|
|
$ mips-tx39-elf-run --board=jmr3904 hello
|
677 |
|
|
Hello, eCos world!
|
678 |
|
|
ASSERT FAIL: <2>cyg_trac.h [ 623] Cyg_TraceFunction_Report_::set_exitvoid() exitvoid used in typed function
|
679 |
|
|
TRACE: <1>mlqueue.cxx [ 395] Cyg_ThreadQueue_Implementation::enqueue() {{enter
|
680 |
|
|
TRACE: <1>mlqueue.cxx [ 395] Cyg_ThreadQueue_Implementation::enqueue() }}RETURNING UNSET!
|
681 |
|
|
TRACE: <1>mlqueue.cxx [ 126] Cyg_Scheduler_Implementation::add_thread() }}RETURNING UNSET!
|
682 |
|
|
TRACE: <1>thread.cxx [ 654] Cyg_Thread::resume() }}return void
|
683 |
|
|
TRACE: <1>cstartup.cxx [ 160] cyg_iso_c_start() }}return void
|
684 |
|
|
TRACE: <1>startup.cxx [ 142] cyg_package_start() }}return void
|
685 |
|
|
TRACE: <1>startup.cxx [ 150] cyg_user_start() {{enter
|
686 |
|
|
TRACE: <1>startup.cxx [ 150] cyg_user_start() (((void)))
|
687 |
|
|
TRACE: <1>startup.cxx [ 153] cyg_user_start() 'This is the system default cyg_user_start()'
|
688 |
|
|
TRACE: <1>startup.cxx [ 157] cyg_user_start() }}return void
|
689 |
|
|
TRACE: <1>sched.cxx [ 212] Cyg_Scheduler::start() {{enter
|
690 |
|
|
TRACE: <1>mlqueue.cxx [ 102] Cyg_Scheduler_Implementation::schedule() {{enter
|
691 |
|
|
TRACE: <1>mlqueue.cxx [ 437] Cyg_ThreadQueue_Implementation::highpri() {{enter
|
692 |
|
|
TRACE: <1>mlqueue.cxx [ 437] Cyg_ThreadQueue_Implementation::highpri() }}RETURNING UNSET!
|
693 |
|
|
TRACE: <1>mlqueue.cxx [ 102] Cyg_Scheduler_Implementation::schedule() }}RETURNING UNSET!
|
694 |
|
|
TRACE: <2>intr.cxx [ 450] Cyg_Interrupt::enable_interrupts() {{enter
|
695 |
|
|
TRACE: <2>intr.cxx [ 450] Cyg_Interrupt::enable_interrupts() }}RETURNING UNSET!
|
696 |
|
|
TRACE: <2>thread.cxx [ 69] Cyg_HardwareThread::thread_entry() {{enter
|
697 |
|
|
TRACE: <2>cstartup.cxx [ 127] invoke_main() {{enter
|
698 |
|
|
TRACE: <2>cstartup.cxx [ 127] invoke_main() ((argument is ignored))
|
699 |
|
|
TRACE: <2>dummyxxmain.cxx [ 60] __main() {{enter
|
700 |
|
|
TRACE: <2>dummyxxmain.cxx [ 60] __main() (((void)))
|
701 |
|
|
TRACE: <2>dummyxxmain.cxx [ 63] __main() 'This is the system default __main()'
|
702 |
|
|
TRACE: <2>dummyxxmain.cxx [ 67] __main() }}return void
|
703 |
|
|
TRACE: <2>memcpy.c [ 112] _memcpy() {{enter
|
704 |
|
|
TRACE: <2>memcpy.c [ 112] _memcpy() ((dst=80002804, src=BFC14E58, n=19))
|
705 |
|
|
TRACE: <2>memcpy.c [ 164] _memcpy() }}returning 80002804
|
706 |
|
|
TRACE: <2>cstartup.cxx [ 137] invoke_main() 'main() has returned with code 0. Calling exit()'
|
707 |
|
|
TRACE: <2>exit.cxx [ 71] __libc_exit() {{enter
|
708 |
|
|
TRACE: <2>exit.cxx [ 71] __libc_exit() ((status=0 ))
|
709 |
|
|
TRACE: <2>atexit.cxx [ 84] cyg_libc_invoke_atexit_handlers() {{enter
|
710 |
|
|
TRACE: <2>atexit.cxx [ 84] cyg_libc_invoke_atexit_handlers() (((void)))
|
711 |
|
|
|
712 |
|
|
Scheduler:
|
713 |
|
|
|
714 |
|
|
Lock: 0
|
715 |
|
|
Current Thread: <null>
|
716 |
|
|
|
717 |
|
|
Threads:
|
718 |
|
|
|
719 |
|
|
Idle Thread pri = 31 state = R id = 1
|
720 |
|
|
stack base = 800021F0 ptr = 80002510 size = 00000400
|
721 |
|
|
sleep reason NONE wake reason NONE
|
722 |
|
|
queue = 80000C54 wait info = 00000000
|
723 |
|
|
|
724 |
|
|
<null> pri = 0 state = R id = 2
|
725 |
|
|
stack base = 80002A48 ptr = 8000A968 size = 00008000
|
726 |
|
|
sleep reason NONE wake reason NONE
|
727 |
|
|
queue = 80000BD8 wait info = 00000000
|
728 |
|
|
|
729 |
|
|
|
730 |
|
|
|
731 |
|
|
|
732 |
|
|
Kernel Instrumentation
|
733 |
|
|
Instrument buffers can be used to
|
734 |
|
|
find out how many events of a given type happened in the
|
735 |
|
|
kernel during execution of a program.
|
736 |
|
|
You can monitor a class of several types of events, or
|
737 |
|
|
you can just look at individual events.
|
738 |
|
|
Examples of events that can be
|
739 |
|
|
monitored are:
|
740 |
|
|
|
741 |
|
|
|
742 |
|
|
|
743 |
|
|
scheduler events
|
744 |
|
|
|
745 |
|
|
|
746 |
|
|
thread operations
|
747 |
|
|
|
748 |
|
|
|
749 |
|
|
interrupts
|
750 |
|
|
|
751 |
|
|
|
752 |
|
|
mutex operations
|
753 |
|
|
|
754 |
|
|
|
755 |
|
|
binary semaphore operations
|
756 |
|
|
|
757 |
|
|
|
758 |
|
|
counting semaphore operations
|
759 |
|
|
|
760 |
|
|
|
761 |
|
|
condition variable operations
|
762 |
|
|
|
763 |
|
|
|
764 |
|
|
event flag operations
|
765 |
|
|
|
766 |
|
|
|
767 |
|
|
message box operations
|
768 |
|
|
|
769 |
|
|
|
770 |
|
|
clock ticks, interrupts and alarms
|
771 |
|
|
|
772 |
|
|
|
773 |
|
|
Examples of fine-grained scheduler event types are:
|
774 |
|
|
|
775 |
|
|
|
776 |
|
|
scheduler lock
|
777 |
|
|
|
778 |
|
|
|
779 |
|
|
scheduler unlock
|
780 |
|
|
|
781 |
|
|
|
782 |
|
|
rescheduling
|
783 |
|
|
|
784 |
|
|
|
785 |
|
|
time slicing
|
786 |
|
|
|
787 |
|
|
|
788 |
|
|
Information about the events is stored in an
|
789 |
|
|
event record. The structure that
|
790 |
|
|
defines this record has type struct
|
791 |
|
|
Instrument_Record:
|
792 |
|
|
|
793 |
|
|
The list of records is stored in an array called instrument_buffer
|
794 |
|
|
which you can let the kernel provide or you can provide yourself
|
795 |
|
|
by setting the configuration option CYGVAR_KERNEL_INSTRUMENT_EXTERNAL_BUFFER.
|
796 |
|
|
To write a program that examines the instrumentation
|
797 |
|
|
buffers:
|
798 |
|
|
|
799 |
|
|
|
800 |
|
|
Enable instrumentation buffers in the eCos kernel configuration.
|
801 |
|
|
The component macro is CYGPKG_KERNEL_INSTRUMENT.
|
802 |
|
|
|
803 |
|
|
|
804 |
|
|
To allocate the buffers yourself, enable the configuration
|
805 |
|
|
option CYGVAR_KERNEL_INSTRUMENT_EXTERNAL_BUFFER.
|
806 |
|
|
|
807 |
|
|
|
808 |
|
|
Include the header file
|
809 |
|
|
cyg/kernel/instrmnt.h
|
810 |
|
|
.
|
811 |
|
|
#include <cyg/kernel/instrmnt.h>
|
812 |
|
|
|
813 |
|
|
|
814 |
|
|
The Instrumentation_Record structure
|
815 |
|
|
is not published in the kernel header file. In the future there
|
816 |
|
|
will be a cleaner mechanism to access it, but for now you should
|
817 |
|
|
paste into your code in the following lines:
|
818 |
|
|
|
819 |
|
|
struct Instrument_Record
|
820 |
|
|
{
|
821 |
|
|
CYG_WORD16 type; // record type
|
822 |
|
|
CYG_WORD16 thread; // current thread id
|
823 |
|
|
CYG_WORD timestamp; // 32 bit timestamp
|
824 |
|
|
CYG_WORD arg1; // first arg
|
825 |
|
|
CYG_WORD arg2; // second arg
|
826 |
|
|
};
|
827 |
|
|
|
828 |
|
|
|
829 |
|
|
Enable the events you want to record using
|
830 |
|
|
cyg_instrument_enable()
|
831 |
|
|
, and disable them later. Look at
|
832 |
|
|
cyg/kernel/instrmnt.h
|
833 |
|
|
and the examples below to see what events can be enabled.
|
834 |
|
|
|
835 |
|
|
|
836 |
|
|
Place the code you want to debug between the matching
|
837 |
|
|
functions
|
838 |
|
|
cyg_instrument_enable()
|
839 |
|
|
and
|
840 |
|
|
cyg_instrument_disable()
|
841 |
|
|
.
|
842 |
|
|
|
843 |
|
|
|
844 |
|
|
Examine the buffer. For now you need to look at the data
|
845 |
|
|
in there (the example program below shows how to do that), and future
|
846 |
|
|
versions of eCos will include a host-side tool to help you understand
|
847 |
|
|
the data.
|
848 |
|
|
|
849 |
|
|
|
850 |
|
|
|
851 |
|
|
Using instrument buffers
|
852 |
|
|
This program is also provided in the
|
853 |
|
|
examples directory.
|
854 |
|
|
|
855 |
|
|
|
856 |
|
|
/* this is a program which uses eCos instrumentation buffers; it needs
|
857 |
|
|
to be linked with a kernel which was compiled with support for
|
858 |
|
|
instrumentation */
|
859 |
|
|
|
860 |
|
|
#include <stdio.h>
|
861 |
|
|
#include <pkgconf/kernel.h>
|
862 |
|
|
#include <cyg/kernel/instrmnt.h>
|
863 |
|
|
#include <cyg/kernel/kapi.h>
|
864 |
|
|
|
865 |
|
|
#ifndef CYGVAR_KERNEL_INSTRUMENT_EXTERNAL_BUFFER
|
866 |
|
|
# error You must configure eCos with CYGVAR_KERNEL_INSTRUMENT_EXTERNAL_BUFFER
|
867 |
|
|
#endif
|
868 |
|
|
|
869 |
|
|
struct Instrument_Record
|
870 |
|
|
{
|
871 |
|
|
CYG_WORD16 type; // record type
|
872 |
|
|
CYG_WORD16 thread; // current thread id
|
873 |
|
|
CYG_WORD timestamp; // 32 bit timestamp
|
874 |
|
|
CYG_WORD arg1; // first arg
|
875 |
|
|
CYG_WORD arg2; // second arg
|
876 |
|
|
};
|
877 |
|
|
|
878 |
|
|
struct Instrument_Record instrument_buffer[20];
|
879 |
|
|
cyg_uint32 instrument_buffer_size = 20;
|
880 |
|
|
|
881 |
|
|
int main(void)
|
882 |
|
|
{
|
883 |
|
|
int i;
|
884 |
|
|
|
885 |
|
|
cyg_instrument_enable(CYG_INSTRUMENT_CLASS_CLOCK, 0);
|
886 |
|
|
cyg_instrument_enable(CYG_INSTRUMENT_CLASS_THREAD, 0);
|
887 |
|
|
cyg_instrument_enable(CYG_INSTRUMENT_CLASS_ALARM, 0);
|
888 |
|
|
|
889 |
|
|
printf("Program to play with instrumentation buffer\n");
|
890 |
|
|
|
891 |
|
|
cyg_thread_delay(2);
|
892 |
|
|
|
893 |
|
|
cyg_instrument_disable(CYG_INSTRUMENT_CLASS_CLOCK, 0);
|
894 |
|
|
cyg_instrument_disable(CYG_INSTRUMENT_CLASS_THREAD, 0);
|
895 |
|
|
cyg_instrument_disable(CYG_INSTRUMENT_CLASS_ALARM, 0);
|
896 |
|
|
|
897 |
|
|
for (i = 0; i < instrument_buffer_size; ++i) {
|
898 |
|
|
printf("Record %02d: type 0x%04x, thread %d, ",
|
899 |
|
|
i, instrument_buffer[i].type, instrument_buffer[i].thread);
|
900 |
|
|
printf("time %5d, arg1 0x%08x, arg2 0x%08x\n",
|
901 |
|
|
instrument_buffer[i].timestamp, instrument_buffer[i].arg1,
|
902 |
|
|
instrument_buffer[i].arg2);
|
903 |
|
|
}
|
904 |
|
|
return 0;
|
905 |
|
|
}
|
906 |
|
|
|
907 |
|
|
Here is how you could compile and run this program in the examples directory,
|
908 |
|
|
using (for example) the MN10300 simulator target:
|
909 |
|
|
|
910 |
|
|
$ make XCC=mn10300-elf-gcc INSTALL_DIR=/tmp/ecos-work-mn10300/install instrument-test
|
911 |
|
|
mn10300-elf-gcc -c -o instrument-test.o -g -Wall -I/tmp/ecos-work-mn10300/install/include \
|
912 |
|
|
-ffunction-sections -fdata-sections instrument-test.c
|
913 |
|
|
mn10300-elf-gcc -nostartfiles -L/tmp/ecos-work-mn10300/install/lib -W1,--gc-sections -o \
|
914 |
|
|
instrument-test instrument-test.o -Ttarget.ld -nostdlib
|
915 |
|
|
$ mn10300-elf-run --board=stdeval1 instrument-test
|
916 |
|
|
|
917 |
|
|
|
918 |
|
|
Instrument buffer output
|
919 |
|
|
Here is the output of the
|
920 |
|
|
instrument-test program. Notice that in
|
921 |
|
|
little over 2 seconds, and with very little activity, and
|
922 |
|
|
with few event types enabled, it gathered 17 records. In
|
923 |
|
|
larger programs it will be necessary to select very few
|
924 |
|
|
event types for debugging.
|
925 |
|
|
Program to play with instrumentation buffer
|
926 |
|
|
Record 00: type 0x0207, thread 2, time 6057, arg1 0x48001cd8, arg2 0x00000002
|
927 |
|
|
Record 01: type 0x0202, thread 2, time 6153, arg1 0x48001cd8, arg2 0x00000000
|
928 |
|
|
Record 02: type 0x0904, thread 2, time 6358, arg1 0x48001d24, arg2 0x00000000
|
929 |
|
|
Record 03: type 0x0905, thread 2, time 6424, arg1 0x00000002, arg2 0x00000000
|
930 |
|
|
Record 04: type 0x0906, thread 2, time 6490, arg1 0x00000000, arg2 0x00000000
|
931 |
|
|
Record 05: type 0x0901, thread 2, time 6608, arg1 0x48009d74, arg2 0x48001d24
|
932 |
|
|
Record 06: type 0x0201, thread 2, time 6804, arg1 0x48001cd8, arg2 0x480013e0
|
933 |
|
|
Record 07: type 0x0803, thread 1, time 94, arg1 0x00000000, arg2 0x00000000
|
934 |
|
|
Record 08: type 0x0801, thread 1, time 361, arg1 0x00000000, arg2 0x00000000
|
935 |
|
|
Record 09: type 0x0802, thread 1, time 548, arg1 0x00000001, arg2 0x00000000
|
936 |
|
|
Record 10: type 0x0803, thread 1, time 94, arg1 0x00000000, arg2 0x00000000
|
937 |
|
|
Record 11: type 0x0801, thread 1, time 361, arg1 0x00000001, arg2 0x00000000
|
938 |
|
|
Record 12: type 0x0903, thread 1, time 513, arg1 0x48009d74, arg2 0x48001d24
|
939 |
|
|
Record 13: type 0x0208, thread 1, time 588, arg1 0x00000000, arg2 0x00000000
|
940 |
|
|
Record 14: type 0x0203, thread 1, time 697, arg1 0x48001cd8, arg2 0x480013e0
|
941 |
|
|
Record 15: type 0x0802, thread 1, time 946, arg1 0x00000002, arg2 0x00000000
|
942 |
|
|
Record 16: type 0x0201, thread 1, time 1083, arg1 0x480013e0, arg2 0x48001cd8
|
943 |
|
|
Record 17: type 0x0000, thread 0, time 0, arg1 0x00000000, arg2 0x00000000
|
944 |
|
|
Record 18: type 0x0000, thread 0, time 0, arg1 0x00000000, arg2 0x00000000
|
945 |
|
|
Record 19: type 0x0000, thread 0, time 0, arg1 0x00000000, arg2 0x00000000
|
946 |
|
|
|
947 |
|
|
|
948 |
|
|
|
949 |
|
|
|
950 |
|
|
|