📄 tcc.c
字号:
/* If executing in a thread's context, bind to that thread's module */
if(TCD_Current_Thread != NU_NULL)
{
if (((TC_TCB*)TCD_Current_Thread) -> tc_id == TC_TASK_ID)
{
status = MSC_Bind_Module_Task(
(MS_MODULE*)(((TC_TCB*)(TCD_Current_Thread))->tc_module), task);
}
else
{
status = MSC_Bind_Module_Task(
(MS_MODULE*)(((TC_HCB*)(TCD_Current_Thread))->tc_module), task);
}
}
else /* It must be initialization time, so use the current module */
{
status = MSC_Bind_Module_Task(msd_current_module, task);
}
#endif /* NU_MODULE_SUPPORT */
/* Link the task into the list of created tasks and increment the
total number of tasks in the system. */
CSC_Place_On_List(&TCD_Created_Tasks_List, &(task -> tc_created));
TCD_Total_Tasks++;
#ifdef NU_PROFILE_PLUS
PRF_PLUS_TCC_CREATE_TASK_0
#endif /* NU_PROFILE_PLUS */
/* Release the protection. */
TCT_Unprotect();
/* Determine if the task should be automatically started. */
if (auto_start == NU_START)
{
/* Protect the system data structures. */
TCT_Protect(&TCD_System_Protect);
/* Start the task by resuming it. If the preemption is required,
leave the current task. */
if (TCC_Resume_Task(task_ptr, NU_PURE_SUSPEND))
/* Transfer control back to the system. */
TCT_Control_To_System();
else
/* Release the protection. */
TCT_Unprotect();
}
/* Return to user mode */
NU_USER_MODE();
/* Return successful completion. */
return(status);
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* TCC_Create_HISR */
/* */
/* DESCRIPTION */
/* */
/* This function creates a High-Level Interrupt Service Routine */
/* (HISR) and then places it on the list of created HISRs. All */
/* the resources necessary to create the HISR are supplied to this */
/* routine. HISRs are always created in a dormant state. */
/* */
/* CALLED BY */
/* */
/* Application */
/* TCCE_Create_HISR Error checking shell */
/* */
/* CALLS */
/* */
/* CSC_Place_On_List Add TCB to linked-list */
/* [HIC_Make_History_Entry] Make entry in history log */
/* TCT_Build_HISR_Stack Build an initial HISR stack */
/* [TCT_Check_Stack] Stack checking function */
/* TCT_Protect Protect created HISR list */
/* TCT_Unprotect Release protection of list */
/* */
/* INPUTS */
/* */
/* hisr_ptr HISR control block pointer */
/* name HISR name */
/* hisr_entry Entry function of the HISR */
/* priority Task priority */
/* stack_address Pointer to start of stack */
/* stack_size Size of HISR stack in bytes */
/* */
/* OUTPUTS */
/* */
/* NU_SUCCESS */
/* */
/*************************************************************************/
STATUS TCC_Create_HISR(NU_HISR *hisr_ptr, CHAR *name,
VOID (*hisr_entry)(VOID), OPTION priority,
VOID *stack_address, UNSIGNED stack_size)
{
R1 TC_HCB *hisr; /* HISR control block ptr */
R2 INT i; /* Working index variable */
STATUS status = NU_SUCCESS;
NU_SUPERV_USER_VARIABLES
/* Switch to supervisor mode */
NU_SUPERVISOR_MODE();
/* Move input HISR pointer into internal pointer. */
hisr = (TC_HCB *) hisr_ptr;
#ifdef NU_ENABLE_STACK_CHECK
/* Call stack checking function to check for an overflow condition. */
TCT_Check_Stack();
#endif
#ifdef NU_ENABLE_HISTORY
/* Make an entry that corresponds to this function in the system history
log. */
HIC_Make_History_Entry(NU_CREATE_HISR_ID, (UNSIGNED) hisr,
(UNSIGNED) name, (UNSIGNED) hisr_entry);
#endif
/* First, clear the HISR ID just in case it is an old HISR
Control Block. */
hisr -> tc_id = 0;
/* Fill in the HISR name. */
for (i = 0; i < NU_MAX_NAME; i++)
hisr -> tc_name[i] = name[i];
/* Fill in the basic HISR information. */
hisr -> tc_entry = hisr_entry;
hisr -> tc_scheduled = 0;
hisr -> tc_activation_count = 0;
hisr -> tc_cur_time_slice = 0;
/* Fill in information about the HISR's stack. */
hisr -> tc_stack_start = stack_address;
hisr -> tc_stack_end = 0;
hisr -> tc_stack_size = stack_size;
hisr -> tc_stack_minimum = stack_size;
/* Setup priority information for the HISR. Priorities range from 0 to
TC_HISR_PRIORITIES - 1. */
hisr -> tc_priority = priority & 3;
/* Initialize link pointers. */
hisr -> tc_created.cs_previous = NU_NULL;
hisr -> tc_created.cs_next = NU_NULL;
hisr -> tc_active_next = NU_NULL;
/* Clear protect pointer. */
hisr -> tc_current_protect = NU_NULL;
/* Initialize additional kernel options data */
#if (NU_SUPERV_USER_MODE == 1)
hisr->tc_su_mode = 1; /* TCT_HISR_Shell in Supervisor mode */
hisr->tc_module = 0; /* Not initially bound to a module */
#endif
/* Build a stack frame for this HISR by calling TCT_Build_HISR_Stack. */
TCT_Build_HISR_Stack(hisr);
/* Protect the list of created HISRs. */
TCT_Protect(&TCD_HISR_Protect);
/* At this point the HISR is completely built. The ID can now be
set and it can be linked into the created HISR list. */
hisr -> tc_id = TC_HISR_ID;
#if defined(NU_MODULE_SUPPORT) && (NU_MODULE_SUPPORT > 0)
/* If executing in a thread's context, bind to that thread's module */
if(TCD_Current_Thread != NU_NULL)
{
if (((TC_TCB*)TCD_Current_Thread) -> tc_id == TC_TASK_ID)
{
status = MSC_Bind_Module_HISR(
(MS_MODULE*)(((TC_TCB*)(TCD_Current_Thread))->tc_module), hisr);
}
else
{
status = MSC_Bind_Module_HISR(
(MS_MODULE*)(((TC_HCB*)(TCD_Current_Thread))->tc_module), hisr);
}
}
else /* It must be initialization time, so use the current module */
{
status = MSC_Bind_Module_HISR(msd_current_module, hisr);
}
#endif /* NU_MODULE_SUPPORT */
/* Link the HISR into the list of created HISRs and increment the
total number of HISRs in the system. */
CSC_Place_On_List(&TCD_Created_HISRs_List, &(hisr -> tc_created));
TCD_Total_HISRs++;
#ifdef NU_PROFILE_PLUS
PRF_PLUS_TCC_CREATE_HISR_0
#endif /* NU_PROFILE_PLUS */
/* Release the protection. */
TCT_Unprotect();
/* Return to user mode */
NU_USER_MODE();
/* Return successful completion. */
return(status);
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* TCC_Delete_Task */
/* */
/* DESCRIPTION */
/* */
/* This function deletes a task and removes it from the list of */
/* created tasks. It is assumed by this function that the task is */
/* in a finished or terminated state. Note that this function */
/* does not free memory associated with the task's control block or */
/* its stack. This is the responsibility of the application. */
/* */
/* CALLED BY */
/* */
/* Application */
/* TCCE_Delete_Task Error checking shell */
/* */
/* CALLS */
/* */
/* CSC_Remove_From_List Remove node from list */
/* [HIC_Make_History_Entry] Make entry in history log */
/* [TCT_Check_Stack] Stack checking function */
/* TCT_Protect Protect created task list */
/* TCT_Unprotect Release protection of list */
/* */
/* INPUTS */
/* */
/* task_ptr Task control block pointer */
/* */
/* OUTPUTS */
/* */
/* NU_SUCCESS */
/* */
/*************************************************************************/
STATUS TCC_Delete_Task(NU_TASK *task_ptr)
{
R1 TC_TCB *task; /* Task control block ptr */
NU_SUPERV_USER_VARIABLES
/* Switch to supervisor mode */
NU_SUPERVISOR_MODE();
/* Move input task pointer into internal pointer. */
task = (TC_TCB *) task_ptr;
#ifdef NU_ENABLE_STACK_CHECK
/* Call stack checking function to check for an overflow condition. */
TCT_Check_Stack();
#endif
#ifdef NU_ENABLE_HISTORY
/* Make an entry that corresponds to this function in the system history
log. */
HIC_Make_History_Entry(NU_DELETE_TASK_ID, (UNSIGNED) task,
(UNSIGNED) 0, (UNSIGNED) 0);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -