I am new user of Free RTOS and have a question regarding vTaskDelay(). I checked the forum regarding my problem, but didn’t find anything that would help me.
I am using the Free RTOS on AurixTC33 microcontroller. First I implemented two tasks, where first task toggle one diode and secound task toggle another diode. Then I used the while loop for blocking delay function, so everything worked properly when it is designed like this.
However, when I put vTaskDelay() function to have nonbloking delay instead of blocking delay function the diodes do not toggle properly.
When I’m debugging this code, I go into the vTaskDelay function but it seems that it doesn’t blocked the desired task and that it doesn’t do any context switch. So, it only toggle LED diode from one of two tasks with frequency same as System timer that is using for calling scheduler.
Has anyone encountered the similar problem and does anyone have any idea what the problem is?
In FreeRTOSConfig.h file the macro INCLUDE_vTaskDelay is defined as 1.
For me, who is begginer in this field it seems that vTaskDelay function affects in that way so that the scheduler stops working and there is no any kind of delay.
Below is part of the code.
Part from main function where the tasks are created.
status = xTaskCreate(task1_handler,"Task-1",200,NULL,5,NULL);
configASSERT(status == pdPASS);
status = xTaskCreate(task2_handler,"Task-2",200,NULL,5,NULL);
configASSERT(status == pdPASS);
vTaskStartScheduler();
Task1_handler and task2_handler functions are below.
However, when I put vTaskDelay() function to have nonbloking delay instead of blocking delay function the diodes do not toggle properly.
What does this mean ? Setting delay ticks to 0 ?
This means that when I put vTaskDelay() function in my code with the number of ticks equivalent to 1 second, the program doesn’t work properly.
vTaskDelay(pdMS_TO_TICKS(1000));
It works as follows: one LED blink at maximum speed and another LED doesn’t toggle at all. The program behaves like there is not any kind of delay (it toggle diode with max possible speed), plus it toggles only one diode, there is not any kind of context switch.
I checked configUSE_TIME_SLICING macro in my code and it is enabled.
Hmm … sounds like the SysTick is not running. Hence no time slicing, too.
Can you verify that xTaskIncrementTick is invoked (by putting a breakpoint at it) resp. if xTickCount is incrementing ?
But I’m not familiar with Aurix controllers. Where did you get the FreeRTOS port for from ?
This is not how the the vTaskDelay is implemented. Is is simply a software timer that puts the task in a blocked state, counts the ticks and unblock the task once it expires.
One thing you can try to create a periodic task is to use vTaskDelayUntil instead. It works like this:
#define POLLING_RATE ( 1000 / portTICK_PERIOD_MS ) //1000ms
static portTASK_FUNCTION( prvMyTask, pvParameters )
{
(void)pvParameters;
TickType_t xLastWakeTime;
xLastWakeTime = xTaskGetTickCount();
while (true)
{
//This task should really do some stuff
vTaskDelayUntil( &xLastWakeTime, POLLING_RATE );
} //while (true))
}