Vignesh
Vignesh

Reputation: 65

Getting info about the sending task from the data in freertos

I am a newbie to FreeRTOS and STM32. And I am working on a project which needs sending data from one task to another. But the receiving task needs to get the info about which task sent the data, because there are multiple tasks in my program. is there any way to get info about sending task from the receiving data in another task in freertos??

Thanks in advance

Upvotes: 0

Views: 341

Answers (1)

aep
aep

Reputation: 1675

Simply use a FreeRTOS Queue. This will allow you to send data from one task to another. One or more tasks can post data to the queue where another task can block until some data arrives to the queue.

The queue can contain data of any type T and FreeRTOS requires you to provide how many items you wish to store in the queue and the size of a single element i.e. sizeof(T).

For your convenience you can simply use the following structure to pass data between the tasks.

typedef struct Data {
  // Basically can be any plain-old-data.
  // Instead you can make a Data a tagged-union of structures as well.
};

typedef struct InterTaskPayload {
  int id; // task identifier
  Data data;
};

By opening up the receiving message, the receiving task can identify the sender(task who post the message) and consume the data.

Upvotes: 3

Related Questions