如下这个是ucos_iii的源码---改变任务优先级函数,大神能在下面的几个地方给小弟讲解一下吗?感谢了~~~
void OSTaskChangePrio (OS_TCB *p_tcb,
OS_PRIO prio_new,
OS_ERR *p_err)
{
CPU_BOOLEAN self;
CPU_SR_ALLOC(); /*问题1:将CPU状态寄存器的值保存起来,我想问:什么时候需要保存这个值?每次调用函数都需要?*/
#ifdef OS_SAFETY_CRITICAL/*问题2:这段代码是什么意思?我找不到它的定义~~~*/
if (p_err == (OS_ERR *)0) {
OS_SAFETY_CRITICAL_EXCEPTION();
return;
}
#endif
#if OS_CFG_CALLED_FROM_ISR_CHK_EN > 0u/*问题3:不能在ISR中创建一个任务,那在中断中具体可以做些什么呢?*/
if (OSIntNestingCtr > (OS_NESTING_CTR)0) {
*p_err = OS_ERR_TASK_CHANGE_PRIO_ISR;
return;
}
#endif
if (prio_new >= (OS_CFG_PRIO_MAX - 1u)) {
*p_err = OS_ERR_PRIO_INVALID;
return;
}
if (p_tcb == (OS_TCB *)0) { /*问题4:这个任务控制块的指针指向空时啥意思?我看源码上的注释是"self",为什么这样就是指向自己呢?*/
CPU_CRITICAL_ENTER();
p_tcb = OSTCBCurPtr;
CPU_CRITICAL_EXIT();
self = DEF_TRUE;
} else {
self = DEF_FALSE;
}
OS_CRITICAL_ENTER();
switch (p_tcb->TaskState) {
case OS_TASK_STATE_RDY:
OS_RdyListRemove(p_tcb);
p_tcb->Prio = prio_new;
OS_PrioInsert(p_tcb->Prio);
if (self == DEF_TRUE) {
OS_RdyListInsertHead(p_tcb);
} else {
OS_RdyListInsertTail(p_tcb);
}
break;
case OS_TASK_STATE_DLY:
case OS_TASK_STATE_SUSPENDED:
case OS_TASK_STATE_DLY_SUSPENDED:
p_tcb->Prio = prio_new;
break;
case OS_TASK_STATE_PEND:
case OS_TASK_STATE_PEND_TIMEOUT:
case OS_TASK_STATE_PEND_SUSPENDED:
case OS_TASK_STATE_PEND_TIMEOUT_SUSPENDED:
switch (p_tcb->PendOn) {
case OS_TASK_PEND_ON_TASK_Q:
case OS_TASK_PEND_ON_TASK_SEM:
case OS_TASK_PEND_ON_FLAG:
p_tcb->Prio = prio_new;
break;
case OS_TASK_PEND_ON_MUTEX:
case OS_TASK_PEND_ON_MULTI:
case OS_TASK_PEND_ON_Q:
case OS_TASK_PEND_ON_SEM:
OS_PendListChangePrio(p_tcb,
prio_new);
break;
default:
break;
}
break;
default:
OS_CRITICAL_EXIT();
*p_err = OS_ERR_STATE_INVALID;
return;
}
OS_CRITICAL_EXIT_NO_SCHED();
OSSched();
*p_err = OS_ERR_NONE;
}
#endif
帮你调整一下对齐。但是感觉怎么多了一个endif?
哦,多了一个endif是因为
#if OS_CFG_TASK_CHANGE_PRIO_EN > 0u
#endif
这个我没加上
哪位大神不惜赐教,帮我分析下这段代码,感激万分~~~