0
0
FreeRTOSprogramming~30 mins

ISR-to-task notification pattern in FreeRTOS - Mini Project: Build & Apply

Choose your learning style9 modes available
ISR-to-task notification pattern
📖 Scenario: You are building a simple embedded system using FreeRTOS. The system has a button connected to an interrupt. When the button is pressed, the interrupt service routine (ISR) should notify a task to handle the button press event.
🎯 Goal: Create a FreeRTOS program where an ISR notifies a task using the ISR-to-task notification pattern. The task will print a message when it receives the notification.
📋 What You'll Learn
Create a task called ButtonTask that waits for a notification.
Create an ISR called ButtonISR that sends a notification to ButtonTask.
Use ulTaskNotifyTake in the task to wait for the notification.
Use xTaskNotifyGiveFromISR in the ISR to notify the task.
Print "Button pressed!" in the task when notified.
💡 Why This Matters
🌍 Real World
This pattern is used in embedded systems where hardware interrupts need to signal tasks to perform work without blocking the ISR.
💼 Career
Embedded software engineers use ISR-to-task notifications to write responsive and efficient real-time applications.
Progress0 / 4 steps
1
Create the ButtonTask task
Create a FreeRTOS task called ButtonTask that runs the function vButtonTask. Inside vButtonTask, write an infinite loop with no code inside yet.
FreeRTOS
Need a hint?

Use xTaskCreate to create the task and vTaskStartScheduler to start FreeRTOS.

2
Add a notification wait in ButtonTask
Inside the infinite loop of vButtonTask, add a call to ulTaskNotifyTake(pdTRUE, portMAX_DELAY) to wait indefinitely for a notification from the ISR.
FreeRTOS
Need a hint?

ulTaskNotifyTake blocks the task until a notification is received.

3
Create the ButtonISR to notify the task
Create an ISR function called ButtonISR that calls xTaskNotifyGiveFromISR to notify ButtonTask. Use a global variable xButtonTaskHandle to store the task handle. Also, declare xButtonTaskHandle as a global variable and assign it when creating the task in main.
FreeRTOS
Need a hint?

Use xTaskNotifyGiveFromISR to notify the task safely from the ISR.

4
Print message when notified in ButtonTask
Modify vButtonTask so that after ulTaskNotifyTake returns, it prints "Button pressed!" using printf.
FreeRTOS
Need a hint?

Use printf("Button pressed!\n") to show the message when the task is notified.