3

Both PendSV and SVCall are called from the software - SVCall by calling svc instruction, PendSV by setting particural register of Cortex-M. PendSV is intended for context switching and SVCall is intended to access OS kernel functions and device drivers.

  1. What determines that PendSV is used for context switching? Why doesn't SVCall do it? As far as I know it is possible to configure the priority of SVCall to the low value.
  2. What are the device drivers, that we cannot acces beyond the SVCall, in the Thread mode in spite of handler? Does it also apply to FreeRTOS? I've never used SVC in order to interact with hardware.
  3. PendSV stands for Pendable Service and SVCall stands for Supervisor Call, why they are name like that? What is the origin?

I would like to know something more than "PendSV is used for context switching and SVCall is used for enabling the scheduler". I couldn't find more informations.

Cheers

Bratw
  • 141
  • 8
  • These are very good questions please update the thread if you get any answer from other sources. – Gábor Jan 24 '23 at 03:57

3 Answers3

1

PendSV is used to pend an service call. It can be pended from interrupt and will occur on the exit from the interrupt. If you do an SVC call from an interrupt you will get a hard fault.

SVC calls are immediate, PendSV leaves it pending until it can execute.

SVC calls are only required to interact with the HW when using unprivileged code. For example when using the MPU, the user code should generally be unprivileged. In order to access anything privileged then it needs to be done via an SVC call.

Realtime Rik
  • 1,632
  • 10
  • 22
1

I think the designed usages are different.

ARM Cortex-M has two modes, thread mode and handler mode. Using the Memory Protection Module (MPU) memory addresses will normally be placed off limits in thread mode. A thread of operating code therefore needs a way to enter interrupt mode. This is done using the SVC instruction which in turn places the processor in handler mode with the MPU turned off.

Cortex-M has prioritized interrupts to allow true realtime behaviour. This allows interrupt handler to run immediately on an interrupt and run time critical code. Most of the time a lot of processing can take place (and therefore should take place) later. This is what the PendSV interrupt is for. It is can operate at lower priority and run once any other pending interrupts have been attended to. On this this is called the "bottom half" of the interrupt controller. Scheduling is one of these lower priority tasks. Scheduling a PendSV is not something a non-privileged thread will be allowed to do.

doron
  • 27,972
  • 12
  • 65
  • 103
0

PendSV is an interrupt-driven request for systerm-lever service. In an OS environment, use PendSV for context switching when no other exception is active. The context switching must happen during the return from an interrupt, such as Systick. But PendSV is not that special for context switching, in principle you could use any other asynchronous exception or interrupt for the purpose of context switching.