This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Question about application of PendSV

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?

Parents
  • 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

Reply
  • 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

Children