jeffou66 wrote on Thursday, August 23, 2018:
Hello, New with RTOS and beginner programming. It’s not right with me but I’m progressing. I have a question, to know why my code is doing a good loop but the second Task stops. I am on arduino MEGA2560. Thanks for your help.
#include <Arduino_FreeRTOS.h>
#include <FreeRTOSConfig.h>
#include <FreeRTOSVariant.h>
#include <task.h>
TaskHandle_t TaskHandle_1;
TaskHandle_t TaskHandle_2;
TaskHandle_t TaskHandle_3;
TaskHandle_t TaskHandle_4;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println(F("*****Setup function*****"));
Serial.println(F("************************"));
delay(2000);
xTaskCreate(TaskReadCalcPID, "Task1", configMINIMAL_STACK_SIZE, NULL, 4, &TaskHandle_1); // paramètre de la TASK ici.
//xTaskCreate(TaskNxtParamP0_ConsMes, "Task2", configMINIMAL_STACK_SIZE, NULL, 4, &TaskHandle_2);
//xTaskCreate(TaskReadCalcPID, "Task3", configMINIMAL_STACK_SIZE, NULL, 3, &TaskHandle_3);
//xTaskCreate(TaskNxtParamP0_PID, "Task4", configMINIMAL_STACK_SIZE, NULL, 1, &TaskHandle_4);
}
void loop() {
Serial.println(F("Loop function"));
delay(4000);
}
/////////////////////////////// TASKS////////////////////////////////////////////////////
//************************************************1*******************************************************************************
void TaskReadCalcPID(void *pvParameters) // Ici c'est la tache avec le rappel de ses paramètres: TaskReadCalcPID , Priorité=6/7
{
while(1)
{
Serial.println("*****START****TASK 1***********");
Serial.println("*******************************");
Serial.println("1_ReadCalcPID : reafect priority 4 at: 1_ReadCalcPID");
vTaskPrioritySet(TaskHandle_1,4); //Now task1 has priority 4
Serial.println("1_ReadCalcPID run: Creating Task2(ParamP0_ConsMes)");
xTaskCreate(TaskNxtParamP0_ConsMes, "Task2", configMINIMAL_STACK_SIZE, NULL, 7, &TaskHandle_2);
}
}
//***********************************************2**********************************************************************************
void TaskNxtParamP0_ConsMes(void *pvParameters) // Ici c'est la tache : TaskNxtParamP0_ConsMes Priorité=5/7
{
while(1)
{
Serial.println("2_ParamP0_ConsMes : Suspend 1_ReadCalcPID");
vTaskSuspend(TaskHandle_1);
Serial.println("2_ParamP0_ConsMes s'octroie Prorité=6");
vTaskPrioritySet(TaskHandle_2,6); //Now task2 has priority 6
Serial.println("2_ParamP0_ConsMes run: Creating Task3(CourbP0)");
xTaskCreate(TaskNxtCourbP0, "Task3", configMINIMAL_STACK_SIZE, NULL, 7, &TaskHandle_3);
}
}
//***********************************************3***********************************************************************************
void TaskNxtCourbP0(void *pvParameters) // Ici c'est la tache : TaskNxtCourbP0 Priorité=4/7
{
while(1)
{
Serial.println("3_CourbP0 delete 2_ParamP0_ConsMes");
vTaskDelete(TaskHandle_2);
Serial.println("3_CourbP0 s'octroie Prorité=6");
vTaskPrioritySet(TaskHandle_3,6); //Now task3 has priority 6
Serial.println("3_CourbP0 run: Creating Task4(ParamP0_PID)");
xTaskCreate(TaskNxtParamP0_PID, "Task4", configMINIMAL_STACK_SIZE, NULL, 6, &TaskHandle_4);
}
}
//*********************************************4*************************************************************************************
void TaskNxtParamP0_PID(void *pvParameters) // Ici c'est la tache : TaskNxtParamP0 Priorité=3/7
{
while(1)
{
Serial.println("4_ParamP0_PID delete 3_CourbP0");
vTaskDelete(TaskHandle_3);
Serial.println("4_ParamP0_PID run: Make Resume task1(ReadCalcPID)");
vTaskResume(TaskHandle_1);
Serial.println("4_ParamP0_PID autodelete");
vTaskDelete(TaskHandle_4);
}
}
Serial Line Response :
Setup function
START****TASK 1******
1_ReadCalcPID : reafect priority 4 at: 1_ReadCalcPID
1_ReadCalcPID run: Creating Task2(ParamP0_ConsMes)
2_ParamP0_ConsMes : Suspend 1_ReadCalcPID
2_ParamP0_ConsMes s’octroie Prorité=6
2_ParamP0_ConsMes run: Creating Task3(CourbP0)
3_CourbP0 delete 2_ParamP0_ConsMes
3_CourbP0 s’octroie Prorité=6
3_CourbP0 run: Creating Task4(ParamP0_PID)
4_ParamP0_PID delete 3_CourbP0
4_ParamP0_PID run: Make Resume task1(ReadCalcPID)
4_ParamP0_PID autodelete
START****TASK 1******
1_ReadCalcPID : reafect priority 4 at: 1_ReadCalcPID
1_ReadCalcPID run: Creating Task2(ParamP0_ConsMes)
Loop function
Loop function
Loop function
Loop function
Loop function
Loop function
Loop function
Loop function
Loop function
And blocked on Loop … :-/
I do not understand too much about memory and stack management.
the size of the stack here is configMINIMAL_STACK_SIZE, but must not agree?
Thanks for all for my study
Jeff