OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [synth/] [arch/] [v2_0/] [doc/] [synth.sgml] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 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
34
35
36
37
38
 
39
40
 
41
eCos Synthetic Target
42
 
43
44
 
45
46
  
47
    Overview
48
  
49
  
50
    The eCos synthetic target
51
    Overview
52
  
53
 
54
  Description
55
    
56
Usually eCos runs on either a custom piece of hardware, specially
57
designed to meet the needs of a specific application, or on a
58
development board of some sort that is available before the final
59
hardware. Such boards have a number of things in common:
60
    
61
    
62
      
63
Obviously there has to be at least one processor to do the work. Often
64
this will be a 32-bit processor, but it can be smaller or larger.
65
Processor speed will vary widely, depending on the expected needs of
66
the application. However the exact processor being used tends not to
67
matter very much for most of the development process: the use of
68
languages such as C or C++ means that the compiler will handle those
69
details.
70
      
71
      
72
There needs to be memory for code and for data. A typical system will
73
have two different types of memory. There will be some non-volatile
74
memory such as flash, EPROM or masked ROM. There will also be some
75
volatile memory such as DRAM or SRAM. Often the code for the final
76
application will reside in the non-volatile memory and all of the RAM
77
will be available for data. However updating non-volatile memory
78
requires a non-trivial amount of effort, so for much of the
79
development process it is more convenient to burn suitable firmware,
80
for example RedBoot, into the non-volatile memory and then use that to
81
load the application being debugged into RAM, alongside the
82
application data and a small area reserved for use by the firmware.
83
      
84
      
85
The platform must provide certain mimimal I/O facilities. Most eCos
86
configurations require a clock signal of some sort. There must also be
87
some way of outputting diagnostics to the user, often but not always
88
via a serial port. Unless special debug hardware is being used, source
89
level debugging will require bidirectional communication between a
90
host machine and the target hardware, usually via a serial port or an
91
ethernet device.
92
      
93
      
94
All the above is not actually very useful yet because there is no way
95
for the embedded device to interact with the rest of the world, except
96
by generating diagnostics. Therefore an embedded device will have
97
additional I/O hardware. This may be fairly standard hardware such as
98
an ethernet or USB interface, or special hardware designed
99
specifically for the intended application, or quite often some
100
combination. Standard hardware such as ethernet or USB may be
101
supported by eCos device drivers and protocol stacks, whereas the
102
special hardware will be driven directly by application code.
103
      
104
    
105
    
106
Much of the above can be emulated on a typical PC running Linux.
107
Instead of running the embedded application being developed on a
108
target board of some sort, it can be run as a Linux process. The
109
processor will be the PC's own processor, for example an x86, and the
110
memory will be the process' address space. Some I/O facilities can be
111
emulated directly through system calls. For example clock hardware can
112
be emulated by setting up a SIGALRM signal, which
113
will cause the process to be interrupted at regular intervals. This
114
emulation of real hardware will not be particularly accurate, the
115
number of cpu cycles available to the eCos application between clock
116
ticks will vary widely depending on what else is running on the PC,
117
but for much development work it will be good enough.
118
    
119
    
120
Other I/O facilities are provided through an I/O auxiliary process,
121
ecosynth, that gets spawned by the eCos application during startup.
122
When an eCos device driver wants to perform some I/O operation, for
123
example send out an ethernet packet, it sends a request to the I/O
124
auxiliary. That is an ordinary Linux application so it has ready
125
access to all normal Linux I/O facilities. To emulate a device
126
interrupt the I/O auxiliary can raise a SIGIO
127
signal within the eCos application. The HAL's interrupt subsystem
128
installs a signal handler for this, which will then invoke the
129
standard eCos ISR/DSR mechanisms. The I/O auxiliary is based around
130
Tcl scripting, making it easy to extend and customize. It should be
131
possible to configure the synthetic target so that its I/O
132
functionality is similar to what will be available on the final target
133
hardware for the application being developed.
134
    
135
    
136
      
137
        
138
          
139
        
140
      
141
    
142
    
143
A key requirement for synthetic target code is that the embedded
144
application must not be linked with any of the standard Linux
145
libraries such as the GNU C library: that would lead to a confusing
146
situation where both eCos and the Linux libraries attempted to provide
147
functions such as printf. Instead the synthetic
148
target support must be implemented directly on top of the Linux
149
kernels' system call interface. For example, the kernel provides a
150
system call for write operations. The actual function
151
write is implemented in the system's C library,
152
but all it does is move its arguments on to the stack or into certain
153
registers and then execute a special trap instruction such as
154
int 0x80. When this instruction is executed
155
control transfers into the kernel, which will validate the arguments
156
and perform the appropriate operation. Now, a synthetic target
157
application cannot be linked with the system's C library. Instead it
158
contains a function cyg_hal_sys_write which, like
159
the C library's write function, pushes its
160
arguments on to the stack and executes the trap instruction. The Linux
161
kernel cannot tell the difference, so it will perform the I/O
162
operation requested by the synthetic target. With appropriate
163
knowledge of what system calls are available, this makes it possible
164
to emulate the required I/O facilities. For example, spawning the
165
ecosynth I/O auxiliary involves system calls
166
cyg_hal_sys_fork and
167
cyg_hal_sys_execve, and sending a request to the
168
auxiliary uses cyg_hal_sys_write.
169
    
170
    
171
In many ways developing for the synthetic target is no different from
172
developing for real embedded targets. eCos must be configured
173
appropriately: selecting a suitable target such as
174
i386linux will cause the configuration system
175
to load the appropriate packages for this hardware; this includes an
176
architectural HAL package and a platform-specific package; the
177
architectural package contains generic code applicable to all Linux
178
platforms, whereas the platform package is for specific Linux
179
implementations such as the x86 version and contains any
180
processor-specific code. Selecting this target will also bring in some
181
device driver packages. Other aspects of the configuration such as
182
which API's are supported are determined by the template, by adding
183
and removing packages, and by fine-grained configuration.
184
    
185
    
186
In other ways developing for the synthetic target can be much easier
187
than developing for a real embedded target. For example there is no
188
need to worry about building and installing suitable firmware on the
189
target hardware, and then downloading and debugging the actual
190
application over a serial line or a similar connection. Instead an
191
eCos application built for the synthetic target is mostly
192
indistinguishable from an ordinary Linux program. It can be run simply
193
by typing the name of the executable file at a shell prompt.
194
Alternatively you can debug the application using whichever version of
195
gdb is provided by your Linux distribution. There is no need to build
196
or install special toolchains. Essentially using the synthetic target
197
means that the various problems associated with real embedded hardware
198
can be bypassed for much of the development process.
199
    
200
    
201
The eCos synthetic target provides emulation, not simulation. It is
202
possible to run eCos in suitable architectural simulators but that
203
involves a rather different approach to software development. For
204
example, when running eCos on the psim PowerPC simulator you need
205
appropriate cross-compilation tools that allow you to build PowerPC
206
executables. These are then loaded into the simulator which interprets
207
every instruction and attempts to simulate what would happen if the
208
application were running on real hardware. This involves a lot of
209
processing overhead, but depending on the functionality provided by
210
the simulator it can give very accurate results. When developing for
211
the synthetic target the executable is compiled for the PC's own
212
processor and will be executed at full speed, with no need for a
213
simulator or special tools. This will be much faster and somewhat
214
simpler than using an architectural simulator, but no attempt is made
215
to accurately match the behaviour of a real embedded target.
216
    
217
  
218
219
 
220
221
222
 
223
224
  
225
    Installation
226
  
227
  
228
    Installation
229
    Preparing to use the synthetic target
230
  
231
 
232
  Host-side Software
233
    
234
To get the full functionality of the synthetic target, users must
235
build and install the I/O auxiliary ecosynth and various support
236
files. It is possible to develop applications for the synthetic target
237
without the auxiliary, but only limited I/O facilities will be
238
available. The relevant code resides in the 
239
class="directory">host subdirectory of the synthetic target
240
architectural HAL package, and building it involves the standard
241
configure, make, and
242
make install steps.
243
    
244
    
245
There are two main ways of building the host-side software. It is
246
possible to build both the generic host-side software and all
247
package-specific host-side software, including the I/O auxiliary. in a
248
single build tree. This involves using the
249
configure script at the toplevel of the eCos
250
repository, which will automatically search the 
251
class="directory">packages hierarchy for host-side
252
software. For more information on this, see the
253
README.host file at the top of the repository.
254
Note that if you have an existing build tree which does not include
255
the synthetic target architectural HAL package then it will be
256
necessary to rerun the toplevel configure script: the search for
257
appropriate packages happens at configure time.
258
    
259
    
260
The alternative is to build just the host-side for this package.
261
This involves creating a suitable build directory and running the
262
configure script. Note that building directly in
263
the source tree is not allowed.
264
    
265
    
266
$ cd <somewhere suitable>
267
$ mkdir synth_build
268
$ cd synth_build
269
$ <repo<>/packages/hal/synth/arch/<version>/host/configure <options>
270
$ make
271
$ make install
272
273
    
274
The code makes extensive use of Tcl/TK and requires version 8.3 or
275
later. This is checked by the configure script. By
276
default it will use the system's Tcl installation in 
277
class="directory">/usr. If a different, more recent Tcl
278
installation should be used then its location can be specified using
279
the options ,
280
 and
281
. For more information on these options
282
see the README.host file at the toplevel of the
283
eCos repository.
284
    
285
    
286
Some users may also want to specify the install location using a
287
 option. The default install
288
location is /usr/local. It is
289
essential that the bin
290
subdirectory of the install location is on the user's search
291
PATH, otherwise the eCos application will be unable to
292
locate and execute the I/O auxiliary ecosynth.
293
    
294
    
295
Because ecosynth is run automatically by an eCos application rather
296
than explicitly by the user, it is not installed in the 
297
class="directory">bin subdirectory itself. Instead it is
298
installed below libexec,
299
together with various support files such as images. At configure time
300
it is usually possible to specify an alternative location for
301
libexec using
302
 or
303
. These options should not
304
be used for this package because the eCos application is built
305
completely separately and does not know how the host-side was
306
configured.
307
    
308
  
309
 
310
  Toolchain
311
    
312
When developing eCos applications for a normal embedded target it is
313
necessary to use a suitable cross-compiler and related tools such as
314
the linker. Developing for the synthetic target is easier because you
315
can just use the standard GNU tools (gcc, g++, ld, …) which
316
were provided with your Linux distribution, or which you used to build
317
your own Linux setup. Any reasonably recent version of the tools, for
318
example gcc 2.96(Red Hat) as shipped with Red Hat Linux 7, should be
319
sufficient.
320
    
321
    
322
There is one important limitation when using these tools: current gdb
323
will not support debugging of eCos threads on the synthetic target. As
324
far as gdb is concerned a synthetic target application is
325
indistinguishable from a normal Linux application, so it assumes that
326
any threads will be created by calls to the Linux
327
pthread_create function provided by the C
328
library. Obviously this is not the case since the application is never
329
linked with that library. Therefore gdb never notices the eCos thread
330
mechanisms and assumes the application is single-threaded. Fixing this
331
is possible but would involve non-trivial changes to gdb.
332
    
333
    
334
Theoretically it is possible to develop synthetic target applications
335
on, for example, a PC running Windows and then run the resulting
336
executables on another machine that runs Linux. This is rarely useful:
337
if a Linux machine is available then usually that machine will also be
338
used for building ecos and the application. However, if for some
339
reason it is necessary or desirable to build on another machine then
340
this requires a suitable cross-compiler and related tools. If the
341
application will be running on a typical PC with an x86 processor then
342
a suitable configure triplet would be
343
i686-pc-linux-gnu. The installation
344
instructions for the various GNU tools should be consulted for further
345
information.
346
    
