0
0
FreeRTOSprogramming~30 mins

Task notification vs queue performance in FreeRTOS - Hands-On Comparison

Choose your learning style9 modes available
Task Notification vs Queue Performance in FreeRTOS
📖 Scenario: You are working on a FreeRTOS embedded system where tasks communicate with each other. You want to compare the performance of two common methods: task notifications and queues.This project will help you understand how to set up tasks, send data using task notifications and queues, and measure the time taken for each method.
🎯 Goal: Build a FreeRTOS program that creates two tasks: a sender and a receiver. The sender will send data to the receiver using task notifications and then using a queue. You will measure and compare the time taken for each communication method.
📋 What You'll Learn
Create a task notification based communication between two tasks
Create a queue based communication between two tasks
Measure the time taken for sending and receiving messages using both methods
Print the timing results to the console
💡 Why This Matters
🌍 Real World
Embedded systems often need efficient communication between tasks. Choosing the right method can improve responsiveness and reduce CPU load.
💼 Career
Understanding FreeRTOS task notifications and queues is essential for embedded software engineers working on real-time applications like IoT devices, automotive systems, and industrial controllers.
Progress0 / 4 steps
1
Create tasks and basic setup
Create two FreeRTOS tasks called SenderTask and ReceiverTask. Also, create a queue called messageQueue that can hold 5 integers. Use xTaskCreate for tasks and xQueueCreate for the queue.
FreeRTOS
Need a hint?

Use xQueueCreate(5, sizeof(int)) to create the queue. Use xTaskCreate to create tasks with a stack size of 1000 and priority 1.

2
Add a variable to hold the test count
Create an integer variable called testCount and set it to 1000. This will be the number of messages sent in each test.
FreeRTOS
Need a hint?

Declare int testCount = 1000; outside of any function so both tasks can access it.

3
Implement sending and receiving using task notifications and queues
In SenderTask, send integers from 0 to testCount - 1 to ReceiverTask using xTaskNotifyGive and ulTaskNotifyTake. Then send the same integers using xQueueSend and receive them with xQueueReceive in ReceiverTask. Use ulTaskNotifyTake(pdTRUE, portMAX_DELAY) to wait for notifications. Use vTaskDelay of 1 tick between sends to avoid flooding. Use vTaskDelay of 1 tick in receiver loop as well.
FreeRTOS
Need a hint?

Use xTaskNotifyGive(receiverHandle) to notify the receiver. Use ulTaskNotifyTake(pdTRUE, portMAX_DELAY) in receiver to wait. Use xQueueSend and xQueueReceive for queue communication. Add vTaskDelay(1) between sends and receives to avoid flooding.

4
Measure and print timing results
Add timing measurements using TickType_t start, end and xTaskGetTickCount() before and after sending and receiving loops for both task notifications and queue. Calculate elapsed ticks and print the results using printf. Print exactly these lines:
"Task Notification time: X ticks"
"Queue time: Y ticks" where X and Y are the elapsed ticks for each method.
FreeRTOS
Need a hint?

Use xTaskGetTickCount() before and after loops to measure elapsed ticks. Use printf to print results exactly as:
Task Notification time: X ticks
Queue time: Y ticks.