STM32汇编的MSP、PSP和SP的区别
最近在看freeRTOS的移植,发现它的堆栈访问代码跟51和x86区别比较大,网上搜到的资料说MSP、PSP、SP、R13都可以访问堆栈。其中MSP对应Main堆栈、PSP对应Process堆栈,那么如果我直接使用SP、R13呢,这个时候这么知道是PSP还是MSP?
附上freeRTOS的任务切换代码:
__asm void xPortPendSVHandler( void )
{
extern uxCriticalNesting;
extern pxCurrentTCB;
extern vTaskSwitchContext;
PRESERVE8
mrs r0, psp
isb
ldr r3, =pxCurrentTCB /* Get the location of the current TCB. */
ldr r2,
stmdb r0!, {r4-r11} /* Save the remaining registers. */
str r0, /* Save the new top of stack into the first member of the TCB. */
stmdb sp!, {r3, r14}
mov r0, #configMAX_SYSCALL_INTERRUPT_PRIORITY
msr basepri, r0
dsb
isb
bl vTaskSwitchContext
mov r0, #0
msr basepri, r0
ldmia sp!, {r3, r14}
ldr r1,
ldr r0, /* The first item in pxCurrentTCB is the task top of stack. */
ldmia r0!, {r4-r11} /* Pop the registers and the critical nesting count. */
msr psp, r0
isb
bx r14
nop
}
/*-----------------------------------------------------------*/
12年前我用LPC2132时纯汇编写程序,那时好像没有见过MSP 和PSP 这两位,可能是后加的宏吧?
至于R13就是SP ,正如R15就是PC 是同一单元
页:
[1]