Hello everyone,
I am a beginner about FreeRTOS and I only want to do a simple program with 2 tasks.
The problem is that when I start the Scheduler with this 2 tasks. The task with the higher priority will start and then without the end of this task the 2nd task will start…
This is my code :
xTaskCreate(TFT_task_coil, "Coils_task", 128, NULL, 2, NULL);
xTaskCreate(TFT_task_display, "Display", 128, NULL, 1, NULL);
/* Scheduler */
vTaskStartScheduler();
void TFT_task_coil(void *param)
{
int i = 0;
uint16_t test_coil = 25;
uint16_t test;
while(1)
{
if (tft_active != 0)
{
printf("Task coil start : %lu \r\n", xTaskGetTickCount());
if(xQueueReceive(Queue_USB_Coils, (void *) &item_coil, 10) == pdTRUE) {
test= item_coil;
}
else if(xQueueReceive(Queue_Ethernet_Coils, (void *) &item_coil, 10) == pdTRUE) {
test= item_coil;
}
else{
test= 300;
}
if(uxQueueSpacesAvailable(Queue_Coils_Display) != 0){
xQueueSend(Queue_Coils_Display, (void *) &test_coil, 10);
}
i++;
if(i>19){
test_coil = (uint16_t)rand();
i = 0;
}
printf("Task coil end : %lu \r\n", xTaskGetTickCount());
vTaskDelay(100);
}
}
}
void TFT_task_display(void *param)
{
while(1)
{
if (tft_active != 0)
{
printf("Task display start : %lu \r\n", xTaskGetTickCount());
EVE_cmd_text_burst(10, 190, 27, 0, "Coils current");
EVE_cmd_text_burst(220, 190, 27, 0, "mA");
/* Display of our variables */
static uint16_t Value_coil = 0.0;
xQueueReceive(Queue_Coils_Display, (void *) &Value_coil, 0);
EVE_cmd_number_burst(170, 190, 27, 0, (uint16_t)Value_coil);
printf("Task display end : %lu \r\n", xTaskGetTickCount());
vTaskDelay(75);
}
}
}
My queue are working well.
The task are working well when I start the Scheduler just with 1 but when I put the 2 tasks this is what I get :
The coil task is not finish that the display task is launch and that make crash my program…
Do you have an idea ?