347
  
348
 
349
  Hardware Preparation
350
    
351
Preparing a real embedded target for eCos development can be tricky.
352
Often the first step is to install suitable firmware, usually RedBoot.
353
This means creating and building a special configuration for eCos with
354
the RedBoot template, then somehow updating the target's flash chips
355
with the resulting RedBoot image. Typically it will also be necessary
356
to get a working serial connection, and possibly set up ethernet as
357
well. Although usually none of the individual steps are particularly
358
complicated, there are plenty of ways in which things can go wrong and
359
it can be hard to figure out what is actually happening. Of course
360
some board manufacturers make life easier for their developers by
361
shipping hardware with RedBoot preinstalled, but even then it is still
362
necessary to set up communication between host and target.
363
    
364
    
365
None of this is applicable to the synthetic target. Instead you can
366
just build a normal eCos configuration, link your application with the
367
resulting libraries, and you end up with an executable that you can
368
run directly on your Linux machine or via gdb. A useful side effect of
369
this is that application development can start before any real
370
embedded hardware is actually available.
371
    
372
    
373
Typically the memory map for a synthetic target application will be
374
set up such that there is a read-only ROM region containing all the
375
code and constant data, and a read-write RAM region for the data. The
376
default locations and sizes of these regions depend on the specific
377
platform being used for development. Note that the application always
378
executes out of ROM: on a real embedded target much of the development
379
would involve running RedBoot firmware there, with application code
380
and data loaded into RAM; usually this would change for the final
381
system; the firmware would be replaced by the eCos application itself,
382
configured for ROM bootstrap, and it would perform the appropriate
383
hardware initialization. Therefore the synthetic target actually
384
emulates the behaviour of a final system, not of a development
385
environment. In practice this is rarely significant, although having
386
the code in read-only memory can help catch some problems in
387
application code.
388
    
389
  
390
 
391
392
 
393
394
395
 
396
397
  
398
    Running a Synthetic Target Application
399
  
400
  
401
    Execution
402
    Arguments and configuration files
403
  
404
 
405
  Description
406
    
407
The procedure for configuring and building eCos and an application for
408
the synthetic target is the same as for any other eCos target. Once an
409
executable has been built it can be run like any Linux program, for
410
example from a shell prompt,
411
    
412
    
413
$ ecos_hello <options>
414
415
    
416
or using gdb:
417
    
418
    
419
$ gdb --nw --quiet --args ecos_hello <options>
420
(gdb) run
421
Starting program: ecos_hello <options>
422
423
    
424
By default use of the I/O auxiliary is disabled. If its I/O facilities
425
are required then the option  must be used.
426
    
427
    
428
In future the default behaviour may change, with the I/O auxiliary
429
being started by default. The option  can be
430
used to prevent the auxiliary from being run.
431
    
432
  
433
 
434
  Command-line Arguments
435
    
436
The syntax for running a synthetic target application is:
437
    
438
    
439
$ <ecos_app> [options] [-- [app_options]]
440
441
    
442
Command line options up to the  are passed on to
443
the I/O auxiliary. Subsequent arguments are not passed on to the
444
auxiliary, and hence can be used by the eCos application itself. The
445
full set of arguments can be accessed through the variables
446
cyg_hal_sys_argc and
447
cyg_hal_sys_argv.
448
    
449
    
450
The following options are accepted as standard:
451
    
452
    
453
      
454
        
455
         
456
This option causes the eCos application to spawn the I/O auxiliary
457
during HAL initialization. Without this option only limited I/O will
458
be available.
459
         
460
      
461
      
462
        
463
         
464
This option prevents the eCos application from spawning the I/O
465
auxiliary. In the current version of the software this is the default.
466
         
467
      
468
      
469
        , 
470
         
471
The I/O auxiliary can either provide a graphical user interface, or it
472
can run in a text-only mode. The default is to provide the graphical
473
interface, but this can be disabled with .
474
Emulation of some devices, for example buttons connected to digital
475
inputs, requires the graphical interface.
476
         
477
      
478
      
479
        , 
480
         
481
The  causes the I/O auxiliary to provide a
482
graphical user interface. This is the default.
483
         
484
      
485
      
486
        , 
487
         
488
The  option can be used to determine the version of
489
the I/O auxiliary being used and where it has been installed. Both the
490
auxiliary and the eCos application will exit immediately.
491
         
492
      
493
      
494
        , 
495
         
496
 causes the I/O auxiliary to list all accepted
497
command-line arguments. This happens after all devices have been
498
initialized, since the host-side support for some of the devices may
499
extend the list of recognised options. After this both the auxiliary
500
and the eCos application will exit immediately. This option implies
501
.
502
         
503
      
504
      
505
        , 
506
         
507
If an error occurs in the I/O auxiliary while reading in any of the
508
configuration files or initializing devices, by default both the
509
auxiliary and the eCos application will exit. The 
510
option can be used to make the auxiliary continue in spite of errors,
511
although obviously it may not be fully functional.
512
         
513
      
514
      
515
        , 
516
         
517
Normally the auxiliary processes two 
518
linkend="synth-running-user-config">user configuration files
519
during startup: initrc.tcl and
520
mainrc.tcl. This can be suppressed using the
521
 option.
522
         
523
      
524
      
525
        , 
526
         
527
When providing a graphical user interface the I/O auxiliary will
528
normally continue running even after the eCos application has exited.
529
This allows the user to take actions such as saving the current
530
contents of the main text window. If run with  then
531
the auxiliary will exit as soon the application exits.
532
         
533
      
534
      
535
        , 
536
         
537
When the graphical user interface is disabled with
538
 the I/O auxiliary will normally exit immediately
539
when the eCos application exits. Without the graphical frontend there
540
is usually no way for the user to interact directly with the
541
auxiliary, so there is no point in continuing to run once the eCos
542
application will no longer request any I/O operations. Specifying the
543
 option causes the auxiliary to continue running
544
even after the application has exited.
545
         
546
      
547
      
548
        , 
549
         
550
This option causes the I/O auxiliary to output some additional
551
information, especially during initialization.
552
         
553
      
554
      
555
        , 
556
         
557
Much of the output of the eCos application and the I/O auxiliary is
558
simple text, for example resulting from eCos
559
printf or diag_printf calls.
560
When running in graphical mode this output goes to a central text
561
window, and can be saved to a file or edited via menus. The
562
 can be used to automatically generate an
563
additional logfile containing all the text. If graphical
564
mode is disabled then by default all the text just goes to the current
565
standard output. Specifying  causes most of the
566
text to go into a logfile instead, although some messages such as
567
errors generated by the auxiliary itself will still go to stdout as
568
well.
569
         
570
      
571
      
572
        , 
573
         
574
During initialization the I/O auxiliary reads in a target definition
575
file. This file holds information such as which Linux devices should
576
be used to emulate the various eCos devices. The 
577
option can be used to specify which target definition should be used
578
for the current run, defaulting to default.tdf.
579
It is not necessary to include the .tdf suffix,
580
this will be appended automatically if necessary.
581
         
582
      
583
      
584
        
585
         
586
This option can be used to control the size and position of the main
587
window, as per X conventions.
588
         
589
      
590
    
591
    
592
The I/O auxiliary loads support for the various devices dynamically
593
and some devices may accept additional command line arguments. Details
594
of these can be obtained using the  option or by
595
consulting the device-specific documentation. If an unrecognised
596
command line argument is used then a warning will be issued.
597
    
598
  
599
 
600
  The Target Definition File
601
    
602
The eCos application will want to access devices such as
603
eth0 or /dev/ser0. These need to
604
be mapped on to Linux devices. For example some users may all traffic
605
on the eCos /dev/ser0 serial device to go via the
606
Linux serial device /dev/ttyS1, while ethernet I/O
607
for the eCos eth0 device should be mapped to the
608
Linux ethertap device tap3. Some devices may need
609
additional configuration information, for example to limit the
610
number of packets that should be buffered within the I/O auxiliary.
611
The target definition file provides all this information.
612
    
613
    
614
By default the I/O auxiliary will look for a file
615
default.tdf. An alternative target definition can
616
be specified on the command line using , for
617
example:
618
    
619
    
620
$ bridge_app --io -t twineth
621
622
    
623
A .tdf suffix will be appended automatically if
624
necessary. If a relative pathname is used then the I/O auxiliary will
625
search for the target definition file in the current directory, then
626
in ~/.ecos/synth/, and finally
627
in its install location.
628
    
629
    
630
A typical target definition file might look like this:
631
    
632
    
633
synth_device console {
634
    # appearance -foreground white -background black
635
    filter trace {^TRACE:.*} -foreground HotPink1 -hide 1
636
}
637
 
638
synth_device ethernet {
639
    eth0 real eth1
640
    eth1 ethertap tap4 00:01:02:03:FE:06
641
 
642
    ## Maximum number of packets that should be buffered per interface.
643
    ## Default 16
644
    #max_buffer 32
645
 
646
    ## Filters for the various recognised protocols.
647
    ## By default all filters are visible and use standard colours.
648
    filter ether  -hide 0
649
    #filter arp    -hide 1
650
    #filter ipv4   -hide 1
651
    #filter ipv6   -hide 1
652
}
653
654
    
655
A target definition file is actually a Tcl script that gets run in the
656
main interpreter of the I/O auxiliary during initialization. This
657
provides a lot of flexibility if necessary. For example the script
658
could open a socket to a resource management server of some sort to
659
determine which hardware facilities are already in use and adapt
660
accordingly. Another possibility is to adapt based on 
661
linkend="synth-new-host-args">command line arguments. Users who
662
are not familiar with Tcl programming should still be able to edit a
663
simple target definition file without too much difficulty, using a
664
mixture of cut'n'paste, commenting or uncommenting various lines, and
665
making small edits such as changing tap4 to
666
eth2.
667
    
668
    
669
Each type of device will have its own entry in the target definition
670
file, taking the form:
671
    
672
    
673
synth_device <device type> {
674
    <options>
675
}
676
677
    
678
The documentaton for each synthetic target device should provide
679
details of the options available for that device, and often a suitable
680
fragment that can be pasted into a target definition file and edited.
681
There is no specific set of options that a given device will always
682
provide. However in practice many devices will use common code
683
exported by the main I/O auxiliary, or their implementation will
684
involve some re-use of code for an existing device. Hence certain
685
types of option are common to many devices.
686
    
687
    
688
A good example of this is filters, which control the appearance of
689
text output. The above target definition file defines a filter
690
trace for output from the eCos application. The
691
regular expression will match output from the infrastructure package's
692
tracing facilities when CYGDBG_USE_TRACING and
693
CYGDBG_INFRA_DEBUG_TRACE_ASSERT_SIMPLE are enabled.
694
With the current settings this output will not be visible by default,
695
but can be made visible using the menu item System
696
Filters. If made visible the trace output will appear in
697
an unusual colour, so users can easily distinguish the trace output
698
from other text. All filters accept the following options:
699
    
700
    
701
      
702
         
703
         
704
This controls whether or not text matching this filter should be
705
invisible by default or not. At run-time the visibility of each filter
706
can be controlled using the System Filters
707
menu item.
708
         
709
      
710
      
711
         
712
         
713
This specifies the foreground colour for all text matching this
714
filter. The colour can be specified using an RGB value such as
715
#F08010, or a symbolic name such as
716
"light steel blue". The X11 utility
717
showrgb can be used to find out
718
about the available colours.
719
         
720
      
721
      
722
         
723
         
724
This specifies the background colour for all text matching the filter.
725
As with  the colour can be specified using
726
a symbolic name or an RGB value.
727
         
728
      
729
    
730
    
731
Some devices may create their own subwindows, for example to monitor
732
ethernet traffic or to provide additional I/O facilities such as
733
emulated LED's or buttons. Usually the target definition file can be
734
used to control the layout of
735
these windows.
736
    
737
    
738
The I/O auxiliary will not normally warn about
739
synth_device entries in the target definition file
740
for devices that are not actually needed by the current eCos
741
application. This makes it easier to use a single file for several
742
different applications. However it can lead to confusion if an entry
743
is spelled incorrectly and hence does not actually get used. The
744
 command line option can be used to get warnings
745
about unused device entries in the target definition file.
746
    
747
    
748
If the body of a synth_device command contains an
749
unrecognised option and the relevant device is in use, the I/O
750
auxiliary will always issue a warning about such options.
751
    
752
  
753
 
754
  User Configuration Files
755
    
756
During initialization the I/O auxiliary will execute two user
757
configuration files, initrc.tcl and
758
mainrc.tcl. It will look for these files in the
759
directory ~/.ecos/synth/. If
760
that directory does not yet exist it will be created and populated
761
with initial dummy files.
762
    
763
    
764
Both of these configuration files are Tcl scripts and will be run in
765
the main interpreter used by the I/O auxiliary itself. This means that
766
they have full access to the internals of the auxiliary including the
767
various Tk widgets, and they can perform file or socket I/O if
768
desired. The section  contains
769
information about the facilities available on the host-side for
770
writing new device drivers, and these can also be used in the
771
initialization scripts.
772
    
773
    
774
The initrc.tcl script is run before the auxiliary
775
has processed any requests from the eCos application, and hence before
776
any devices have been instantiated. At this point the generic
777
command-line arguments has been processed, the target definition file
778
has been read in, and the hooks functionality has been initialized. If
779
running in graphical mode the main window will have been created, but
780
has been withdrawn from the screen to allow new widgets to be added
781
without annoying screen flicker. A typical
782
initrc.tcl script could add some menu or toolbar
783
options, or install a hook function that will be run when the
784
eCos application exits.
785
    
786
    
787
The mainrc.tcl script is run after eCos has
788
performed all its device initialization and after C++ static
789
constructors have run, and just before the call to
790
cyg_start which will end up transferring control
791
to the application itself. A typical mainrc.tcl
792
script could look at what interrupt vectors have been allocated to
793
which devices and create a little monitor window that shows interrupt
794
activity.
795
    
796
  
797
 
798
  Session Information
799
    
800
When running in graphical mode, the I/O auxiliary will read in a file
801
~/.ecos/synth/guisession containing session
802
information. This file should not normally be edited manually, instead
803
it gets updated automatically when the auxiliary exits. The purpose of
804
this file is to hold configuration options that are manipulated via
805
the graphical interface, for example which browser should be used to
806
display online help.
807
    
808
    
809
GUI session functionality is not yet available in the current release.
810
When that functionality is fully implemented it is possible that some
811
target definition file options may be removed, to be replaced by
812
graphical editing via a suitable preferences dialog, with the
813
current settings saved in the session file.
814
    
815
  
816
 
817
818
 
819
820
821
 
822
823
  
824
    The I/O Auxiliary's User Interface
825
  
826
  
827
    User Interface
828
    Controlling the I/O Auxiliary
829
  
830
 
831
  Description
832
    
833
The synthetic target auxiliary is designed to support both extensions
834
and user customization. Support for the desired devices is dynamically
835
loaded, and each device can extend the user interface. For example it
836
is possible for a device to add menu options, place new buttons on the
837
toolbar, create its own sub-window within the overall layout, or even
838
create entire new toplevel windows. These subwindows or toplevels
839
could show graphs of activity such as interrupts or packets being
840
transferred. They could also allow users to interact with the eCos
841
application, for example by showing a number of buttons which will be
842
mapped on to digital inputs in the eCos application. Different
843
applications will have their own I/O requirements, changing the
844
host-side support files that get loaded and that may modify the user
845
interface. The I/O auxiliary also reads in user configuration scripts
846
which can enhance the interface in the same way. Therefore the exact
847
user interface will depend on the user and on the eCos application
848
being run. However the overall layout is likely to remain the same.
849
    
850
    
851
      
852
        
853
          
854
        
855
      
856
    
857
    
858
The title bar identifies the window as belonging to an eCos synthetic
859
target application and lists both the application name and its process
860
id. The latter is especially useful if the application was started
861
directly from a shell prompt and the user now wants to attach a gdb
862
session. The window has a conventional menu bar with the usual
863
entries, plus a toolbar with buttons for common operations such as cut
864
and paste. Balloon help is supported.
865
    
866
    
867
There is a central text window,
868
possibly surrounded by various sub-windows for various devices. For
869
example there could be a row of emulated LED's above the text window,
870
and monitors of ethernet traffic and interrupt activity on the right.
871
At the bottom of the window is a status line, including a small
872
animation that shows whether or not the eCos application is still
873
running.
874
    
875
  
876
 
877
  Menus and the Toolbar
878
    
879
Usually there will be four menus on the menu bar:
880
File, Edit,
881
View and Help.
882
    
883
      
884
      
885
        
886
          
887
        
888
      
889
    
890
    
891
On the File menu there are three entries related to
892
saving the current contents of the central text window.
893
Save is used to save the currently visible
894
contents of the text window. Any text that is hidden because of
895
filters will not be written to the savefile. If there has been a
896
previous Save or Save
897
As operation then the existing savefile will be re-used,
898
otherwise the user will be asked to select a suitable file.
899
Save As also saves just the currently
900
visible contents but will always prompt the user for a filename.
901
Save All can be used to save the full
902
contents of the text window, including any text that is currently
903
hidden. It will always prompt for a new filename, to avoid confusion
904
with partial savefiles.
905
    
906
    
907
Usually the eCos application will be run from inside gdb or from a
908
shell prompt. Killing off the application while it is being debugged
909
in a gdb session is not a good idea, it would be better to use gdb's
910
own kill command. Alternatively the eCos
911
application itself can use the CYG_TEST_EXIT or
912
cyg_hal_sys_exit functionality. However it is
913
possible to terminate the application from the I/O auxiliary using
914
Kill eCos. A clean shutdown will be
915
attempted, but that can fail if the application is currently halted
916
inside gdb or if it has crashed completely. As a last resort
917
SIGKILL will be used.
918
    
919
    
920
When operating in graphical mode the I/O auxiliary will normally
921
continue to run even after the eCos application has exited. This
922
allows the user to examine the last few lines of output, and perhaps
923
perform actions such as saving the output to a file. The
924
Exit menu item can be used to shut down the
925
auxiliary. Note that this behaviour can be changed with command line
926
arguments 
927
linkend="synth-running-arguments"> and
928
929
linkend="synth-running-arguments">.
930
    
931
    
932
If Exit is used while the eCos application
933
is still running then the I/O auxiliary will first attempt to
934
terminate the application cleanly, and then exit.
935
    
936
    
937
      
938
        
939
          
940
        
941
      
942
    
943
    
944
The Edit menu contains the usual entries for
945
text manipulation: Cut,
946
Copy, Paste,
947
Clear and Select
948
All. These all operate on the central text window. By
949
default this window cannot be edited so the cut, paste and clear
950
operations are disabled. If the user wants to edit the contents of the
951
text window then the Read Only checkbutton
952
should be toggled.
953
    
954
    
955
The Preferences menu item brings up a
956
miscellaneous preferences dialog. One of the preferences relates to
957
online help: the I/O auxiliary does not currently have a built-in html
958
viewer; instead it will execute an external browser of some sort. With
959
the example settings shown, the I/O auxiliary will first attempt to
960
interact with an existing mozilla session. If that fails it will try
961
to run a new mozilla instance, or as a last result use the Gnome help
962
viewer.
963
    
964
    
965
      
966
        
967
          
968
        
969
      
970
    
971
    
972
The View menu contains the System
973
Filters entry, used to edit the settings for the current
974
filters.
975
    
976
     
977
      
978
        
979
          
980
        
981
      
982
    
983
    
984
The Help menu can be used to activate online help
985
for eCos generally, for the synthetic target as a whole, and for
986
specific devices supported by the generic target. The Preferences
987
dialog can be used to select the browser that will be used.
988
    
989
    
990
      
991
        
992
          
993
        
994
      
995
    
996
    
997
At the time of writing there is no well-defined toplevel index file
998
for all eCos documentation. Hence the relevant menu item is disabled.
999
Documentation for the synthetic target and the supported devices
1000
is stored as part of the package itself so can usually be found fairly
1001
easily. It may be necessary to set the ECOS_REPOSITORY
1002
environment variable.
1003
    
1004
 
1005
  
1006
 
1007
  The Main Text Window
1008
    
1009
The central text window holds the console output from the eCos
1010
application: the screen shot above shows DHCP initialization data from
1011
the TCP/IP stack, and some output from the main
1012
thread at the bottom. Some devices can insert text of their own, for
1013
example the ethernet device support can be configured to show details
1014
of incoming and outgoing packets. Mixing the output from the eCos
1015
application and the various devices can make it easier to understand
1016
the order in which events occur.
1017
    
1018
    
1019
The appearance of text from different sources can be controlled by
1020
means of filters, and it is also possible to hide some of the text.
1021
For example, if tracing is enabled in the eCos configuration then the
1022
trace output can be given its own colour scheme, making it stand out
1023
from the rest of the output. In addition the trace output is generally
1024
voluminous so it can be hidden by default, made visible only to find
1025
out more about what was happening when a particular problem occurred.
1026
Similarly the ethernet device support can output details of the
1027
various packets being transferred, and using a different background
1028
colour for this output again makes it easier to distinguish from
1029
console output.
1030
    
1031
    
1032
The default appearance for most filters is controlled via the
1033
target definition file. An
1034
example entry might be:
1035
    
1036
    
1037
  filter trace {^TRACE:.*} -foreground HotPink1 -hide 1
1038
1039
    
1040
The various colours and the hide flag for each filter can be changed
1041
at run-time, using the System Filters item
1042
on the View menu. This will bring up a dialog like
1043
the following:
1044
    
1045
    
1046
      
1047
        
1048
          
1049
        
1050
      
1051
    
1052
    
1053
It should be noted that the text window is line-oriented, not
1054
character-oriented. If an eCos application sends a partial line of
1055
text then that will remain buffered until a newline character is
1056
received, rather than being displayed immediately. This avoids
1057
confusion when there is concurrent output from several sources.
1058
    
1059
    
1060
By default the text window is read-only. This means it will not allow
1061
cut, paste and clear operations, and keyboard input will be ignored.
1062
The Edit menu has a checkbutton Read
1063
Only which can be toggled to allow write operations. For
1064
example, a user could type in a reminder of what was happening at this
1065
time, or paste in part of a gdb session. Such keyboard input does not
1066
get forwarded to the eCos application: if the latter requires keyboard
1067
input then that should happen via a separate keyboard device.
1068
    
1069
  
1070
 
1071
  Positioning Optional Windows
1072
    
1073
Some devices may create their own subwindows, for example to monitor
1074
ethernet traffic or to provide additional I/O facilities such as
1075
emulated LED's or buttons. Usually the target definition file can be
1076
used to control the layout of
1077
these windows. This requires an understanding of the overall layout of
1078
the display.
1079
    
1080
    
1081
      
1082
        
1083
          
1084
        
1085
      
1086
    
1087
    
1088
Subwindows are generally packed in one of eight frames surrounding the
1089
central text window: .main.nw,
1090
.main.n, .main.ne,
1091
.main.w, .main.e,
1092
.main.sw, .main.s, and
1093
.main.se. To position a row of LED's above the text
1094
window and towards the left, a target definition file could contain an
1095
entry such as:
1096
    
1097
    
1098
synth_device led {
1099
    pack -in .main.n -side left
1100
1101
}
1102
1103
    
1104
Similarly, to put a traffic monitor window on the right of the text
1105
window would involve something like:
1106
    
1107
    
1108
1109
    monitor_pack -in .main.e -side bottom
1110
1111
1112
    
1113
Often it will be sufficient to specify a container frame and one of
1114
left, right,
1115
top or bottom. Full control
1116
over the positioning requires an understanding of Tcl/Tk and in
1117
particular the packing algorithm, and an appropriate reference work
1118
should be consulted.
1119
    
1120
  
1121
 
1122
  Global Settings
1123
    
1124
This section still to be written - it should document the interaction
1125
between X resources and ecosynth, and how users can control settings
1126
such as the main foreground and background colours.
1127
    
1128
  
1129
 
1130
1131
 
1132
1133
1134
 
1135
1136
  
1137
    The Console Device
1138
  
1139
  
1140
    The console device 
1141
    Show output from the eCos application
1142
  
1143
 
1144
  Description
1145
    
1146
The eCos application can generate text output in a variety of ways,
1147
including calling printf or
1148
diag_printf. When the I/O auxiliary is enabled
1149
the eCos startup code will instantiate a console device to process all
1150
such output. If operating in text mode the output will simply go to
1151
standard output, or to a logfile if the  command
1152
line option is specified. If operating in graphical mode the output
1153
will go to the central text window, and optionally to a logfile as
1154
well. In addition it is possible to control the appearance of the main
1155
text via the target definition file, and to install extra filters for
1156
certain types of text.
1157
    
1158
    
1159
It should be noted that the console device is line-oriented, not
1160
character-oriented. This means that outputting partial lines is not
1161
supported, and some functions such as fflush and
1162
setvbuf will not operate as expected. This
1163
limitation prevents much possible confusion when using filters to
1164
control the appearance of the text window, and has some performance
1165
benefits - especially when the eCos application generates a great deal
1166
of output such as when tracing is enabled. For most applications this
1167
is not a problem, but it is something that developers should be aware
1168
of.
1169
    
1170
    
1171
The console device is output-only, it does not provide any support for
1172
keyboard input. If the application requires keyboard input then that
1173
should be handled by a separate eCos device package and matching
1174
host-side code.
1175
    
1176
  
1177
 
1178
  Installation
1179
    
1180
The eCos side of the console device is implemented by the
1181
architectural HAL itself, in the source file
1182
synth_diag.c, rather than in a separate device
1183
package. Similarly the host-side implementation,
1184
console.tcl, is part of the architectural HAL's
1185
host-side support. It gets installed automatically alongside the I/O
1186
auxiliary itself, so no separate installation procedure is required.
1187
    
1188
  
1189
 
1190
  Target Definition File
1191
    
1192
The target definition file
1193
can contain a number of entries related to the console device. These
1194
are all optional, they only control the appearance of text output. If
1195
such control is desired then the relevant options should appear in the
1196
body of a synth_device entry:
1197
    
1198
    
1199
synth_device console {
1200
1201
}
1202
1203
    
1204
The first option is appearance, used to control the
1205
appearance of any text generated by the eCos application that does not
1206
match one of the installed filters. This option takes the same
1207
argument as any other filter, for example:
1208
    
1209
    
1210
synth_device console {
1211
    appearance -foreground white -background black
1212
1213
}
1214
1215
    
1216
Any number of additional filters can be created with a
1217
filter option, for example:
1218
    
1219
    
1220
synth_device console {
1221
1222
    filter trace {^TRACE:.*} -foreground HotPink1 -hide 1
1223
1224
}
1225
1226
    
1227
The first argument gives the new filter a name which will be used in
1228
the filters dialog. Filter names
1229
should be unique. The second argument is a Tcl regular expression. The
1230
console support will match each line of eCos output against this
1231
regular expression, and if a match is found then the filter will be
1232
used for this line of text. The above example matches any line of
1233
output that begins with TRACE:, which corresponds
1234
to the eCos infrastructure's tracing facilities. The remaining options
1235
control the desired appearance for matched text. If some eCos output
1236
matches the regular expressions for several different filters then
1237
only the first match will be used.
1238
    
1239
  
1240
 
1241
  Target-side</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>1242</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>  Configuration Options
1243
    
1244
There are no target-side configuration options related to the console
1245
device.
1246
    
1247
  
1248
 
1249
  Command Line Arguments
1250
    
1251
The console device does not use any command-line arguments.
1252
    
1253
  
1254
 
1255
  Hooks
1256
    
1257
The console device does not provide any hooks.
1258
    
1259
  
1260
 
1261
  Additional Tcl Procedures
1262
    
1263
The console device does not provide any additional Tcl procedures that
1264
can be used by other scripts.
1265
    
1266
  
1267
 
1268
1269
 
1270
1271
1272
 
1273
1274
  
1275
    System Calls
1276
  
1277
 
1278
  
1279
    cyg_hal_sys_xyz
1280
    Access Linux system facilities
1281
  
1282
 
1283
  
1284
    
1285
      
1286
#include <cyg/hal/hal_io.h>
1287
      
1288
      
1289
        int cyg_hal_sys_xyzzy
1290
        
1291
      
1292
    
1293
  
1294
 
1295
  Description
1296
    
1297
On a real embedded target eCos interacts with the hardware by peeking
1298
and poking various registers, manipulating special regions of memory,
1299
and so on. The synthetic target does not access hardware directly.
1300
Instead I/O and other operations are emulated by making appropriate
1301
Linux system calls. The HAL package exports a number of functions
1302
which allow other packages, or even application code, to make these
1303
same system calls. However this facility must be used with care: any
1304
code which calls, for example, cyg_hal_sys_write
1305
will only ever run on the synthetic target; that functionality is
1306
obviously not provided on any real hardware because there is no
1307
underlying Linux kernel to implement it.
1308
    
1309
    
1310
The synthetic target only provides a subset of the available system
1311
calls, specifically those calls which have proved useful to implement
1312
I/O emulation. This subset can be extended fairly easily if necessary.
1313
All of the available calls, plus associated data structures and
1314
macros, are defined in the header file 
1315
class="headerfile">cyg/hal/hal_io.h. There is a simple
1316
convention: given a Linux system call such as
1317
open, the synthetic target will prefix
1318
cyg_hal_sys and provide a function with that name.
1319
The second argument to the open system call is
1320
a set of flags such as O_RDONLY, and the header
1321
file will define a matching constant
1322
CYG_HAL_SYS_O_RDONLY. There are also data
1323
structures such as cyg_hal_sys_sigset_t,
1324
matching the Linux data structure sigset_t.
1325
    
1326
    
1327
In most cases the functions provided by the synthetic target behave as
1328
per the documentation for the Linux system calls, and section 2 of the
1329
Linux man pages can be consulted for more information. There is one
1330
important difference: typically the documentation will say that a
1331
function returns -1 to indicate an error, with the
1332
actual error code held in errno; the actual
1333
underlying system call and hence the
1334
cyg_hal_sys_xyz provided by eCos instead returns
1335
a negative number to indicate an error, with the absolute value of
1336
that number corresponding to the error code; usually it is the C
1337
library which handles this and manipulates errno, but of course
1338
synthetic target applications are not linked with that Linux library.
1339
    
1340
    
1341
However, there are some exceptions. The Linux kernel has evolved over
1342
the years, and some of the original system call interfaces are no
1343
longer appropriate. For example the original
1344
select system call has been superseded by
1345
_newselect, and that is what the
1346
select function in the C library actually uses.
1347
The old call is still available to preserve binary compatibility but,
1348
like the C library, eCos makes use of the new one because it provides
1349
the appropriate functionality. In an attempt to reduce confusion the
1350
eCos function is called cyg_hal_sys__newselect,
1351
in other words it matches the official system call naming scheme. The
1352
authoritive source of information on such matters is the Linux kernel
1353
sources themselves, and especially its header files.
1354
    
1355
    
1356
eCos packages and applications should never
1357
#include Linux header files directly. For example,
1358
doing a #include </usr/include/fcntl.h>
1359
to access additional macros or structure definitions, or alternatively
1360
manipulating the header file search path, will lead to problems
1361
because the Linux header files are likely to duplicate and clash with
1362
definitions in the eCos headers. Instead the appropriate functionality
1363
should be extracted from the Linux headers and moved into either
1364
cyg/hal/hal_io.h or into
1365
application code, with suitable renaming to avoid clashes with eCos
1366
names. Users should be aware that large-scale copying may involve
1367
licensing complications.
1368
    
1369
    
1370
Adding more system calls is usually straightforward and involves
1371
adding one or more lines to the platform-specific file in the
1372
appropriate platform HAL, for example
1373
syscall-i386-linux-1.0.S. However it is necessary
1374
to do some research first about the exact interface implemented by the
1375
system call, because of issues such as old system calls that have been
1376
superseded. The required information can usually be found fairly
1377
easily by searching through the Linux kernel sources and possibly the
1378
GNU C library sources.
1379
    
1380
  
1381
1382
 
1383
1384
1385
 
1386
1387
  
1388
    Writing New Devices - target
1389
  
1390
  
1391
    Writing New Devices
1392
    extending the synthetic target, target-side
1393
  
1394
 
1395
  
1396
    
1397
      
1398
#include <cyg/hal/hal_io.h>
1399
      
1400
 
1401
      
1402
        int synth_auxiliary_instantiate
1403
        const char* package
1404
        const char* version
1405
        const char* device
1406
        const char* instance
1407
        const char* data
1408
      
1409
      
1410
        void synth_auxiliary_xchgmsg
1411
        int device_id
1412
        int request
1413
        int arg1
1414
        int arg2
1415
        const unsigned char* txdata
1416
        int txlen
1417
        int* reply
1418
        unsigned char* rxdata
1419
        int* rxlen
1420
        int max_rxlen
1421
      
1422
    
1423
  
1424
 
1425
  Description
1426
    
1427
In some ways writing a device driver for the synthetic target is very
1428
similar to writing one for a real target. Obviously it has to provide
1429
the standard interface for that class of device, so for example an
1430
ethernet device has to provide can_send,
1431
send, recv and similar
1432
functions. Many devices will involve interrupts, so the driver
1433
contains ISR and DSR functions and will call
1434
cyg_drv_interrupt_create,
1435
cyg_drv_interrupt_acknowledge, and related
1436
functions.
1437
    
1438
    
1439
In other ways writing a device driver for the synthetic target is very
1440
different. Usually the driver will not have any direct access to the
1441
underlying hardware. In fact for some devices the I/O may not involve
1442
real hardware, instead everything is emulated by widgets on the
1443
graphical display. Therefore the driver cannot just peek and poke
1444
device registers, instead it must interact with host-side code by
1445
exchanging message. The synthetic target HAL provides a function
1446
synth_auxiliary_xchgmsg for this purpose.
1447
    
1448
    
1449
Initialization of a synthetic target device driver is also very
1450
different. On real targets the device hardware already exists when the
1451
driver's initialization routine runs. On the synthetic target it is
1452
first necessary to instantiate the device inside the I/O auxiliary, by
1453
a call to synth_auxiliary_instantiate. That
1454
function performs a special message exchange with the I/O auxiliary,
1455
causing it to load a Tcl script for the desired type of device and run
1456
an instantiation procedure within that script.
1457
    
