
CHAPTER 13 SERVICE CALLS
User’s Manual U14833EJ2V0UM
130
Change Task Priority
chg_pri/ichg_pri
[Overview]
Changes the priority of a task
[C format]
#include <kernel.h>
ER chg_pri(ID tskid, PRI tskpri);
[Parameters]
I/O
Parameter
Description
I
ID
tskid
ID number of task whose priority is to be changed
I
PRI
tskpri
Priority after change
[Explanation]
The base priority of the task specified by tskid is changed to the value specified by tskpri. If TSK_SELF = 0 is set
for tskid, the task itself is the target of the service call.
An integer of 1 or higher is specified for tskpri; the lower the value, the higher the priority. The maximum specifiable
value (lowest priority) is the one specified at configuration. By specifying TPRI_INI = 0 for tskpri, it is also possible to
make the base priority after the change the same as the activation priority specified when the task was created.
If the target task is not locking a mutex, the base priority and the current priority are the same, and therefore the
current priority of the target task also changes to tskpri. If the target task is locking a mutex with the attribute
TA_INHERIT or TA_CEILING and a priority lower than the task’s current priority is specified, it is possible that only the
base priority will change (i.e., the current priority will not change). Also if this service call is issued to a task locking a
mutex with the attribute TA_CEILING and the specified priority is higher than the top priority of the mutex, an error
occurs, and the error code E_ILUSE is returned.
If the target task is in the running or ready state, the task shifts to the bottom of the corresponding priority section
of the ready queue. Even if the priority before chg_pri was issued is the same as that after the change, the task is still
moved to the bottom of the ready queue. It is therefore possible to make a task relinquish the right to use the CPU by
making the task itself the target, specifying the same priority as the current one, and issuing chg_pri. Note that if
chg_pri is issued to a task in the running or ready state while dispatch is disabled, ready queue manipulation is the
only processing performed, and the task in the running state continues processing.