REXIS Use of Cortex-M Exceptions

In addition to the SysTick timer, REXIS makes use of the Cortex PendSV interrupt to perform context-switching, and the SVC instruction for making kernel API calls. Both of these are described below.

REXIS kernel code always runs in handler (exception) mode, which is entered through different exceptions, and uses the system stack pointer.

REXIS user tasks run in thread mode, and each task has its own stack using the process stack pointer.

Interrupt handlers, including user-written ones, run in exception mode, and use the same system stack pointer as the REXIS kernel.

To summarize, REXIS kernel code runs in Cortex-M exception handlers:

·         System tick interrupt. This occurs every 10 milliseconds by default. If a task runs the entire duration of its time-slice (5 ticks, or 50 milliseconds), then the scheduler is called to find a new task to run. To perform the actual context-switching, the scheduler sets the PendSV related bits in the NVIC.

·         A PendSV interrupt happens as a result of the scheduler’s actions. This performs the actual context-switching, as described above.

·         REXIS API calls (e.g. REXIS_TaskCreate) use the SVC instruction to enter the handler mode and run the kernel code. By running in an exception handler, other interrupts (including the SysTick timer preemption) cannot interrupt its operations, which protect critical kernel resources against data corruption. REXIS kernel code is written efficiently so as to minimize the kernel overhead, and also to minimize the impact on the response time to peripheral interrupts.

Depending on the API being called, the SVC handler may return, may unblock another task, or may put the current task into the blocked state. In the latter two cases, the scheduler is called to find a new task to run.

·         Peripheral interrupt handlers may call kernel API with names ending with “FromISR”. These are normal function calls to the kernel code without SVC exceptions (which cannot work due to the CPU is already running in exception mode).