ISR/xHigherPriorityTaskWoken/invoke context switch - non default?

Hi,

Thank you for your quick reply.

The second link should probably be FreeRTOS FAQ - FreeRTOS API - FreeRTOS

Here is my summary, which might be added to the FAQ:

Q:

• Why do APIs for exclusive use in ISRs set pxHigherPriorityTaskWoken rather than perform a context switch?

A:

• demand to automatically call the context switch isn’t very high

• backwards compatibility
– we’d need yet another config value (not a fan of even more config values)

• don’t enforce unique behaviours across ISRs
– you may want certain ISRs to cause a context switch always, others you may want to perform a context switch only under certain conditions (see FAQ below)

• deal with irregular (hardware/ISR) behaviours across ports - the context switch may need to be called at the end, it may not
– for some processors, you need to wait until the end of the ISR to do that operation, as it will actually switch to the new task right there and then and not wait for the ISR to return
– if the only processors to be supported did the switch by pending an interrupt that only happens when all ISRs have returned, this wouldn’t have been needed
– some FreeRTOS features are port-specific and might not be applicable on all ports/processors
– different ports handle the scheduling differently
· In some ports, the call to portYIELD_FROM_ISR will immediately go to the scheduler and it will then go to that task,
· stopping in the middle of the ISR
· the ISR is really running in the context of the task that was interrupted,
· just as if it had a subroutine call at that point
· this means the rest of the ISR code won’t run until that task gets its next chance to run,
· and since the whole point of putting code into an ISR is to get it to run right away,
· that tends not to be what you want
· On machines where portYIELD_FROM_ISR just sets a pending interrupt bit at the lowest priority,
· then yes, that could have been done in the FreeRTOS functions,
· but then FreeRTOS could not be run on machines which don’t work that way,
· and one goal of FreeRTOS was to support a wide variety of platforms

• (from FreeRTOS FAQ):

• in summary, it empowers the application writer to decide if a context switch is necessary, and in so doing, enables the application writer to prevent unnecessary context switch thrashing
• as an example, imagine a simple interrupt service routine that receives strings character by character
– rather than performing a context switch after each character it might be more efficient to perform a context switch only once the entire string has been received

• See full discussion here:
FromISR/FROM_ISR

• Another post here:
Why don't do the context switch in the internal of the API ended with FromISR? - #5 by richard-damon

• FreeRTOS FAQ:
FreeRTOS FAQ - FreeRTOS API - FreeRTOS

Regards,

Robert