Chapter 14. 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 has two variables you will need to adjust: PKG_INSTALL_DIR and XCC. Edit the Makefile, setting PKG_INSTALL_DIR to the install tree previously created by pkgconf.tcl and uncommenting the relevant XCC line for your architecture.

eCos hello world

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

Example 14-1. 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 type this explicit compilation instruction (assuming your current working directory is also where you built the eCos kernel):

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

The compilation instruction 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 in the simulator using GDB the way you ran the test case. The sequence of steps will be the same (skip steps 2 and 3 if using the synthetic Linux target):

  1. Run gdb specifying -nw a.out on the command line:

    $ gdb -nw a.out

  2. Type msim on the MN10300, tsim on the TX39, psim on the PowerPC, or ssim on the SPARClite.

  3. Type load

At this point you are ready to run the usual GDB commands. For example, you can simply type run at the (gdb) prompt and the program will execute and print the string Hello, eCos world! on your screen.