# taskYIELD in an ISR

**URL:** <https://forums.freertos.org/t/taskyield-in-an-isr/670>\
**Category:** Kernel\
**Created:** [October 7, 2011, 1:08am UTC](https://forums.freertos.org/t/taskyield-in-an-isr/670 "2011-10-07T01:08:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlafleur](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tlafleur](https://forums.freertos.org/u/tlafleur)\
**Post date:** [October 7, 2011, 1:08am UTC](https://forums.freertos.org/t/taskyield-in-an-isr/670/1 "2011-10-07T01:08:00Z")

</div>

**[tlafleur](https://sourceforge.net/u/tlafleur/)** wrote on [Friday, October 07, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/17242342/#b0f0):

In the dsPIC33 demo, the serial driver interrupt routine has a taskYIELD, but in the Using the FreeRTOS Real Time Kernel, Sep 2011 edition (for the PIC32) stated that only API that end with FromISR are allowed in ISR… why is this an exception?? and not documented??

thanks…

also, in Microchips MPLAB Ver 8.76 there is a FreeRTOS&nbsp; viewing tool for displaying information on the current program… It display information on Task and CoRoutines, but never on Queues???&nbsp; is it outdated??

void \_\_attribute\_\_((\_\_interrupt\_\_, auto\_psv)) \_U2RXInterrupt( void )  
{  
char cChar;  
portBASE\_TYPE xHigherPriorityTaskWoken = pdFALSE;

/\* Get the character and post it on the queue of Rxed characters.  
If the post causes a task to wake force a context switch as the woken task  
may have a higher priority than the task we have interrupted. \*/  
IFS1bits.U2RXIF = serCLEAR\_FLAG;  
while( U2STAbits.URXDA )  
{  
cChar = U2RXREG;  
xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );  
}

if( xHigherPriorityTaskWoken != pdFALSE )  
{  
taskYIELD();  
}  
}

---

<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:** [October 7, 2011, 7:53am UTC](https://forums.freertos.org/t/taskyield-in-an-isr/670/2 "2011-10-07T07:53:43Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, October 07, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/17242342/#52bf):

> In the dsPIC33 demo, the serial driver interrupt routine has a taskYIELD, but in the Using the FreeRTOS Real Time Kernel, Sep 2011 edition (for the PIC32) stated that only API that end with FromISR are allowed in ISR

The PIC32 book is for the PIC32, which in architecture terms is about as far away from a dsPIC as you can get.&nbsp; Why would it talk about an exception for a dsPIC any more than it would for a Cortex-M3?

Not calling a function that does not end in FromISR from an ISR is a very good general rule in all cases.&nbsp; Some, but not many, ports can tolerate taskYIELD() being called from an ISR, provided it is the last instruction in the ISR.&nbsp; In most cases, where this is the case, the call to taskYIELD() is hidden behind a macro called portYIELD\_FROM\_ISR(), or portEND\_SWITCHING\_ISR().&nbsp; The PIC24/dsPIC port is rather old, and that is probably why it was not done in that case.&nbsp; The documentation page for that port ([http://www.freertos.org/portpic24\_dspic.html)](http://www.freertos.org/portpic24_dspic.html%29) does however say how it is done, albeit rather briefly.

> also, in Microchips MPLAB Ver 8.76 there is a FreeRTOS&nbsp; viewing tool for displaying information on the current program… It display information on Task and CoRoutines, but never on Queues???&nbsp; is it outdated??

See configQUEUE\_REGISTRY\_SIZE on [http://www.freertos.org/a00110.html](http://www.freertos.org/a00110.html) and  
[http://www.freertos.org/vQueueAddToRegistry.html](http://www.freertos.org/vQueueAddToRegistry.html)

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 14, 2011, 3:37am UTC](https://forums.freertos.org/t/taskyield-in-an-isr/670/3 "2011-10-14T03:37:43Z")

</div>

**[gridsense](https://sourceforge.net/u/gridsense/)** wrote on [Friday, October 14, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/17242342/#d389):

We bought two documents from website, I get confused about “xSemaphoreGiveFromISR()”.

1. In document “FreeRTOS Reference Manual”, in page93,  
&nbsp;&nbsp;&nbsp; void VISR( void \*pvParameters)  
&nbsp;&nbsp;&nbsp; { ……  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; taskYIELD\_FROM\_ISR( xHigherPriorityTaskWoken);  
&nbsp;&nbsp;&nbsp; }

2. In document " Using the RTOS REal Time Kernel" ARM Cortex-M3 Edition, page 93  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp; void vSoftwareInterruptHandler (void)  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; …  
&nbsp;&nbsp;&nbsp;&nbsp; portEND\_SWITCHING\_ISR(xHigherPriorityTaskWoken);  
&nbsp;&nbsp;&nbsp; }.

My question is:  
&nbsp;&nbsp; I can’t find the function prototype for&nbsp;&nbsp; taskYIELD\_FROM\_ISR( ) and&nbsp; portEND\_SWITCHING\_ISR().  
&nbsp;&nbsp;  
Regards  
Samuel

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [October 14, 2011, 3:30pm UTC](https://forums.freertos.org/t/taskyield-in-an-isr/670/4 "2011-10-14T15:30:47Z")

</div>

**[richard\_damon](https://sourceforge.net/u/richard_damon/)** wrote on [Friday, October 14, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/17242342/#a68c):

These are macros in port macro.h (for the appropriate port). The exact method used to end an interrupt depends on the port.
