#if OS_TASK_SUSPEND_EN > 0
INT8U OSTaskSuspend (INT8U prio)
{
#if OS_CRITICAL_METHOD == 3
OS_CPU_SR cpu_sr;
#endif
BOOLEAN self;
OS_TCB *ptcb; //ptcb保存prio的任務(wù)控制塊
#if OS_ARG_CHK_EN > 0
if (prio == OS_IDLE_PRIO) { //不能將空閑任務(wù)掛起
return (OS_TASK_SUSPEND_IDLE);
}
if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) { //判斷優(yōu)先級的有效性
return (OS_PRIO_INVALID);
}
#endif
OS_ENTER_CRITICAL();
//如果掛起任務(wù)自身,獲得當前任務(wù)的優(yōu)先級
if (prio == OS_PRIO_SELF) {
prio = OSTCBCur->OSTCBPrio;
self = TRUE;
//如果掛起的任務(wù)是當前正在運行的任務(wù),也即要掛起任務(wù)自身
} else if (prio == OSTCBCur->OSTCBPrio) {
self = TRUE;
} else {
self = FALSE;
}
//ptcb獲得要刪除的任務(wù)控制塊,如果刪除的任務(wù)為空,則返回OS_TASK_SUSPEND_PRIO
if ((ptcb = OSTCBPrioTbl[prio]) == (OS_TCB *)0) {
OS_EXIT_CRITICAL();
return (OS_TASK_SUSPEND_PRIO);
}
//從就緒表中將該任務(wù)刪除,即修改OSRdyTbl[]和OSRdyGrp的值
if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) {
OSRdyGrp &= ~ptcb->OSTCBBitY;
}
ptcb->OSTCBStat |= OS_STAT_SUSPEND; //將當前任務(wù)的狀態(tài)設(shè)置為OS_STAT_SUSPEND
OS_EXIT_CRITICAL();
if (self == TRUE) { //如果正在執(zhí)行任務(wù)掛起自身,則需要進行任務(wù)調(diào)度,獲得優(yōu)先級最高任務(wù)
OS_Sched();
}
return (OS_NO_ERR);
}
#endif