uC /OS-II中任务的挂起和恢复
2015-03-28 14:40
399 查看
任务的挂起
1.定义:什么是挂起一个任务?
所谓任务的挂起,就是停止这个任务的运行
2.方法:如何挂起一个任务?
通过调用系统提供的
OSTaskSuspend ()函数来挂起自身或除空闲任务之外的其他任务。
3.函数分析
/* ********************************************************************************************************* * SUSPEND A TASK * * Description: This function is called to suspend a task. The task can be the calling task if the * priority passed to OSTaskSuspend() is the priority of the calling task or OS_PRIO_SELF. * * Arguments : prio is the priority of the task to suspend. If you specify OS_PRIO_SELF, the * calling task will suspend itself and rescheduling will occur. * * Returns : OS_NO_ERR if the requested task is suspended * OS_TASK_SUSPEND_IDLE if you attempted to suspend the idle task which is not allowed. * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF. * OS_TASK_SUSPEND_PRIO if the task to suspend does not exist * * Note : You should use this function with great care. If you suspend a task that is waiting for * an event (i.e. a message, a semaphore, a queue ...) you will prevent this task from * running when the event arrives. ********************************************************************************************************* */ #if OS_TASK_SUSPEND_EN > 0 INT8U OSTaskSuspend (INT8U prio) { #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ OS_CPU_SR cpu_sr; #endif BOOLEAN self; OS_TCB *ptcb; #if OS_ARG_CHK_EN > 0 if (prio == OS_IDLE_PRIO) { /* Not allowed to suspend idle task */ return (OS_TASK_SUSPEND_IDLE); } if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) { /* Task priority valid ? */ return (OS_PRIO_INVALID); } #endif OS_ENTER_CRITICAL(); if (prio == OS_PRIO_SELF) { /* See if suspend SELF */ prio = OSTCBCur->OSTCBPrio; self = TRUE; } else if (prio == OSTCBCur->OSTCBPrio) { /* See if suspending self */ self = TRUE; } else { self = FALSE; /* No suspending another task */ } ptcb = OSTCBPrioTbl[prio]; if (ptcb == (OS_TCB *)0) { /* Task to suspend must exist */ OS_EXIT_CRITICAL(); return (OS_TASK_SUSPEND_PRIO); } if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) { /* Make task not ready */ OSRdyGrp &= ~ptcb->OSTCBBitY; } ptcb->OSTCBStat |= OS_STAT_SUSPEND; /* Status of task is 'SUSPENDED' */ OS_EXIT_CRITICAL(); if (self == TRUE) { /* Context switch only if SELF */ OS_Sched(); } return (OS_NO_ERR); } #endif
相关文章推荐
- uc/os-ii任务的挂起与恢复
- 【iCore4 双核心板_uC/OS-II】例程三:任务的挂起与恢复
- uC/OS-II 学习笔记之:任务挂起与恢复,调度器上锁与解锁!
- UC/OS基础知识之任务的挂起和恢复
- 【iCore3 双核心板_ uC/OS-III】例程三:任务的挂起与恢复
- UC/OS II 任务管理(5)之任务删除、阻塞和恢复
- uC/OS-II 中的任务
- uC/OS-II 学习笔记:任务堆栈
- uC/OS-II 学习笔记:任务创建步骤
- uC/OS-II的任务切换总结
- uC/OS-II 函数之任务相关函数
- uC/OS II任务就绪表
- uC/OS-II 学习笔记之:任务堆栈
- uC/OS-II 学习笔记:任务控制块ECB
- [uC/OS-II]基本操作:新建任务,分配信号量
- uC/OS-II互斥信号量与任务优先级反转
- 嵌入式上UC/OS - II使用注意点------任务调度
- UC/OS-II的任务切换
- uc/os-ii删除任务
- uC/OS-II任务机制理解