Problem with portSUPPRESS_TICKS_AND_SLEEP and msp430fr4

eduardobern wrote on Wednesday, December 21, 2016:

Hello,

I am trying to use the tickless low power feature of FreeRtos in my application.

I noticed that portSUPPRESS_TICKS_AND_SLEEP never get called, the only way to make it work is disabling the only task that i have in my test application. This is very weird because the test task that i have only does this:

for(;:wink:
{
if(xQueueReceive(handler->events, &cur_event, portMAX_DELAY) == pdTRUE)
{
FSM_Process((HSM_PRIME*) handler, &cur_event);
}
}

I disabled all the interrupts that puts some data into this queue, so it would block indefinitely, leaving the system in IDLE state, i am using the IdleHook callback to make sure it is locked in this state, but still the portSUPPRESS_TICKS_AND_SLEEP doesnt get called. This is VERY frustrating.

configUSE_TICKLESS_IDLE is 2
configEXPECTED_IDLE_TIME_BEFORE_SLEEP is 200
INCLUDE_vTaskSuspend is 1

I really cant figure out what is happening, Could you guys help me?

heinbali01 wrote on Thursday, December 22, 2016:

I can not think of a reason, but could you try replace portMAX_DELAY with a value of e.g. 1000? Does that make a difference?

Could you through the code in tasks.c starting here:

    xExpectedIdleTime = prvGetExpectedIdleTime();

eduardobern wrote on Thursday, December 22, 2016:

Tried different values. Still not working. xExpectedIdleTime is always 0 when my test tasking is running which is why portSUPPRESS_TICKS_AND_SLEEP never get called. This two conditions are true in most times:

if( pxCurrentTCB->uxPriority > tskIDLE_PRIORITY )
{
    xReturn = 0;
}
else if( uxHigherPriorityReadyTasks != pdFALSE )
{
/* There are tasks in the Ready state that have a priority above the
			idle priority.  This path can only be reached if
			configUSE_PREEMPTION is 0. */
			xReturn = 0;
}

I also modified my test task like this and still didnt work:

static void vTestTask(void * pvParameters)
{
	 TickType_t xLastWakeTime;
	 const TickType_t xFrequency = 450;

	 xLastWakeTime = xTaskGetTickCount();

	 for(;;)
	 {
		 vTaskDelayUntil( &xLastWakeTime, xFrequency );
	 }
 }

eduardobern wrote on Thursday, December 22, 2016:

Also noticed that this condition is always true when the test task is running

#if( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 )
		{
			if( uxTopReadyPriority > tskIDLE_PRIORITY )
			{
				uxHigherPriorityReadyTasks = pdTRUE;
			}
		}

It is acting like even with vTaskDelayUntil or xQueueReceive blocking my task, it always counts as a Ready state. Cant figure out why this is happening.

Update: Now there is something even more weird, i switched from FreeRtos v9 to FreeRtos v8.1 and it worked with the same application source code. I only got only one warning during the build related to cast in task.c.

rtel wrote on Thursday, December 22, 2016:

This is on an MSP430F - did you provide your own implementation of the tickless idle feature? Which compiler are you using? If IAR then you should be able to use their StateViewer plug-in to see which task the system thinks is running.

eduardobern wrote on Monday, December 26, 2016:

Yes, i made my own implementation, but the problem was that the portSUPPRESS_TICKS_AND_SLEEP never get called. With some debugging i discovered that was because there was always at least one task in ready state which was not true since my only task was blocked due to vTaskDelayUntil.

Then I switched to FreeRtos 8.1 and the problem was gone.

I am using CCS 6.1 with Ti compiler.

rtel wrote on Tuesday, December 27, 2016:

Are you using software timers? If so, then the change history for V8.2 could have explained it perhaps, but I’m not sure about 8.1: http://www.freertos.org/History.txt

eduardobern wrote on Wednesday, December 28, 2016:

I am not using software timers. I just ported the freertos v9 to msp430fr4133 and made a simple tasks (that sleeps/blocks most of the time), but no matter what i do, all tasks always stays in ready status and then i couldnt make the tickless feature work.

I moved to freertos v8,1 and everything worked, but i get some warnings during the compilation.

I believe that is a problem with my enviroment and compiler, because there is a example code on freertos v9 with the msp430fr5 series that is very similar with my current msp430.

rtel wrote on Wednesday, December 28, 2016:

You can use the debugger to step through the prvGetExpectedIdleTime()
function in tasks.c to see why it is returning whatever it is returning.

eduardobern wrote on Thursday, December 29, 2016:

It always returns 0 because of this condition inside the prvGetExpectedIdleTime() function:

else if( uxHigherPriorityReadyTasks != pdFALSE )
{
/* There are tasks in the Ready state that have a priority above the
            idle priority.  This path can only be reached if
            configUSE_PREEMPTION is 0. */
            xReturn = 0;
}

rtel wrote on Friday, December 30, 2016:

That doesn’t help. uxHigherPriorityReadyTasks is set in that function.
Why is it being set to pdTRUE?