2021年4月8日星期四

Cortex M0+ MSP/PSP Context Switching

I am using a NXP S32K118 Cortex M0+ processor

I have a "scheduler" function used to call different tasks and i need to do the following:

  • Use the main stack pointer (MSP) for this "scheduler" function

  • Use the process stack pointer (PSP) for a list of scheduled tasks, that are called from this scheduler function.

I have 3 stacks defined in ram ( main stack, secondary stack 1, secondary stack 2 ). The idea is that the scheduler function uses the main stack, and the scheduled tasks that are called from here use the secondary stack 1 or secondary stack 2, so i need to switch from MSP to PSP when i´m in the scheduer, before calling the corresponding task, and switch back from PSP to MSP once the corresponding task is completed and im back on the scheduler.

I know how to do the switch of these pointers writing to PSP/MSP/CONTROL registers, but the problem I have is i dont know how to do this context switch / what i need to do in addition of simply changing stack pointers in order to keep all the stacks working properly, so im here just finding for any help/tips if anyone knows how to implement this properly.

https://stackoverflow.com/questions/67001374/cortex-m0-msp-psp-context-switching April 08, 2021 at 05:42PM

没有评论:

发表评论