1458
    
1459
Use of the I/O auxiliary is optional: if the user does not specify
1460
 on the command line then the auxiliary will not
1461
be started and hence most I/O operations will not be possible. Device
1462
drivers should allow for this possibility, for example by just
1463
discarding any data that gets written. The HAL exports a flag
1464
synth_auxiliary_running which should be checked.
1465
    
1466
  
1467
 
1468
  Instantiating a Device
1469
    
1470
Device instantiation should happen during the C++ prioritized static
1471
constructor phase of system initialization, before control switches to
1472
cyg_user_start and general application code. This
1473
ensures that there is a clearly defined point at which the I/O
1474
auxiliary knows that all required devices have been loaded. It can
1475
then perform various consistency checks and clean-ups, run the user's
1476
mainrc.tcl script, and make the main window
1477
visible.
1478
    
1479
    
1480
For standard devices generic eCos I/O code will call the device
1481
initialization routines at the right time, iterating through the
1482
DEVTAB table in a static constructor. The same
1483
holds for network devices and file systems. For more custom devices
1484
code like the following can be used:
1485
    
1486
    
1487
#include <cyg/infra/cyg_type.h>
1488
class mydev_init {
1489
  public:
1490
    mydev_init() {
1491
1492
    }
1493
};
1494
static mydev_init mydev_init_object CYGBLD_ATTRIB_INIT_PRI(CYG_INIT_IO);
1495
1496
    
1497
Some care has to be taken because the object
1498
mydev_init_object will typically not be referenced
1499
by other code, and hence may get eliminated at link-time. If the code
1500
is part of an eCos package then problems can be avoided by putting the
1501
relevant file in libextras.a:
1502
    
1503
    
1504
cdl_package CYGPKG_DEVS_MINE {
1505
1506
    compile -library=libextras.a init.cxx
1507
}
1508
1509
    
1510
For devices inside application code the same can be achieved by
1511
linking the relevant module as a .o file rather
1512
than putting it in a .a library.
1513
    
1514
    
1515
In the device initialization routine the main operation is a call to
1516
synth_auxiliary_instantiate. This takes five
1517
arguments, all of which should be strings:
1518
    
1519
    
1520
      
1521
        package
1522
        
1523
For device drivers which are eCos packages this should be a directory
1524
path relative to the eCos repository, for example
1525
devs/eth/synth/ecosynth. This will allow the I/O
1526
auxiliary to find the various host-side support files for this package
1527
within the install tree. If the device is application-specific and not
1528
part of an eCos package then a NULL pointer can be used, causing the
1529
I/O auxiliary to search for the support files in the current directory
1530
and then in ~/.ecos/synth
1531
instead.
1532
        
1533
      
1534
      
1535
        version
1536
        
1537
For eCos packages this argument should be the version of the package
1538
that is being used, for example current. A simple
1539
way to get this version is to use the
1540
SYNTH_MAKESTRING macro on the package name.
1541
If the device is application-specific then a NULL pointer should be
1542
used.
1543
        
1544
      
1545
      
1546
        device
1547
        
1548
This argument specifies the type of device being instantiated, for
1549
example ethernet. More specifically the I/O
1550
auxiliary will append a .tcl suffix, giving
1551
the name of a Tcl script that will handle all I/O requests for the
1552
device. If the application requires several instances of a type
1553
of device then the script will only be loaded once, but the script
1554
will contain an instantiation procedure that will be called for each
1555
device instance.
1556
        
1557
      
1558
      
1559
        instance
1560
        
1561
If it is possible to have multiple instances of a device then this
1562
argument identifies the particular instance, for example
1563
eth0 or eth1. Otherwise a NULL
1564
pointer can be used.
1565
        
1566
      
1567
      
1568
        data
1569
        
1570
This argument can be used to pass additional initialization data from
1571
eCos to the host-side support. This is useful for devices where eCos
1572
configury must control certain aspects of the device, rather than
1573
host-side configury such as the target definition file, because eCos
1574
has compile-time dependencies on some or all of the relevant options.
1575
An example might be an emulated frame buffer where eCos has been
1576
statically configured for a particular screen size, orientation and
1577
depth. There is no fixed format for this string, it will be
1578
interpreted only by the device-specific host-side Tcl script. However
1579
the string length should be limited to a couple of hundred bytes to
1580
avoid possible buffer overflow problems.
1581
        
1582
      
1583
    
1584
    
1585
Typical usage would look like:
1586
    
1587
    
1588
    if (!synth_auxiliary_running) {
1589
      return;
1590
    }
1591
    id = synth_auxiliary_instantiate("devs/eth/synth/ecosynth",
1592
             SYNTH_MAKESTRING(CYGPKG_DEVS_ETH_ECOSYNTH),
1593
             "ethernet",
1594
             "eth0",
1595
             (const char*) 0);
1596
1597
    
1598
The return value will be a device identifier which can be used for
1599
subsequent calls to synth_auxiliary_xchgmsg. If
1600
the device could not be instantiated then -1 will
1601
be returned. It is the responsibility of the host-side software to
1602
issue suitable diagnostics explaining what went wrong, so normally the
1603
target-side code should fail silently.
1604
    
1605
    
1606
Once the desired device has been instantiated, often it will be
1607
necessary to do some additional initialization by a message exchange.
1608
For example an ethernet device might need information from the
1609
host-side about the MAC address, the 
1610
linkend="synth-new-target-interrupts">interrupt vector, and
1611
whether or not multicasting is supported.
1612
    
1613
  
1614
 
1615
  Communicating with a Device
1616
    
1617
Once a device has been instantiated it is possible to perform I/O by
1618
sending messages to the appropriate Tcl script running inside the
1619
auxiliary, and optionally getting back replies. I/O operations are
1620
always initiated by the eCos target-side, it is not possible for the
1621
host-side software to initiate data transfers. However the host-side
1622
can raise interrupts, and the interrupt handler inside the target can
1623
then exchange one or more messages with the host.
1624
    
1625
    
1626
There is a single function to perform I/O operations,
1627
synth_auxiliary_xchgmsg. This takes the following
1628
arguments:
1629
    
1630
    
1631
      
1632
        device_id
1633
         
1634
This should be one of the identifiers returned by a previous
1635
call to synth_auxiliary_instantiate, specifying the
1636
particular device which should perform some I/O.
1637
         
1638
       
1639
      
1640
        request
1641
         
1642
Request are just signed 32-bit integers that identify the particular
1643
I/O operation being requested. There is no fixed set of codes, instead
1644
each type of device can define its own.
1645
         
1646
       
1647
      
1648
        arg1
1649
        arg2
1650
         
1651
For some requests it is convenient to pass one or two additional
1652
parameters alongside the request code. For example an ethernet device
1653
could define a multicast-all request, with arg1
1654
controlling whether this mode should be enabled or disabled. Both
1655
arg1 and arg2 should be signed
1656
32-bit integers, and their values are interpreted only by the
1657
device-specific Tcl script.
1658
         
1659
       
1660
      
1661
        txdata
1662
        txlen
1663
         
1664
Some I/O operations may involve sending additional data, for example
1665
an ethernet packet. Alternatively a control operation may require many
1666
more parameters than can easily be encoded in arg1
1667
and arg2, so those parameters have to be placed in
1668
a suitable buffer and extracted at the other end.
1669
txdata is an arbitrary buffer of
1670
txlen bytes that should be sent to the host-side.
1671
There is no specific upper bound on the number of bytes that can be
1672
sent, but usually it is a good idea to allocate the transmit buffer
1673
statically and keep transfers down to at most several kilobytes.
1674
         
1675
       
1676
      
1677
        reply
1678
         
1679
If the host-side is expected to send a reply message then
1680
reply should be a pointer to an integer variable
1681
and will be updated with a reply code, a simple 32-bit integer. The
1682
synthetic target HAL code assumes that the host-side and target-side
1683
agree on the protocol being used: if the host-side will not send a
1684
reply to this message then the reply argument
1685
should be a NULL pointer; otherwise the host-side must always send
1686
a reply code and the reply argument must be valid.
1687
         
1688
       
1689
      
1690
        rxdata
1691
        rxlen
1692
         
1693
Some operations may involve additional data coming from the host-side,
1694
for example an incoming ethernet packet. rxdata
1695
should be a suitably-sized buffer, and rxlen a
1696
pointer to an integer variable that will end up containing the number
1697
of bytes that were actually received. These arguments will only be
1698
used if the host-side is expected to send a reply and hence the
1699
reply argument was not NULL.
1700
         
1701
       
1702
      
1703
        max_rxlen
1704
         
1705
If a reply to this message is expected and that reply may involve
1706
additional data, max_rxlen limits the size of that
1707
reply. In other words, it corresponds to the size of the
1708
rxdata buffer.
1709
         
1710
       
1711
    
1712
    
1713
Most I/O operations involve only some of the arguments. For example
1714
transmitting an ethernet packet would use the
1715
request, txdata and
1716
txlen fields (in addition to
1717
device_id which is always required), but would not
1718
involve arg1 or arg2 and no
1719
reply would be expected. Receiving an ethernet packet would involve
1720
request, rxdata,
1721
rxlen and max_rxlen; in addition
1722
reply is needed to get any reply from the host-side
1723
at all, and could be used to indicate whether or not any more packets
1724
are buffered up. A control operation such as enabling multicast mode
1725
would involve request and arg1,
1726
but none of the remaining arguments.
1727
    
1728
  
1729
 
1730
  Interrupt Handling
1731
    
1732
Interrupt handling in the synthetic target is much the same as on a
1733
real target. An interrupt object is created using
1734
cyg_drv_interrupt_create, attached, and unmasked.
1735
The emulated device - in other words the Tcl script running inside the
1736
I/O auxiliary - can raise an interrupt. Subject to interrupts being
1737
disabled and the appropriate vector being masked, the system will
1738
invoke the specified ISR function. The synthetic target HAL
1739
implementation does have some limitations: there is no support for
1740
nested interrupts, interrupt priorities, or a separate interrupt
1741
stack. Supporting those might be appropriate when targetting a
1742
simulator that attempts to model real hardware accurately, but not for
1743
the simple emulation provided by the synthetic target.
1744
    
1745
    
1746
Of course the actual implementation of the ISR and DSR functions will
1747
be rather different for a synthetic target device driver. For real
1748
hardware the device driver will interact with the device by reading
1749
and writing device registers, managing DMA engines, and the like. A
1750
synthetic target driver will instead call
1751
synth_auxiliary_xchgmsg to perform the I/O
1752
operations.
1753
    
1754
    
1755
There is one other significant difference between interrupt handling
1756
on the synthetic target and on real hardware. Usually the eCos code
1757
will know which interrupt vectors are used for which devices. That
1758
information is fixed when the target hardware is designed. With the
1759
synthetic target interrupt vectors are assigned to devices on the host
1760
side, either via the target definition file or dynamically when the
1761
device is instantiated. Therefore the initialization code for a
1762
target-side device driver will need to request interrupt vector
1763
information from the host-side, via a message exchange. Such interrupt
1764
vectors will be in the range 1 to 31 inclusive, with interrupt 0 being
1765
reserved for the real-time clock.
1766
    
1767
  
1768
 
1769
1770
 
1771
1772
1773
 
1774
1775
  
1776
    Writing New Devices - host
1777
  
1778
  
1779
    Writing New Devices
1780
    extending the synthetic target, host-side
1781
  
1782
 
