/* |------------------+-------------------------------------------------------------| */ StatusType ChainTask ( TaskType TaskID ) { StatusType ercd = E_NOT_OK; TCB * tcb; TSTAT state; OS_CHECK((TaskID<cfgOSEK_TASK_NUM),E_OS_ID); OS_CHECK_EXT(!in_indp(),E_OS_CALLEVEL); OS_CHECK_EXT(isQueEmpty(&knl_ctxtsk->resque),E_OS_RESOURCE); DISABLE_INTERRUPT; if(TaskID == knl_ctxtsk->tskid){ /* chain to itself */ knl_search_schedtsk(); knl_make_active(knl_ctxtsk); } else{ /* firstly terminate current running task knl_ctxtsk, * and then activate TaskID */ tcb = &knl_tcb_table[TaskID]; state = (TSTAT)tcb->state; if (TS_DORMANT != state) { #if((cfgOS_CONFORMANCE_CLASS == ECC2) || (cfgOS_CONFORMANCE_CLASS == BCC2)) if(tcb->actcnt < knl_gtsk_table[TaskID].maxact) { tcb->actcnt += 1; } else #endif { ercd = E_OS_LIMIT; goto Error_Exit; } } knl_ctxtsk->state = TS_DORMANT; knl_search_schedtsk(); #if((cfgOS_CONFORMANCE_CLASS == ECC2) || (cfgOS_CONFORMANCE_CLASS == BCC2)) if(knl_ctxtsk->actcnt > 0) { knl_ctxtsk->actcnt -= 1; knl_make_active(knl_ctxtsk); } #endif if (TS_DORMANT == state) { knl_make_active(tcb); } } knl_force_dispatch(); /* No return */ Error_Exit: return ercd; }
/* |------------------+------------------------------------------------------------| */ StatusType ActivateTask ( TaskType TaskID ) { StatusType ercd = E_OK; TCB *tcb; TSTAT state; OS_CHECK((TaskID<cfgOSEK_TASK_NUM),E_OS_ID); tcb = &knl_tcb_table[TaskID]; BEGIN_CRITICAL_SECTION; state = (TSTAT)tcb->state; if (TS_DORMANT == state) { knl_make_active(tcb); } else { #if((cfgOS_CONFORMANCE_CLASS == ECC2) || (cfgOS_CONFORMANCE_CLASS == BCC2)) if(tcb->actcnt < knl_gtsk_table[TaskID].maxact) { tcb->actcnt += 1; } else #endif { ercd = E_OS_LIMIT; } } END_CRITICAL_SECTION; Error_Exit: return ercd; }
/* |------------------+------------------------------------------------------------| */ StatusType ActivateTask ( TaskType TaskID ) { StatusType ercd = E_OK; TCB *tcb; TSTAT state; OS_CHECK((TaskID<cfgOSEK_TASK_NUM),E_OS_ID); tcb = &knl_tcb_table[TaskID]; BEGIN_CRITICAL_SECTION; state = (TSTAT)tcb->state; if (TS_DORMANT == state) { knl_make_active(tcb); } else { #if((cfgOS_CONFORMANCE_CLASS == ECC2) || (cfgOS_CONFORMANCE_CLASS == BCC2)) if(tcb->actcnt < knl_gtsk_table[TaskID].maxact) { tcb->actcnt += 1; #if(cfgOSEK_FIFO_QUEUE_PER_PRIORITY == STD_ON) knl_ready_queue_insert(&knl_ready_queue, tcb); #endif } else #endif { ercd = E_OS_LIMIT; } } END_CRITICAL_SECTION; Error_Exit: #if(cfgOS_ERROR_HOOK == STD_ON) if(E_OK != ercd) { BEGIN_CRITICAL_SECTION; _errorhook_svcid = OSServiceId_ActivateTask; _errorhook_par1.tskid = TaskID; CallErrorHook(ercd); END_CRITICAL_SECTION; } #endif /* cfgOS_ERROR_HOOK */ return ercd; }
/* |------------------+--------------------------------------------------------------| */ StatusType TerminateTask ( void ) { StatusType ercd = E_NOT_OK; OS_CHECK_EXT(!in_indp(),E_OS_CALLEVEL); OS_CHECK_EXT(isQueEmpty(&knl_ctxtsk->resque),E_OS_RESOURCE); DISABLE_INTERRUPT; #if(cfgOS_POST_TASK_HOOK == STD_ON) PostTaskHook(); #endif knl_ctxtsk->state = TS_DORMANT; //release internal resource or for non-preemtable task ReleaseInternalResource(); knl_ctxtsk->priority = knl_ctxtsk->itskpri; knl_search_schedtsk(); #if((cfgOS_CONFORMANCE_CLASS == ECC2) || (cfgOS_CONFORMANCE_CLASS == BCC2)) if(knl_ctxtsk->actcnt > 0) { knl_ctxtsk->actcnt -= 1; #if(cfgOSEK_FIFO_QUEUE_PER_PRIORITY == STD_OFF) knl_make_active(knl_ctxtsk); #else knl_make_ready(knl_ctxtsk); #endif } #endif knl_force_dispatch(); /* No return */ Error_Exit: #if(cfgOS_ERROR_HOOK == STD_ON) if(E_OK != ercd) { BEGIN_CRITICAL_SECTION; _errorhook_svcid = OSServiceId_TerminateTask; CallErrorHook(ercd); END_CRITICAL_SECTION; } #endif /* cfgOS_ERROR_HOOK */ return ercd; }
/* |------------------+--------------------------------------------------------------| */ StatusType TerminateTask ( void ) { StatusType ercd = E_NOT_OK; OS_CHECK_EXT(!in_indp(),E_OS_CALLEVEL); OS_CHECK_EXT(isQueEmpty(&knl_ctxtsk->resque),E_OS_RESOURCE); DISABLE_INTERRUPT; knl_ctxtsk->state = TS_DORMANT; knl_search_schedtsk(); #if((cfgOS_CONFORMANCE_CLASS == ECC2) || (cfgOS_CONFORMANCE_CLASS == BCC2)) if(knl_ctxtsk->actcnt > 0) { knl_ctxtsk->actcnt -= 1; knl_make_active(knl_ctxtsk); } #endif knl_force_dispatch(); /* No return */ Error_Exit: return ercd; }
/* |------------------+-------------------------------------------------------------| */ StatusType ChainTask ( TaskType TaskID ) { StatusType ercd = E_NOT_OK; TCB * tcb; TSTAT state; OS_CHECK((TaskID<cfgOSEK_TASK_NUM),E_OS_ID); OS_CHECK_EXT(!in_indp(),E_OS_CALLEVEL); OS_CHECK_EXT(isQueEmpty(&knl_ctxtsk->resque),E_OS_RESOURCE); DISABLE_INTERRUPT; if(TaskID == knl_ctxtsk->tskid){ /* chain to itself */ knl_search_schedtsk(); knl_make_active(knl_ctxtsk); } else{ /* firstly terminate current running task knl_ctxtsk, * and then activate TaskID */ tcb = &knl_tcb_table[TaskID]; state = (TSTAT)tcb->state; if (TS_DORMANT != state) { #if((cfgOS_CONFORMANCE_CLASS == ECC2) || (cfgOS_CONFORMANCE_CLASS == BCC2)) if(tcb->actcnt < knl_gtsk_table[TaskID].maxact) { tcb->actcnt += 1; #if(cfgOSEK_FIFO_QUEUE_PER_PRIORITY == STD_ON) knl_ready_queue_insert(&knl_ready_queue, tcb); #endif } else #endif { ercd = E_OS_LIMIT; goto Error_Exit; } } #if(cfgOS_POST_TASK_HOOK == STD_ON) PostTaskHook(); #endif knl_ctxtsk->state = TS_DORMANT; knl_search_schedtsk(); #if((cfgOS_CONFORMANCE_CLASS == ECC2) || (cfgOS_CONFORMANCE_CLASS == BCC2)) if(knl_ctxtsk->actcnt > 0) { knl_ctxtsk->actcnt -= 1; #if(cfgOSEK_FIFO_QUEUE_PER_PRIORITY == STD_OFF) knl_make_active(knl_ctxtsk); #else knl_make_ready(knl_ctxtsk); #endif } #endif if (TS_DORMANT == state) { knl_make_active(tcb); } } knl_force_dispatch(); /* No return */ Error_Exit: ENABLE_INTERRUPT; #if(cfgOS_ERROR_HOOK == STD_ON) if(E_OK != ercd) { BEGIN_CRITICAL_SECTION; _errorhook_svcid = OSServiceId_ChainTask; _errorhook_par1.tskid = TaskID; CallErrorHook(ercd); END_CRITICAL_SECTION; } #endif /* cfgOS_ERROR_HOOK */ return ercd; }