Please note as of Wednesday, August 15th, 2018 this wiki has been set to read only. If you are a TI Employee and require Edit ability please contact x0211426 from the company directory.

Accessing Variables and Macros in RTSC projects

From Texas Instruments Wiki
Jump to: navigation, search

The steps below show how to define environment variables and access them within RTSC configuration files and C source files.

1) Define an environment variable under Project Properties->Build->Environment.

This example shows a variable named MYREALSTRING with the value HelloWorld.

Env var1.png

2) To access this variable in RTSC .cfg, .c and .h files, define a Java property under Project Properties->Build->XDCtools->Advanced Options->Java properties by clicking on the Add button.

This example defines two Java properties:
BUILDDIR=${PROJECT_BUILD_DIR} - this references the CCS system variable PROJECT_BUILD_DIR that points to the project build directory
MYSTRING=${MYREALSTRING} - this references the environment variable created in step 1

Java define.png

3) In the RTSC .cfg script add the following lines (for each variable). The first line reads that variable and the second one makes it available to .c and .h files. The empty string at the end of the second line is there just to fix some type incompatibilities between JavaScript and Java strings.

This example shows the lines added for both variables BUILDDIR and MYSTRING. There are also some additional/optional print lines added for testing purposes.

var build_dir = environment["BUILDDIR"];
Program.global.build_dir = build_dir + "";

var mystring = environment["MYSTRING"];
Program.global.mystring = mystring + "";

print( "*******************************************" );
print( "build_dir = '" + environment["BUILDDIR"] + "'" );
print( "*******************************************" );

4) In the C files and header files where you need to access the variable, add the following line to include the header file <xdc/cfg/global.h>

# include <xdc/cfg/global.h>

You can then access the variable within the C code, for example:

    System_printf("%s\n", build_dir);
    System_printf("%s\n", mystring);

5) If you need to make the variable accessible in a linker command file, it should also be defined in the --define option under Project Properties->Build->Linker->Advanced Options->Command File Preprocessing.