0
0
FreeRTOSprogramming~30 mins

ISR-safe API functions (FromISR suffix) in FreeRTOS - Mini Project: Build & Apply

Choose your learning style9 modes available
Using ISR-safe API functions with FromISR suffix in FreeRTOS
📖 Scenario: You are programming a microcontroller using FreeRTOS. You want to safely send data from an interrupt service routine (ISR) to a task without causing problems in your program.
🎯 Goal: Build a simple program that creates a queue, sets up a variable to track if a context switch is needed, uses the ISR-safe function xQueueSendFromISR to send data from an ISR, and then prints the result.
📋 What You'll Learn
Create a queue called myQueue that can hold 5 integers.
Create a variable called higherPriorityTaskWoken of type BaseType_t and initialize it to pdFALSE.
Use xQueueSendFromISR to send the integer 100 to myQueue from an ISR context, passing &higherPriorityTaskWoken as the last argument.
Print the return value of xQueueSendFromISR.
💡 Why This Matters
🌍 Real World
In embedded systems, interrupts happen asynchronously. Using ISR-safe API functions like those with the FromISR suffix ensures safe communication between interrupts and tasks without causing crashes or data corruption.
💼 Career
Embedded software engineers often write interrupt handlers that must interact with FreeRTOS tasks safely. Knowing how to use FromISR functions is essential for writing reliable real-time applications.
Progress0 / 4 steps
1
Create a queue called myQueue
Create a queue called myQueue using xQueueCreate that can hold 5 integers.
FreeRTOS
Need a hint?

Use xQueueCreate with 5 as the number of items and sizeof(int) as the size of each item.

2
Create a variable higherPriorityTaskWoken
Create a variable called higherPriorityTaskWoken of type BaseType_t and set it to pdFALSE.
FreeRTOS
Need a hint?

Use BaseType_t type and initialize with pdFALSE.

3
Send data from ISR using xQueueSendFromISR
Use xQueueSendFromISR to send the integer 100 to myQueue from an ISR context. Pass &higherPriorityTaskWoken as the last argument and store the return value in a variable called result.
FreeRTOS
Need a hint?

Declare an integer variable with value 100, then call xQueueSendFromISR with the queue, address of the integer, and address of higherPriorityTaskWoken.

4
Print the result of xQueueSendFromISR
Print the value of the variable result using printf.
FreeRTOS
Need a hint?

Use printf to print the text and the value of result. The function xQueueSendFromISR returns pdTRUE (1) on success.