v8.2.2 - xTaskCallApplicationTaskHook() Question

westmorelandeng wrote on Sunday, August 16, 2015:

Hello All,

I am using the following call:

xTaskCallApplicationTaskHook( NULL, 0 );

that goes to (example)

BaseType_t prvExampleTaskHook4( void * pvParameter )

when I step through in a debugger - the task hook is called twice -
I was wondering if there was a way to have it only called once - of course this (probably) has everything to do with the parent task but I was wondering if there is a way to make sure the call only happens once per time slice of the parent task. (Or maybe the parent task in this case is getting two time slices in a row?)

John W.

rtel wrote on Sunday, August 16, 2015:

Where are you calling xTaskCallApplicationTaskHook() from, and which port are you using?

If you are calling it from traceTASK_SWITCHED_OUT() then some (older) ports might call it on each tick, whereas newer ports should only call it when a context switch is actually required. The way to tell would be to look at how xTaskIncrementTick() is called in the port layer. If the return value of xTaskIncrementTick() is used to determine if vTaskSwitchContext() is called then it should traceTASK_SWITCHED_OUT() should not be called on each tick, if the return value is ignored then it probably will be called on each tick.

If you are using traceTASK_SWITCHED_OUT() then you can update your macro definition as follows:

static TaskHandle_t xLastTaskHandle = NULL;

    if( pxCurrentTCB != xLastTaskHandle )
        /* The task changed - run your code here. */
    xLastTaskHandle = pxCurrentTCB;


westmorelandeng wrote on Sunday, August 16, 2015:

I am calling xTaskCallApplicationTaskHook() in the regular task - this is defined before the
/* Register our callback function. */
vTaskSetApplicationTaskTag( NULL, prvExampleTaskHook4 );

Well, yes, the port I am using is checking the return value of xTaskIncrementTick().

westmorelandeng wrote on Sunday, August 16, 2015:

OK - this is fixed - but have a related question - what is the correct way to reference pxCurrentTCB if I am not in task.c? This works fine in assembly:

rtel wrote on Sunday, August 16, 2015:

Try “extern void*”. It might generate a compiler warning but should work.

westmorelandeng wrote on Sunday, August 16, 2015:

OK - thanks -
extern PRIVILEGED_DATA TCB_t * volatile pxCurrentTCB;
didn’t work so well. :wink: