FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [December 2006 Threads] Generic ISR dispatch routinePosted 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) { portENTER_SWITCHING_ISR(); unsigned portBASE_TYPE prevTopPriority = TopPriority();
ISRDispatch();
portEXIT_SWITCHING_ISR(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 routinePosted 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 routinePosted 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.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|