# Example of using xSemaphoreGiveFromISR in both ISR and a task

**URL:** <https://forums.freertos.org/t/example-of-using-xsemaphoregivefromisr-in-both-isr-and-a-task/3639>\
**Category:** Kernel\
**Created:** [August 14, 2015, 11:55pm UTC](https://forums.freertos.org/t/example-of-using-xsemaphoregivefromisr-in-both-isr-and-a-task/3639 "2015-08-14T23:55:17Z")\
**Posts on this page:** 2\
**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:** [August 14, 2015, 11:55pm UTC](https://forums.freertos.org/t/example-of-using-xsemaphoregivefromisr-in-both-isr-and-a-task/3639/1 "2015-08-14T23:55:17Z")

</div>

**[danbeadle](https://sourceforge.net/u/danbeadle/)** wrote on [Friday, August 14, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/9da89653/#c031):

I want to create a generic object that can protect its resource. In my case, it is a SPI channel object. I need to be able to call this from either a normal task or from an ISR.

I saw a post from 2009, but didn’t understand the reply.

Alternatively, is there a way to determine at run time if a function has been invoked from a task or from an ISR?

---

<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:** [August 15, 2015, 7:28am UTC](https://forums.freertos.org/t/example-of-using-xsemaphoregivefromisr-in-both-isr-and-a-task/3639/2 "2015-08-15T07:28:57Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Saturday, August 15, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/9da89653/#c7b1):

I can only answer your question with a question - which port are you using?
