The example programs in this tutorial are included, along
with a Makefile, in the examples directory
of the eCos distribution. The first program you will run is a hello
world-style application, then you will run a more complex
application that demonstrates the creation of threads and the use
of cyg_thread_delay(), and finally you will run
one that uses clocks and alarm handlers.
INSTALL_DIR may be either be set in the shell
environment or may be supplied on the command line. To set it in the
shell do the following in a bash shell:
/* this is a simple hello world program */
#include <stdio.h>
int main(void)
{
printf("Hello, eCos world!\n");
return 0;
}
To compile this or any other program that is not part of the
eCos distribution, you can follow the procedures described below. Type
this explicit compilation command (assuming your current working
directory is also where you built the eCos kernel):
The compilation command above contains some standard GCC
options (for example, -g enables debugging), as well
as some mention of paths
(-IBASE_DIR/ecos-work/install/include allows files
like cyg/kernel/kapi.h to be found, and
-LBASE_DIR/ecos-work/install/lib allows the linker to
find -Ttarget.ld).
The executable program will be called a.out.
Note: Some target systems require special options to be passed to
gcc to compile correctly for that system. Please examine the Makefile
in the examples directory to see if this applies to your target.
You can now run the resulting program using GDB in exactly the
same the way you ran the test case before. The procedure will be the
same, but this time run
TARGET-gdb specifying
-nw a.out on the command line:
$ TARGET-gdb -nw a.out
For targets other than the synthetic linux target, you should
now run the usual GDB commands described earlier. Once this is done,
typing the command "continue" at the (gdb) prompt ("run" for
simulators) will allow the program to execute and print the string
"Hello, eCos world!" on your screen.
On the synthetic linux target, you may use the "run" command
immediately - you do not need to connect to the target, nor use the
"load" command.