Reading jyiu book on Cortex-M4 and general information about usage of PendSV exception type.
One application highlighted is of context switching in the RTOS wherein on a Systick timer interrupt, instead of context switching, it will set the PendSV bit. This will then execute the context switching at the lowest priority after all other interrupts have been handled. Again this is because the priority of PendSV will be kept the lowest.
However, is the same not possible if we just lower down the priority of Systick timer exception? In that case, if any interrupt is active, the systick timer exception handler will get executed after all other interrupts are done with.
If that is possible, then what is the major benefit in using PendSV?
Am I missing something?
Thank you yasuhikokoumoto
Yes that is correct that it is kind of asynchronous trap/exception. But I wonder the same purpose may be achieved using low priority Systick. Or there may be some more uses of the pendsv which I have not understood.
There is another example for non-OS based systems like you can split a long running ISR in two parts. First you execute the high priority work in the main ISR and then rest of the low priority work can be postponed to PendSV handler. This makes sense.
You could achieve something similar by setting the priority of Systick to be very low. But there is a danger in that. The system tick timer is usually one of the most important events in the system and needs servicing with short latency as much of the functionality of the system will depend on it (context switches, task scheduling, watchdogs etc). If you set the priority very low then its latency will inevitably increase as it will have to wait for all other interrupts to be serviced before it is handled. But, for something like a context switch, the important thing is to capture that a context switch needs to occur, the context switch itself can usually wait for other urgent tasks to complete. This is what PendSV allows you to do - the Systick timer can be set to have high priority so it is serviced with very low latency and then time-consuming operations (like a context switch) can be pended to occur later.
I hope that makes sense.
Chris
Thank you Chris. That is good explanation. Basically since Systick can be used for other purpose as well in addition to the context switching, it makes sense not to disturb the execution times of those things done in Systick.