trace Hook Macros

rafia-inam wrote on Monday, December 20, 2010:

i am using FreeRTOS on Avr32 UC3A0512 .
I tried many methods to use traceTASK_SWITCHED_OUT() or traceTASK_SWITCHED_IN(), but could not succeed.
configUSE_APPLICATION_TASK_TAG is defined 1 in FreeRTOSConfig.h file.
static portBASE_TYPE pTaskHook( void * pvParameter ) {
portTickType   c; 
        c = xTaskGetTickCount();
        tickarray_ = c;
        i++;               //tick array and i are global variables.
        return 0;

static void start_task(void)
int i;
// Register our callback function.
vTaskSetApplicationTaskTag( NULL, pTaskHook );
           // task body

what is the exact place to define the Macro #define traceTASK_SWITCHED_OUT() xTaskCallApplicationTaskHook( pxCurrentTCB, 0 ). i tried it in FreeRTOS.h, and in the main.c but nothing works.
Can someone help me please?


rtel wrote on Monday, December 20, 2010:

I have actually just written two new sections to the FreeRTOS tutorial book, one of which is specifically on the trace hook macros .

The best place to define hook macros, such as traceTASK_SWITCHED_OUT(), is in FreeRTOSConfig.h.  That way the order in which macros are defined is guaranteed to be correct.  If you are going to write complex macros then you can put them in their own header file, and include that header file from FreeRTOSConfig.h.

The task hook function is only really required if you want each task to execute a different function.  If ever task is to execute the same function you can call the function directly from your definition fo traceTASK_SWITCHED_OUT().

See the following page for more examples (if you have not done so already):


modiallen wrote on Sunday, August 19, 2012:

Hi Richard,
i tried to define the macros in FreeRTOSConfig.h, but it did not work.

here is the code.

void log_event(char *Buffer);
char TraceBuffer;

#define traceTASK_SWITCHED_IN() log_event(TraceBuffer)
void log_event(char *Buffer)
static int i=0;
i just want only to have the first letter of each taskname.
the error here is that the “pxCurrentTCB” is stil not defined in FreeRTOS.config
that is why, i tried it in tasks.c after the definition of pxCurrentTCB, and it works and log alle the switches.

but how can i use the pxCurrentTCB in the main.c ? is there a posibility?


rtel wrote on Sunday, August 19, 2012:

pxCurrentTCB can be used in main by externing it “extern void *pxCurrentTCB”, but it won’t do you much good because the (deliberate) data hiding policy used in FreeRTOS will note expose the structure members to you.  If you define a macro that uses pxCurrentTCB, and that macro is defined in FreeRTOSConfig.h but called in tasks.c, then you can access the structure members because the code is in effect inlined in tasks.c (which contains the full TCB structure definition).