Search code examples
freertos

What in FreeRTOS's xStreamBufferSendFromISR() makes it "ISR safe"?


The FreeRTOS docs:
https://www.freertos.org/xStreamBufferSendFromISR.html
has the generic NOTE which says the function is safe for use in an ISR but it doesn't explain why.
What is in this function that's not in xStreamBufferSend() which makes it ISR safe?


Solution

  • This is explained in the Chapter 6 of the FreeRTOS book:

    The Interrupt Safe API

    Often it is necessary to use the functionality provided by a FreeRTOS API function from an interrupt service routine (ISR), but many FreeRTOS API functions perform actions that are not valid inside an ISR—the most notable of which is placing the task that called the API function into the Blocked state; if an API function is called from an ISR, then it is not being called from a task, so there is no calling task that can be placed into the Blocked state. FreeRTOS solves this problem by providing two versions of some API functions; one version for use from tasks, and one version for use from ISRs. Functions intended for use from ISRs have “FromISR” appended to their name.