Hi, I just started to learn about freertos and i have a question about task management.
I made two tasks in following the code and assuming that two functions will be called one at a time when tick interrupt.
But result is different, taks2 was never called
The code is following…
xTaskCreate(vContinuousProcessingTask, "Task1", configMINIMAL_STACK_SIZE + 100,pcTextForTask1,1, NULL)
xTaskCreate(vContinuousProcessingTask, "Task2", configMINIMAL_STACK_SIZE + 100,pcTextForTask2,1, NULL)
And function itself is just calling printf in the loop...
static void vContinuousProcessingTask(void *text)
{
for(;;)
{
PRINTF(text);
}
}
What is PRINTF() doing? Try replacing the print statement with a simple increment of a variable, using a different variable in each task. What happens then? Do both variables increment or just one?
One comment, you have configUSE_PREEMPTION = 0, which means that the only point when any task switch will occur, is on calls to FreeRTOS operations. Neither of your tasks seem to do that (unless it is buried in PRINTF).
The configUSE_TIME_SLICING means that on the tick interrupt, the other task will become ahead of the current on in priority, but until an opportunity arrises to perform a task switch, nothing will happen. While configUSE_PREEMPTION = 0 does make some program tasks easier because you don’t need to worry about race conditions as much, it does mean you need to worry about providing for opportunity for a task switch or they might not happen, which can make latency promises a lot harder to make.
It does, UNLESS you have explicitly disabled that by turning off preemption. That option changes FreeRTOS from a preemptive Real Time system into a cooperative Real Time System.
My suggestion, don’t turn off preemption unless you have a real need to do so.