Challenge - 5 Problems
Event Group Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediateWhy use event groups in FreeRTOS?
In FreeRTOS, event groups help tasks coordinate by setting and waiting for bits. What is the main reason tasks use event groups to coordinate?
Attempts:
2 left
💡 Hint
Think about how event groups use bits to signal multiple events at once.
✗ Incorrect
Event groups let tasks wait for one or more bits to be set, allowing efficient coordination of multiple events in a single variable.
❓ Predict Output
intermediateOutput of event group synchronization example
Given the following FreeRTOS code snippet, what will be the output printed by the task waiting on the event group?
FreeRTOS
EventGroupHandle_t xEventGroup = xEventGroupCreate();
void vTask1(void *pvParameters) {
xEventGroupSetBits(xEventGroup, (1 << 0));
vTaskDelay(pdMS_TO_TICKS(100));
xEventGroupSetBits(xEventGroup, (1 << 1));
vTaskDelete(NULL);
}
void vTask2(void *pvParameters) {
EventBits_t uxBits = xEventGroupWaitBits(
xEventGroup,
(1 << 0) | (1 << 1),
pdTRUE,
pdTRUE,
portMAX_DELAY
);
if ((uxBits & ((1 << 0) | (1 << 1))) == ((1 << 0) | (1 << 1))) {
printf("Both bits set\n");
} else {
printf("Bits not set\n");
}
vTaskDelete(NULL);
}Attempts:
2 left
💡 Hint
Consider the order and timing of bits being set and waited on.
✗ Incorrect
Task1 sets bit 0, then after 100ms sets bit 1. Task2 waits for both bits to be set before continuing, so it prints "Both bits set".
🔧 Debug
advancedIdentify the error in event group usage
What is the error in the following FreeRTOS code snippet that uses event groups to coordinate tasks?
FreeRTOS
EventGroupHandle_t xEventGroup;
void vTask1(void *pvParameters) {
xEventGroupSetBits(xEventGroup, (1 << 0));
vTaskDelete(NULL);
}
void vTask2(void *pvParameters) {
EventBits_t bits = xEventGroupWaitBits(xEventGroup, (1 << 0), pdTRUE, pdFALSE, portMAX_DELAY);
if (bits & (1 << 0)) {
printf("Bit 0 received\n");
}
vTaskDelete(NULL);
}
int main(void) {
vTaskStartScheduler();
return 0;
}Attempts:
2 left
💡 Hint
Check if the event group handle is initialized before use.
✗ Incorrect
The event group handle xEventGroup is declared but never created with xEventGroupCreate(), so it is NULL and causes a crash when used.
📝 Syntax
advancedCorrect syntax for waiting on multiple event bits
Which option shows the correct syntax to wait for bits 0 and 2 to be set in a FreeRTOS event group, clearing the bits on exit and waiting for both bits?
Attempts:
2 left
💡 Hint
Use bitwise OR to combine bits and set clear on exit and wait for all bits flags correctly.
✗ Incorrect
To wait for bits 0 and 2, combine with bitwise OR. pdTRUE for clear on exit and pdTRUE for wait for all bits.
🚀 Application
expertHow event groups improve task coordination efficiency
In a FreeRTOS system with multiple tasks waiting on different events, why are event groups more efficient than using multiple binary semaphores for coordination?
Attempts:
2 left
💡 Hint
Think about how waiting on multiple events with one call compares to waiting on many semaphores separately.
✗ Incorrect
Event groups let tasks wait for multiple events at once, reducing the number of blocking calls and context switches, which improves efficiency.
