Acquire Task Priority
ER get_pri(ID tskid, PRI *p_tskpri)
{
if (tskid is TSK_SELF)
Take taskid from Ready Queue[0]
if (Task ID is greater than maximum of Task ID)
return E_ID;
if (called from ISR and specified task id as SELF)
return E_ID;
if (task id is currently running one) {
assign p_tskpri = Running priority from TCB;
return E_OK
}
/* For any other task */
Enter critical section;
Take TCB
if (TCB == NULL)
return E_NOEXS;
if (Task status is Dormat)
return E_OBJ;
assign p_tskpri = Running priority from TCB;
Exit critical section
return E_OK;
}
Reference Task State
ER ref_tsk(ID tskid, T_RTSK *pk_rtsk)
{
if (Task ID is greater than maximum of Task ID)
return E_ID;
Enter critical section;
if (tskid is TSK_SELF)
Take taskid from Ready Queue[0]
Take TCB
if (TCB == NULL)
return E_NOEXS;
Fill out following information from TCB
pk_rtsk->tskpri
pk_rtsk->tskbpri
pk_rtsk->actcnt
Take task status from TCB
if (status is Dormant) {
Exit critical section
pk_rtsk->tskstat = TTS_DMT;
Fill out all other fields with Zero.
return E_OK;
}
Assign pk_rtsk->wupcnt from TCB;
if (status is Ready) {
if (Task is currently running) {
exit critical sections
Fill pk_rtsk->tskstat = TTS_RUN;
Fill suspension count as zero
} else /* Not currently running */ {
Take suspension status from TCB
Exit critical section
Fill pk_rtsk->suscnt with the suspension count
If (task is not suspended)
Assign task state as TTS_RDY;
else
Assign task state as TTS_SUS;
}
/* Assign the following fields as zero */
pk_rtsk->tskwait = 0;
pk_rtsk->lefttmo = 0;
pk_rtsk->wobjid = 0;
return E_OK;
}
/* Status is not Ready */
if (waiting in timer queue)
assign pk_rtsk->lefttmo = TCB timeout - current system time;
else
assign pk_rtsk->lefttmo = TMO_FEVR;
if (waiting in dlt_tsk call)
pk_rtsk->wobjid = 0;
else
pk_rtsk->wobjid = Take the object id from the saved context;
Take suspension status
Exit critical section
Assign pk_rtsk->suscnt with suspension count
if (status is suspended)
pk_rtsk->tskstat = WAITING state ;
else
pk_rtsk->tskstat = WAITING SUSPENDED state;
Assign pk_rtsk->tskwait with WAITING Resource type
return E_OK;
}
Simplified Reference Task State
ER ref_tst(ID tskid, T_RTST *pk_rtst)
{
if (Task ID is greater than maximum of Task ID)
return E_ID;
Enter critical section;
if (tskid is TSK_SELF)
Take taskid from Ready Queue[0]
Take TCB
if (TCB == NULL)
return E_NOEXS;
Take task status from TCB
if (status is Dormant) {
Exit critical section
pk_rtsk->tskstat = TTS_DMT;
Fill out all other fields with Zero.
return E_OK;
}
if (status is Ready) {
if (Task is currently running) {
exit critical sections
Fill pk_rtsk->tskstat = TTS_RUN;
} else /* Not currently running */ {
Take suspension status from TCB
Exit critical section
If (task is not suspended)
Assign task state as TTS_RDY;
else
Assign task state as TTS_SUS;
}
/* Assign the following fields as zero */
pk_rtsk->tskwait = 0;
return E_OK;
}
Take suspension status
Exit critical section
Assign pk_rtsk->suscnt with suspension count
if (status is suspended)
pk_rtsk->tskstat = WAITING state ;
else
pk_rtsk->tskstat = WAITING SUSPENDED state;
Assign pk_rtsk->tskwait with WAITING Resource type
return E_OK;
}
ER get_pri(ID tskid, PRI *p_tskpri)
{
if (tskid is TSK_SELF)
Take taskid from Ready Queue[0]
if (Task ID is greater than maximum of Task ID)
return E_ID;
if (called from ISR and specified task id as SELF)
return E_ID;
if (task id is currently running one) {
assign p_tskpri = Running priority from TCB;
return E_OK
}
/* For any other task */
Enter critical section;
Take TCB
if (TCB == NULL)
return E_NOEXS;
if (Task status is Dormat)
return E_OBJ;
assign p_tskpri = Running priority from TCB;
Exit critical section
return E_OK;
}
Reference Task State
ER ref_tsk(ID tskid, T_RTSK *pk_rtsk)
{
if (Task ID is greater than maximum of Task ID)
return E_ID;
Enter critical section;
if (tskid is TSK_SELF)
Take taskid from Ready Queue[0]
Take TCB
if (TCB == NULL)
return E_NOEXS;
Fill out following information from TCB
pk_rtsk->tskpri
pk_rtsk->tskbpri
pk_rtsk->actcnt
Take task status from TCB
if (status is Dormant) {
Exit critical section
pk_rtsk->tskstat = TTS_DMT;
Fill out all other fields with Zero.
return E_OK;
}
Assign pk_rtsk->wupcnt from TCB;
if (status is Ready) {
if (Task is currently running) {
exit critical sections
Fill pk_rtsk->tskstat = TTS_RUN;
Fill suspension count as zero
} else /* Not currently running */ {
Take suspension status from TCB
Exit critical section
Fill pk_rtsk->suscnt with the suspension count
If (task is not suspended)
Assign task state as TTS_RDY;
else
Assign task state as TTS_SUS;
}
/* Assign the following fields as zero */
pk_rtsk->tskwait = 0;
pk_rtsk->lefttmo = 0;
pk_rtsk->wobjid = 0;
return E_OK;
}
/* Status is not Ready */
if (waiting in timer queue)
assign pk_rtsk->lefttmo = TCB timeout - current system time;
else
assign pk_rtsk->lefttmo = TMO_FEVR;
if (waiting in dlt_tsk call)
pk_rtsk->wobjid = 0;
else
pk_rtsk->wobjid = Take the object id from the saved context;
Take suspension status
Exit critical section
Assign pk_rtsk->suscnt with suspension count
if (status is suspended)
pk_rtsk->tskstat = WAITING state ;
else
pk_rtsk->tskstat = WAITING SUSPENDED state;
Assign pk_rtsk->tskwait with WAITING Resource type
return E_OK;
}
Simplified Reference Task State
ER ref_tst(ID tskid, T_RTST *pk_rtst)
{
if (Task ID is greater than maximum of Task ID)
return E_ID;
Enter critical section;
if (tskid is TSK_SELF)
Take taskid from Ready Queue[0]
Take TCB
if (TCB == NULL)
return E_NOEXS;
Take task status from TCB
if (status is Dormant) {
Exit critical section
pk_rtsk->tskstat = TTS_DMT;
Fill out all other fields with Zero.
return E_OK;
}
if (status is Ready) {
if (Task is currently running) {
exit critical sections
Fill pk_rtsk->tskstat = TTS_RUN;
} else /* Not currently running */ {
Take suspension status from TCB
Exit critical section
If (task is not suspended)
Assign task state as TTS_RDY;
else
Assign task state as TTS_SUS;
}
/* Assign the following fields as zero */
pk_rtsk->tskwait = 0;
return E_OK;
}
Take suspension status
Exit critical section
Assign pk_rtsk->suscnt with suspension count
if (status is suspended)
pk_rtsk->tskstat = WAITING state ;
else
pk_rtsk->tskstat = WAITING SUSPENDED state;
Assign pk_rtsk->tskwait with WAITING Resource type
return E_OK;
}
No comments:
Post a Comment