I am trying to learn how to use FreeRTOS, and I have a disfunctionning when I use the EventGroup.
My exercise projet is to create a counter using seconds, minutes, hours. I used different tasks for each RaZ (dont say me you could use only one task cause the goal was to learn). My code is as following, the eventgroup has been put as a global variable :
In main() :
~~~
/* Create tasks
/
xTaskCreate(
IncVar_Timer, / Function pointer
/
“Task1”, / Task name – for debugging only
/
configMINIMAL_STACK_SIZE, / Stack depth in words
/
(void) NULL, /* Pointer to tasks arguments (parameter)
/
1, / Task priority
/
NULL / Task handle */
);
xTaskCreate(
DetectLimitReach,
"Task2",
configMINIMAL_STACK_SIZE,
(void*) NULL,
1,
NULL);
xTaskCreate(
RaZsec_IPC,
"Task3",
configMINIMAL_STACK_SIZE,
(void*) NULL,
1,
&Task_sec);
xTaskCreate(
RaZmin_IPC,
"Task4",
configMINIMAL_STACK_SIZE,
(void*) NULL,
1,
&Task_min);
xTaskCreate(
RaZheure_IPC,
"Task5",
configMINIMAL_STACK_SIZE,
(void*) NULL,
1,
&Task_heure);
/* Start the RTOS Scheduler */
vTaskStartScheduler();
/* HALT */
while(1);
Tasks : (their prototype has been written before the main)
void IncVar_Timer(void *pvParameters){
while (1) {
vTaskDelay(1000 / portTICK_RATE_MS);
secondes += 1;
}
vTaskDelete(NULL);
}
void DetectLimitReach(void *pvParameters){
ComptFin_Group = xEventGroupCreate(); //nom du EventGroup
if (ComptFin_Group == NULL)
{ while (1); }//fatal error
while (1) {
if(secondes>=3)
{
ComptFin = xEventGroupSetBits(
ComptFin_Group,
( 1 << 0 ));
}
if(minutes>=2)
{
ComptFin = xEventGroupSetBits(
ComptFin_Group,
( 1 << 1 ));
}
if(heures>=2)
{
ComptFin = xEventGroupSetBits(
ComptFin_Group,
( 1 << 2 ));
}
vTaskDelay(400 / portTICK
RATEMS);
}
vTaskDelete(NULL);
}
void RaZsec_IPC(void *pvParameters) {
EventBits_t ComptFin;
while (1) {
ComptFin = xEventGroupWaitBits(
ComptFin_Group,
( 1 << 0 ),
pdTRUE,
pdTRUE,
portMAX_DELAY );
secondes = 0;
minutes += 1;
}
vTaskDelete(NULL);
}
void RaZmin_IPC(void *pvParameters) {
EventBits_t ComptFin;
while (1) {
ComptFin = xEventGroupWaitBits(
ComptFin_Group,
( 1 << 1 ),
pdTRUE,
pdTRUE,
portMAX_DELAY );
minutes = 0;
heures += 1;
}
vTaskDelete(NULL);
}
void RaZheure_IPC(void *pvParameters) {
EventBits_t ComptFinn;
while (1) {
ComptFin = xEventGroupWaitBits(
ComptFin_Group,
( 1 << 2 ),
pdTRUE,
pdTRUE,
portMAX_DELAY );
heures = 0;
}
vTaskDelete(NULL);
}
~~~
Actualy my problem is as following : the flag needed for RaZheure
IPC is up, but the tasks never goes out from the blocking state.
I know how to fix the problem : create the task IncVarTimer in last or put her at a higher priority.
To prevent any problem from that cause in future projetcs, I would like to find what causes it, but actualy I don’t get why this fix works nor why I have this problem.
Any idea ?
[RB edited for formatting]