idleTask - utilization

wella wrote on Tuesday, November 18, 2008:

Hi,

is there a different method to measure time (with logic analyzer, pin L/H) how long FRTOS stays in the idleTask?

I have tried trace macros
traceTASK_SWITCHED_IN()
if (0 == strcmp(pxCurrentTCB->pcTaskName, "IDLE")) …

traceTASK_SWITCHED_OUT()
if (0 == strcmp(pxCurrentTCB->pcTaskName, "IDLE")) …

but it is a little uncomfortably to compare 5 bytes and call library function.

Thanks
Martin

davedoors wrote on Tuesday, November 18, 2008:

The idle task is automatically created when the scheduler is started. If you create all your tasks before the scheduler starts, and never delete any tasks, then you can use

traceTASK_SWITCHED_IN()
if( (uxCurrentNumberOfTasks - 1) == pxCurrentTCB->uxTCBNumber )

but configUSE_TRACE_FACILITY must be set to 1.

Another way is to store a handle to the idle. Assuming you store this in a variable called xIdleTaskHandle then you can do

traceTASK_SWITCHED_IN()
if( pxCurrentTCB == xIdleTaskHandle )

wella wrote on Tuesday, November 18, 2008:

Yes,

the first solution seems fine.

How to store xIdleTaskHandle? In vTaskStartScheduler() is called xTaskCreate( prvIdleTask, ( signed portCHAR * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL ); so I think that I should create vApplicationIdleHook(), call xTaskGetCurrentTaskHandle() in it and store to global variable?

Thank You

Martin

davedoors wrote on Tuesday, November 18, 2008:

That would work, but you could just edit the call to

xTaskCreate( prvIdleTask, ( signed portCHAR * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL );

as

xTaskCreate( prvIdleTask, ( signed portCHAR * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, &xIdleTaskHandle );

just the last parameter is different.

wella wrote on Tuesday, November 18, 2008:

Ok, I only wanted to avoid editing source code of FT(task.c).

Many thanks that you noticed configUSE_TRACE_FACILITY option. I was confused, why it don’t work before reading third paragraph :).

Martin