From RTSC-Pedia

Jump to: navigation, search
revision tip
—— LANDSCAPE orientation
[printable version]  offline version generated on 04-Aug-2010 21:08 UTC

Using xdc.runtime System/Example 1

Classic "hello world" using System

"hello world"

In this section, we use the System module to implement a "hello world" application.

The C application - shown in the table below - uses System_printf() to output the string "hello world." and its configuration file uses xdc.useModule() to declare that the application directly references the xdc.runtime.System module. This configuration statement is necessary - without it the configuration process will not know the initial set of package to load or which modules need to be part of the application link step. Note that only those modules directly referenced by the application need to be declared in this manner; modules used by this initial set are implicitly included based on information supplied by the packages containing these initial modules.

Why do we need a "printf-like" function, why not simply use the ANSI C Standard library printf() function? The printf() function is required by the ANSI standard to support a rich set of format specifications. While this set is necessary for sophisticated text output, most embedded systems use only a few basic formats and typically only as a debugging aid during development. As a result, it it possible to implement a much smaller and faster printf-like function that provides all of the functionality typically needed in embedded systems. For comparison, the ANSI C printf() implementation provided by the TI C6x code-gen tools is approximately 35KB whereas the corresponding System_printf() function in the xdc.runtime package is only 4KB. This reduction in size is possible because System_printf() does not support all of the ANSI C format specifications nor does it need to support the rich FILE * stream abstraction.

hello.c
 
 
 
 
 
 
 
 
 
 
#include <xdc/std.h>
 
#include <xdc/runtime/System.h>
 
/*  ======== main ======== */
Int main(Int argc, String argv[])
{
    System_printf("hello world\n");
    return (0);
}
hello.cfg
 
var System = xdc.useModule("xdc.runtime.System");

The output of this application is just:

 
hello world

How are the characters generated by System_printf() output? After all, every embedded application has a different way of interacting with the external environment. The System module can't possibly work in every embedded application environment without some means for the the developer to "tell" the System module how to output characters. To keep the implementation of System 100% portable, the System module provides a configuration parameter, called SupportProxy, which allows each developer to "bind" a unique set of low-level functions required in the implementation of System services.

In the next example, we use the same application C sources but we explicitly "bind" an implementation of the low-level functions necessary to do character output via configuration of the System module itself. Because the configuration script binds SysMin as the "service provider" for the System module, each character of output is simply copied to an internal buffer (managed by SysMin). When the application exits, the contents of the buffer are output to the screen (again, by SysMin).

In outline, the configuration file below

  1. gets a reference to the System module (via xdc.useModule()) so that subsequent statements can configure this module. This statement is necessary because the application directly references System functions.
  2. selects a "system provider" module, SysMin, that will be used to implement low-level services needed by the System module.
  3. configures the SysMin module's internal character output buffer to only hold 128 characters (more than enough for "hello world").
  4. "binds" the selected system provider to the System module by assigning to the System.SupportProxy configuration parameter.
hello.c
 
 
 
 
 
 
 
 
 
 
#include <xdc/std.h>
 
#include <xdc/runtime/System.h>
 
/*  ======== main ======== */
Int main(Int argc, String argv[])
{
    System_printf("hello world\n");
    return (0);
}
hello.cfg
 
 
 
 
 
 
 
 
 
 
var System = xdc.useModule("xdc.runtime.System");
 
/* declare that this app uses the SysMin module */
var SysMin = xdc.useModule("xdc.runtime.SysMin");
 
/* set SysMin's output buffer size */
SysMin.bufSize = 128;   
 
/* tell System to use SysMin's implementation of putchar() */
System.SupportProxy = SysMin;

The output of this configuration is simply:

Output
 
hello world
[printable version]  offline version generated on 04-Aug-2010 21:08 UTC
Copyright © 2008 The Eclipse Foundation. All Rights Reserved
Views
Personal tools
package reference