当前位置: 代码迷 >> 单片机 >> 相熟FREERTOS+arm的进
  详细解决方案

相熟FREERTOS+arm的进

热度:25   发布时间:2016-04-28 15:08:46.0
熟悉FREERTOS+arm的进
本帖最后由 zlb21 于 2014-01-09 23:09:12 编辑
STM32开发板
__asm void vPortSVCHandler( void )
{
PRESERVE8

ldr r3, =pxCurrentTCB /* Restore the context. */
ldr r1, [r3] /* Use pxCurrentTCBConst to get the pxCurrentTCB address. */
ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */
ldmia r0!, {r4-r11} /* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */
msr psp, r0 /* Restore the task stack pointer. */
mov r0, #0
msr basepri, r0
orr r14, #0xd
bx r14
}
/*-----------------------------------------------------------*/

__asm void vPortStartFirstTask( void )
{
PRESERVE8

/* Use the NVIC offset register to locate the stack. */
ldr r0, =0xE000ED08
ldr r0, [r0]
ldr r0, [r0]
/* Set the msp back to the start of the stack. */
msr msp, r0
/* Globally enable interrupts. */
cpsie i
/* Call SVC to start the first task. */
svc 0
nop
}
标红的地方,就是我的疑问

SVC 0实现软中断,此时下一个指令地址写入R14,
vPortSVCHandler就是软中断处理函数,为什么要执行这句orr r14, #0xd 之后进行跳转呢?
还有就是svc 0之后为什么要加NOP呢,请大师帮我解答下,先谢谢啦
PS:
对了还有就是我用JTAG调试查看SVC 0 后的R14是FFFFFFF9异或后为FFFFFFD,跳转也可以没有地址访问异常


------解决方案--------------------
通常用OS,用移植好的很少查低层,,,
------解决方案--------------------
svc 0
nop
现在的cpu都是多流水的,前一个指令执行的时候,后一条指定已经在译码了,所以svc 0后面必须跟条指令,不让cpu译码的时候出错就行

orr r14, #0xd
bx r14
当r14为0xFFFFFFFX,执行是中断返回指令,cortext-m3的做法,X的bit0为1表示返回thumb状态,bit1和bit2分别表示返回后sp用msp还是psp、以及返回到特权模式还是用户模式

有本书叫做 cortex-m3权威指南,既然搞M3,那本书是必读的
  相关解决方案