Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


Yielding from ISR on preemptive vs cooperative

Posted by ecab on February 24, 2017


I have been using FreeRTOS on cooperative mode on an Atmel SAMA5D3 Xplained for a while and wanted to check how my system behaved with a preemptive scheme when I came up with this problem and wanted to share the way I circumvented it so maybe you can think about adding this to future versions.

First I realized that in order for preemptive to work as I wanted it to work I had to end every interruption with a portYIELD_FROM_ISR( xHigherPriorityTaskWoken). Otherwise I had some problems when an interrupt happened when in IDLE (it would not switch to the higher priority task and stay in IDLE for the rest of the tick).

So I added this to every interruption and everything worked fine. Then I switched back to cooperative changing the value of configUSE_PREEMPTION (not removing the portYIELD_FROM_ISR call) and got this behaviour:


In this screenshot I have the green task running with low priority. The orange task is a deferred interrupt handler and the ISR just sends a notification to this task so it wakes up. The problem for me is since it is in cooperative I would like it to return from the ISR to the green task (I'd have to remove the portYIELD_FROM_ISR) so if I want to smoothly switch between the two desired behaviours (preemptive and cooperative) I would have to add something like this to the end of every interrupt:

~~~ if (configUSEPREEMPTION == 1) { portENDSWITCHING_ISR( xHigherPriorityTaskWoken); } ~~~

Since this is a hassle I created the macros that can be seen in the following screenshots to add to the end of the interrupts so I can just change the value of configUSE_PREEMPTION to switch between the desired behaviours.

http://imgur.com/ZfzYWSJ http://imgur.com/aPOt382

1- Is there already a way to do this and I haven't seen it? And if there isn't, would you consider adding something like this to future versions?

2- Am I the only one expecting this behaviour?

3- Do you see any side effects for this?


EDIT: Image Links

Yielding from ISR on preemptive vs cooperative

Posted by rtel on February 24, 2017

I'm not sure if you are reporting a problem, or that the behaviour is just not what is necessary in your particular application.

I don't think we would add something like the macros you have created as I've not come across this scenario before - when switching between co-operative and pre-emptive would be done more than once. Starting co-operative, and then changing to pre-emptive later, or the other way around, are normal, but switching back and forth is not. Also, as you have shown if users want to do that then it is easy enough for them to put in the pre-processor guards themselves.

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists