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.

Printing in stubs and skeletons

From Texas Instruments Wiki
Jump to: navigation, search

This page is about printing to a trace file in stubs and skeletons for debuggging purposes.


This topic deals with printing from stubs and skeletons used by a specific codec, in the context of the creation of an extension package or when overriding the stubs and skeletons. To maximize performance, the stubs and skeletons shipped in the Codec Engine do not print anything out to the trace files by default. But for debugging purposes the user might want to print something out temporarily. This procedure describes how to do this when you are in hurry to figure out a potential issue.

Procedure in Codec Engine 2.x or below

Add the following lines at the top of your stubs/skeleton C file:

#include <ti/sdo/utils/trace/gt.h>
/* This needs to be globally unique in the system */
#define GTNAME ""
static GT_Mask curTrace = {NULL, NULL};
static Bool curInit = FALSE;

This defines the trace object (and its name) that would be used with a module called "GT" to produce output in the Codec Engine trace.

After that, add the following lines in the function where you'd like to print things out to the CE trace.

if (curInit != TRUE) {
    curInit = TRUE;
    GT_create(&curTrace, GTNAME);
    GT_set(GTNAME "=01234567");
GT_0trace(curTrace, GT_4CLASS, "Hello World!\n");
GT_1trace(curTrace, GT_4CLASS, "Hello World with an arg: %d!\n", 1);

GT_create() is used to initialize the trace object with its name, which will appear on every line that is printed out using this trace object. The GT_set() call turns on all 8 levels of trace (0-7) for the module named GTNAME. The GT_<num>trace() function can be used to print a formatted string to the CE trace, where <num> corresponds to the number of parameters in the string.

GT_4CLASS corresponds to trace level 4 used in CE trace. Hence, when running the application, you must ensure trace level 4 is enabled in order to see the output. See the Codec Engine Application Developer User's Guide for more detail on how to use CE trace and to set the trace level. And for those of you who are sharp, you probably realized by now that if you change the number in the class you can get output at other levels of trace.

Note that, as a convention, GT_6CLASS is used for warnings and GT_7CLASS is used for errors.


For those of you who are observant, there is a potential race condition in the above code, as stubs and skeletons can be run in different thread contexts. There is a very small chance that GT_create() is called more than once if curInit is read simultaneously in multiple process/control calls that preempt one another during the first time when the function is called. This is believed to be a rare occurrence; however, if it does happen, rest assured that in the current implementation (CE 2.x or below) of GT_create(), it is ok to call it more than once.

Also note that floating point numbers are not supported in the GT_*trace() calls on the DSP. (The GT_*trace made on a DSP/BIOS-based system are are bound to BIOS's SYS_printf() implementations which is small and fast, but does not support %f or %lf.) If you need to print a floating point number, however, you can use sprintf() -- which does support floats -- and then pass sprintf-created string to GT_*trace().