0
0
FreeRTOSprogramming~30 mins

Event-driven architecture in FreeRTOS - Mini Project: Build & Apply

Choose your learning style9 modes available
Event-driven Architecture with FreeRTOS
📖 Scenario: You are building a simple embedded system using FreeRTOS. The system should respond to button presses by sending events to a task that processes them. This simulates how event-driven architecture works in real devices.
🎯 Goal: Create a FreeRTOS program that uses an event queue to handle button press events. You will set up the event queue, send events from an interrupt handler, and process them in a task.
📋 What You'll Learn
Create an event queue called eventQueue with space for 5 events
Define an event type ButtonEvent as an integer
Create a task called EventProcessorTask that waits for events from eventQueue
Simulate sending a button press event with value 1 to eventQueue
Print the received event value inside EventProcessorTask
💡 Why This Matters
🌍 Real World
Event-driven architecture is common in embedded systems where tasks react to hardware events like button presses or sensor signals.
💼 Career
Understanding event queues and task communication is essential for embedded software developers working with real-time operating systems like FreeRTOS.
Progress0 / 4 steps
1
Setup Event Queue and Event Type
Create a FreeRTOS queue called eventQueue that can hold 5 integers. Define a type ButtonEvent as int.
FreeRTOS
Need a hint?

Use xQueueCreate to make the queue. The queue holds 5 items of type ButtonEvent.

2
Create Event Processor Task
Write a FreeRTOS task function called EventProcessorTask that waits indefinitely to receive a ButtonEvent from eventQueue. Inside the task, declare a variable event of type ButtonEvent to receive the event.
FreeRTOS
Need a hint?

Use xQueueReceive with portMAX_DELAY to wait forever for an event.

3
Send Button Press Event
Inside the setup function, send a button press event with value 1 to eventQueue using xQueueSend.
FreeRTOS
Need a hint?

Create a variable pressEvent with value 1 and send it to eventQueue with zero wait time.

4
Print Event in Task
Add a main function that calls setup(), creates the EventProcessorTask with priority 1, and starts the FreeRTOS scheduler. The program should print Received event: 1 when the event is processed.
FreeRTOS
Need a hint?

Use xTaskCreate to create the task and vTaskStartScheduler() to start FreeRTOS. The program prints the event when received.