📖 Scenario: Imagine you have two tasks in a FreeRTOS system: one reads sensor data, and the other processes it. They need to work together smoothly. Event groups help these tasks know when to start and stop by sharing signals.
🎯 Goal: You will create two tasks that coordinate using an event group. One task will set an event bit when data is ready, and the other will wait for that event bit before processing the data.
📋 What You'll Learn
Create an event group called dataEventGroup
Create two tasks: SensorTask and ProcessingTask
In SensorTask, set event bit 0x01 when data is ready
In ProcessingTask, wait for event bit 0x01 before processing
Print messages to show when each task runs
💡 Why This Matters
🌍 Real World
In real embedded systems, sensors and processors must work together without missing signals. Event groups help tasks wait for each other safely.
💼 Career
Understanding event groups is important for embedded software developers working on real-time systems like IoT devices, automotive controls, and industrial machines.
Progress0 / 4 steps
1
Create the event group
Create an event group called dataEventGroup using xEventGroupCreate().
FreeRTOS
Hint
Use xEventGroupCreate() to make a new event group and assign it to dataEventGroup.
2
Create the two tasks
Create two tasks called SensorTask and ProcessingTask using xTaskCreate(). Use empty functions for now.
FreeRTOS
Hint
Define two functions named SensorTask and ProcessingTask. Then create them with xTaskCreate().
3
Set and wait for event bits
In SensorTask, set event bit 0x01 using xEventGroupSetBits(dataEventGroup, 0x01). In ProcessingTask, wait for event bit 0x01 using xEventGroupWaitBits(dataEventGroup, 0x01, pdTRUE, pdFALSE, portMAX_DELAY).
FreeRTOS
Hint
Use xEventGroupSetBits() in SensorTask to signal data ready. Use xEventGroupWaitBits() in ProcessingTask to wait for that signal.
4
Print messages to show coordination
Add printf statements in SensorTask to print "SensorTask: Data ready" after setting the event bit, and in ProcessingTask to print "ProcessingTask: Processing data" after waiting for the event bit.
FreeRTOS
Hint
Use printf to show when each task runs after setting or waiting for the event bit.
Practice
(1/5)
1. What is the main purpose of event groups in FreeRTOS?
easy
A. To handle hardware interrupts directly
B. To create new tasks dynamically
C. To let tasks wait for or signal events using bits
D. To manage memory allocation
Solution
Step 1: Understand event groups role
Event groups use bits to represent events that tasks can wait for or signal.
Step 2: Compare with other options
Creating tasks, managing memory, and handling interrupts are different FreeRTOS features.
Final Answer:
To let tasks wait for or signal events using bits -> Option C
Quick Check:
Event groups coordinate tasks by signaling bits [OK]
Hint: Event groups use bits to sync tasks quickly [OK]
Common Mistakes:
Confusing event groups with task creation
Thinking event groups manage memory
Assuming event groups handle interrupts
2. Which of the following is the correct way to create an event group in FreeRTOS?
easy
A. vEventGroupCreate()
B. xEventGroupCreate()
C. xCreateEventGroup()
D. vCreateEventGroup()
Solution
Step 1: Recall FreeRTOS naming conventions
Functions returning handles usually start with 'x' and create functions end with 'Create'.
Step 2: Identify correct function
The correct function to create an event group is xEventGroupCreate().
Final Answer:
xEventGroupCreate() -> Option B
Quick Check:
Event group creation uses xEventGroupCreate() [OK]
Hint: Creation functions start with 'x' and end with 'Create' [OK]
Common Mistakes:
Using 'v' prefix which is for void functions
Swapping function name order
Assuming event groups are created with task functions