0
0
FreeRTOSprogramming~5 mins

Event-driven architecture in FreeRTOS - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Event-driven architecture
O(n)
Understanding Time Complexity

When using event-driven architecture in FreeRTOS, tasks wait for events to happen before running. We want to understand how the time to handle events changes as more events occur.

How does the system's work grow when more events are sent and processed?

Scenario Under Consideration

Analyze the time complexity of the following code snippet.


// Task waits for events and processes them
void vEventTask(void *pvParameters) {
    EventBits_t uxBits;
    for (;;) {
        uxBits = xEventGroupWaitBits(xEventGroup, EVENT_1 | EVENT_2, pdTRUE, pdFALSE, portMAX_DELAY);
        if (uxBits & EVENT_1) {
            // Handle EVENT_1
        }
        if (uxBits & EVENT_2) {
            // Handle EVENT_2
        }
    }
}
    

This task waits for one or more events and then processes each event that occurred.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: The infinite loop that waits for events and processes them.
  • How many times: The loop runs forever, processing events as they come.
How Execution Grows With Input

Each time an event occurs, the task wakes and processes it. If more events happen at once, the task processes each one in turn.

Input Size (number of events)Approx. Operations
11 event processed
55 events processed
1010 events processed

Pattern observation: The work grows directly with the number of events to handle.

Final Time Complexity

Time Complexity: O(n)

This means the time to process events grows linearly with the number of events received.

Common Mistake

[X] Wrong: "The task processes all events instantly, so time does not grow with more events."

[OK] Correct: Each event needs some time to be handled, so more events mean more total processing time.

Interview Connect

Understanding how event-driven tasks scale helps you design responsive and efficient embedded systems. This skill shows you can think about system behavior as workload changes.

Self-Check

"What if the task handled events using multiple smaller tasks instead of one? How would the time complexity change?"