R_RTOS  0.1
DistributedRealTimeOperatingSystemfortheARMCortexMArchitecture
R_RTOS_PendSV.S File Reference

PendSV service routine - Context Switch. More...

Variables

globl _offsetOfTskState thumb_func align globl PendSV_Handler weak PendSV_Handler type PendSV_Handler
 Context switching. More...
 

Detailed Description

PendSV service routine - Context Switch.

Author
Christian Neuberger (Neube.nosp@m.rger.nosp@m.Ch503.nosp@m.44@t.nosp@m.h-nue.nosp@m.rnbe.nosp@m.rg.de)
Date
11.12.2015

The PendSV exception occurs as soon as it is called by setting its pending flag. Therefore it can be used as a software interrupt. Its use case here is to make a context switch from (if existing) the current task (p_cur_tsk_tcb) to task scheduled to run next (p_nxt_tsk_tcb).

Variable Documentation

globl _offsetOfTskState thumb_func align globl PendSV_Handler weak PendSV_Handler type function PendSV_Handler

Context switching.

First the stackpointer has to be extracted from the pointer to the TskTCB. The stack has to be unstacked according to the stack frame. Since the exception stack frame only saves the lower registers (r0-r3 and r12) the upper registers (r7-r11) have to saved by hand. In order not to falsify the register's content they are saved in groups of four (using already saved r0-r3).

After saving the context of the current task, the pointer to the current task has to be changed to point to the next task (p_nxt_tst_tcb). The new task's context has to be restored/created using its stack (thus its context contained in the stack frame). The unstacking process works analog to the stacking process described above.

After restoring/creating the next task's context, a branch instruction to the link register's content will set the program counter to the next task's function.