A "hello, world" Example

The following C code shows how to write the cannonical "hello, world" program for the LayGO PXS:

#include "ecosmain.h"

ecos_IDENTITY(pdkhello, 1.01)

int ecos_Main(int argc, char ** argv)
{
    ecos_Log(log_PRIORITY_INFO, "hello, world");

    return (0);
}

This program is available in the PDK as pdkhello.c in the etc/pdkhello directory. When executed on the PXS, the following output appears in the remote log server's log file:

Nov 02 11:06:39 2004 Info : pxs-1309671422 : eCos starting pdkhello version 1.01.
Nov 02 11:06:39 2004 Info : pxs-1309671422 : hello, world
Nov 02 11:06:39 2004 Info : pxs-1309671422 : eCos exiting pdkhello version 1.01.

Program Notes

#include "ecosmain.h"

The file ecosmain.h contains the prototype for the ecos_Main() function as well as including the headers required for serial IO and remote logging.

ecos_IDENTITY(pdkhello, 1.01)

Every PDK program must instantiate the ecos_IDENTITY() macro somewhere its source code. This macro creates a static string and access function which other components can use to determine the name and version of the currectly executing eCos program.

int ecos_Main(int argc, char ** argv)
{
    ecos_Log(log_PRIORITY_INFO, "hello, world");

    return (0);
}

The ecos_Main() function is like a regular C program's main(), the entry point for all PDK programs. It must be called ecos_Main(). The parameters argc and argv contain the parsed application options string from the PXS configuration, just like a regular C program's arguments to main() with one exception: argc may be 0 and if it is greater than 0, argv[0] contains the first argument from the options string, not the name of the program.

Before the call to ecos_Main(), all configured subsystems are initialized. These subsystems are:

The runtime environment has also been initialized with the values stored in the PXS application environment string. ecos_Main() is called in a thread running at the default priority. The application is free to use this thread in any way it sees fit. It is often used to execute an eCos Control command loop to control the running application after other threads have been started to do whatever work the program is designed to do. (This is demonstrated in the pdktest test program discussed in A Complete PDK Program.) Returning from ecos_Main() does not stop any of the services started prior to its being called. The services continue to run so that the PXS can be controlled using the eCos Control API or reconfigured using the web server. This means that ecos_Main() can return while other threads continue to run, although this is not normally done. Normally, ecos_Main() simply does not return unless the program is given a halt command to do an orderly shutdown proior to resetting the PXS. (Should ecos_Main() return, the value it returns is ignored. The thread executing ecos_Main() simply terminates.)