Application note for using config.xml

Introduction

The Lightfoot SDK provides a very easy way to configure your application for multiple environments. You do this by creating a config.xml file and defining the values that you require. This allows you to configure the drivers provided by the BSP, the networking environment, memory requirements for various threads and many other features.

This application note describes how to define various different environments using the configuration file and lists all the different configuration values available.

Details

The easiest way to understand the configuration process is to understand an existing example. The examples used in this application note can be found in the config package on the SDK examples web page.

Simple example

The simple example is based on a very basic hello world application, but uses the configuration file to define application constants. The configuration file allows you to specify constants as pre-processor macros and as variables.

simple.c

#include <dct_config.h>

#include <stdio.h>

void main(void) {
  printf("%s\n", DCT_CONST_APP_VAR_MESSAGE);
  printf("%s\n", DCT_CONST_APP_PREPROCESS_MESSAGE);
}

This simply includes the application configuration file dct_config.h and then displays two messages.

The configuration file for this example defines these two constants.

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE dctapp PUBLIC "-//DCT//APP" "http://www.dctl.com/dtd/DCTAPP.dtd">

  <dctapp>

    <target tag="vs2000_evb_1_2">
      <constants>
        <!-- application-specific constants -->
        <constant type="var"     name="VAR_MESSAGE" value="Variable message"   format="string"/>
        <constant type="preproc" name="PREPROCESS_MESSAGE"  value="preprocess message"   format="string"/>
      </constants>
    </target>
  </dctapp>


To build the example,  type lfmake. This starts off the build process that processes the application configuration file, the default BSP configuration file and the default SDK configuration file to produce a number of files in the derived subdirectory.

derived\platform\platform.c            This file contains diagnostic levels.

derived\<bsp name>\dct_config.c            This file contains all the variable constants.

derived\<bsp name>\dct_config.h            This file contains all the variable definitions and pre-processor macros.

derived\<bsp name>\dct_config.mk          This file contains makefile constants and is used for determining whether to build an application to run in ram or in rom.

derived\<bsp name>\dct_devices.c          This file contains the table defining all the devices to use and the names of devices to use for the standard input and output streams.

derived\<bsp name>\network_init.c       This file contains the code to initialise the network.

derived\<bsp name>\application\Properties.java            This file contains all the variable properties that can be accesed from a Java class.

Selecting device drivers

When you build an application, it gets linked with the BSP that you specify through the DCT_BUILD_TARGET and DCT_BUILD_TARGET_VERSION environment variables. Each BSP enables all of its device drivers by default, and while this allows you to use all of the features of the board, may be wasteful of memory.

This example is an extension of the first example, but disables all the non-essential drivers, and chooses the minimal timer and uart drivers. These minimal drivers provide the functionality required for the LightOS timer and serial I/O for messages.

This example also changes the timer instance used by the LightOS RTOS to schedule tasks by overriding the default value. The application configuration file overrides all values specified in the BSP configuration file and the Lightfoot SDK configuration file.

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE dctapp PUBLIC "-//DCT//APP" "http://www.dctl.com/dtd/DCTAPP.dtd">

  <dctapp>

    <target tag="vs2000_evb_1_2">
      <constants>
        <!-- application-specific constants -->
        <constant type="var"     name="VAR_MESSAGE" value="Variable message"   format="string"/>
        <constant type="preproc" name="PREPROCESS_MESSAGE"  value="preprocess message"   format="string"/>

        <!-- change the lightos timer to use timer 0 -->
        <constant type="var" name="LIGHTOS_TIMER" value="0" format="integer"/>
      </constants>

      <devices>
        <!-- use the minimal uart and timer devices -->
        <device class="uart"            instances="0,1"         minimal="yes"/>
        <device class="timer"           instances="0"           minimal="yes"/>

        <!-- disable all the other devices -->
        <device class="ethernet"        instances="none"/>
        <device class="configmgr"       instances="none"/>
        <device class="eeprom"          instances="none"/>
        <device class="spi"             instances="none"/>
        <device class="gpio"            instances="none"/>
        <device class="watchdog"        instances="none"/>
        <device class="flash"           instances="none"/>
        <device class="ffs"             instances="none"/>
      </devices>
    </target>
  </dctapp>


Build the application using lfmake as normal. If you compare this application size with the original one, you can see that it is about half the size as it now only contains the essential drivers.