单步调试追踪,发现在初始化空闲任务OS_InitTaskIdle时,程序执行到任务创建函数OSTaskCreateExt()的
err = OS_TCBInit(prio, psp, pbos, id, stk_size, pext, opt);(初始化任务控制块)处。
不知道是不是移植过程中任务切换和任务堆栈没有处理好,附上任务切换和任务堆栈相关代码:
OSCtxSw
POPX.W R12 ; Pop lower 16 bits of PC.
POPX.W R13 ; Pop upper 4 bits of PC.
PUSHX.W R12 ; Save lower 16 bits of PC.
RLAM.A #4, R13 ; Save SR + upper 4 bits of PC.
RLAM.A #4, R13
RLAM.A #4, R13
MOVX.W SR, R12
ADDX.A R13, R12
PUSHX.W R12
PUSHM.A #12, R15 ; Save R4-R15.
MOVX.A &OSTCBCur, R13 ; OSTCBCur->OSTCBStkPtr = SP
MOVX.A SP, 0(R13)
CALLA #OSTaskSwHook
MOVX.B &OSPrioHighRdy, R13 ; OSPrioCur = OSPrioHighRdy
MOVX.B R13, &OSPrioCur
MOVX.A &OSTCBHighRdy, R13 ; OSTCBCur = OSTCBHighRdy
MOVX.A R13, &OSTCBCur
MOVX.A @R13, SP ; SP = OSTCBHighRdy->OSTCBStkPtr
POPM.A #12, R15 ; Restore R4-R15.
RETI ; Return from interrupt.
OS_STK *OSTaskStkInit (void (*task)(void *pd), void *p_arg, OS_STK *ptos, INT16U opt)
{
INT16U tmp;
INT16U *top;
opt = opt;
top = (INT16U *)ptos;
top--;
*top-- = (INT16U) ((INT32U)task & 0xFFFF); /* Interrupt return pointer */
tmp = (INT32U)(((INT32U)task & 0xF0000) >> 4);
*top-- = (INT16U)0x0008 | tmp; /* Status register */
*top-- = (INT16U)0x0015; //R4L(H) R4寄存器低字节的高4位
// *top-- = (INT16U)0x1515;
*top-- = (INT16U)0x0014; // //R4L(L) R4寄存器低字节的低4位
// *top-- = (INT16U)0x1414;
*top-- = (INT16U)0x0013;
*top-- = (INT16U)0x1313;
*top-- = (INT16U)((INT32U)p_arg >> 16); /* Pass 'p_arg' through register R12 */
*top-- = (INT16U)((INT32U)p_arg && 0xFFFF); /* Pass 'p_arg' through register R12 */
*top-- = (INT16U)0x0011;
// *top-- = (INT16U)0x1111;
*top-- = (INT16U)0x0010;
*top-- = (INT16U)0x1010;
*top-- = (INT16U)0x0009;
*top-- = (INT16U)0x0909;
*top-- = (INT16U)0x0008;
*top-- = (INT16U)0x0808;
*top-- = (INT16U)0x0007;
*top-- = (INT16U)0x0707;
*top-- = (INT16U)0x0006;
*top-- = (INT16U)0x0606;
*top-- = (INT16U)0x0005;
*top-- = (INT16U)0x0505;
*top-- = (INT16U)0x0004;
*top = (INT16U)0x0404;
return ((OS_STK *)top);
} |