void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
/* Prepare TCB and saved context for a first time start of a task. */
U32 *stk,i,size;
/* Prepare a complete interrupt frame for first task start */
size = p_TCB->priv_stack >> 2;
//这里为什么要除以4?
if (size == 0) {
size = (U16)os_stackinfo >> 2;
}
/* Write to the top of stack. */
stk = &p_TCB->stack[size];
/* Auto correct to 8-byte ARM stack alignment. */
if ((U32)stk & 0x04) {
//-1把不对齐部分跳过
stk--;
}
stk -= 16;
/* Default xPSR and initial PC */
stk[15] = INITIAL_xPSR;
//xPSR
stk[14] = (U32)task_body;
//RL
/* Clear R1-R12,LR registers. */
for (i = 0; i < 14; i++) {
//这是R1~R13?
stk = 0;
}
/* Assign a void pointer to R0. */
stk[8] = (U32)p_TCB->msg;
//这是R0?
/* Initial Task stack pointer. */
p_TCB->tsk_stack = (U32)stk;
//任务栈起始位置
/* Task entry point. */
p_TCB->ptask = task_body;
//任务函数体
/* Set a magic word for checking of stack overflow. */
p_TCB->stack[0] = MAGIC_WORD;
//栈溢出测量字
} |