0
0
FreeRTOSprogramming~3 mins

Why ISR-safe API functions (FromISR suffix) in FreeRTOS? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if your program crashes just because it tried to talk inside an interrupt the wrong way?

The Scenario

Imagine you have a program that reacts to hardware events like button presses or sensor signals. These events happen anytime, and your program must respond quickly. If you try to update shared data or send messages from these event handlers (called Interrupt Service Routines or ISRs) using normal functions, things can go wrong.

The Problem

Using regular functions inside ISRs can cause your program to freeze or crash because those functions might wait for resources or disable interrupts, which is not allowed during an interrupt. This makes your system unreliable and hard to debug.

The Solution

FreeRTOS provides special ISR-safe API functions with the suffix 'FromISR' designed to be called safely inside ISRs. These functions avoid waiting or blocking and handle critical sections properly, so your program stays stable and responsive.

Before vs After
Before
xQueueSend(queue, &data, portMAX_DELAY);
After
xQueueSendFromISR(queue, &data, &higherPriorityTaskWoken);
What It Enables

It allows your program to safely communicate and synchronize between interrupts and tasks without risking crashes or delays.

Real Life Example

When a sensor triggers an interrupt, you can quickly send its data to a processing task using 'FromISR' functions, ensuring the system stays fast and stable.

Key Takeaways

Normal API calls can cause problems inside interrupts.

'FromISR' functions are specially made to be safe in ISRs.

Using them keeps your system reliable and responsive.