/* _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ Funtion :_bk_sus_tsk Input :struct task *task < task to suspend > Output :void Return :ER < result > Description :suspend a task for btron _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ */ EXPORT ER _bk_sus_tsk(struct task *task) { TSTAT state; ER ercd = E_OK; state = (TSTAT)task->state; if ( !task_alive(state) ) { ercd = ( state == TS_NONEXIST )? E_NOEXS: E_OBJ; goto error_exit; } if ( task == ctxtsk && dispatch_disabled >= DDS_DISABLE ) { ercd = E_CTX; goto error_exit; } if ( task->suscnt == INT_MAX ) { ercd = E_QOVR; goto error_exit; } /* Update suspend request count */ ++task->suscnt; /* Move to forced wait state */ if ( state == TS_READY ) { make_non_ready(task); task->state = TS_SUSPEND; } else if ( state == TS_WAIT ) { task->state = TS_WAITSUS; } error_exit: return ercd; }
/* * Send task event */ SYSCALL ER _tk_sig_tev( ID tskid, INT tskevt ) { UINT evtmsk; TCB *tcb; TSTAT state; ER ercd = E_OK; CHECK_TSKID_SELF(tskid); CHECK_PAR(tskevt >= 1 && tskevt <= 8); evtmsk = (UINT)(1 << (tskevt - 1)); tcb = get_tcb_self(tskid); BEGIN_CRITICAL_SECTION; state = (TSTAT)tcb->state; if ( !task_alive(state) ) { ercd = ( state == TS_NONEXIST )? E_NOEXS: E_OBJ; goto error_exit; } if ( (state & TS_WAIT) != 0 && (tcb->wspec->tskwait & toTTW(evtmsk)) != 0 ) { wait_release_ok_ercd(tcb, (ER)(tcb->tskevt | evtmsk)); } else { tcb->tskevt |= evtmsk; } error_exit: END_CRITICAL_SECTION; return ercd; }
/* * Wakeup task */ SYSCALL ER _tk_wup_tsk( ID tskid ) { TCB *tcb; TSTAT state; ER ercd = E_OK; CHECK_TSKID(tskid); CHECK_NONSELF(tskid); tcb = get_tcb(tskid); BEGIN_CRITICAL_SECTION; state = (TSTAT)tcb->state; if ( !task_alive(state) ) { ercd = ( state == TS_NONEXIST )? E_NOEXS: E_OBJ; } else if ( (state & TS_WAIT) != 0 && tcb->wspec == &wspec_slp ) { wait_release_ok(tcb); } else if ( tcb->wupcnt == INT_MAX ) { ercd = E_QOVR; } else { ++tcb->wupcnt; } END_CRITICAL_SECTION; return ercd; }
/* * Termination of other task */ SYSCALL ER _tk_ter_tsk( ID tskid ) { TCB *tcb; TSTAT state; ER ercd = E_OK; CHECK_TSKID(tskid); CHECK_NONSELF(tskid); tcb = get_tcb(tskid); BEGIN_CRITICAL_SECTION; state = (TSTAT)tcb->state; if ( !task_alive(state) ) { ercd = ( state == TS_NONEXIST )? E_NOEXS: E_OBJ; } else if ( tcb->klocked ) { /* Normally, it does not become this state. * When the state is page-in wait in the virtual memory * system and when trying to terminate any task, * it becomes this state. */ ercd = E_OBJ; } else { _ter_tsk(tcb); make_dormant(tcb); } END_CRITICAL_SECTION; return ercd; }
/* * Suspend task */ SYSCALL ER _tk_sus_tsk( ID tskid ) { TCB *tcb; TSTAT state; ER ercd = E_OK; CHECK_TSKID(tskid); CHECK_NONSELF(tskid); tcb = get_tcb(tskid); BEGIN_CRITICAL_SECTION; state = (TSTAT)tcb->state; if ( !task_alive(state) ) { ercd = ( state == TS_NONEXIST )? E_NOEXS: E_OBJ; goto error_exit; } if ( tcb == ctxtsk && dispatch_disabled >= DDS_DISABLE ) { ercd = E_CTX; goto error_exit; } if ( tcb->suscnt == INT_MAX ) { ercd = E_QOVR; goto error_exit; } /* Update suspend request count */ ++tcb->suscnt; /* Move to forced wait state */ if ( state == TS_READY ) { make_non_ready(tcb); tcb->state = TS_SUSPEND; } else if ( state == TS_WAIT ) { tcb->state = TS_WAITSUS; } error_exit: END_CRITICAL_SECTION; return ercd; }
/* _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ Funtion :_bk_wup_tsk Input :struct task *task < task to wake up > Output :void Return :ER < result > Description :wake up a task for btron _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ */ EXPORT ER _bk_wup_tsk(struct task *task) { ER ercd = E_OK; TSTAT state; state = (TSTAT)task->state; if ( !task_alive(state) ) { ercd = ( state == TS_NONEXIST )? E_NOEXS: E_OBJ; } else if ( (state & TS_WAIT) != 0 && task->wspec == &wspec_slp ) { wait_release_ok(task); } else if ( task->wupcnt == INT_MAX ) { ercd = E_QOVR; } else { ++task->wupcnt; } return(ercd); }
SYSCALL ER i_vsnd_tmb(ID tskid,T_MSG *pk_msg) { TCB *tcb; TSTAT state; ER ercd = E_OK; CHECK_TSKID(tskid); CHECK_TSKACV(tskid); CHECK_NONSELF(tskid); tcb = get_tcb(tskid); BEGIN_CRITICAL_SECTION; if ( !task_alive(state = tcb->state) ) { ercd = (state == TS_NONEXIST) ? E_NOEXS : E_OBJ; } else if ((state & TS_WAIT) && tcb->wspec == &wspec_tmb_tfifo) { *(tcb->winfo.tmb.ppk_msg) = pk_msg; wait_release_ok(tcb); } else { nextmsg(pk_msg) = (T_MSG *) 0; if (tcb->tmq_head) { nextmsg(tcb->tmq_tail) = pk_msg; } else { tcb->tmq_head = pk_msg; } tcb->tmq_tail = pk_msg; } END_CRITICAL_SECTION; return(ercd); }
SYSCALL ER i_vref_tmb(T_RTMB *pk_rtmb,ID tskid) { TCB *tcb; TSTAT state; ER ercd = E_OK; CHECK_TSKID_SELF(tskid); CHECK_TSKACV(tskid); tcb = get_tcb_self(tskid); BEGIN_CRITICAL_SECTION; if ( !task_alive(state = tcb->state) ) { ercd = (state == TS_NONEXIST) ? E_NOEXS : E_OBJ; } else { if ( (state & TS_WAIT) && tcb->wspec == &wspec_tmb_tfifo ) { pk_rtmb->wtsk = tcb->tskid; } else { pk_rtmb->wtsk = 0; } if ( tcb->tmq_head ) { pk_rtmb->pk_msg = tcb->tmq_head; } else { pk_rtmb->pk_msg = (T_MSG *)NADR; } } END_CRITICAL_SECTION; return(ercd); }