Events in FreeRTOS 7.1.1

cfreertosrtos

I'm looking for method how to inform one task in firmware about change somewhere else (Using FreeRTOS 7.1.1). I need to receive information about changes, but I wouldn't want check value in cycle – something like interrupts, but coming internal.

For example (in C-like pseudocode)

void task1(int change1)
{
 int value1 = change1;
}

void task2(int change2)
{
 int value2 = change2;
}

void task3(int change3)
{
 int value3 = change3;
}

void taskCheck()
{
  doSomething();
}

And when any value in any task is changed, taskCheck() is activated.

I thought about queues, but I prefered to ask first if there is no better solution.

P.S. There is no Event Bits and Event Group in FreeRTOS 7.1.1

Best Answer

You can use a semaphore to signal an event. If the event is generic to taskCheck and there is no data associated with the event then you might do it something like this.

void task1(int change1)
{
 int value1 = change1;
 xSemaphoreGive(the_semaphore);
}

void task2(int change2)
{
 int value2 = change2;
 xSemaphoreGive(the_semaphore);
}

void task3(int change3)
{
 int value3 = change3;
 xSemaphoreGive(the_semaphore);
}

void taskCheck()
{
  xSemaphoreTake(the_semaphore, WAIT_FOREVER);
  doSomething();
}

If the_semaphore is a counting semaphore then multiple events could stack up while taskCheck handles them one at a time.

But if the events are specific or contain data then you probably want to use a queue instead of a semaphore.

Read about FreeRTOS queues and semaphores here.

Related Topic