0
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ Why can you not upgrade to the latest version of FreeRTOS, where you may have the option of using direct to task notifications? \$\endgroup\$
    – Richard
    Commented May 15, 2015 at 7:15

1 Answer 1

2
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.