Chapter 13. Building and Running Sample Applications

Table of Contents
eCos Hello World
A Sample Program with Two Threads

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.

The Makefile depends on an externally defined variable to find the eCos library and header files. This variable is INSTALL_DIR and must be set to the pathname of the install directory created in the Section called Configuration Tool on Windows and Linux Quick Start in Chapter 11.

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:

$ export INSTALL_DIR=BASE_DIR/ecos-work/arm_install

You can then run make without any extra parameters to build the examples.

Alternatively, if you can do the following:

$ make INSTALL_DIR=BASE_DIR/ecos-work/arm_install

eCos Hello World

The following code is found in the file hello.c in the examples directory:

eCos hello world program listing

/* 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):

$ TARGET-gcc -g -IBASE_DIR/ecos-work/install/include hello.c -LBASE_DIR/ecos-work/install/lib -Ttarget.ld -nostdlib

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.

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.