1783
  Description
1784
    
1785
On the host-side adding a new device means writing a Tcl/Tk script
1786
that will handle instantiation and subsequent requests from the
1787
target-side. These scripts all run in the same full interpreter,
1788
extended with various commands provided by the main I/O auxiliary
1789
code, and running in an overall GUI framework. Some knowledge of
1790
programming with Tcl/Tk is required to implement host-side device
1791
support.
1792
    
1793
    
1794
Some devices can be implemented entirely using a Tcl/Tk script. For
1795
example, if the final system will have some buttons then those can be
1796
emulated in the synthetic target using a few Tk widgets. A simple
1797
emulation could just have the right number of buttons in a row. A more
1798
advanced emulation could organize the buttons with the right layout,
1799
perhaps even matching the colour scheme, the shapes, and the relative
1800
sizes. With other devices it may be necessary for the Tcl script to
1801
interact with an external program, because the required functionality
1802
cannot easily be accessed from a Tcl script. For example interacting
1803
with a raw ethernet device involves some ioctl
1804
calls, which is easier to do in a C program. Therefore the
1805
ethernet.tcl script which implements the
1806
host-side ethernet support spawns a separate program
1807
rawether, written in C, that performs the
1808
low-level I/O. Raw ethernet access usually also requires root
1809
privileges, and running a small program rawether
1810
with such privileges is somewhat less of a security risk than the
1811
whole eCos application, the I/O auxiliary, and various dynamically
1812
loaded Tcl scripts.
1813
    
1814
    
1815
Because all scripts run in a single interpreter, some care has
1816
to be taken to avoid accidental sharing of global variables. The best
1817
way to avoid problems is to have each script create its own Tcl
1818
namespace, so for example the ethernet.tcl script
1819
creates a namespace ethernet:: and all variables
1820
and procedures reside in this namespace. Similarly the I/O auxiliary
1821
itself makes use of a synth:: namespace.
1822
    
1823
  
1824
 
1825
  Building and Installation
1826
    
1827
When an eCos device driver or application code instantiates a device,
1828
the I/O auxiliary will attempt to load a matching Tcl script. The
1829
third argument to synth_auxiliary_instantiate
1830
specifies the type of device, for example ethernet,
1831
and the I/O auxiliary will append a .tcl suffix
1832
and look for a script ethernet.tcl.
1833
    
1834
    
1835
If the device being instantiated is application-specific rather than
1836
part of an eCos package, the I/O auxiliary will look first in the
1837
current directory, then in 
1838
class="directory">~/.ecos/synth. If it is part of an eCos
1839
package then the auxiliary will expect to find the Tcl script and any
1840
support files below 
1841
class="directory">libexec/ecos in the install tree - note
1842
that the same install tree must be used for the I/O auxiliary itself
1843
and for any device driver support. The directory hierarchy below
1844
libexec/ecos matches the
1845
structure of the eCos repository, allowing multiple versions of a
1846
package to be installed to allow for incompatible protocol changes.
1847
    
1848
    
1849
The preferred way to build host-side software is to use
1850
autoconf and automake. Usually
1851
this involves little more than copying the
1852
acinclude.m4, configure.in
1853
and Makefile.am files from an existing package,
1854
for example the synthetic target ethernet driver, and then making
1855
minor edits. In acinclude.m4 it may be necessary
1856
to adjust the path to the root of the repository.
1857
configure.in may require a similar change, and
1858
the AC_INIT macro invocation will have to be
1859
changed to match one of the files in the new package. A critical macro
1860
in this file is ECOS_PACKAGE_DIRS which will set
1861
up the correct install directory. Makefile.am may
1862
require some more changes, for example to specify the data files that
1863
should be installed (including the Tcl script). These files should
1864
then be processed using aclocal,
1865
autoconf and automake in that
1866
order. Actually building the software then just involves
1867
configure, make and
1868
make install, as per the instructions in the
1869
toplevel README.host file.
1870
    
1871
    
1872
To assist developers, if the environment variable
1873
ECOSYNTH_DEVEL is set then a slightly different
1874
algorithm is used for locating device Tcl scripts. Instead of looking
1875
only in the install tree the I/O auxiliary will also look in the
1876
source tree, and if the script there is more recent than the installed
1877
version it will be used in preference. This allows developers to
1878
modify the master copy without having to run make
1879
install all the time.
1880
    
1881
    
1882
If a script needs to know where it has been installed it can examine
1883
the Tcl variable synth::device_install_dir . This
1884
variable gets updated whenever a  script is loaded, so if the
1885
value may be needed later it should be saved away in a device-specific
1886
variable.
1887
    
1888
  
1889
 
1890
  Instantiation
1891
    
1892
The I/O auxiliary will source the device-specific
1893
Tcl script when the eCos application first attempts to instantiate a
1894
device of that type. The script should return a procedure that will be
1895
invoked to instantiate a device.
1896
    
1897
    
1898
namespace eval ethernet {
1899
1900
    proc instantiate { id instance data } {
1901
1902
        return ethernet::handle_request
1903
    }
1904
}
1905
return ethernet::instantiate
1906
1907
    
1908
The id argument is a unique identifier for this
1909
device instance. It will also be supplied on subsequent calls to the
1910
request handler, and will match the return value of
1911
synth_auxiliary_instantiate on the target side. A
1912
common use for this value is as an array index to support multiple
1913
instances of this types of device. The instance and
1914
data arguments match the corresponding arguments to
1915
synth_auxiliary_instantiate on the target side, so
1916
a typical value for instance would be
1917
eth0, and data is used to pass
1918
arbitrary initialization parameters from target to host.
1919
    
1920
    
1921
The actual work done by the instantiation procedure is obviously
1922
device-specific. It may involve allocating an 
1923
linkend="synth-new-host-interrupts">interrupt vector, adding a
1924
device-specific subwindow to the display, opening a real Linux device,
1925
establishing a socket connection to some server, spawning a separate
1926
process to handle the actual I/O, or a combination of some or all of
1927
the above.
1928
    
1929
    
1930
If the device is successfully instantiated then the return value
1931
should be a handler for subsequent I/O requests. Otherwise the return
1932
value should be an empty string, and on the target-side the
1933
synth_auxiliary_instantiate call will return
1934
-1. The script is responsible for providing
1935
diagnostics explaining
1936
why the device could not be instantiated.
1937
    
1938
  
1939
 
1940
  Handling Requests
1941
    
1942
When the target-side calls
1943
synth_auxiliary_xchgmsg, the I/O auxiliary will
1944
end up calling the request handler for the appropriate device instance
1945
returned during instantiation:
1946
    
1947
    
1948
namespace eval ethernet {
1949
1950
    proc handle_request { id request arg1 arg2 txdata txlen max_rxlen } {
1951
1952
        if { <some condition> } {
1953
            synth::send_reply <error code> 0 ""
1954
            return
1955
        }
1956
1957
        synth::send_reply <reply code> $packet_len $packet
1958
    }
1959
1960
}
1961
1962
    
1963
The id argument is the same device id that was
1964
passed to the instantiate function, and is typically used as an array
1965
index to access per-device data. The request,
1966
arg1, arg2, and
1967
max_rxlen are the same values that were passed to
1968
synth_auxiliary_xchgmsg on the target-side,
1969
although since this is a Tcl script obviously the numbers have been
1970
converted to strings. The txdata buffer is raw data
1971
as transmitted by the target, or an empty string if the I/O operation
1972
does not involve any additional data. The Tcl procedures
1973
binary scan, string index and
1974
string range may be found especially useful when
1975
manipulating this buffer. txlen is provided for
1976
convenience, although string length $txdata would
1977
give the same information.
1978
    
1979
    
1980
The code for actually processing the request is of course device
1981
specific. If the target does not expect a reply then the request
1982
handler should just return when finished. If a reply is expected then
1983
there should be a call to synth::send_reply. The
1984
first argument is the reply code, and will be turned into a 32-bit
1985
integer on the target side. The second argument specifies the length
1986
of the reply data, and the third argument is the reply data itself.
1987
For some devices the Tcl procedure binary format
1988
may prove useful. If the reply involves just a code and no additional
1989
data, the second and third arguments should be 0
1990
and an empty string respectively.
1991
    
1992
    
1993
Attempts to send a reply when none is expected, fail to send a reply
1994
when one is expected, or send a reply that is larger than the
1995
target-side expects, will all be detected by the I/O auxiliary and
1996
result in run-time error messages.
1997
    
1998
    
1999
It is not possible for the host-side code to send unsolicited messages
2000
to the target. If host-side code needs attention from the target, for
2001
example because some I/O operation has completed, then an interrupt
2002
should be raised.
2003
    
2004
  
2005
 
2006
  Interrupts
2007
    
2008
The I/O auxiliary provides a number of procedures for interrupt
2009
handling.
2010
    
2011
    
2012
synth::interrupt_allocate <name>
2013
synth::interrupt_get_max
2014
synth::interrupt_get_devicename <vector>
2015
synth::interrupt_raise <vector>
2016
2017
    
2018
synth::interrupt_allocate is normally called during
2019
device instantiation, and returns the next free interrupt vector. This
2020
can be passed on to the target-side device driver in response to a
2021
suitable request, and it can then install an interrupt handler on that
2022
vector. Interrupt vector 0 is used within the
2023
target-side code for the real-time clock, so the allocated vectors
2024
will start at 1. The argument identifies the
2025
device, for example eth0. This is not actually used
2026
internally, but can be accessed by user-initialization scripts that
2027
provide some sort of interrupt monitoring facility (typically via the
2028
interrupt 
2029
linkend="synth-new-host-hooks">hook). It is possible for a
2030
single device to allocate multiple interrupt vectors, but the
2031
synthetic target supports a maximum of 32 such vectors.
2032
    
2033
    
2034
synth::interrupt_get_max returns the highest
2035
interrupt vector that has been allocated, or 0 if
2036
there have been no calls to
2037
synth::interrupt_allocate.
2038
synth::interrupt_get_devicename returns the string
2039
that was passed to synth::interrupt_allocate when
2040
the vector was allocated.
2041
    
2042
    
2043
synth::interrupt_raise can be called any time after
2044
initialization. The argument should be the vector returned by
2045
synth::interrupt_allocate for this device. It will
2046
activate the normal eCos interrupt handling mechanism so, subject to
2047
interrupts being enabled and this particular interrupt not being
2048
masked out, the appropriate ISR will run.
2049
    
2050
    
2051
At this time it is not possible for a device to allocate a specific
2052
interrupt vector. The order in which interrupt vectors are assigned to
2053
devices effectively depends on the order in which the eCos devices get
2054
initialized, and that may change if the eCos application is rebuilt. A
2055
future extension may allow devices to allocate specific vectors, thus
2056
making things more deterministic. However that will introduce new
2057
problems, in particular the code will have to start worrying about
2058
requests for vectors that have already been allocated.
2059
    
2060
  
2061
 
2062
  Flags and Command Line Arguments
2063
    
2064
The generic I/O auxiliary code will process the standard command line
2065
arguments, and will set various flag variables accordingly. Some of
2066
these should be checked by device-specific scripts.
2067
    
2068
    
2069
      
2070
        synth::flag_gui
2071
        
2072
This is set when the I/O auxiliary is operating in graphical mode
2073
rather than text mode. Some functionality such as filters and the GUI
2074
layout are only available in graphical mode.
2075
        
2076
        
2077
    if { $synth::flag_gui } {
2078
2079
    }
2080
2081
      
2082
      
2083
        synth::flag_verbose
2084
         
2085
The user has requested additional information during startup. Each
2086
device driver can decide how much additional information, if any,
2087
should be produced.
2088
         
2089
      
2090
      
2091
        synth::flag_keep_going
2092
        
2093
The user has specified  or
2094
, so even if an error occurs the I/O
2095
auxiliary and the various device driver scripts should continue running
2096
if at all possible. Diagnostics should still be generated.
2097
        
2098
      
2099
    
2100
    
2101
Some scripts may want to support additional command line arguments.
2102
This facility should be used with care since there is no way to
2103
prevent two different scripts from trying to use the same argument.
2104
The following Tcl procedures are available:
2105
    
2106
    
2107
synth::argv_defined <name>
2108
synth::argv_get_value <name>
2109
2110
    
2111
synth::argv_defined returns a boolean to indicate
2112
whether or not a particular argument is present. If the argument is
2113
the name part of a name/value pair, an = character
2114
should be appended. Typical uses might be:
2115
    
2116
    
2117
    if { [synth::argv_defined "-o13"] } {
2118
2119
    }
2120
 
2121
    if { [synth::argv_defined "-mark="] } {
2122
2123
    }
2124
2125
    
2126
The first call checks for a flag -o13 or
2127
--o13 - the code treats options with single and
2128
double hyphens interchangeably. The second call checks for an argument
2129
of the form -mark=<value> or a pair of
2130
arguments -mark <value>. The value part of a
2131
name/value pair can be obtained using
2132
synth::argv_get_value;
2133
    
2134
    
2135
    variable speed 1
2136
    if { [synth::argv_defined "-mark="] } {
2137
        set mark [synth::argv_get_value "-mark="]
2138
        if { ![string is integer $mark] || ($mark < 1) || ($mark > 9) } {
2139
            <issue diagnostic>
2140
        } else {
2141
            set speed $mark
2142
        }
2143
    }
2144
2145
    
2146
synth::argv_get_value should only be used after a
2147
successful call to synth::argv_defined.
2148
At present there is no support for some advanced forms of command line
2149
argument processing. For example it is not possible to repeat a
2150
certain option such as  or
2151
, with each occurrence increasing the level
2152
of verbosity.
2153
    
2154
    
2155
If a script is going to have its own set of command-line arguments
2156
then it should give appropriate details if the user specifies
2157
. This involves a hook function:
2158
    
2159
    
2160
namespace eval my_device {
2161
    proc help_hook { } {
2162
        puts " -o13          : activate the omega 13 device"
2163
        puts " -mark <speed> : set speed. Valid values are 1 to 9."
2164
    }
2165
 
2166
    synth::hook_add "help" my_device::help_hook
2167
}
2168
2169
  
2170
 
2171
  The Target Definition File
2172
    
2173
Most device scripts will want to check entries in the target
2174
definition file for run-time configuration information. The Tcl
2175
procedures for this are as follows:
2176
    
2177
    
2178
synth::tdf_has_device <name>
2179
synth::tdf_get_devices
2180
synth::tdf_has_option <devname> <option>
2181
synth::tdf_get_option <devname> <option>
2182
synth::tdf_get_options <devname> <option>
2183
synth::tdf_get_all_options <devname>
2184
2185
    
2186
synth::tdf_has_device can be used to check whether
2187
or not the target definition file had an entry
2188
synth_device <name>. Usually the name
2189
will match the type of device, so the
2190
console.tcl script will look for a target
2191
definition file entry console.
2192
synth::tdf_get_devices returns a list of all
2193
device entries in the target definition file.
2194
    
2195
    
2196
Once it is known that the target definition file has an entry for a
2197
certain device, it is possible to check for options within the entry.
2198
synth::tdf_has_option just checks for the presence,
2199
returning a boolean:
2200
    
2201
    
2202
    if { [synth::tdf_has_option "console" "appearance"] } {
2203
2204
    }
2205
2206
    
2207
synth::tdf_get_option returns a list of all the
2208
arguments for a given option. For example, if the target definition
2209
file contains an entry:
2210
    
2211
    
2212
synth_device console {
2213
    appearance -foreground white -background black
2214
    filter trace {^TRACE:.*} -foreground HotPink1 -hide 1
2215
    filter xyzzy {.*xyzzy.*} -foreground PapayaWhip
2216
}
2217
2218
    
2219
A call
2220
synth::tdf_get_option console appearance
2221
will return the list {-foreground white -background
2222
black}. This list can be manipulated using standard Tcl routines
2223
such as llength and lindex. Some
2224
options can occur multiple times in one entry, for example
2225
 in the console entry.
2226
synth::tdf_get_options returns a list of lists,
2227
with one entry for each option occurrence.
2228
synth::tdf_get_all_options returns a list of lists
2229
of all options. This time each entry will include the option name as
2230
well.
2231
    
2232
    
2233
The I/O auxiliary will not issue warnings about entries in the target
2234
definition file for devices which were not loaded, unless the
2235
 or  command line
2236
argument was used. This makes it easier to use a single target
2237
definition file for different applications. However the auxiliary will
2238
issue warnings about options within an entry that were ignored,
2239
because often these indicate a typing mistake of some sort. Hence a
2240
script should always call synth::tdf_has_option,
2241
synth:;tdf_get_option or
2242
synth::tdf_get_options for all valid options, even
2243
if some of the options preclude the use of others.
2244
    
2245
  
2246
 
2247
  Hooks
2248
    
2249
Some scripts may want to take action when particular events occur, for
2250
example when the eCos application has exited and there is no need for
2251
further I/O. This is supported using hooks:
2252
    
2253
    
2254
namespace eval my_device {
2255
2256
    proc handle_ecos_exit { arg_list } {
2257
2258
    }
2259
    synth::hook_add "ecos_exit" my_device::handle_ecos_exit
2260
}
2261
2262
    
2263
It is possible for device scripts to add their own hooks and call all
2264
functions registered for those hooks. A typical use for this is by
2265
user initialization scripts that want to monitor some types of I/O.
2266
The available Tcl procedures for manipulating hooks are:
2267
    
2268
    
2269
synth::hook_define <name>
2270
synth::hook_defined <name>
2271
synth::hook_add <name> <function>
2272
synth::hook_call <name> <args>
2273
2274
    
2275
synth::hook_define creates a new hook with the
2276
specified name. This hook must not already exist.
2277
synth::hook_defined can be used to check for the
2278
existence of a hook. synth::hook_add allows other
2279
scripts to register a callback function for this hook, and
2280
synth::hook_call allows the owner script to invoke
2281
all such callback functions. A hook must already be defined before a
2282
callback can be attached. Therefore typically device scripts will only
2283
use standard hooks and their own hooks, not hooks created by some
2284
other device, because the order of device initialization is not
2285
sufficiently defined. User scripts run from
2286
mainrc.tcl can use any hooks that have been
2287
defined.
2288
    
2289
    
2290
synth::hook_call takes an arbitrary list of
2291
arguments, for example:
2292
    
2293
    
2294
    synth::hook_call "ethernet_rx" "eth0" $packet
2295
2296
    
2297
The callback function will always be invoked with a single argument,
2298
a list of the arguments that were passed to
2299
synth::hook_call:
2300
    
2301
    
2302
    proc rx_callback { arg_list } {
2303
        set device [lindex $arg_list 0]
2304
        set packet [lindex $arg_list 1]
2305
    }
2306
2307
    
