# FromISR functions outside of the ISR context

**URL:** <https://forums.freertos.org/t/fromisr-functions-outside-of-the-isr-context/6429>\
**Category:** Kernel\
**Created:** [February 23, 2017, 9:04pm UTC](https://forums.freertos.org/t/fromisr-functions-outside-of-the-isr-context/6429 "2017-02-23T21:04:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 23, 2017, 9:04pm UTC](https://forums.freertos.org/t/fromisr-functions-outside-of-the-isr-context/6429/1 "2017-02-23T21:04:24Z")

</div>

**[lpmay](https://sourceforge.net/u/lpmay/)** wrote on [Thursday, February 23, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/f36e532c/#8aae):

I’m looking for clarification whether it is safe to call “FromISR” functions from outside an ISR. Below is the broader context of what I’m trying to do that is leading to this question.

I’m writing a software module which uses time from a RTC. My module has a task which consumes commands from a queue (very similar to the software timers in FreeRTOS). One of the functions in my API is called to indicate an RTC alarm went off, and loads a command into the queue. I want to abstract my module to work with several RTCs. If it is an internal RTC, this alarm function will likely be called from an ISR context and I would use the “FromISR” functions. However, if I’m using an external RTC, the interrupt source may have to be read over I2C or another slow bus before I can categorize it as the alarm going off - something I do not want to do in the ISR context. If my code still calls the “FromISR” functions in this case can that corrupt the kernel? I could #define my way through this, but I’d prefer to limit the amount of configuration users need to put in to use this code.

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [February 23, 2017, 9:35pm UTC](https://forums.freertos.org/t/fromisr-functions-outside-of-the-isr-context/6429/2 "2017-02-23T21:35:56Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, February 23, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/f36e532c/#8aae/f92f):

> I’m looking for clarification whether it is safe to call “FromISR”  
> functions from outside an ISR.

Yes…and no, depending on the port you are using.

You need to be careful with critical sections. If the port you are  
using supports interrupt nesting then you are probably ok, otherwise you  
will have to implement the portSET\_INTERRUPT\_MASK\_FROM\_ISR() and  
portCLEAR\_INTERRUPT\_MASK\_FROM\_ISR() macros in such a way that they can  
be used from both an interrupt and a task.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 24, 2017, 4:50pm UTC](https://forums.freertos.org/t/fromisr-functions-outside-of-the-isr-context/6429/3 "2017-02-24T16:50:13Z")

</div>

**[lpmay](https://sourceforge.net/u/lpmay/)** wrote on [Friday, February 24, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/f36e532c/#ff85):

Hi, thanks for the reply.

After thinking about it some more, I think I’ll mirror the FreeRTOS API and have normal and “FromISR” versions of the function and leave it up to the user to call the appropriate one.

Thanks for the help!
