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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [synth/] [arch/] [current/] [doc/] [synth.sgml] - Blame information for rev 838

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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