2308
Although it might seem more appropriate to use Tcl's
2309
eval procedure and have the callback functions
2310
invoked with the right number of arguments rather than a single list,
2311
that would cause serious problems if any of the data contained special
2312
characters such as [ or $. The
2313
current implementation of hooks avoids such problems, at the cost of
2314
minor inconvenience when writing callbacks.
2315
    
2316
    
2317
A number of hooks are defined as standard. Some devices will add
2318
additional hooks, and the device-specific documentation should be
2319
consulted for those. User scripts can add their own hooks if desired.
2320
    
2321
    
2322
      
2323
        exit
2324
        
2325
This hook is called just before the I/O auxiliary exits. Hence it
2326
provides much the same functionality as atexit in
2327
C programs. The argument list passed to the callback function will be
2328
empty.
2329
        
2330
      
2331
      
2332
        ecos_exit
2333
        
2334
This hook is called when the eCos application has exited. It is used
2335
mainly to shut down I/O operations: if the application is no longer
2336
running then there is no point in raising interrupts or storing
2337
incoming packets. The callback argument list will be empty.
2338
        
2339
      
2340
      
2341
        ecos_initialized
2342
        
2343
The synthetic target HAL will send a request to the I/O auxiliary once
2344
the static constructors have been run. All devices should now have been
2345
instantiated. A script could now check how many instances there are of
2346
a given type of device, for example ethernet devices, and create a
2347
little monitor window showing traffic on all the devices. The
2348
ecos_initialized callbacks will be run just before
2349
the user's mainrc.tcl script. The callback
2350
argument list will be empty.
2351
        
2352
      
2353
      
2354
        help
2355
        
2356
This hook is also invoked once static constructors have been run, but
2357
only if the user specified  or
2358
. Any scripts that add their own command line
2359
arguments should add a callback to this hook which outputs details of
2360
the additional arguments. The callback argument list will be empty.
2361
        
2362
      
2363
      
2364
        interrupt
2365
        
2366
Whenever a device calls synth::interrupt_raise the
2367
interrupt hook will be called with a single
2368
argument, the interrupt vector. The main use for this is to allow
2369
user scripts to monitor interrupt traffic.
2370
        
2371
      
2372
    
2373
  
2374
 
2375
  Output and Filters
2376
    
2377
Scripts can use conventional facilities for sending text output to the
2378
user, for example calling puts or directly
2379
manipulating the central text widget
2380
.main.centre.text. However in nearly all cases it
2381
is better to use output facilities provided by the I/O auxiliary
2382
itself:
2383
    
2384
    
2385
synth::report <msg>
2386
synth::report_warning <msg>
2387
synth::report_error <msg>
2388
synth::internal_error <msg>
2389
synth::output <msg> <filter>
2390
2391
    
2392
synth::report is intended for messages related to
2393
the operation of the I/O auxiliary itself, especially additional
2394
output resulting from  or
2395
. If running in text mode the output will go
2396
to standard output. If running in graphical mode the output will go to
2397
the central text window. In both modes, use of  or
2398
 will modify the behaviour.
2399
    
2400
    
2401
synth::report_warning,
2402
synth::report_error and
2403
synth::internal_error have the obvious meaning,
2404
including prepending strings such as Warning: and
2405
Error:. When the eCos application informs the I/O
2406
auxiliary that all static constructors have run, if at that point
2407
there have been any calls to synth::error then the
2408
I/O auxiliary will exit. This can be suppressed with command line
2409
arguments  or .
2410
synth::internal_error will output some information
2411
about the current state of the I/O auxiliary and then exit
2412
immediately. Of course it should never be necessary to call this
2413
function.
2414
    
2415
    
2416
synth::output is the main routine for outputting
2417
text. The second argument identifies a filter. If running in text mode
2418
the filter is ignored, but if running in graphical mode the filter can
2419
be used to control the appearance of this output. A typical use would
2420
be:
2421
    
2422
    
2423
    synth::output $line "console"
2424
2425
    
2426
This outputs a single line of text using the
2427
console filter. If running in graphical mode the
2428
default appearance of this text can be modified with the
2429
 option in the
2430
synth_device console entry of the target
2431
definition file. The System filters menu
2432
option can be used to change the appearance at run-time.
2433
    
2434
    
2435
Filters should be created before they are used. The procedures
2436
available for this are:
2437
    
2438
    
2439
synth::filter_exists <name>
2440
synth::filter_get_list
2441
synth::filter_add <name> [options]
2442
synth::filter_parse_options <options> <parsed_options> <message>
2443
synth::filter_add_parsed <name> <parsed_options>
2444
2445
    
2446
synth::filter_exists can be used to check whether
2447
or not a particular filter already exists: creating two filters with
2448
the same name is not allowed.
2449
synth::filter_get_list returns a list of the
2450
current known filters. synth::filter_add can be
2451
used to create a new filter. The first argument names the new filter,
2452
and the remaining arguments control the initial appearance. A typical
2453
use might be:
2454
    
2455
    
2456
    synth::filter_add "my_device_tx" -foreground yellow -hide 1
2457
2458
    
2459
It is assumed that the supplied arguments are valid, which typically
2460
means that they are hard-wired in the script. If instead the data
2461
comes out of a configuration file and hence may be invalid, the
2462
I/O auxiliary provides a parsing utility. Typical usage would be:
2463
    
2464
    
2465
    array set parsed_options [list]
2466
    set message ""
2467
    if { ![synth::filter_parse_options $console_appearance parsed_options message] } {
2468
        synth::report_error \
2469
                "Invalid entry in target definition file $synth::target_definition\
2470
                 \n  synth_device \"console\", entry \"appearance\"\n$message"
2471
    } else {
2472
        synth::filter_add_parsed "console" parsed_options
2473
    }
2474
2475
    
2476
On success parsed_options will be updated with an
2477
internal representation of the desired appearance, which can then be
2478
used in a call to synth::filter_add_parsed. On
2479
failure message will be updated with details of the
2480
parsing error that occurred.
2481
    
2482
  
2483
 
2484
  The Graphical Interface
2485
    
2486
When the I/O auxiliary is running in graphical mode, many scripts will
2487
want to update the user interface in some way. This may be as simple
2488
as adding another entry to the help menu for the device, or adding a
2489
new button to the toolbar. It may also involve adding new subwindows,
2490
or even creating entire new toplevel windows. These may be simple
2491
monitor windows, displaying additional information about what is going
2492
on in the system in a graphical format. Alternatively they may emulate
2493
actual I/O operations, for example button widgets could be used to
2494
emulate real physical buttons.
2495
    
2496
    
2497
The I/O auxiliary does not provide many procedures related to the
2498
graphical interface. Instead it is expected that scripts will just
2499
update the widget hierarchy directly.
2500
    
2501
    
2502
      
2503
        
2504
          
2505
        
2506
      
2507
    
2508
    
2509
So adding a new item to the Help menu involves a
2510
.menubar.help add operation with suitable
2511
arguments. Adding a new button to the toolbar involves creating a
2512
child window in .toolbar and packing it
2513
appropriately. Scripts can create their own subwindows and then pack
2514
it into one of .main.nw,
2515
.main.n, .main.ne,
2516
.main.w, .main.e,
2517
.main.sw, .main.s or
2518
.main.se. Normally the user should be allowed to
2519
control this via the target
2520
definition file. The central window .main.centre
2521
should normally be left alone by other scripts since it gets used for
2522
text output.
2523
    
2524
    
2525
The following graphics-related utilities may be found useful:
2526
    
2527
    
2528
synth::load_image <image name> <filename>
2529
synth::register_ballon_help <widget> <message>
2530
synth::handle_help <URL>
2531
2532
    
2533
synth::load_image can be used to add a new image to
2534
the current interpreter. If the specified file has a
2535
.xbm extension then the image will be a
2536
monochrome bitmap, otherwise it will be a colour image of some sort.
2537
A boolean will be returned to indicate success or failure, and
2538
suitable diagnostics will be generated if necessary.
2539
    
2540
    
2541
synth::register_balloon_help provides balloon help
2542
for a specific widget, usually a button on the toolbar.
2543
    
2544
    
2545
synth::handle_help is a utility routine that can be
2546
installed as the command for displaying online help, for example:
2547
    
2548
    
2549
    .menubar.help add command -label "my device" -command \
2550
        [list synth::handle_help "file://$path"]
2551
2552
  
2553
 
2554
2555
 
2556
2557
2558
 
2559
2560
  
2561
    Porting
2562
  
2563
  
2564
    Porting
2565
    Adding support for other hosts
2566
  
2567
 
2568
  Description
2569
    
2570
The initial development effort of the eCos synthetic target happened
2571
on x86 Linux machines. Porting to other platforms involves addressing
2572
a number of different issues. Some ports should be fairly
2573
straightforward, for example a port to Linux on a processor other than
2574
an x86. Porting to Unix or Unix-like operating systems other than
2575
Linux may be possible, but would involve more effort. Porting to a
2576
completely different operating system such as Windows would be very
2577
difficult. The text below complements the eCos Porting Guide.
2578
    
2579
  
2580
 
2581
  Other Linux Platforms
2582
    
2583
Porting the synthetic target to a Linux platform that uses a processor
2584
other than x86 should be straightforward. The simplest approach is to
2585
copy the existing i386linux
2586
directory tree in the hal/synth
2587
hierarchy, then rename and edit the ten or so files in this package.
2588
Most of the changes should be pretty obvious, for example on a 64-bit
2589
processor some new data types will be needed in the
2590
basetype.h header file. It will also be necessary
2591
to update the toplevel ecos.db database with an
2592
entry for the new HAL package, and a new target entry will be needed.
2593
    
2594
    
2595
Obviously a different processor will have different register sets and
2596
calling conventions, so the code for saving and restoring thread
2597
contexts and for implementing setjmp and
2598
longjmp will need to be updated. The exact way of
2599
performing Linux system calls will vary: on x86 linux this usually
2600
involves pushing some registers on the stack and then executing an
2601
int 0x080 trap instruction, but on a different
2602
processor the arguments might be passed in registers instead and
2603
certainly a different trap instruction will be used. The startup code
2604
is written in assembler, but needs to do little more than extract the
2605
process' argument and environment variables and then jump to the main
2606
linux_entry function provided by the
2607
architectural synthetic target HAL package.
2608
    
2609
    
2610
The header file hal_io.h provided by the
2611
architectural HAL package provides various structure definitions,
2612
function prototypes, and macros related to system calls. These are
2613
correct for x86 linux, but there may be problems on other processors.
2614
For example a structure field that is currently defined as a 32-bit
2615
number may in fact may be a 64-bit number instead.
2616
    
2617
    
2618
The synthetic target's memory map is defined in two files in the
2619
include/pkgconf subdirectory.
2620
For x86 the default memory map involves eight megabytes of read-only
2621
memory for the code at location 0x1000000 and another eight megabytes
2622
for data at 0x2000000. These address ranges may be reserved for other
2623
purposes on the new architecture, so may need changing. There may be
2624
some additional areas of memory allocated by the system for other
2625
purposes, for example the startup stack and any environment variables,
2626
but usually eCos applications can and should ignore those.
2627
    
2628
    
2629
Other HAL functionality such as interrupt handling, diagnostics, and
2630
the system clock are provided by the architectural HAL package and
2631
should work on different processors with few if any changes. There may
2632
be some problems in the code that interacts with the I/O auxiliary
2633
because of lurking assumptions about endianness or the sizes of
2634
various data types.
2635
    
2636
    
2637
When porting to other processors, a number of sources of information
2638
are likely to prove useful. Obviously the Linux kernel sources and
2639
header files constitute the ultimate authority on how things work at
2640
the system call level. The GNU C library sources may also prove very
2641
useful: for a normal Linux application it is the C library that
2642
provides the startup code and the system call interface.
2643
    
2644
  
2645
 
2646
  Other Unix Platforms
2647
    
2648
Porting to a Unix or Unix-like operating system other than Linux would
2649
be somewhat more involved. The first requirement is toolchains: the
2650
GNU compilers, gcc and g++, must definitely be used; use of other GNU
2651
tools such as the linker may be needed as well, because eCos depends
2652
on functionality such as prioritizing C++ static constructors, and
2653
other linkers may not implement this or may implement it in a
2654
different and incompatible way. A closely related requirement is the
2655
use of ELF format for binary executables: if the operating system
2656
still uses an older format such as COFF then there are likely to be
2657
problems because they do not provide the flexibility required by eCos.
2658
    
2659
    
2660
In the architectural HAL there should be very little code that is
2661
specific to Linux. Instead the code should work on any operating
2662
system that provides a reasonable implementation of the POSIX
2663
standard. There may be some problems with program startup, but those
2664
could be handled at the architectural level. Some changes may also be
2665
required to the exception handling code. However one file which will
2666
present a problem is hal_io.h, which contains
2667
various structure definitions and macros used with the system call
2668
interface. It is likely that many of these definitions will need
2669
changing, and it may well be appropriate to implement variant HAL
2670
packages for the different operating systems where this information
2671
can be separated out. Another possible problem is that the generic
2672
code assumes that system calls such as
2673
cyg_hal_sys_write are available. On an operating
2674
system other than Linux it is possible that some of these are not
2675
simple system calls, and instead wrapper functions will need to be
2676
implemented at the variant HAL level.
2677
    
2678
    
2679
The generic I/O auxiliary code should be fairly portable to other Unix
2680
platforms. However some of the device drivers may contain code that is
2681
specific to Linux, for example the PF_PACKET socket
2682
address family and the ethertap virtual tunnelling interface. These
2683
may prove quite difficult to port.
2684
    
2685
    
2686
The remaining porting task is to implement one or more platform HAL
2687
packages, one per processor type that is supported. This should
2688
involve much the same work as a port to 
2689
linkend="synth-porting-linux">another processor running Linux.
2690
    
2691
    
2692
When using other Unix operating systems the kernel source code may not
2693
be available, which would make any porting effort more challenging.
2694
However there is still a good chance that the GNU C library will have
2695
been ported already, so its source code may contain much useful
2696
information.
2697
    
2698
  
2699
 
2700
  Windows Platforms
2701
    
2702
Porting the current synthetic target code to some version of Windows
2703
or to another non-Unix platform is likely to prove very difficult. The
2704
first hurdle that needs to be crossed is the file format for binary
2705
executables: current Windows implementations do not use ELF, instead
2706
they use their own format PE which is a variant of the rather old and
2707
limited COFF format. It may well prove easier to first write an ELF
2708
loader for Windows executables, rather than try to get eCos to work
2709
within the constraints of PE. Of course that introduces new problems,
2710
for example existing source-level debuggers will still expect
2711
executables to be in PE format.
2712
    
2713
    
2714
Under Linux a synthetic target application is not linked with the
2715
system's C library or any other standard system library. That would
2716
cause confusion, for example both eCos and the system's C library
2717
might try to define the printf function, and
2718
introduce complications such as working with shared libraries. For
2719
much the same reasons, a synthetic target application under Windows
2720
should not be linked with any Windows DLL's. If an ELF loader has been
2721
specially written then this may not be much of a problem.
2722
    
2723
    
2724
The next big problem is the system call interface. Under Windows
2725
system calls are generally made via DLL's, and it is not clear that
2726
the underlying trap mechanism is well-documented or consistent between
2727
different releases of Windows.
2728
    
2729
    
2730
The current code depends on the operating system providing an
2731
implementation of POSIX signal handling. This is used for I/O
2732
purposes, for example SIGALRM is used for the
2733
system clock, and for exceptions. It is not known what equivalent
2734
functionality is available under Windows.
2735
    
2736
    
2737
Given the above problems a port of the synthetic target to Windows may
2738
or may not be technically feasible, but it would certainly require a
2739
very large amount of effort.
2740
    
2741
  
2742
 
2743
2744
 
2745
2746
 
2747

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.