cesarverdes wrote on Tuesday, May 04, 2010:
I’ve noted that when the system uses co-routines it’s dificult to know when send the CPU to sleep.
As I could understand, the documentation suggests to include the vCoRoutineSchedule() call into the vApplicationIdleHook() function, setting configUSE_IDLE_HOOK to 1. I reference the “Scheduling the co-routine” topic at the documentation.
The Solution #2 of the FreeRTOS Tutorial evaluates that for a fully preemptive system the power consumption can be reduced if the idle task places the processor into power save (sleep) mode.
With the present co-routine implementation I find hard to detect when all the co-rutines are blocked (delayed) in order to place the processor into a power save mode until the next tick.
In this post Richard Damon sugest this pseudo-code for the idle hook funcion:
idle hook function (will be called periodically by the idle task)
{
Enter Critical Section
if(ok to go to sleep)
{
prepare system to go to sleep
enter sleep state
wake system up from sleep state
end critical section
}
else
{
end critical section
maybe go to idle state if one is available
}
}
The question is, how to know when is ok to go to sleep when co-ruoutines are used?
As a possile solution I suggest to change the return value of vCoRoutineSchedule() from void to portBASE_TYPE, and modify this function in order to return pdTRUE when there is at least one ready co-rutine, and return pdFALSE if there is not.
As the documentation declares, Co-routines are really only intended for use on very small processors that have severe RAM constraints. This kind of constraints can be common in small battery operated appliances.
Please, does anyone see the same dificulty that I do? Does anyone found a good way to solve it?
I know myself as a newbie, in case than more experienced FreeRTOS developers find my suggestion a good one, I would like to work on it and propose some code to discuss.
I’m studing FreeRTOS only for pleasure, as a hobby in my free time. I’m trying to understand line by line, function by function. That’s why I could even think about situations that perhaps they are not real life ones.
Regards,
César