简体   繁体   中英

PendSV and SVCall in RTOS

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM