TSK_setpri
Application Program Interface
2-503
C Interface
Syntax
oldpri = TSK_setpri(task, newpri);
Parameters
TSK_Handle task;
/* task object handle */
Int
newpri;
/* task’s new priority */
Return Value
Int
oldpri;
/* task’s old priority */
Description
TSK_setpri sets the execution priority of task to newpri, and returns that
task’s old priority value. Raising or lowering a task’s priority does not
necessarily force preemption and re-scheduling of the caller: tasks in the
TSK_BLOCKED mode remain suspended despite a change in priority;
and tasks in the TSK_READY mode gain control only if their (new) priority
is greater than that of the currently executing task.
The maximum value of newpri is TSK_MAXPRI(15). If the minimum value
of newpri is TSK_MINPRI(0). If newpri is less than 0, the task is barred
from further execution until its priority is raised at a later time by another
task; if newpri equals TSK_MAXPRI, execution of the task effectively
locks out all other program activity, except for the handling of interrupts.
The current task can change its own priority (and possibly preempt its
execution) by passing the output of TSK_self as the value of the task
parameter.
A context switch occurs when calling TSK_setpri if a task makes its own
priority lower than the priority of another currently ready task, or if the
currently executing task makes a ready task’s priority higher than its own
priority. TSK_setpri can be used for mutual exclusion.
Constraints and
Calling Context
❏
newpri must be less than or equal to TSK_MAXPRI.
❏
The task cannot be TSK_TERMINATED.
❏
The new priority should not be zero (0). This priority level is reserved
for the TSK_idle task.
See Also
TSK_setpri
Set a task’s execution priority