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


Generic ISR dispatch routine

Posted by Glen B. on December 24, 2006
In order to have a single generic ISR dispatch routine, I have added a function to tasks.c that returns the priority of the highest priority ready task.

unsigned portBASE_TYPE TopPriority(void)
return uxTopReadyPriority;

My generic dispatch routine captures this priority before dispatching to the proper ISR. When the ISR returns, it tests whether the highest priority has changed. If so, it calls for a context switch, else it doesn't.

void PortIRQDispatch(void)

unsigned portBASE_TYPE prevTopPriority = TopPriority();



I wonder if anyone has any comments on issues/problems this may raise.

One point is that this subverts time slicing between tasks of equal priority. Using <= rather than < in the final test would be similar to time slicing, although not quite the same.

RE: Generic ISR dispatch routine

Posted by Nobody/Anonymous on December 24, 2006
I'm not sure I follow the object of this code, what you are trying to achieve?

If you want to only cause a switch to another task when there is a task of higher priority than the running task then you could add the code to vTaskSwitchContext in tasks.c to only execute the while loop if the top ready priority is greater than the running priority.

If this is just to have commonality in your IRQs and to prevent the application writer having to use the ENTER/EXIT macros then I think the code is good. You of coarse have a few little expenses in an extra layer of indirection. Also you are going to save and restore the context even when the task does not need it saved and restored. Each IRQ in the system will save the context.

Different ports handle this in different ways. Some only save the context when a switch is actually required which is really nice as this is the most optimal. From the macros you quote I assume you are using the ARM port. This itself uses two different techniques. Looking at the STR750 (and I think the ARM9) ports you will see that there is an IRQ wrapper written in assembler that saves the context before calling the IRQ C function, then restores it again prior to exiting the ASM wrapper (on completion of the interrupt). The portEND_SWITCHING_ISR macro then becomes a simple call to vTaskSwitchContext() if a switch is required. Take a look at the port page for STR750/RIDE at the section "Interrupt service routines".

RE: Generic ISR dispatch routine

Posted by Glen B. on December 24, 2006
I am using an LPC2xxx. The VIC priority vectored interrupts and the FIQ interrupt are handled separately and each in there own way. In my case, they all operate outside the realm of FreeRTOS, never triggering context switches.

My PortIRQDispatch() is the common routine entered off of the VIC default IRQ. All of these have to go through such a common handler. So it can perform operations common to all of the default vector ISRs. I was looking for a common way of determining if a context switch was required on exiting the ISR.

I really don't like to tamper with FreeRTOS, so I look for ways to work with it with as few changes as possible. My TopPriority() function added into tasks.c seemed like a pretty inocuous change that gave me what I wanted. But I wonder if others might have tried a similar stunt and run into some subtle 'gotcha'.

In this particular case, I'm not sure tampering vTaskSwitchContext() would be a good thing to do. I think it would mean that taskYIELD() wouldn't perform as expected.

Thanks for the feedback.

[ 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