Ucos ii Task Management II: restore a task
After a task is suspended, it needs to be restored and called to be executed again.
Ostaskresume () function implementation. Like ostasksuspend (), only one parameter is required to call ostaskresume (), that is, the priority. For example, ostaskresume (5) is a task with a recovery priority of 5.
Int8u ostaskresume (int8u PRIO) |
{ |
OS _tcb * ptcb; |
|
|
If (PRIO> = OS _lowest_prio) {(1) |
Return (OS _prio_invalid ); |
} |
OS _enter_critical (); |
If (ptcb = ostcbpriotbl [PRIO]) = (OS _tcb *) 0) {(2) |
OS _exit_critical (); |
Return (OS _task_resume_prio ); |
} Else { |
If (ptcb-> ostcbstat & OS _stat_suspend) {(3) |
If (ptcb-> ostcbstat & = ~ OS _stat_suspend) = OS _stat_rdy) & (4) |
(Ptcb-> ostcbdly = 0) {(5) |
Osrdygrp | = ptcb-> ostcbbity; (6) |
Osrdytbl [ptcb-> ostcby] | = ptcb-> ostcbbitx; |
OS _exit_critical (); |
Ossched (); (7) |
} Else { |
OS _exit_critical (); |
} |
Return (OS _no_err ); |
} Else { |
OS _exit_critical (); |
Return (OS _task_not_suincluded ); |
} |
} |
} |
The implementation of task recovery is basically a reverse operation of task suspension.
Because ostasksuspend () cannot suspend idle tasks, you must ensure that your applications are not restoring idle tasks [(1)]. Note: This test also ensures that the user is not performing a task with a recovery priority of OS _prio_self (OS _prio_self is defined as 0xff, which is always larger than OS _lowest_prio ).
The task to be restored must exist because the task control block OS _tcb [(2)] that you want to operate on must be suspended [(3)]. Ostaskresume () cancels the pending [(4)] by clearing the OS _stat_suspend bit in the ostcbstat field. To make the task ready, the OS _tcbdly field must be 0 [(5)], because there is no mark in ostcbstat that the task is waiting for the delay to expire. The task is ready only when both of the preceding conditions are met [(6)]. Finally, the task scheduler checks whether the priority of the recovered task is higher than that of the task that calls this function [
(7)].
The most important of these two statements are:
Osrdygrp | = ptcb-> ostcbbity;
Osrdytbl [ptcb-> ostcby] | = ptcb-> ostcbbitx;
The role of the program is to re-Add the task to the ready table.