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