NOTICE: The Processors Wiki will End-of-Life on January 15, 2021. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.
Accessing Variables and Macros in RTSC projects
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.
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
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.