📄 tcc.c
字号:
/* NU_SUCCESS */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* W. Lamie 03-01-1993 Created initial version 1.0 */
/* D. Lamie 04-19-1993 Verified version 1.0 */
/* W. Lamie 03-01-1994 Modified function interface, */
/* added register optimizations, */
/* added system protection logic, */
/* resulting in version 1.1 */
/* R. Pfaff - */
/* D. Lamie 03-18-1994 Verified version 1.1 */
/* */
/*************************************************************************/
STATUS TCC_Create_Task(NU_TASK *task_ptr, CHAR *name,
VOID (*task_entry)(UNSIGNED, VOID *), UNSIGNED argc, VOID *argv,
VOID *stack_address, UNSIGNED stack_size,
OPTION priority, UNSIGNED time_slice,
OPTION preempt, OPTION auto_start)
{
R1 TC_TCB *task; /* Task control block ptr */
R2 INT i; /* Working index variable */
/* 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_CREATE_TASK_ID, (UNSIGNED) task,
(UNSIGNED) name, (UNSIGNED) task_entry);
#endif
/* First, clear the task ID just in case it is an old Task
Control Block. */
task -> tc_id = 0;
/* Fill in the task name. */
for (i = 0; i < NU_MAX_NAME; i++)
task -> tc_name[i] = name[i];
/* Fill in the basic task information. */
task -> tc_entry = task_entry;
task -> tc_argc = argc;
task -> tc_argv = argv;
task -> tc_status = NU_PURE_SUSPEND;
task -> tc_delayed_suspend = NU_FALSE;
task -> tc_scheduled = 0;
task -> tc_time_slice = time_slice;
task -> tc_cur_time_slice = time_slice;
task -> tc_current_protect = NU_NULL;
task -> tc_suspend_protect = NU_NULL;
task -> tc_cleanup = NU_NULL;
task -> tc_cleanup_info = NU_NULL;
/* Setup task's preemption posture. */
if (preempt == NU_PREEMPT)
task -> tc_preemption = NU_TRUE;
else
task -> tc_preemption = NU_FALSE;
/* Fill in information about the task's stack. */
task -> tc_stack_start = stack_address;
task -> tc_stack_end = 0;
task -> tc_stack_size = stack_size;
task -> tc_stack_minimum = stack_size;
/* Setup priority information for the task. There are two bit maps
associated with each task. The first bit map indicates which group
of 8-priorities it is. The second bit map indicates the actual
priority within the group. */
task -> tc_priority = priority;
task -> tc_priority_head = &(TCD_Priority_List[priority]);
task -> tc_sub_priority = (DATA_ELEMENT) (1 << (priority & 7));
priority = priority >> 3;
task -> tc_priority_group = ((UNSIGNED) 1) << priority;
task -> tc_sub_priority_ptr = &(TCD_Sub_Priority_Groups[priority]);
/* Initialize link pointers. */
task -> tc_created.cs_previous = NU_NULL;
task -> tc_created.cs_next = NU_NULL;
task -> tc_ready_previous = NU_NULL;
task -> tc_ready_next = NU_NULL;
/* Build a stack frame for this task by calling TCT_Build_Task_Stack. */
TCT_Build_Task_Stack(task);
/* Initialize the signal information of the task. */
task -> tc_signals = 0;
task -> tc_enabled_signals = 0;
task -> tc_signal_handler = 0;
task -> tc_signal_active = NU_FALSE;
/* Initialize the task timer. */
task -> tc_timer_active = NU_FALSE;
TMC_Init_Task_Timer(&(task -> tc_timer_control), (VOID *) task);
/* Protect the list of created tasks. */
TCT_Protect(&TCD_List_Protect);
/* At this point the task is completely built. The ID can now be
set and it can be linked into the created task list. */
task -> tc_id = TC_TASK_ID;
/* 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++;
/* 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 successful completion. */
return(NU_SUCCESS);
}
/*************************************************************************/
/* */
/* 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. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology, Inc. */
/* */
/* 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 */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* W. Lamie 03-01-1993 Created initial version 1.0 */
/* D. Lamie 04-19-1993 Verified version 1.0 */
/* W. Lamie 03-01-1994 Modified function interface, */
/* added register optimizations, */
/* added more control block */
/* initialization, resulting in */
/* version 1.1 */
/* R. Pfaff - */
/* D. Lamie 03-18-1994 Verified version 1.1 */
/* */
/*************************************************************************/
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 */
/* 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. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -