# Calling portEND\_SWITCHING\_ISR() with  Cooperative Scheduling.

**URL:** <https://forums.freertos.org/t/calling-portend-switching-isr-with-cooperative-scheduling/7238>\
**Category:** Kernel\
**Created:** [May 31, 2018, 10:27pm UTC](https://forums.freertos.org/t/calling-portend-switching-isr-with-cooperative-scheduling/7238 "2018-05-31T22:27:10Z")\
**Posts on this page:** 4\
**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:** [May 31, 2018, 10:27pm UTC](https://forums.freertos.org/t/calling-portend-switching-isr-with-cooperative-scheduling/7238/1 "2018-05-31T22:27:10Z")

</div>

**[medaver](https://sourceforge.net/u/medaver/)** wrote on [Thursday, May 31, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/95d3765d/#3b76):

I’m running FreeRTOS on the SAMV71 in cooperative mode. I’m having an issue where tasks unexpectedly seem to get preempted.

Will calling portEND\_SWITCHING\_ISR() form an ISR (with xProrityTaskWoken set) cause a lower priority task to get preempted? Or does the lower priority task need to yield before a context switch occurs?

If the lower priority task must yield first, is there any reason to call portEND\_SWITCHING\_ISR() from an ISR when using cooperative scheduling?

---

<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:** [May 31, 2018, 10:53pm UTC](https://forums.freertos.org/t/calling-portend-switching-isr-with-cooperative-scheduling/7238/2 "2018-05-31T22:53:32Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, May 31, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/95d3765d/#3b76/176b):

Calling porEND\_SWITCHING\_ISR() is effectively asking for a yield. Other  
ports call the same macro portYIELD\_FROM\_ISR() (in fact, I thought that  
was what it was called in the Cortex-M7 demo). So yes - calling  
portEND\_SWITCHING\_ISR() will cause a context switch just as calling  
taskYIELD() would from a task.

---

<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:** [June 1, 2018, 2:20am UTC](https://forums.freertos.org/t/calling-portend-switching-isr-with-cooperative-scheduling/7238/3 "2018-06-01T02:20:14Z")

</div>

**[richard\_damon](https://sourceforge.net/u/richard_damon/)** wrote on [Friday, June 01, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/95d3765d/#0094):

In some ways, if premption is turned off, portEND\_SWITCHING\_ISR() should be created as an empty macro, so that the decision to use premption automatically get reflected in the ISRs.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 4, 2018, 4:48pm UTC](https://forums.freertos.org/t/calling-portend-switching-isr-with-cooperative-scheduling/7238/4 "2018-06-04T16:48:20Z")

</div>

**[medaver](https://sourceforge.net/u/medaver/)** wrote on [Monday, June 04, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/95d3765d/#04ea):

Both portEND\_SWITCHING\_ISR() and portYIELD\_FROM\_ISR() are defined (the same) in the CM7 portmacro.h header.

I created a modifed version of portEND\_SWITCHING\_ISR() that only calls taskYield() if the Idle-Task is the current task (when preemption is turned off).

Thank you for the clarification.
